Search in sources :

Example 1 with AnnotatedIdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime in project ma-modules-public by infiniteautomation.

the class MultiPointLatestDatabaseStream method buildCache.

/**
 * Build the cache based on our Query Info
 * @param voMap
 * @param limit
 * @return
 */
protected Map<Integer, List<IdPointValueTime>> buildCache() {
    Map<Integer, List<IdPointValueTime>> map = new HashMap<>();
    for (Integer id : voMap.keySet()) {
        DataPointRT rt = Common.runtimeManager.getDataPoint(id);
        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.isAnnotated())
                        idPvtCache.add(new AnnotatedIdPointValueTime(id, pvt.getValue(), pvt.getTime(), ((AnnotatedPointValueTime) pvt).getSourceMessage()));
                    else
                        idPvtCache.add(new IdPointValueTime(id, pvt.getValue(), pvt.getTime()));
                }
            }
            if (!idPvtCache.isEmpty()) {
                sortCache(idPvtCache);
                map.put(id, idPvtCache);
            }
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)

Example 2 with AnnotatedIdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime in project ma-modules-public by infiniteautomation.

the class MultiPointTimeRangeDatabaseStream method processCacheOnly.

/* (non-Javadoc)
     * @see com.infiniteautomation.mango.rest.v2.model.pointValue.query.MultiPointLatestDatabaseStream#processCacheOnly()
     */
@Override
protected void processCacheOnly() throws IOException {
    // Performance enhancement to return data within cache only
    Iterator<Integer> it = voMap.keySet().iterator();
    int index = 0;
    while (it.hasNext()) {
        List<IdPointValueTime> values = cache.get(it.next());
        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()) {
                    IdPointValueTime bookend;
                    if (value.isAnnotated())
                        bookend = new AnnotatedIdPointValueTime(value.getId(), value.getValue(), info.getFromMillis(), ((AnnotatedIdPointValueTime) value).getSourceMessage());
                    else
                        bookend = new IdPointValueTime(value.getId(), value.getValue(), info.getFromMillis());
                    processRow(bookend, index, true, false, true);
                    processRow(value, index, false, false, true);
                } else
                    processRow(value, index, true, false, true);
                first = false;
            } else
                processRow(value, index, false, false, true);
            index++;
            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.isAnnotated())
                    bookend = new AnnotatedIdPointValueTime(last.getId(), last.getValue(), info.getToMillis(), ((AnnotatedIdPointValueTime) last).getSourceMessage());
                else
                    bookend = new IdPointValueTime(last.getId(), last.getValue(), info.getToMillis());
                processRow(bookend, index, false, true, true);
            }
        }
    }
}
Also used : IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)

Aggregations

AnnotatedIdPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)2 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)2 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)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