Search in sources :

Example 31 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testRangeMultiplePointValuesOrderByIdLimitOffsetSeries.

public void testRangeMultiplePointValuesOrderByIdLimitOffsetSeries() {
    MutableInt count1 = new MutableInt();
    MutableInt count2 = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp1 = new MutableLong(series2StartTs);
    MutableLong timestamp2 = new MutableLong(series2StartTs);
    this.dao.getPointValuesBetween(ids, series2StartTs, series2EndTs, true, 20, new PVTQueryCallback<IdPointValueTime>() {

        int seriesIdCounter = 0;

        // Skip first 3
        int seriesId2Counter = 0;

        @Override
        public void row(IdPointValueTime value, int index) throws IOException {
            Assert.assertEquals(mutableIndex.intValue(), index);
            mutableIndex.increment();
            if (index < 20) {
                // Should be first id
                Assert.assertEquals((int) seriesId, value.getId());
            } else {
                Assert.assertEquals((int) seriesId2, value.getId());
            }
            if (value.getId() == seriesId2) {
                if (value.getTime() < timestamp2.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp2.setValue(value.getTime());
                count2.increment();
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
                seriesId2Counter++;
            } else {
                if (value.getTime() < timestamp1.getValue())
                    Assert.fail("Timestamp out of order.");
                timestamp1.setValue(value.getTime());
                count1.increment();
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(data.get(value.getId()).get(seriesIdCounter).getTime(), value.getTime());
                seriesIdCounter++;
            }
        }
    });
    Assert.assertEquals(new Integer(20), count1.getValue());
    Assert.assertEquals(new Integer(20), count2.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 32 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testLatestNoDataInOneSeries.

public void testLatestNoDataInOneSeries() {
    MutableInt count = new MutableInt();
    MutableInt mutableIndex = new MutableInt();
    MutableLong timestamp = new MutableLong(startTs);
    this.dao.getLatestPointValues(ids, startTs, false, null, new PVTQueryCallback<IdPointValueTime>() {

        int seriesId2Counter = 2;

        @Override
        public void row(IdPointValueTime value, int index) throws IOException {
            Assert.assertEquals(mutableIndex.intValue(), index);
            mutableIndex.increment();
            count.increment();
            if (value.getTime() > timestamp.getValue())
                Assert.fail("Timestamp out of order.");
            timestamp.setValue(value.getTime());
            if (value.getId() == seriesId2) {
                // Check value
                Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getDoubleValue(), value.getDoubleValue(), 0.001);
                // Check time
                Assert.assertEquals(data.get(value.getId()).get(seriesId2Counter).getTime(), value.getTime());
                seriesId2Counter--;
            } else {
                Assert.fail("Should not get data for series 1");
            }
        }
    });
    // Total is all samples + the extra 3 at the beginning of series2
    Assert.assertEquals(new Integer(3), count.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 33 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-core-public by infiniteautomation.

the class NumericPointValueDaoTestHelper method testLatestNoDataInBothSeries.

public void testLatestNoDataInBothSeries() {
    MutableInt count = new MutableInt();
    this.dao.getLatestPointValues(ids, series2StartTs, false, null, new PVTQueryCallback<IdPointValueTime>() {

        @Override
        public void row(IdPointValueTime value, int index) throws IOException {
            count.increment();
        }
    });
    Assert.assertEquals(new Integer(0), count.getValue());
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException)

Example 34 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-modules-public by infiniteautomation.

the class MultiPointLatestDatabaseStream method processValueThroughCache.

/**
 * Write out any cached values that would be equal to or between the time of the incomming
 *   point value and the next one to be returned by the query.
 *   this should be called before processing this value
 * @param value
 * @param bookend
 * @return true to continue to process the incoming value, false if it was a bookend that was replaced via the cache
 * @throws IOException
 */
protected boolean processValueThroughCache(IdPointValueTime value, int index, boolean firstBookend, boolean lastBookend) throws IOException {
    List<IdPointValueTime> pointCache = this.cache.get(value.getId());
    if (pointCache != null) {
        ListIterator<IdPointValueTime> it = pointCache.listIterator();
        while (it.hasNext()) {
            IdPointValueTime pvt = it.next();
            if (pvt.getTime() > value.getTime()) {
                // Can't be a bookend
                processRow(pvt, index, false, false, true);
                it.remove();
            } else if (pvt.getTime() == value.getTime()) {
                // Could be a bookend
                processRow(pvt, index, firstBookend, lastBookend, true);
                it.remove();
                if (pointCache.size() == 0)
                    this.cache.remove(value.getId());
                return false;
            } else
                // No more since we are in time order of the query
                break;
        }
        if (pointCache.size() == 0)
            this.cache.remove(value.getId());
    }
    return true;
}
Also used : IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)

Example 35 with IdPointValueTime

use of com.serotonin.m2m2.rt.dataImage.IdPointValueTime in project ma-modules-public by infiniteautomation.

the class MultiPointTimeRangeDatabaseStream method processCacheOnly.

/* (non-Javadoc)
     * @see com.infiniteautomation.mango.rest.v2.model.pointValue.query.MultiPointLatestDatabaseStream#processCacheOnly()
     */
@Override
protected void processCacheOnly() throws IOException {
    // Performance enhancement to return data within cache only
    Iterator<Integer> it = voMap.keySet().iterator();
    int index = 0;
    while (it.hasNext()) {
        List<IdPointValueTime> values = cache.get(it.next());
        boolean first = true;
        int limitCount = 0;
        for (IdPointValueTime value : values) {
            if (first && info.isBookend()) {
                // Send out first value as bookend if necessary
                if (value.getTime() != info.getFromMillis()) {
                    IdPointValueTime bookend;
                    if (value.isAnnotated())
                        bookend = new AnnotatedIdPointValueTime(value.getId(), value.getValue(), info.getFromMillis(), ((AnnotatedIdPointValueTime) value).getSourceMessage());
                    else
                        bookend = new IdPointValueTime(value.getId(), value.getValue(), info.getFromMillis());
                    processRow(bookend, index, true, false, true);
                    processRow(value, index, false, false, true);
                } else
                    processRow(value, index, true, false, true);
                first = false;
            } else
                processRow(value, index, false, false, true);
            index++;
            limitCount++;
            if (info.getLimit() != null && limitCount >= info.getLimit())
                break;
        }
        // Send out last value as bookend if necessary
        if (info.isBookend()) {
            IdPointValueTime last = values.get(values.size() - 1);
            if (last.getTime() != info.getToMillis()) {
                IdPointValueTime bookend;
                if (last.isAnnotated())
                    bookend = new AnnotatedIdPointValueTime(last.getId(), last.getValue(), info.getToMillis(), ((AnnotatedIdPointValueTime) last).getSourceMessage());
                else
                    bookend = new IdPointValueTime(last.getId(), last.getValue(), info.getToMillis());
                processRow(bookend, index, false, true, true);
            }
        }
    }
}
Also used : IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)

Aggregations

IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)68 IOException (java.io.IOException)60 MutableInt (org.apache.commons.lang3.mutable.MutableInt)60 MutableLong (org.apache.commons.lang3.mutable.MutableLong)36 NextTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster)21 ZonedDateTime (java.time.ZonedDateTime)21 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)14 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)9 AnalogStatistics (com.infiniteautomation.mango.statistics.AnalogStatistics)7 StartsAndRuntime (com.infiniteautomation.mango.statistics.StartsAndRuntime)7 StartsAndRuntimeList (com.infiniteautomation.mango.statistics.StartsAndRuntimeList)7 ValueChangeCounter (com.infiniteautomation.mango.statistics.ValueChangeCounter)7 AnnotatedIdPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)6 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)2 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)2 HashMap (java.util.HashMap)2