Search in sources :

Example 1 with BucketsBucketCalculator

use of com.infiniteautomation.mango.quantize.BucketsBucketCalculator in project ma-modules-public by infiniteautomation.

the class MultiDataPointStatisticsQuantizerStream method finish.

@Override
public void finish(PointValueTimeWriter writer) throws QueryCancelledException, IOException {
    if (info.isSingleArray() && voMap.size() > 1) {
        // Fast forward to end to fill any gaps at the end and stream out data in time
        BucketCalculator bc;
        if (this.info.getTimePeriod() == null) {
            bc = new BucketsBucketCalculator(ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastFullPeriodToMillis), info.getZoneId()), info.getTo(), 1);
        } else {
            bc = new TimePeriodBucketCalculator(ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastFullPeriodToMillis), info.getZoneId()), info.getTo(), TimePeriodType.convertFrom(this.info.getTimePeriod().getType()), this.info.getTimePeriod().getPeriods());
        }
        Instant currentPeriodTo = bc.getStartTime().toInstant();
        Instant end = bc.getEndTime().toInstant();
        while (currentPeriodTo.isBefore(end)) {
            long nextTo = currentPeriodTo.toEpochMilli();
            for (DataPointStatisticsQuantizer<?> quant : this.quantizerMap.values()) {
                quant.fastForward(nextTo);
            }
            currentPeriodTo = bc.getNextPeriodTo().toInstant();
        }
        for (DataPointStatisticsQuantizer<?> quant : this.quantizerMap.values()) {
            if (!quant.isDone())
                quant.done();
        }
        // TODO This is likely not necessary
        Iterator<Long> it = this.periodStats.keySet().iterator();
        while (it.hasNext()) {
            List<DataPointValueTime> entries = this.periodStats.get(it.next());
            writePeriodStats(entries);
            it.remove();
        }
    } else {
        // The last data point may not have been done() as well as any with 0 data
        if (currentDataPointId != -1) {
            DataPointStatisticsQuantizer<?> quant = this.quantizerMap.get(currentDataPointId);
            if (!quant.isDone()) {
                quant.done();
            }
        }
        // For any with 0 data TODO Check for is open?
        for (DataPointStatisticsQuantizer<?> q : this.quantizerMap.values()) {
            if (!q.isDone()) {
                q.done();
            }
        }
    }
    super.finish(writer);
}
Also used : Instant(java.time.Instant) DataPointValueTime(com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointValueTime) BucketsBucketCalculator(com.infiniteautomation.mango.quantize.BucketsBucketCalculator) TimePeriodBucketCalculator(com.infiniteautomation.mango.quantize.TimePeriodBucketCalculator) BucketsBucketCalculator(com.infiniteautomation.mango.quantize.BucketsBucketCalculator) BucketCalculator(com.infiniteautomation.mango.quantize.BucketCalculator) TimePeriodBucketCalculator(com.infiniteautomation.mango.quantize.TimePeriodBucketCalculator)

Aggregations

BucketCalculator (com.infiniteautomation.mango.quantize.BucketCalculator)1 BucketsBucketCalculator (com.infiniteautomation.mango.quantize.BucketsBucketCalculator)1 TimePeriodBucketCalculator (com.infiniteautomation.mango.quantize.TimePeriodBucketCalculator)1 DataPointValueTime (com.infiniteautomation.mango.rest.latest.model.pointValue.DataPointValueTime)1 Instant (java.time.Instant)1