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