use of com.infiniteautomation.mango.quantize.BucketCalculator 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);
}
use of com.infiniteautomation.mango.quantize.BucketCalculator in project ma-core-public by infiniteautomation.
the class StatisticsAggregatorTest method emptyStream.
@Test
public void emptyStream() {
BucketCalculator bucketCalc = new TemporalAmountBucketCalculator(from, to, aggregatePeriod);
List<NumericAggregate> aggregates = StatisticsAggregator.aggregate(Stream.empty(), new AnalogStatisticsQuantizer(bucketCalc)).collect(Collectors.toList());
Assert.assertEquals(expectedAggregateValues, aggregates.size());
for (var aggregate : aggregates) {
assertEquals(0L, aggregate.getCount());
assertEquals(Double.NaN, aggregate.getArithmeticMean(), 0.0D);
assertEquals(Double.NaN, aggregate.getAverage(), 0.0D);
}
}
use of com.infiniteautomation.mango.quantize.BucketCalculator in project ma-core-public by infiniteautomation.
the class StatisticsAggregatorTest method aggregateWithInitialValue.
@Test
public void aggregateWithInitialValue() {
PointValueTime initialValue = new PointValueTime(1.0D, from.minusHours(1L).toInstant().toEpochMilli());
PointValueGenerator generator = new ConstantPointValueGenerator(from.toInstant(), to.toInstant(), pollPeriod, new NumericValue(0.0D));
var stream = generator.apply(new DataPointVO()).map(BatchPointValue::getValue);
BucketCalculator bucketCalc = new TemporalAmountBucketCalculator(from, to, aggregatePeriod);
List<NumericAggregate> aggregates = StatisticsAggregator.aggregate(Stream.concat(Stream.of(initialValue), stream), new AnalogStatisticsQuantizer(bucketCalc)).collect(Collectors.toList());
Assert.assertEquals(expectedAggregateValues, aggregates.size());
for (var aggregate : aggregates) {
assertEquals(180L, aggregate.getCount());
assertEquals(0.0D, aggregate.getArithmeticMean(), 0.0D);
assertEquals(0.0D, aggregate.getArithmeticMean(), 0.0D);
}
}
use of com.infiniteautomation.mango.quantize.BucketCalculator in project ma-core-public by infiniteautomation.
the class StatisticsAggregatorTest method initialValueOnly.
@Test
public void initialValueOnly() {
PointValueTime initialValue = new PointValueTime(1.0D, from.minusHours(1L).toInstant().toEpochMilli());
BucketCalculator bucketCalc = new TemporalAmountBucketCalculator(from, to, aggregatePeriod);
List<NumericAggregate> aggregates = StatisticsAggregator.aggregate(Stream.of(initialValue), new AnalogStatisticsQuantizer(bucketCalc)).collect(Collectors.toList());
Assert.assertEquals(expectedAggregateValues, aggregates.size());
for (var aggregate : aggregates) {
assertEquals(0L, aggregate.getCount());
assertEquals(Double.NaN, aggregate.getArithmeticMean(), 0.0D);
assertEquals(1.0D, aggregate.getAverage(), 0.0D);
}
}
use of com.infiniteautomation.mango.quantize.BucketCalculator in project ma-core-public by infiniteautomation.
the class StatisticsAggregatorTest method aggregate.
@Test
public void aggregate() {
PointValueGenerator generator = new ConstantPointValueGenerator(from.toInstant(), to.toInstant(), pollPeriod, new NumericValue(0.0D));
var stream = generator.apply(new DataPointVO()).map(BatchPointValue::getValue);
BucketCalculator bucketCalc = new TemporalAmountBucketCalculator(from, to, aggregatePeriod);
List<NumericAggregate> aggregates = StatisticsAggregator.aggregate(stream, new AnalogStatisticsQuantizer(bucketCalc)).collect(Collectors.toList());
Assert.assertEquals(expectedAggregateValues, aggregates.size());
for (var aggregate : aggregates) {
assertEquals(180L, aggregate.getCount());
assertEquals(0.0D, aggregate.getArithmeticMean(), 0.0D);
assertEquals(0.0D, aggregate.getArithmeticMean(), 0.0D);
}
}
Aggregations