use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class ReportDao method reportInstanceDataNoSQL.
public void reportInstanceDataNoSQL(int instanceId, final ExportDataStreamHandler handler) {
// Retrieve point information.
List<ExportPointInfo> pointInfos = query(REPORT_INSTANCE_POINT_SELECT + "where reportInstanceId=?", new Object[] { instanceId }, new RowMapper<ExportPointInfo>() {
@Override
public ExportPointInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
int i = 0;
ExportPointInfo rp = new ExportPointInfo();
rp.setReportPointId(rs.getInt(++i));
rp.setDeviceName(rs.getString(++i));
rp.setPointName(rs.getString(++i));
rp.setXid(rs.getString(++i));
rp.setDataType(rs.getInt(++i));
String startValue = rs.getString(++i);
if (startValue != null)
rp.setStartValue(DataValue.stringToValue(startValue, rp.getDataType()));
rp.setTextRenderer((TextRenderer) SerializationHelper.readObjectInContext(rs.getBlob(++i).getBinaryStream()));
rp.setColour(rs.getString(++i));
rp.setWeight(rs.getFloat(++i));
rp.setConsolidatedChart(charToBool(rs.getString(++i)));
rp.setPlotType(rs.getInt(++i));
return rp;
}
});
final ExportDataValue edv = new ExportDataValue();
for (final ExportPointInfo point : pointInfos) {
if (point.getDataType() == DataTypes.IMAGE) {
DataPointVO vo = DataPointDao.instance.getByXid(point.getXid());
if (vo != null)
point.setDataPointId(vo.getId());
else
point.setDataPointId(-1);
}
handler.startPoint(point);
edv.setReportPointId(point.getReportPointId());
final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
final String pointStore = instanceId + "_" + point.getReportPointId();
dao.getData(pointStore, 0, Long.MAX_VALUE, -1, false, new NoSQLQueryCallback() {
@Override
public void entry(String storeName, long timestamp, ITime entry) {
PointValueTime pvt = (PointValueTime) entry;
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
handler.pointData(edv);
}
});
}
handler.done();
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class IdPointValueTimeLatestPointValueFacadeStream method streamData.
/* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeStream#streamData(com.fasterxml.jackson.core.JsonGenerator)
*/
@Override
public void streamData(JsonGenerator jgen) {
IdPointValueTimeJsonStreamCallback callback = new IdPointValueTimeJsonStreamCallback(jgen, 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>() {
// Compare such that data sets are returned in time descending order
// which turns out is opposite of compare to method for PointValueTime objects
@Override
public int compare(IdPointValueTime o1, IdPointValueTime o2) {
if (o1.getTime() < o2.getTime())
return 1;
if (o1.getTime() > o2.getTime())
return -1;
return 0;
}
});
for (int i = 0; i < ipvts.size(); i++) callback.row(ipvts.get(i), i);
callback.finish();
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime 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.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointValueFftCalculator method calculate.
/**
* Generate FFT
* @return
*/
public FftGenerator calculate(DateTime from, DateTime to) {
PointValueDao pvd = Common.databaseProxy.newPointValueDao();
long count = pvd.dateRangeCount(vo.getId(), from.getMillis(), to.getMillis());
final FftGenerator generator = new FftGenerator(count);
// Make the call to get the data and quantize it
pvd.getPointValuesBetween(vo.getId(), from.getMillis(), to.getMillis(), new MappedRowCallback<PointValueTime>() {
@Override
public void row(PointValueTime pvt, int row) {
generator.data(pvt);
}
});
generator.done(getEndValue());
return generator;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointValueTimeCsvStreamCallback method row.
/* (non-Javadoc)
* @see com.serotonin.db.MappedRowCallback#row(java.lang.Object, int)
*/
@Override
public void row(PointValueTime pvt, int index) {
if (this.limiter.limited())
return;
try {
String annotation = null;
if (pvt.isAnnotated())
annotation = ((AnnotatedPointValueTime) pvt).getAnnotation(translations);
if (useRendered) {
// Convert to Alphanumeric Value
String textValue = Functions.getRenderedText(vo, pvt);
this.writePointValueTime(new AlphanumericValue(textValue), pvt.getTime(), annotation, vo);
} else if (unitConversion) {
if (pvt.getValue() instanceof NumericValue)
this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(pvt.getValue().getDoubleValue()), pvt.getTime(), annotation, vo);
else
this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
} else {
if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
this.writePointValueTime(imageServletBuilder.buildAndExpand(pvt.getTime(), vo.getId()).toUri().toString(), pvt.getTime(), annotation, vo);
else
this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
}
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
Aggregations