Search in sources :

Example 1 with ValueTime

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;
}
Also used : ValueTime(com.webstart.DTO.ValueTime) WateringValueTime(com.webstart.DTO.WateringValueTime) PdfPCell(com.itextpdf.text.pdf.PdfPCell) SimpleDateFormat(java.text.SimpleDateFormat) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 2 with ValueTime

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;
}
Also used : ValueTime(com.webstart.DTO.ValueTime) WateringValueTime(com.webstart.DTO.WateringValueTime) PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) SimpleDateFormat(java.text.SimpleDateFormat) Font(com.itextpdf.text.Font) BigDecimal(java.math.BigDecimal)

Example 3 with ValueTime

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();
    }
}
Also used : Featureofinterest(com.webstart.model.Featureofinterest) HelperCls(com.webstart.Helpers.HelperCls) ArrayList(java.util.ArrayList) Users(com.webstart.model.Users) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ValueTime(com.webstart.DTO.ValueTime) WateringValueTime(com.webstart.DTO.WateringValueTime) ObservableMeasure(com.webstart.DTO.ObservableMeasure) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ValueTime (com.webstart.DTO.ValueTime)3 WateringValueTime (com.webstart.DTO.WateringValueTime)3 SimpleDateFormat (java.text.SimpleDateFormat)3 PdfPCell (com.itextpdf.text.pdf.PdfPCell)2 Font (com.itextpdf.text.Font)1 PdfPTable (com.itextpdf.text.pdf.PdfPTable)1 ObservableMeasure (com.webstart.DTO.ObservableMeasure)1 HelperCls (com.webstart.Helpers.HelperCls)1 Featureofinterest (com.webstart.model.Featureofinterest)1 Users (com.webstart.model.Users)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 DateTime (org.joda.time.DateTime)1 LocalDateTime (org.joda.time.LocalDateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1