use of com.webstart.DTO.ValueTime in project FarmCloud by vratsasg.
the class ExtractController method createXlsx.
private HSSFWorkbook createXlsx(ObservableMeasure observableMeasure) throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet(observableMeasure.getObservableProperty());
Row row = null;
Cell cell = null;
int r = 0;
int c = 0;
// Style for header cell
CellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.SEA_GREEN.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
// Create header cells
row = sheet.createRow(r++);
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Measure date & time");
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Measure value");
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Measure unit");
// Create data cell
for (ValueTime valueTime : observableMeasure.getMeasuredata()) {
row = sheet.createRow(r++);
c = 0;
row.createCell(c++).setCellValue(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTime()));
row.createCell(c++).setCellValue(valueTime.getValue().toString());
row.createCell(c++).setCellValue(observableMeasure.getUnit());
}
for (int i = 0; i < observableMeasure.getMeasuredata().size(); i++) {
sheet.autoSizeColumn(i, true);
}
return workbook;
}
use of com.webstart.DTO.ValueTime in project FarmCloud by vratsasg.
the class ExtractController method createPDF.
private com.itextpdf.text.Document createPDF(ObservableMeasure observableMeasure, String dtfrom, String dtto, com.itextpdf.text.Document doc) throws Exception {
String paragraph = String.format("Measures for %1$s(%2$s) from end device with identifier %3$s \n from %4$s until %5$s", observableMeasure.getObservableProperty(), observableMeasure.getUnit(), observableMeasure.getIdentifier(), dtfrom, dtto);
doc.add(new Paragraph(paragraph));
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100.0f);
table.setWidths(new float[] { 4.0f, 2.0f });
table.setSpacingBefore(10);
// define font for table header row
Font font = FontFactory.getFont(FontFactory.HELVETICA);
font.setColor(BaseColor.DARK_GRAY);
// define table header cell
PdfPCell cell = new PdfPCell();
cell.setBackgroundColor(new BaseColor(197, 255, 165));
cell.setPadding(5);
// write table header
cell.setPhrase(new Phrase("Measure date & time", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Measure value", font));
table.addCell(cell);
BigDecimal valuemin = new BigDecimal(200.0);
BigDecimal valuemax = new BigDecimal(-100.0);
BigDecimal valuesum = new BigDecimal(0.0);
// write table row data
for (ValueTime valueTime : observableMeasure.getMeasuredata()) {
valuesum = valuesum.add(valueTime.getValue());
valuemax = valueTime.getValue().max(valuemax);
valuemin = valueTime.getValue().min(valuemin);
table.addCell(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTime()));
table.addCell(String.format("%1$s %2$s", valueTime.getValue().toString(), observableMeasure.getUnit()));
}
BigDecimal avg = valuesum.divide(BigDecimal.valueOf(observableMeasure.getMeasuredata().size()), 2, BigDecimal.ROUND_CEILING);
doc.add(table);
doc.add(new Paragraph(String.format("\n minimum %1$s: %3$s %2$s \n maximum %1$s: %4$s %2$s \n average %1$s: %5$s %2$s", observableMeasure.getObservableProperty(), observableMeasure.getUnit(), valuemin.toString(), valuemax.toString(), avg.toString())));
return doc;
}
use of com.webstart.DTO.ValueTime in project FarmCloud by vratsasg.
the class ExtractController method getCsv.
@RequestMapping(value = "{mydevice}/{observablepropertyid}/csv", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public void getCsv(@PathVariable("observablepropertyid") Long observablepropertyid, @PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/plain");
DateTime.now().toString("yyyyMMddHHmmss");
// String reportName = String.format("Measures-%1$s.csv", DateTime.now().toString("yyyyMMddHHmmss"));
String reportName = "Measures.csv";
response.setHeader("Content-disposition", "attachment; filename=" + reportName);
try {
Users user = (Users) request.getSession().getAttribute("current_user");
// DateTime Convertable
Featureofinterest featureofinterest = featureofInterestService.getFeatureofinterestByIdentifier(mydevice);
DateTimeFormatter dtfInput = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
HelperCls.ConvertToDateTime convertable = new HelperCls.ConvertToDateTime();
DateTime from = convertable.GetUTCDateTime(datetimestart, dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
DateTime to = convertable.GetUTCDateTime(datetimeend, dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
//
// ObservableMeasure observableMeasure = observationProperyService.getObservationData(observablepropertyid, user.getUser_id(), mydevice, from, to);
ObservableMeasure observableMeasure = observationProperyService.getObservationData(observablepropertyid, 1, mydevice, from, to);
ArrayList<String> rows = new ArrayList<String>();
rows.add("Measure date & time");
rows.add(";");
rows.add("Measure value");
rows.add(";");
rows.add("Measure unit");
rows.add("\n");
// write table row data
for (ValueTime valueTime : observableMeasure.getMeasuredata()) {
rows.add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTime()));
rows.add(";");
rows.add(valueTime.getValue().toString());
rows.add(";");
rows.add(observableMeasure.getUnit());
rows.add("\n");
}
Iterator<String> iter = rows.iterator();
while (iter.hasNext()) {
String outputString = (String) iter.next();
response.getOutputStream().print(outputString);
}
response.getOutputStream().flush();
} catch (Exception exc) {
exc.printStackTrace();
}
}
Aggregations