Search in sources :

Example 36 with IdPointValueTime

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

the class MultiPointTimeRangeDatabaseStream method processValueThroughCache.

@Override
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 37 with IdPointValueTime

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

the class XidPointValueTimeJsonWriter method writeXidTime.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.time.XidTimeJsonWriter#writeXidTime(com.fasterxml.jackson.core.JsonGenerator, com.serotonin.m2m2.vo.DataPointVO, com.serotonin.m2m2.rt.dataImage.IdTime)
	 */
@Override
public void writeXidTime(JsonGenerator jgen, DataPointVO vo, IdPointValueTime value) throws IOException {
    if (useRendered) {
        // Convert to Alphanumeric Value
        this.writeXidPointValue(value.getTime(), new AlphanumericValue(Functions.getRenderedText(vo, value)), vo);
    } else if (unitConversion) {
        if (value.getValue() instanceof NumericValue)
            this.writeXidPointValue(value.getTime(), new NumericValue(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value.getValue().getDoubleValue())), vo);
        else
            this.writeXidPointValue(value.getTime(), value.getValue(), vo);
    } else {
        if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
            this.writeXidPointValue(value.getTime(), new AlphanumericValue(imageServletBuilder.buildAndExpand(value.getTime(), vo.getId()).toUri().toString()), vo);
        else
            this.writeXidPointValue(value.getTime(), value.getValue(), vo);
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 38 with IdPointValueTime

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

the class PointValueDaoSQL method getPointValuesBetween.

@Override
public void getPointValuesBetween(List<Integer> ids, long from, long to, boolean orderById, Integer limit, PVTQueryCallback<IdPointValueTime> callback) {
    if (ids.size() == 0)
        return;
    if (orderById) {
        // Limit results of each data point to size limit, i.e. loop over all points and query with limit
        MutableInt counter = new MutableInt(0);
        for (Integer id : ids) {
            TimeRangeSinglePointValuesPreparedStatementCreator<PVTQueryCallback<IdPointValueTime>> c = new TimeRangeSinglePointValuesPreparedStatementCreator<PVTQueryCallback<IdPointValueTime>>(id, from, to, limit, callback, counter);
            ejt.execute(c, c);
        }
    } else {
        // Limit total results to limit
        TimeRangeMultiplePointsValuesPreparedStatementCreator<PVTQueryCallback<IdPointValueTime>> c = new TimeRangeMultiplePointsValuesPreparedStatementCreator<PVTQueryCallback<IdPointValueTime>>(ids, from, to, limit, callback);
        ejt.execute(c, c);
    }
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedIdPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime) PVTQueryCallback(com.infiniteautomation.mango.db.query.PVTQueryCallback)

Example 39 with IdPointValueTime

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

the class AnalogStatisticsQuantizerTest method testStartValueOneValuePerPeriod.

// Test with Start Value and Values
@Test
public void testStartValueOneValuePerPeriod() throws IOException {
    // Generate data at 12 noon for every day in the period
    NextTimePeriodAdjuster adjuster = new NextTimePeriodAdjuster(TimePeriods.DAYS, 1);
    time = ZonedDateTime.of(2017, 01, 01, 12, 00, 00, 0, zoneId);
    List<IdPointValueTime> data = new ArrayList<>();
    double value = 1.0;
    while (time.toInstant().isBefore(to.toInstant())) {
        data.add(new IdPointValueTime(1, new NumericValue(value), time.toInstant().toEpochMilli()));
        time = (ZonedDateTime) adjuster.adjustInto(time);
    }
    // Reset time to track periods
    time = ZonedDateTime.of(2017, 01, 01, 00, 00, 00, 0, zoneId);
    MutableInt counter = new MutableInt(0);
    BucketCalculator bc = new TimePeriodBucketCalculator(from, to, TimePeriods.DAYS, 1);
    AnalogStatisticsQuantizer quantizer = new AnalogStatisticsQuantizer(bc, new StatisticsGeneratorQuantizerCallback<AnalogStatistics>() {

        @Override
        public void quantizedStatistics(AnalogStatistics statisticsGenerator) throws IOException {
            counter.increment();
            AnalogStatistics stats = (AnalogStatistics) statisticsGenerator;
            // Test periodStart
            Assert.assertEquals(time.toInstant().toEpochMilli(), stats.getPeriodStartTime());
            // Test periiodEnd
            Assert.assertEquals(time.plusDays(1).toInstant().toEpochMilli(), stats.getPeriodEndTime());
            ZonedDateTime sampleTime = time.plusHours(12);
            // Start Value was 3 hrs before 1st period start
            // Test Minimum
            Assert.assertEquals(1.0, stats.getMinimumValue(), 0.0001);
            Assert.assertEquals(time.toInstant().toEpochMilli(), (long) stats.getMinimumTime());
            // Test Maximum
            Assert.assertEquals(1.0, stats.getMaximumValue(), 0.0001);
            Assert.assertEquals(time.toInstant().toEpochMilli(), (long) stats.getMaximumTime());
            // Test Average
            Assert.assertEquals(1.0d, stats.getAverage(), 0.0001);
            // Test Integral
            // 24Hrs
            double integral = 1.0d * 24 * 60 * 60;
            Assert.assertEquals(integral, stats.getIntegral(), 0.0001);
            // Test sum
            Assert.assertEquals(1.0d, stats.getSum(), 0.0001);
            // Test first
            Assert.assertEquals(1.0d, stats.getFirstValue(), 0.0001);
            Assert.assertEquals((long) sampleTime.toInstant().toEpochMilli(), (long) stats.getFirstTime());
            // Test last
            Assert.assertEquals(1.0d, stats.getLastValue(), 0.0001);
            Assert.assertEquals((long) sampleTime.toInstant().toEpochMilli(), (long) stats.getLastTime());
            // Test start (the first start value will be null
            Assert.assertEquals(1.0, stats.getStartValue(), 0.0001);
            // Test count
            Assert.assertEquals(1, stats.getCount());
            // Test delta
            Assert.assertEquals(0.0, stats.getDelta(), 0.0001);
            // Move to next period time
            time = (ZonedDateTime) adjuster.adjustInto(time);
        }
    });
    quantizer.firstValue(new IdPointValueTime(1, new NumericValue(1.0), time.minusHours(3).toInstant().toEpochMilli()), 0, true);
    for (int count = 0; count < data.size(); count++) quantizer.row(data.get(count), count + 1);
    quantizer.lastValue(data.get(data.size() - 1), data.size() + 1, true);
    quantizer.done();
    Assert.assertEquals(new Integer(31), counter.getValue());
}
Also used : ArrayList(java.util.ArrayList) AnalogStatistics(com.infiniteautomation.mango.statistics.AnalogStatistics) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException) ZonedDateTime(java.time.ZonedDateTime) MutableInt(org.apache.commons.lang3.mutable.MutableInt) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) NextTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster) Test(org.junit.Test)

Example 40 with IdPointValueTime

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

the class StartsAndRuntimeListQuantizerTest method testStartValueOneValuePerPeriod.

@Test
public void testStartValueOneValuePerPeriod() throws IOException {
    // Generate data at 12 noon for every day in the period
    NextTimePeriodAdjuster adjuster = new NextTimePeriodAdjuster(TimePeriods.DAYS, 1);
    time = ZonedDateTime.of(2017, 01, 01, 12, 00, 00, 0, zoneId);
    List<IdPointValueTime> data = new ArrayList<>();
    int value = 1;
    while (time.toInstant().isBefore(to.toInstant())) {
        data.add(new IdPointValueTime(1, new MultistateValue(value), time.toInstant().toEpochMilli()));
        time = (ZonedDateTime) adjuster.adjustInto(time);
    }
    // Reset time to track periods
    time = ZonedDateTime.of(2017, 01, 01, 00, 00, 00, 0, zoneId);
    MutableInt counter = new MutableInt(0);
    BucketCalculator bc = new TimePeriodBucketCalculator(from, to, TimePeriods.DAYS, 1);
    StartsAndRuntimeListQuantizer quantizer = new StartsAndRuntimeListQuantizer(bc, new StatisticsGeneratorQuantizerCallback<StartsAndRuntimeList>() {

        @Override
        public void quantizedStatistics(StartsAndRuntimeList statisticsGenerator) throws IOException {
            counter.increment();
            StartsAndRuntimeList stats = (StartsAndRuntimeList) statisticsGenerator;
            // Test periodStart
            Assert.assertEquals(time.toInstant().toEpochMilli(), stats.getPeriodStartTime());
            // Test periiodEnd
            Assert.assertEquals(time.plusDays(1).toInstant().toEpochMilli(), stats.getPeriodEndTime());
            ZonedDateTime sampleTime = time.plusHours(12);
            // Test first
            Assert.assertEquals(1, stats.getFirstValue().getIntegerValue());
            Assert.assertEquals((long) sampleTime.toInstant().toEpochMilli(), (long) stats.getFirstTime());
            // Test last
            Assert.assertEquals(1, stats.getLastValue().getIntegerValue());
            Assert.assertEquals((long) sampleTime.toInstant().toEpochMilli(), (long) stats.getLastTime());
            // Test start (the first start value will be null
            Assert.assertEquals(1, stats.getStartValue().getIntegerValue());
            // Test count
            Assert.assertEquals(1, stats.getCount());
            // Ensure data
            Assert.assertEquals(1, stats.getStartsAndRuntime().size());
            StartsAndRuntime one = stats.getStartsAndRuntime().get(1);
            Assert.assertEquals(1, one.getStarts());
            Assert.assertEquals(100.0d, one.getPercentage(), 0.0001);
            Assert.assertEquals(1.0d, one.getProportion(), 0.0001);
            Assert.assertEquals(24 * 60 * 60 * 1000, one.getRuntime());
            // Move to next period time
            time = (ZonedDateTime) adjuster.adjustInto(time);
        }
    });
    quantizer.firstValue(new IdPointValueTime(1, new MultistateValue(1), time.minusHours(3).toInstant().toEpochMilli()), 0, true);
    for (int count = 0; count < data.size(); count++) quantizer.row(data.get(count), count + 1);
    quantizer.lastValue(data.get(data.size() - 1), data.size() + 1, true);
    quantizer.done();
    Assert.assertEquals(new Integer(31), counter.getValue());
}
Also used : ArrayList(java.util.ArrayList) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) IOException(java.io.IOException) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) StartsAndRuntime(com.infiniteautomation.mango.statistics.StartsAndRuntime) ZonedDateTime(java.time.ZonedDateTime) MutableInt(org.apache.commons.lang3.mutable.MutableInt) StartsAndRuntimeList(com.infiniteautomation.mango.statistics.StartsAndRuntimeList) NextTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster) Test(org.junit.Test)

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