Search in sources :

Example 6 with NumericAggregate

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

the class AggregateDaoTest method query.

@Test
public void query() {
    var ds = createMockDataSource();
    var point = createMockDataPoint(ds, new MockPointLocatorVO(DataType.NUMERIC, false));
    ZonedDateTime from = ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 0, 0), ZoneOffset.UTC);
    ZonedDateTime to = from.plusDays(1L);
    Duration period = Duration.ofSeconds(5L);
    PointValueGenerator generator = new LinearPointValueGenerator(from.toInstant(), to.toInstant(), period, 0.0D, 1.0D);
    pointValueDao.savePointValues(generator.apply(point));
    Duration aggregatePeriod = Duration.ofMinutes(15L);
    long outputExpectedSamples = Duration.between(from, to).dividedBy(aggregatePeriod);
    AggregateDao aggregateDao = pointValueDao.getAggregateDao();
    try (var stream = aggregateDao.query(point, from, to, null, aggregatePeriod)) {
        var list = stream.collect(Collectors.toList());
        Assert.assertEquals(outputExpectedSamples, list.size());
        for (int i = 0; i < outputExpectedSamples; i++) {
            var destinationValue = list.get(i);
            assertEquals(point.getSeriesId(), destinationValue.getSeriesId());
            assertEquals(from.plus(aggregatePeriod.multipliedBy(i)).toInstant().toEpochMilli(), destinationValue.getTime());
            NumericAggregate aggregate = (NumericAggregate) destinationValue.getValue();
            assertEquals(180, aggregate.getCount());
            double expectedAverage = 180.0 * i + 89.5;
            assertEquals(expectedAverage, aggregate.getArithmeticMean(), 0.0D);
        }
    }
}
Also used : LinearPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator) ZonedDateTime(java.time.ZonedDateTime) PointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator) LinearPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator) Duration(java.time.Duration) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) 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