Search in sources :

Example 1 with NumericAggregate

use of com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate 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);
    }
}
Also used : TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) BucketCalculator(com.infiniteautomation.mango.quantize.BucketCalculator) TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) AnalogStatisticsQuantizer(com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer) NumericAggregate(com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate) Test(org.junit.Test)

Example 2 with NumericAggregate

use of com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate in project ma-modules-public by infiniteautomation.

the class AggregateValueMapper method getAllRollup.

private AllStatisticsModel getAllRollup(DataPointVO point, AggregateValue stats) {
    AllStatisticsModel all;
    if (stats instanceof NumericAggregate) {
        NumericAllModel model = new NumericAllModel();
        model.setAccumulator(getRollupValue(point, stats, RollupEnum.ACCUMULATOR));
        model.setAverage(getRollupValue(point, stats, RollupEnum.AVERAGE));
        model.setDelta(getRollupValue(point, stats, RollupEnum.DELTA));
        model.setIntegral(getRollupValue(point, stats, RollupEnum.INTEGRAL));
        model.setMaximum(getRollupValue(point, stats, RollupEnum.MAXIMUM));
        model.setMinimum(getRollupValue(point, stats, RollupEnum.MINIMUM));
        model.setSum(getRollupValue(point, stats, RollupEnum.SUM));
        model.setMaximumInPeriod(getRollupValue(point, stats, RollupEnum.MAXIMUM_IN_PERIOD));
        model.setMinimumInPeriod(getRollupValue(point, stats, RollupEnum.MINIMUM_IN_PERIOD));
        model.setArithmeticMean(getRollupValue(point, stats, RollupEnum.ARITHMETIC_MEAN));
        all = model;
    } else if (stats instanceof StartsAndRuntimeAggregate) {
        MultistateAllStatisticsModel model = new MultistateAllStatisticsModel();
        var startsStats = ((StartsAndRuntimeAggregate) stats);
        var startsModel = startsStats.getData().stream().map(start -> {
            String rendered = renderValue(point, start.getDataValue());
            return new StartsAndRuntimeModel(start.getDataValue(), rendered, start.getStarts(), start.getRuntime(), start.getProportion());
        }).collect(Collectors.toUnmodifiableList());
        model.setStartsAndRuntimes(startsModel);
        all = model;
    } else {
        all = new AllStatisticsModel();
    }
    if (fields.contains(PointValueField.TIMESTAMP)) {
        all.setTimestamp(formatTime(stats.getPeriodStartTime()));
    }
    all.setCount(stats.getCount());
    all.setFirst(getRollupValue(point, stats, RollupEnum.FIRST));
    all.setLast(getRollupValue(point, stats, RollupEnum.LAST));
    all.setStart(getRollupValue(point, stats, RollupEnum.START));
    return all;
}
Also used : AllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel) MultistateAllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel) MultistateAllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel) StartsAndRuntimeAggregate(com.serotonin.m2m2.db.dao.pointvalue.StartsAndRuntimeAggregate) NumericAllModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.NumericAllModel) StartsAndRuntimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel.StartsAndRuntimeModel) NumericAggregate(com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate)

Example 3 with NumericAggregate

use of com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate 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);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) BatchPointValue(com.serotonin.m2m2.db.dao.BatchPointValue) TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ConstantPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator) PointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator) ConstantPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator) BucketCalculator(com.infiniteautomation.mango.quantize.BucketCalculator) TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) AnalogStatisticsQuantizer(com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer) NumericAggregate(com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate) Test(org.junit.Test)

Example 4 with NumericAggregate

use of com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate 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);
    }
}
Also used : TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) BucketCalculator(com.infiniteautomation.mango.quantize.BucketCalculator) TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) AnalogStatisticsQuantizer(com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer) NumericAggregate(com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate) Test(org.junit.Test)

Example 5 with NumericAggregate

use of com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate 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);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) BatchPointValue(com.serotonin.m2m2.db.dao.BatchPointValue) TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) ConstantPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator) PointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator) ConstantPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator) BucketCalculator(com.infiniteautomation.mango.quantize.BucketCalculator) TemporalAmountBucketCalculator(com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) AnalogStatisticsQuantizer(com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer) NumericAggregate(com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate) Test(org.junit.Test)

Aggregations

NumericAggregate (com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate)5 Test (org.junit.Test)5 AnalogStatisticsQuantizer (com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer)4 BucketCalculator (com.infiniteautomation.mango.quantize.BucketCalculator)4 TemporalAmountBucketCalculator (com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator)4 PointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator)3 ConstantPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator)2 BatchPointValue (com.serotonin.m2m2.db.dao.BatchPointValue)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 LinearPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator)1 AllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel)1 MultistateAllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel)1 StartsAndRuntimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel.StartsAndRuntimeModel)1 NumericAllModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.NumericAllModel)1 StartsAndRuntimeAggregate (com.serotonin.m2m2.db.dao.pointvalue.StartsAndRuntimeAggregate)1 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)1 Duration (java.time.Duration)1 ZonedDateTime (java.time.ZonedDateTime)1