Search in sources :

Example 1 with PointValueGenerator

use of com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator 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 2 with PointValueGenerator

use of com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator 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)

Example 3 with PointValueGenerator

use of com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator in project ma-core-public by infiniteautomation.

the class MigrationPointValueDaoTest method downsampledAggregate.

@Test
@Ignore
public void downsampledAggregate() throws ExecutionException, InterruptedException, TimeoutException {
    Duration aggregationPeriod = Duration.ofMinutes(15);
    TestMigrationConfig config = new TestMigrationConfig();
    config.setAggregationPeriod(aggregationPeriod);
    useMigrationConfig(config);
    var dataSource = createMockDataSource();
    var point = createMockDataPoint(dataSource, new MockPointLocatorVO());
    TemporalAmount testDuration = Duration.ofDays(1);
    ZonedDateTime from = ZonedDateTime.of(LocalDateTime.of(2020, 1, 1, 0, 0), ZoneOffset.UTC);
    ZonedDateTime to = from.plus(testDuration);
    Duration period = Duration.ofSeconds(5L);
    long inputExpectedSamples = Duration.between(from, to).dividedBy(period);
    // migration stops at the current time
    timer.setStartTime(to.toInstant().toEpochMilli());
    PointValueGenerator generator = new LinearPointValueGenerator(from.toInstant(), to.toInstant(), period, 0.0D, 1.0D);
    source.savePointValues(generator.apply(point));
    // sanity check
    assertEquals(inputExpectedSamples, source.dateRangeCount(point, null, null));
    migrationPointValueDao.startMigration();
    migrationPointValueDao.migrationFinished().get(30, TimeUnit.SECONDS);
    List<IdPointValueTime> destinationValues;
    try (var stream = destination.streamPointValues(point, null, null, null, TimeOrder.ASCENDING)) {
        destinationValues = stream.collect(Collectors.toList());
    }
    long outputExpectedSamples = Duration.between(from, to).dividedBy(aggregationPeriod);
    assertEquals(outputExpectedSamples, destinationValues.size());
    for (int i = 0; i < outputExpectedSamples; i++) {
        var destinationValue = destinationValues.get(i);
        assertEquals(point.getSeriesId(), destinationValue.getSeriesId());
        assertEquals(from.plus(aggregationPeriod.multipliedBy(i)).toInstant().toEpochMilli(), destinationValue.getTime());
        double expected = 180.0 * i + 89.5;
        assertEquals(expected, destinationValue.getDoubleValue(), 0.0D);
    }
}
Also used : Duration(java.time.Duration) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) LinearPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator) ZonedDateTime(java.time.ZonedDateTime) TemporalAmount(java.time.temporal.TemporalAmount) BrownianPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator) PointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator) LinearPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with PointValueGenerator

use of com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator 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

PointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator)4 Test (org.junit.Test)4 ConstantPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator)2 LinearPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator)2 AnalogStatisticsQuantizer (com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer)2 BucketCalculator (com.infiniteautomation.mango.quantize.BucketCalculator)2 TemporalAmountBucketCalculator (com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator)2 BatchPointValue (com.serotonin.m2m2.db.dao.BatchPointValue)2 NumericAggregate (com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)2 Duration (java.time.Duration)2 ZonedDateTime (java.time.ZonedDateTime)2 BrownianPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator)1 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 TemporalAmount (java.time.temporal.TemporalAmount)1 Ignore (org.junit.Ignore)1