Search in sources :

Example 1 with IAnnotated

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();
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) IAnnotated(com.serotonin.m2m2.rt.dataImage.IAnnotated)

Example 2 with IAnnotated

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) IAnnotated(com.serotonin.m2m2.rt.dataImage.IAnnotated) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) DataPointValueTime(com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList) List(java.util.List) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)

Example 3 with IAnnotated

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);
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IAnnotated(com.serotonin.m2m2.rt.dataImage.IAnnotated) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)

Example 4 with IAnnotated

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);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) IAnnotated(com.serotonin.m2m2.rt.dataImage.IAnnotated)

Example 5 with IAnnotated

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();
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) IAnnotated(com.serotonin.m2m2.rt.dataImage.IAnnotated)

Aggregations

IAnnotated (com.serotonin.m2m2.rt.dataImage.IAnnotated)5 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 AnnotatedIdPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)2 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)2 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)2 DataPointValueTime (com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointValueTime)1 StreamingPointValueTimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1