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