Search in sources :

Example 11 with PointValueField

use of com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField in project ma-modules-public by infiniteautomation.

the class MultiPointStatisticsStreamTest method getStatistics.

private Map<String, StreamingPointValueTimeModel> getStatistics(Collection<? extends DataPointVO> points, ZonedDateTime from, ZonedDateTime to, String timezone, PointValueField[] fields) {
    // AbstractStreamMapper stores itself in a request attribute for retrieval inside HttpMessageConverter
    MockHttpServletRequest request = new MockHttpServletRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    var mapper = new StreamMapperBuilder().withDataPoints(points).withRollup(RollupEnum.ALL).withFields(fields).withTimezone(timezone, from, to).withTimestampSource(TimestampSource.STATISTIC).build(AggregateValueMapper::new);
    return points.stream().collect(Collectors.toMap(DataPointVO::getXid, point -> pointValueDao.getAggregateDao().query(point, from, to, null, Duration.between(from, to)).map(mapper).findAny().orElseThrow()));
}
Also used : StatisticsGenerator(com.serotonin.m2m2.view.stats.StatisticsGenerator) DataSourceDao(com.serotonin.m2m2.db.dao.DataSourceDao) Module(com.serotonin.m2m2.module.Module) REST_OBJECT_MAPPER_NAME(com.infiniteautomation.mango.spring.MangoRuntimeContextConfiguration.REST_OBJECT_MAPPER_NAME) ZonedDateTime(java.time.ZonedDateTime) MockRuntimeManager(com.serotonin.m2m2.MockRuntimeManager) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) RequestContextHolder(org.springframework.web.context.request.RequestContextHolder) ValueChangeCounter(com.infiniteautomation.mango.statistics.ValueChangeCounter) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder) AnalogStatistics(com.infiniteautomation.mango.statistics.AnalogStatistics) StartsAndRuntimeList(com.infiniteautomation.mango.statistics.StartsAndRuntimeList) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) Duration(java.time.Duration) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) JsonNode(com.fasterxml.jackson.databind.JsonNode) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) Collection(java.util.Collection) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Collectors(java.util.stream.Collectors) StartsAndRuntime(com.infiniteautomation.mango.statistics.StartsAndRuntime) ZoneId(java.time.ZoneId) List(java.util.List) MockMangoLifecycle(com.serotonin.m2m2.MockMangoLifecycle) TimestampSource(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.TimestampSource) BeforeClass(org.junit.BeforeClass) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) DataType(com.serotonin.m2m2.DataType) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) MangoTestBase(com.serotonin.m2m2.MangoTestBase) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) PointValueField(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField) Common(com.serotonin.m2m2.Common) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) ApplicationContext(org.springframework.context.ApplicationContext) LoggingTypes(com.serotonin.m2m2.vo.DataPointVO.LoggingTypes) RollupEnum(com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum) Assert.assertEquals(org.junit.Assert.assertEquals) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder)

Example 12 with PointValueField

use of com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField in project ma-modules-public by infiniteautomation.

the class MultiPointStatisticsStreamTest method testSingleNumericPointNoCacheChangeInitialValue.

@Test
public void testSingleNumericPointNoCacheChangeInitialValue() {
    // Setup the data to run once daily for 30 days
    ZonedDateTime from = ZonedDateTime.of(2017, 1, 1, 0, 0, 0, 0, zoneId);
    ZonedDateTime to = ZonedDateTime.of(2017, 2, 1, 0, 0, 0, 0, zoneId);
    Duration adjuster = Duration.ofDays(1);
    MockDataSourceVO ds = createDataSource();
    DataPointVO dp = createDataPoint(ds.getId(), DataType.NUMERIC, 1);
    DataPointWrapper<AnalogStatistics> wrapper = new DataPointWrapper<>(ds, dp, new PointValueTime(1.0, 0), (value) -> new NumericValue(value.getDoubleValue() + 1.0), (w) -> new AnalogStatistics(from.toInstant().toEpochMilli(), to.toInstant().toEpochMilli(), w.initialValue, w.values), new AnalogStatisticsVerifier());
    // Insert the data skipping first day so we get the initial value
    ZonedDateTime time = from.plus(adjuster);
    timer.setStartTime(time.toInstant().toEpochMilli());
    while (time.toInstant().isBefore(to.toInstant())) {
        wrapper.updatePointValue(new PointValueTime(wrapper.getNextValue(), time.toInstant().toEpochMilli()));
        time = time.plus(adjuster);
        timer.fastForwardTo(time.toInstant().toEpochMilli());
    }
    // Perform the query
    String timezone = zoneId.getId();
    PointValueField[] fields = getFields();
    var result = getStatistics(List.of(dp), from, to, timezone, fields);
    test(result, wrapper);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) AnalogStatistics(com.infiniteautomation.mango.statistics.AnalogStatistics) Duration(java.time.Duration) ZonedDateTime(java.time.ZonedDateTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) PointValueField(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField) Test(org.junit.Test)

Example 13 with PointValueField

use of com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField in project ma-modules-public by infiniteautomation.

the class MultiPointStatisticsStreamTest method testSingleAlphanumericPointNoCacheNoChangeInitialValue.

@Test
public void testSingleAlphanumericPointNoCacheNoChangeInitialValue() {
    // Setup the data to run once daily for 30 days
    ZonedDateTime from = ZonedDateTime.of(2017, 1, 1, 0, 0, 0, 0, zoneId);
    ZonedDateTime to = ZonedDateTime.of(2017, 2, 1, 0, 0, 0, 0, zoneId);
    Duration adjuster = Duration.ofDays(1);
    MockDataSourceVO ds = createDataSource();
    DataPointVO dp = createDataPoint(ds.getId(), DataType.ALPHANUMERIC, 1);
    DataPointWrapper<ValueChangeCounter> point = new DataPointWrapper<>(ds, dp, new PointValueTime("TESTING", 0), // no change
    Function.identity(), (w) -> new ValueChangeCounter(from.toInstant().toEpochMilli(), to.toInstant().toEpochMilli(), w.initialValue, w.values), new ValueChangeCounterVerifier());
    // Insert the data skipping first day so we get the initial value
    ZonedDateTime time = from.plus(adjuster);
    timer.setStartTime(time.toInstant().toEpochMilli());
    while (time.toInstant().isBefore(to.toInstant())) {
        point.updatePointValue(new PointValueTime(point.getNextValue(), time.toInstant().toEpochMilli()));
        time = time.plus(adjuster);
        timer.fastForwardTo(time.toInstant().toEpochMilli());
    }
    // Perform the query
    String timezone = zoneId.getId();
    PointValueField[] fields = getFields();
    var result = getStatistics(List.of(dp), from, to, timezone, fields);
    test(result, point);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) Duration(java.time.Duration) ZonedDateTime(java.time.ZonedDateTime) ValueChangeCounter(com.infiniteautomation.mango.statistics.ValueChangeCounter) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) PointValueField(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField) Test(org.junit.Test)

Aggregations

PointValueField (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField)13 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)13 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)11 ZonedDateTime (java.time.ZonedDateTime)11 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)10 Test (org.junit.Test)10 AnalogStatistics (com.infiniteautomation.mango.statistics.AnalogStatistics)9 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)8 Duration (java.time.Duration)7 StartsAndRuntimeList (com.infiniteautomation.mango.statistics.StartsAndRuntimeList)5 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)5 Instant (java.time.Instant)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 NextTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster)4 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)4 RollupEnum (com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum)3 ValueChangeCounter (com.infiniteautomation.mango.statistics.ValueChangeCounter)3 Map (java.util.Map)3 AggregateValueMapper (com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper)2 StreamMapperBuilder (com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder)2