Search in sources :

Example 1 with BatchPointValueImpl

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

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

the class MigrationPointValueDaoTest method singleValue.

@Test
public void singleValue() throws ExecutionException, InterruptedException, TimeoutException {
    var dataSource = createMockDataSource();
    var point = createMockDataPoint(dataSource, new MockPointLocatorVO());
    Instant from = Instant.ofEpochMilli(0L);
    var sourceValues = List.of(new PointValueTime(0.0D, from.toEpochMilli()));
    var batchInsertValues = sourceValues.stream().map(v -> new BatchPointValueImpl<>(point, v)).collect(Collectors.toList());
    source.savePointValues(batchInsertValues.stream());
    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());
    }
    assertEquals(sourceValues.size(), destinationValues.size());
    for (int i = 0; i < sourceValues.size(); i++) {
        var sourceValue = sourceValues.get(i);
        var destinationValue = destinationValues.get(i);
        assertEquals(point.getSeriesId(), destinationValue.getSeriesId());
        assertEquals(sourceValue.getTime(), destinationValue.getTime());
        assertEquals(sourceValue.getValue(), destinationValue.getValue());
    }
}
Also used : BrownianPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.BrownianPointValueGenerator) MigrationProgressDao(com.serotonin.m2m2.db.dao.migration.progress.MigrationProgressDao) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) TimeoutException(java.util.concurrent.TimeoutException) SimulationTimerProvider(com.serotonin.m2m2.SimulationTimerProvider) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) MockPointValueDao(com.serotonin.m2m2.MockPointValueDao) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MangoTestBase(com.serotonin.m2m2.MangoTestBase) TemporalAmount(java.time.temporal.TemporalAmount) SimulationTimer(com.serotonin.timer.SimulationTimer) ZoneOffset(java.time.ZoneOffset) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ExecutorService(java.util.concurrent.ExecutorService) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) Period(java.time.Period) Test(org.junit.Test) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MockMangoLifecycle(com.serotonin.m2m2.MockMangoLifecycle) PointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.PointValueGenerator) Ignore(org.junit.Ignore) TimeOrder(com.serotonin.m2m2.db.dao.pointvalue.TimeOrder) LinearPointValueGenerator(com.infiniteautomation.mango.pointvalue.generator.LinearPointValueGenerator) Assert.assertEquals(org.junit.Assert.assertEquals) BatchPointValueImpl(com.serotonin.m2m2.db.dao.BatchPointValueImpl) Instant(java.time.Instant) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Test(org.junit.Test)

Example 3 with BatchPointValueImpl

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

BatchPointValueImpl (com.serotonin.m2m2.db.dao.BatchPointValueImpl)3 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 QueryCancelledException (com.infiniteautomation.mango.db.query.QueryCancelledException)2 WideCallback (com.infiniteautomation.mango.db.query.WideCallback)2 BatchPointValue (com.serotonin.m2m2.db.dao.BatchPointValue)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 TimeOrder (com.serotonin.m2m2.db.dao.pointvalue.TimeOrder)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)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 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Objects (java.util.Objects)2