Search in sources :

Example 1 with CSVPojoWriter

use of com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter in project ma-modules-public by infiniteautomation.

the class XidPointValueMapRollupCalculator method generateStream.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream#streamData(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
	 */
@Override
protected void generateStream(DateTime from, DateTime to, CSVPojoWriter<Map<String, List<PointValueTime>>> writer) {
    Iterator<Integer> it = this.voMap.keySet().iterator();
    boolean writeHeaders = true;
    while (it.hasNext()) {
        DataPointVO vo = this.voMap.get(it.next());
        DataValue startValue = this.getStartValue(vo.getId());
        BucketCalculator bc = this.getBucketCalculator(from, to);
        final AbstractDataQuantizer quantizer = createQuantizer(vo, startValue, bc, writer, true, writeHeaders);
        this.calculate(quantizer, vo.getId(), from, to);
        // Only write the headers on the first iteration
        writeHeaders = false;
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BucketCalculator(com.serotonin.m2m2.view.quantize2.BucketCalculator) AbstractDataQuantizer(com.serotonin.m2m2.view.quantize2.AbstractDataQuantizer)

Example 2 with CSVPojoWriter

use of com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter in project ma-modules-public by infiniteautomation.

the class PointValueRollupCalculator method generateStream.

@Override
protected void generateStream(DateTime from, DateTime to, CSVPojoWriter<PointValueTimeModel> writer) {
    DataValue startValue = this.getStartValue(vo.getId());
    BucketCalculator bc = this.getBucketCalculator(from, to);
    final AbstractDataQuantizer quantizer = createQuantizer(vo, startValue, bc, writer, false, true);
    this.calculate(quantizer, vo.getId(), from, to);
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BucketCalculator(com.serotonin.m2m2.view.quantize2.BucketCalculator) AbstractDataQuantizer(com.serotonin.m2m2.view.quantize2.AbstractDataQuantizer)

Example 3 with CSVPojoWriter

use of com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter in project ma-modules-public by infiniteautomation.

the class IdPointValueRollupCalculator method generateStream.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.AbstractPointValueRollupCalculator#generateStream(org.joda.time.DateTime, org.joda.time.DateTime, com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
	 */
@Override
protected void generateStream(DateTime from, DateTime to, CSVPojoWriter<PointValueTimeModel> writer) {
    BucketCalculator bc = this.getBucketCalculator(from, to);
    IdPointValueStatisticsQuantizerCsvCallback callback = new IdPointValueStatisticsQuantizerCsvCallback(writer.getWriter(), this.voMap, this.useRendered, this.unitConversion, this.rollup, this.dateTimeFormat, timezone);
    Iterator<Integer> it = this.voMap.keySet().iterator();
    ParentDataQuantizer quantizer = new ParentDataQuantizer(bc, callback);
    while (it.hasNext()) {
        DataPointVO vo = this.voMap.get(it.next());
        DataValue startValue = this.getStartValue(vo.getId());
        if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC) {
            quantizer.startQuantizer(vo.getId(), startValue, new AnalogStatisticsChildQuantizer(vo.getId(), quantizer));
        } else {
            quantizer.startQuantizer(vo.getId(), startValue, new ValueChangeCounterChildQuantizer(vo.getId(), quantizer));
        }
    }
    this.calculate(quantizer, from, to);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) IdPointValueStatisticsQuantizerCsvCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.statistics.IdPointValueStatisticsQuantizerCsvCallback) AnalogStatisticsChildQuantizer(com.serotonin.m2m2.web.mvc.rest.v1.statistics.AnalogStatisticsChildQuantizer) BucketCalculator(com.serotonin.m2m2.view.quantize2.BucketCalculator) ParentDataQuantizer(com.serotonin.m2m2.web.mvc.rest.v1.statistics.ParentDataQuantizer) ValueChangeCounterChildQuantizer(com.serotonin.m2m2.web.mvc.rest.v1.statistics.ValueChangeCounterChildQuantizer)

Example 4 with CSVPojoWriter

use of com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter in project ma-modules-public by infiniteautomation.

the class IdPointValueTimeLatestPointValueFacadeStream method streamData.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream#streamData(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
	 */
@Override
public void streamData(CSVPojoWriter<PointValueTimeModel> writer) throws IOException {
    IdPointValueTimeCsvStreamCallback callback = new IdPointValueTimeCsvStreamCallback(writer.getWriter(), pointMap, useRendered, unitConversion, null, dateTimeFormat, timezone);
    // Sadly in this scenario we must collect all the data and then order it
    List<IdPointValueTime> ipvts = new ArrayList<IdPointValueTime>();
    Iterator<Integer> it = this.pointMap.keySet().iterator();
    while (it.hasNext()) {
        DataPointVO vo = this.pointMap.get(it.next());
        PointValueFacade pointValueFacade = new PointValueFacade(vo.getId(), useCache);
        List<PointValueTime> pvts = pointValueFacade.getLatestPointValues(limit);
        for (PointValueTime pvt : pvts) ipvts.add(new IdPointValueTime(vo.getId(), pvt.getValue(), pvt.getTime()));
    }
    // Sort it all
    Collections.sort(ipvts, new Comparator<IdPointValueTime>() {

        @Override
        public int compare(IdPointValueTime o1, IdPointValueTime o2) {
            return Long.compare(o1.getTime(), o2.getTime());
        }
    });
    for (int i = 0; i < ipvts.size(); i++) callback.row(ipvts.get(i), i);
    callback.finish();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) ArrayList(java.util.ArrayList) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 5 with CSVPojoWriter

use of com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter in project ma-modules-public by infiniteautomation.

the class CsvObjectStreamMessageConverter method writeInternal.

/* (non-Javadoc)
	 * @see org.springframework.http.converter.AbstractHttpMessageConverter#writeInternal(java.lang.Object, org.springframework.http.HttpOutputMessage)
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void writeInternal(ObjectStream<?> stream, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    CSVPojoWriter out = new CSVPojoWriter(new CSVWriter(new OutputStreamWriter(outputMessage.getBody(), Common.UTF8_CS), separator, quote));
    stream.streamData(out);
    out.close();
}
Also used : CSVPojoWriter(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter) CSVWriter(au.com.bytecode.opencsv.CSVWriter) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

CSVWriter (au.com.bytecode.opencsv.CSVWriter)5 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 CSVPojoWriter (com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)5 OutputStreamWriter (java.io.OutputStreamWriter)5 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)3 BucketCalculator (com.serotonin.m2m2.view.quantize2.BucketCalculator)3 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 AbstractDataQuantizer (com.serotonin.m2m2.view.quantize2.AbstractDataQuantizer)2 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 AnalogStatisticsQuantizer (com.serotonin.m2m2.view.quantize2.AnalogStatisticsQuantizer)1 ValueChangeCounterQuantizer (com.serotonin.m2m2.view.quantize2.ValueChangeCounterQuantizer)1 IdPointValueStatisticsQuantizerCsvCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.statistics.IdPointValueStatisticsQuantizerCsvCallback)1 NonNumericPointValueStatisticsQuantizerCsvCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.statistics.NonNumericPointValueStatisticsQuantizerCsvCallback)1 NumericPointValueStatisticsQuantizerCsvCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.statistics.NumericPointValueStatisticsQuantizerCsvCallback)1 AnalogStatisticsChildQuantizer (com.serotonin.m2m2.web.mvc.rest.v1.statistics.AnalogStatisticsChildQuantizer)1 ParentDataQuantizer (com.serotonin.m2m2.web.mvc.rest.v1.statistics.ParentDataQuantizer)1 ValueChangeCounterChildQuantizer (com.serotonin.m2m2.web.mvc.rest.v1.statistics.ValueChangeCounterChildQuantizer)1 ArrayList (java.util.ArrayList)1