Search in sources :

Example 6 with TimeOrder

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

the class BasicSQLPointValueDao method getPointValuesPerPoint.

@Override
public void getPointValuesPerPoint(Collection<? extends DataPointVO> vos, @Nullable Long from, @Nullable Long to, @Nullable Integer limit, TimeOrder sortOrder, Consumer<? super IdPointValueTime> callback) {
    PointValueDao.validateNotNull(vos);
    PointValueDao.validateTimePeriod(from, to);
    PointValueDao.validateLimit(limit);
    PointValueDao.validateNotNull(callback);
    PointValueDao.validateNotNull(sortOrder);
    if (vos.isEmpty() || limit != null && limit == 0)
        return;
    // Limit results of each data point to size limit, i.e. loop over all points and query with limit
    var query = betweenQuery(from, to, limit, sortOrder, pv.dataPointId.eq(DSL.param("seriesId", Integer.class)));
    try (var queryKept = query.keepStatement(true)) {
        for (DataPointVO vo : vos) {
            try (var cursor = queryKept.bind("seriesId", vo.getSeriesId()).fetchLazy()) {
                for (var record : cursor) {
                    callback.accept(mapRecord(record));
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO)

Example 7 with TimeOrder

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

the class BasicSQLPointValueDao method getPointValuesPerPoint.

@Override
public void getPointValuesPerPoint(Collection<? extends DataPointVO> vos, @Nullable Long from, @Nullable Long to, @Nullable Integer limit, TimeOrder sortOrder, Consumer<? super IdPointValueTime> callback) {
    PointValueDao.validateNotNull(vos);
    PointValueDao.validateTimePeriod(from, to);
    PointValueDao.validateLimit(limit);
    PointValueDao.validateNotNull(callback);
    PointValueDao.validateNotNull(sortOrder);
    if (vos.isEmpty() || limit != null && limit == 0)
        return;
    // Limit results of each data point to size limit, i.e. loop over all points and query with limit
    var query = betweenQuery(from, to, limit, sortOrder, pv.dataPointId.eq(DSL.param("seriesId", Integer.class)));
    try (var queryKept = query.keepStatement(true)) {
        for (DataPointVO vo : vos) {
            try (var cursor = queryKept.bind("seriesId", vo.getSeriesId()).fetchLazy()) {
                for (var record : cursor) {
                    callback.accept(mapRecord(record));
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO)

Example 8 with TimeOrder

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

the class NumericPointValueDaoTestHelper method streamPointValues.

public void streamPointValues(TimeOrder order) {
    Map<Long, PointValueTime> values = timeIndexedValues(vo1);
    AtomicLong count = new AtomicLong();
    AtomicLong previousTime = new AtomicLong(order == TimeOrder.ASCENDING ? Long.MIN_VALUE : Long.MAX_VALUE);
    try (var stream = dao.streamPointValues(vo1, startTs, endTs, null, order)) {
        stream.forEach(pvt -> {
            long lastTimestamp = previousTime.getAndSet(pvt.getTime());
            count.incrementAndGet();
            PointValueTime expectedValue = values.get(pvt.getTime());
            if (order == TimeOrder.ASCENDING) {
                Assert.assertTrue(pvt.getTime() > lastTimestamp);
            } else {
                Assert.assertTrue(pvt.getTime() < lastTimestamp);
            }
            Assert.assertNotNull(expectedValue);
            Assert.assertEquals(expectedValue.getValue(), pvt.getValue());
        });
    }
    Assert.assertEquals(totalSampleCount, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) MutableLong(org.apache.commons.lang3.mutable.MutableLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 9 with TimeOrder

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

the class NumericPointValueDaoTestHelper method streamPointValuesCombined.

public void streamPointValuesCombined(TimeOrder order) {
    var values = timeIndexedValues();
    AtomicLong count = new AtomicLong();
    AtomicLong previousTime = new AtomicLong(order == TimeOrder.ASCENDING ? Long.MIN_VALUE : Long.MAX_VALUE);
    Set<Integer> seriesIds = new HashSet<>();
    try (var stream = dao.streamPointValuesCombined(vos, startTs, endTs, null, order)) {
        stream.forEach(pvt -> {
            long lastTimestamp = previousTime.getAndSet(pvt.getTime());
            count.incrementAndGet();
            PointValueTime expectedValue = values.get(pvt.getSeriesId()).get(pvt.getTime());
            seriesIds.add(pvt.getSeriesId());
            if (order == TimeOrder.ASCENDING) {
                Assert.assertTrue(pvt.getTime() >= lastTimestamp);
            } else {
                Assert.assertTrue(pvt.getTime() <= lastTimestamp);
            }
            Assert.assertNotNull(expectedValue);
            Assert.assertEquals(expectedValue.getValue(), pvt.getValue());
        });
    }
    Assert.assertEquals(vos.size(), seriesIds.size());
    Assert.assertEquals(totalSampleCount * 2, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) HashSet(java.util.HashSet)

Example 10 with TimeOrder

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

the class NumericPointValueDaoTestHelper method streamPointValuesPerPoint.

public void streamPointValuesPerPoint(TimeOrder order) {
    var values = timeIndexedValues();
    AtomicLong count = new AtomicLong();
    AtomicLong previousTime = new AtomicLong();
    Deque<Integer> seriesIds = new ArrayDeque<>();
    try (var stream = dao.streamPointValuesPerPoint(vos, startTs, endTs, null, order)) {
        stream.forEach(pvt -> {
            if (seriesIds.contains(pvt.getSeriesId())) {
                // already seen this series, ensure that it is the last one
                Assert.assertEquals(pvt.getSeriesId(), (long) Objects.requireNonNull(seriesIds.peekLast()));
            } else {
                seriesIds.add(pvt.getSeriesId());
                previousTime.set(order == TimeOrder.ASCENDING ? Long.MIN_VALUE : Long.MAX_VALUE);
            }
            long lastTimestamp = previousTime.getAndSet(pvt.getTime());
            count.incrementAndGet();
            PointValueTime expectedValue = values.get(pvt.getSeriesId()).get(pvt.getTime());
            if (order == TimeOrder.ASCENDING) {
                Assert.assertTrue(pvt.getTime() > lastTimestamp);
            } else {
                Assert.assertTrue(pvt.getTime() < lastTimestamp);
            }
            Assert.assertNotNull(expectedValue);
            Assert.assertEquals(expectedValue.getValue(), pvt.getValue());
        });
    }
    Assert.assertEquals(vos.size(), seriesIds.size());
    Assert.assertEquals(totalSampleCount * 2, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayDeque(java.util.ArrayDeque)

Aggregations

IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ArrayDeque (java.util.ArrayDeque)2 HashSet (java.util.HashSet)2 MutableLong (org.apache.commons.lang3.mutable.MutableLong)2 PointValueIterator (com.infiniteautomation.mango.db.iterators.PointValueIterator)1