Search in sources :

Example 1 with BatchPointValue

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

the class NumericPointValueDaoTestHelper method before.

/**
 * Insert some test data.
 * Call before every test.
 */
public void before() {
    List<BatchPointValue<PointValueTime>> values = new ArrayList<>();
    // Start back 30 days
    endTs = System.currentTimeMillis();
    startTs = endTs - (30L * 24L * 60L * 60L * 1000L);
    // Insert a few samples for series 2 before our time
    series2StartTs = startTs - (1000 * 60 * 15);
    long time = series2StartTs;
    PointValueTime p2vt = new PointValueTime(-3.0, time);
    values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
    time = startTs - (1000 * 60 * 10);
    p2vt = new PointValueTime(-2.0, time);
    values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
    time = startTs - (1000 * 60 * 5);
    p2vt = new PointValueTime(-1.0, time);
    values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
    time = startTs;
    // Insert a sample every 5 minutes
    double value = 0.0;
    while (time < endTs) {
        PointValueTime pvt = new PointValueTime(value, time);
        values.add(new BatchPointValueImpl<PointValueTime>(vo1, pvt));
        values.add(new BatchPointValueImpl<PointValueTime>(vo2, pvt));
        time = time + 1000 * 60 * 5;
        totalSampleCount++;
        value++;
    }
    // Add a few more samples for series 2 after our time
    p2vt = new PointValueTime(value++, time);
    values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
    time = time + (1000 * 60 * 5);
    p2vt = new PointValueTime(value++, time);
    values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
    time = time + (1000 * 60 * 5);
    p2vt = new PointValueTime(value, time);
    values.add(new BatchPointValueImpl<PointValueTime>(vo2, p2vt));
    this.series2EndTs = time;
    dao.savePointValues(values.stream().peek(v -> {
        data.computeIfAbsent(v.getPoint().getSeriesId(), k -> new ArrayList<>()).add(v.getValue());
    }), 10000);
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Map(java.util.Map) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) BatchPointValue(com.serotonin.m2m2.db.dao.BatchPointValue) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) TreeMap(java.util.TreeMap) WideCallback(com.infiniteautomation.mango.db.query.WideCallback) TimeOrder(com.serotonin.m2m2.db.dao.pointvalue.TimeOrder) ArrayDeque(java.util.ArrayDeque) Assert(org.junit.Assert) Collections(java.util.Collections) BatchPointValue(com.serotonin.m2m2.db.dao.BatchPointValue) ArrayList(java.util.ArrayList) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 2 with BatchPointValue

use of com.serotonin.m2m2.db.dao.BatchPointValue 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 3 with BatchPointValue

use of com.serotonin.m2m2.db.dao.BatchPointValue 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 4 with BatchPointValue

use of com.serotonin.m2m2.db.dao.BatchPointValue in project ma-core-public by MangoAutomation.

the class NumericPointValueDaoTestHelper method before.

/**
 * Insert some test data.
 * Call before every test.
 */
public void before() {
    List<BatchPointValue> values = new ArrayList<>();
    // Start back 30 days
    endTs = System.currentTimeMillis();
    startTs = endTs - (30L * 24L * 60L * 60L * 1000L);
    // Insert a few samples for series 2 before our time
    series2StartTs = startTs - (1000 * 60 * 15);
    long time = series2StartTs;
    PointValueTime p2vt = new PointValueTime(-3.0, time);
    values.add(new BatchPointValueImpl(vo2, p2vt));
    time = startTs - (1000 * 60 * 10);
    p2vt = new PointValueTime(-2.0, time);
    values.add(new BatchPointValueImpl(vo2, p2vt));
    time = startTs - (1000 * 60 * 5);
    p2vt = new PointValueTime(-1.0, time);
    values.add(new BatchPointValueImpl(vo2, p2vt));
    time = startTs;
    // Insert a sample every 5 minutes
    double value = 0.0;
    while (time < endTs) {
        PointValueTime pvt = new PointValueTime(value, time);
        values.add(new BatchPointValueImpl(vo1, pvt));
        values.add(new BatchPointValueImpl(vo2, pvt));
        time = time + 1000 * 60 * 5;
        totalSampleCount++;
        value++;
    }
    // Add a few more samples for series 2 after our time
    p2vt = new PointValueTime(value++, time);
    values.add(new BatchPointValueImpl(vo2, p2vt));
    time = time + (1000 * 60 * 5);
    p2vt = new PointValueTime(value++, time);
    values.add(new BatchPointValueImpl(vo2, p2vt));
    time = time + (1000 * 60 * 5);
    p2vt = new PointValueTime(value, time);
    values.add(new BatchPointValueImpl(vo2, p2vt));
    this.series2EndTs = time;
    dao.savePointValues(values.stream().peek(v -> {
        data.computeIfAbsent(v.getVo().getSeriesId(), k -> new ArrayList<>()).add(v.getPointValue());
    }), 10000);
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Map(java.util.Map) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) TimeOrder(com.serotonin.m2m2.db.dao.PointValueDao.TimeOrder) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) BatchPointValue(com.serotonin.m2m2.db.dao.BatchPointValue) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) TreeMap(java.util.TreeMap) WideCallback(com.infiniteautomation.mango.db.query.WideCallback) ArrayDeque(java.util.ArrayDeque) Assert(org.junit.Assert) Collections(java.util.Collections) BatchPointValue(com.serotonin.m2m2.db.dao.BatchPointValue) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) ArrayList(java.util.ArrayList) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Aggregations

BatchPointValue (com.serotonin.m2m2.db.dao.BatchPointValue)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 QueryCancelledException (com.infiniteautomation.mango.db.query.QueryCancelledException)2 WideCallback (com.infiniteautomation.mango.db.query.WideCallback)2 ConstantPointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.ConstantPointValueGenerator)2 PointValueGenerator (com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator)2 AnalogStatisticsQuantizer (com.infiniteautomation.mango.quantize.AnalogStatisticsQuantizer)2 BucketCalculator (com.infiniteautomation.mango.quantize.BucketCalculator)2 TemporalAmountBucketCalculator (com.infiniteautomation.mango.quantize.TemporalAmountBucketCalculator)2 BatchPointValueImpl (com.serotonin.m2m2.db.dao.BatchPointValueImpl)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 NumericAggregate (com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate)2 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Deque (java.util.Deque)2