Search in sources :

Example 1 with DataPointVOPointValueTimeBookend

use of com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend in project ma-modules-public by infiniteautomation.

the class MultiPointSimplifyTimeRangeDatabaseStream method finish.

@Override
public void finish(PointValueTimeWriter writer) throws QueryCancelledException, IOException {
    // Write out the values after simplifying
    Iterator<Integer> it = voMap.keySet().iterator();
    if (info.isSingleArray() && voMap.size() > 1) {
        List<DataPointVOPointValueTimeBookend> sorted = new ArrayList<>();
        while (it.hasNext()) {
            Integer seriesId = it.next();
            BookendPair pair = bookendMap.get(seriesId);
            if (pair != null && pair.startBookend != null)
                sorted.add(pair.startBookend);
            List<DataPointVOPointValueTimeBookend> values = valuesMap.get(seriesId);
            if (values != null) {
                sorted.addAll(SimplifyUtility.simplify(info.simplifyTolerance, info.simplifyTarget, info.simplifyHighQuality, info.simplifyPrePostProcess, values));
            }
            if (// Can be null bookend if limit is hit
            pair != null && pair.endBookend != null)
                sorted.add(pair.endBookend);
        }
        // Sort the Sorted List
        Collections.sort(sorted, new Comparator<DataPointVOPointValueTimeBookend>() {

            @Override
            public int compare(DataPointVOPointValueTimeBookend o1, DataPointVOPointValueTimeBookend o2) {
                return o1.getPvt().compareTo(o2.getPvt());
            }
        });
        for (DataPointVOPointValueTimeBookend value : sorted) super.writeValue(value);
    } else {
        while (it.hasNext()) {
            Integer seriesId = it.next();
            List<DataPointVOPointValueTimeBookend> simplified;
            List<DataPointVOPointValueTimeBookend> values = valuesMap.get(seriesId);
            if (values == null) {
                simplified = Collections.emptyList();
            } else {
                simplified = SimplifyUtility.simplify(info.simplifyTolerance, info.simplifyTarget, info.simplifyHighQuality, info.simplifyPrePostProcess, values);
            }
            BookendPair pair = bookendMap.get(seriesId);
            if (pair != null && pair.startBookend != null)
                super.writeValue(pair.startBookend);
            for (DataPointVOPointValueTimeBookend value : simplified) super.writeValue(value);
            if (// Can be null bookend if limit is hit
            pair != null && pair.endBookend != null)
                super.writeValue(pair.endBookend);
        }
    }
    super.finish(writer);
}
Also used : ArrayList(java.util.ArrayList) DataPointVOPointValueTimeBookend(com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend)

Example 2 with DataPointVOPointValueTimeBookend

use of com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend in project ma-modules-public by infiniteautomation.

the class MultiDataPointDefaultRollupStatisticsQuantizerStream method process.

/**
 * Process the data into lists per data point, simplify if necessary
 */
private Map<DataPointVO, List<DataPointValueTime>> process(Integer limit) {
    Map<DataPointVO, List<DataPointValueTime>> processed = new LinkedHashMap<>();
    for (DataPointVO vo : voMap.values()) {
        List<DataPointStatisticsGenerator> generators = valueMap.get(vo.getId());
        List<DataPointValueTime> values = new ArrayList<>();
        if (generators.get(0).getGenerator() instanceof NoStatisticsGenerator) {
            // Iterate and combine into an array
            for (DataPointStatisticsGenerator gen : generators) {
                NoStatisticsGenerator noGen = (NoStatisticsGenerator) gen.getGenerator();
                for (IValueTime value : noGen.getValues()) {
                    values.add(new DataPointVOPointValueTimeBookend(vo, (IdPointValueTime) value));
                }
            }
        } else {
            for (DataPointStatisticsGenerator generator : generators) {
                values.add(new DataPointRollupPeriodValue(generator, RollupEnum.convertTo(vo.getRollup())));
            }
        }
        if (values.size() > 0) {
            // As the other endpoints, limit before simplification
            if (limit != null)
                values = values.subList(0, limit);
            if (vo.isSimplifyDataSets()) {
                if (vo.getSimplifyType() == DataPointVO.SimplifyTypes.TARGET)
                    values = SimplifyUtility.simplify(null, vo.getSimplifyTarget(), true, true, values);
                else
                    values = SimplifyUtility.simplify(vo.getSimplifyTolerance(), null, true, true, values);
            }
            processed.put(vo, values);
        }
    }
    return processed;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) NoStatisticsGenerator(com.infiniteautomation.mango.statistics.NoStatisticsGenerator) ArrayList(java.util.ArrayList) IValueTime(com.serotonin.m2m2.view.stats.IValueTime) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) DataPointVOPointValueTimeBookend(com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend) LinkedHashMap(java.util.LinkedHashMap) DataPointValueTime(com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointValueTime) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with DataPointVOPointValueTimeBookend

use of com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend in project ma-modules-public by infiniteautomation.

the class MultiPointSimplifyLatestDatabaseStream method finish.

@Override
public void finish(PointValueTimeWriter writer) throws QueryCancelledException, IOException {
    // Write out the values after simplifying
    Iterator<Integer> it = valuesMap.keySet().iterator();
    if (info.isSingleArray() && voMap.size() > 1) {
        List<DataPointVOPointValueTimeBookend> sorted = new ArrayList<>();
        while (it.hasNext()) sorted.addAll(SimplifyUtility.simplify(info.simplifyTolerance, info.simplifyTarget, info.simplifyHighQuality, info.simplifyPrePostProcess, valuesMap.get(it.next())));
        // Sort the Sorted List
        Collections.sort(sorted, new Comparator<DataPointVOPointValueTimeBookend>() {

            @Override
            public int compare(DataPointVOPointValueTimeBookend o1, DataPointVOPointValueTimeBookend o2) {
                return o1.getPvt().compareTo(o2.getPvt());
            }
        });
        for (DataPointVOPointValueTimeBookend value : sorted) super.writeValue(value);
    } else {
        while (it.hasNext()) {
            List<DataPointVOPointValueTimeBookend> values = SimplifyUtility.simplify(info.simplifyTolerance, info.simplifyTarget, info.simplifyHighQuality, info.simplifyPrePostProcess, valuesMap.get(it.next()));
            for (DataPointVOPointValueTimeBookend value : values) super.writeValue(value);
        }
    }
    super.finish(writer);
}
Also used : ArrayList(java.util.ArrayList) DataPointVOPointValueTimeBookend(com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend)

Aggregations

DataPointVOPointValueTimeBookend (com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointVOPointValueTimeBookend)3 ArrayList (java.util.ArrayList)3 DataPointValueTime (com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointValueTime)1 NoStatisticsGenerator (com.infiniteautomation.mango.statistics.NoStatisticsGenerator)1 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 IValueTime (com.serotonin.m2m2.view.stats.IValueTime)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1