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