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;
}
}
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);
}
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);
}
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();
}
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();
}
Aggregations