use of com.webstart.DTO.WateringValueTime in project FarmCloud by vratsasg.
the class ExtractController method createPDF.
private com.itextpdf.text.Document createPDF(WateringMeasure wateringMeasure, 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", wateringMeasure.getObservableProperty(), wateringMeasure.getUnit(), wateringMeasure.getIdentifier(), dtfrom, dtto);
doc.add(new Paragraph(paragraph));
PdfPTable table = new PdfPTable(4);
table.setWidthPercentage(100.0f);
table.setWidths(new float[] { 3.0f, 3.0f, 3.0f, 3.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("Watering time from", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Watering time until", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Total Duration", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Total Consumption", 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 (WateringValueTime valueTime : wateringMeasure.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.getPhenomenonDateTimeFrom()));
table.addCell(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeTo()));
table.addCell(valueTime.getDateTimeDiff());
table.addCell(String.format("%1$s %2$s", valueTime.getValue().toString(), wateringMeasure.getUnit()));
}
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 Total %1$s: %5$s %2$s", wateringMeasure.getObservableProperty(), wateringMeasure.getUnit(), valuemin.toString(), valuemax.toString(), valuesum.toString())));
return doc;
}
use of com.webstart.DTO.WateringValueTime in project FarmCloud by vratsasg.
the class ExtractController method createXlsx.
private HSSFWorkbook createXlsx(WateringMeasure wateringMeasure) throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet(wateringMeasure.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("Watering Time from");
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Watering Time until");
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Total Duration");
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Total Consumption");
cell = row.createCell(c++);
cell.setCellStyle(style);
cell.setCellValue("Unit");
// Create data cell
for (WateringValueTime valueTime : wateringMeasure.getMeasuredata()) {
row = sheet.createRow(r++);
c = 0;
row.createCell(c++).setCellValue(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeFrom()));
row.createCell(c++).setCellValue(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeTo()));
row.createCell(c++).setCellValue(valueTime.getDateTimeDiff());
row.createCell(c++).setCellValue(valueTime.getValue().toString());
row.createCell(c++).setCellValue(wateringMeasure.getUnit());
}
for (int i = 0; i < wateringMeasure.getMeasuredata().size(); i++) {
sheet.autoSizeColumn(i, true);
}
return workbook;
}
use of com.webstart.DTO.WateringValueTime in project FarmCloud by vratsasg.
the class ExtractController method getCsv.
@RequestMapping(value = "{mydevice}/watering/csv", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public void getCsv(@PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/plain");
String reportName = "Watering_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);
//
WateringMeasure wateringMeasure = observationProperyService.getWateringData(user.getUser_id(), mydevice, from, to);
//
ArrayList<String> rows = new ArrayList<String>();
rows.add("Watering Time from");
rows.add(";");
rows.add("Watering Time until");
rows.add(";");
rows.add("Total Duration");
rows.add(";");
rows.add("Watering consumption");
rows.add(";");
rows.add("Unit");
rows.add("\n");
// write table row data
for (WateringValueTime valueTime : wateringMeasure.getMeasuredata()) {
rows.add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeFrom()));
rows.add(";");
rows.add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeTo()));
rows.add(";");
rows.add(valueTime.getDateTimeDiff());
rows.add(";");
rows.add(valueTime.getValue().toString());
rows.add(";");
rows.add(wateringMeasure.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