use of com.serotonin.m2m2.rt.dataImage.IAnnotated in project ma-core-public by MangoAutomation.
the class PointValueTimeSerializer method serialize.
@Override
public void serialize(PointValueTime pointValueTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
DataValue value = pointValueTime.getValue();
switch(value.getDataType()) {
case ALPHANUMERIC:
jsonGenerator.writeStringField("dataType", "ALPHANUMERIC");
jsonGenerator.writeStringField("value", value.getStringValue());
break;
case BINARY:
jsonGenerator.writeStringField("dataType", "BINARY");
jsonGenerator.writeBooleanField("value", value.getBooleanValue());
break;
case MULTISTATE:
jsonGenerator.writeStringField("dataType", "MULTISTATE");
jsonGenerator.writeNumberField("value", value.getIntegerValue());
break;
case NUMERIC:
jsonGenerator.writeStringField("dataType", "NUMERIC");
jsonGenerator.writeNumberField("value", value.getDoubleValue());
break;
}
jsonGenerator.writeNumberField("timestamp", pointValueTime.getTime());
if (pointValueTime instanceof IAnnotated) {
jsonGenerator.writeStringField("serializedAnnotation", ((IAnnotated) pointValueTime).getSourceMessage().serialize());
}
jsonGenerator.writeEndObject();
}
use of com.serotonin.m2m2.rt.dataImage.IAnnotated in project ma-modules-public by infiniteautomation.
the class MultiPointLatestDatabaseStream method buildCache.
/**
* Build the cache based on our Query Info
*/
protected Map<Integer, List<IdPointValueTime>> buildCache() {
Map<Integer, List<IdPointValueTime>> map = new HashMap<>();
for (Entry<Integer, DataPointVO> entry : voMap.entrySet()) {
DataPointVO vo = entry.getValue();
DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getId());
if (rt != null) {
List<PointValueTime> cache;
if (info.getLimit() != null)
cache = rt.getCacheCopy(info.getLimit());
else
cache = rt.getCacheCopy();
List<IdPointValueTime> idPvtCache = new ArrayList<>(cache.size());
for (PointValueTime pvt : cache) {
if (includeCachedPoint(pvt)) {
if (pvt instanceof IAnnotated)
idPvtCache.add(new AnnotatedIdPointValueTime(vo.getSeriesId(), pvt.getValue(), pvt.getTime(), ((IAnnotated) pvt).getSourceMessage()));
else
idPvtCache.add(new IdPointValueTime(vo.getSeriesId(), pvt.getValue(), pvt.getTime()));
}
}
if (!idPvtCache.isEmpty()) {
sortCache(idPvtCache);
map.put(vo.getSeriesId(), idPvtCache);
}
}
}
return map;
}
use of com.serotonin.m2m2.rt.dataImage.IAnnotated in project ma-modules-public by infiniteautomation.
the class MultiPointTimeRangeDatabaseStream method processCacheOnly.
@Override
protected void processCacheOnly() throws QueryCancelledException {
// Performance enhancement to return data within cache only
Iterator<Integer> it = voMap.keySet().iterator();
while (it.hasNext()) {
Integer id = it.next();
DataPointVO vo = voMap.get(id);
List<IdPointValueTime> values = cache.get(id);
if (values == null || values.size() == 0) {
if (info.isBookend()) {
processRow(new IdPointValueTime(vo.getSeriesId(), null, info.getFromMillis()), true, false, true);
processRow(new IdPointValueTime(vo.getSeriesId(), null, info.getToMillis()), false, true, true);
}
} else {
boolean first = true;
int limitCount = 0;
for (IdPointValueTime value : values) {
if (first && info.isBookend()) {
// Send out first value as bookend if necessary
if (value.getTime() != info.getFromMillis()) {
// The cache should have been pruned so the value is after the start of the query and thus a null bookend
// is sent
IdPointValueTime bookend = new IdPointValueTime(value.getSeriesId(), null, info.getFromMillis());
processRow(bookend, true, false, true);
processRow(value, false, false, true);
} else
processRow(value, false, false, true);
first = false;
} else
processRow(value, false, false, true);
limitCount++;
if (info.getLimit() != null && limitCount >= info.getLimit())
break;
}
// Send out last value as bookend if necessary
if (info.isBookend()) {
IdPointValueTime last = values.get(values.size() - 1);
if (last.getTime() != info.getToMillis()) {
IdPointValueTime bookend;
if (last instanceof IAnnotated)
bookend = new AnnotatedIdPointValueTime(last.getSeriesId(), last.getValue(), info.getToMillis(), ((IAnnotated) last).getSourceMessage());
else
bookend = new IdPointValueTime(last.getSeriesId(), last.getValue(), info.getToMillis());
processRow(bookend, false, true, true);
}
}
}
}
}
use of com.serotonin.m2m2.rt.dataImage.IAnnotated in project ma-modules-public by infiniteautomation.
the class DefaultStreamMapper method apply.
@Override
public StreamingPointValueTimeModel apply(IdPointValueTime valueTime) {
DataPointVO point = lookupPoint(valueTime.getSeriesId());
StreamingPointValueTimeModel model = new StreamingPointValueTimeModel(point.getXid(), valueTime.getTime());
model.setValueModel(getValue(point, valueTime));
if (fields.contains(PointValueField.CACHED)) {
model.setCached(valueTime.isFromCache());
}
if (fields.contains(PointValueField.BOOKEND)) {
model.setBookend(valueTime.isBookend());
}
if (fields.contains(PointValueField.ANNOTATION)) {
if (valueTime instanceof IAnnotated) {
model.setAnnotation(((IAnnotated) valueTime).getSourceMessage());
}
}
return copyPointPropertiesToModel(point, model);
}
use of com.serotonin.m2m2.rt.dataImage.IAnnotated in project ma-core-public by infiniteautomation.
the class PointValueTimeSerializer method serialize.
@Override
public void serialize(PointValueTime pointValueTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
DataValue value = pointValueTime.getValue();
switch(value.getDataType()) {
case ALPHANUMERIC:
jsonGenerator.writeStringField("dataType", "ALPHANUMERIC");
jsonGenerator.writeStringField("value", value.getStringValue());
break;
case BINARY:
jsonGenerator.writeStringField("dataType", "BINARY");
jsonGenerator.writeBooleanField("value", value.getBooleanValue());
break;
case MULTISTATE:
jsonGenerator.writeStringField("dataType", "MULTISTATE");
jsonGenerator.writeNumberField("value", value.getIntegerValue());
break;
case NUMERIC:
jsonGenerator.writeStringField("dataType", "NUMERIC");
jsonGenerator.writeNumberField("value", value.getDoubleValue());
break;
}
jsonGenerator.writeNumberField("timestamp", pointValueTime.getTime());
if (pointValueTime instanceof IAnnotated) {
jsonGenerator.writeStringField("serializedAnnotation", ((IAnnotated) pointValueTime).getSourceMessage().serialize());
}
jsonGenerator.writeEndObject();
}
Aggregations