Search in sources :

Example 1 with AggregateValueMapper

use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper in project ma-modules-public by infiniteautomation.

the class PointValueRestController method getRollupPointValuesAsSingleArray.

@ApiOperation(value = "Rollup values for multiple data points, return in time ascending order", notes = "From time inclusive, To time exclusive. Return in single array.", response = PointValueTimeModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, value = "/single-array/time-period/{xids}/{rollup}")
public Stream<StreamingMultiPointModel> getRollupPointValuesAsSingleArray(@ApiParam(value = "Point xids", required = true, allowMultiple = true) @PathVariable String[] xids, @ApiParam(value = "Rollup type") @PathVariable(value = "rollup") RollupEnum rollup, @ApiParam(value = "From time") @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time") @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time Period Type") @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods") @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Time zone") @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Limit, limits returned array size") @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used") @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Truncate the from time and expand to time based on the time period settings") @RequestParam(value = "truncate", required = false, defaultValue = "false") boolean truncate, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE") @RequestParam(required = false) PointValueField[] fields, Locale locale) {
    var points = Arrays.stream(xids).distinct().map(dataPointService::get).collect(Collectors.toUnmodifiableSet());
    var mapperBuilder = new StreamMapperBuilder().withDataPoints(points).withRollup(rollup).withFields(fields).withDateTimeFormat(dateTimeFormat).withTimezone(timezone, from, to).withLocale(locale).withTimestampSource(TimestampSource.STATISTIC);
    var defaultMapper = mapperBuilder.build(DefaultStreamMapper::new);
    var aggregateMapper = mapperBuilder.build(AggregateValueMapper::new);
    from = from.withZoneSameInstant(defaultMapper.getZoneId());
    to = to.withZoneSameInstant(defaultMapper.getZoneId());
    TemporalAmount rollupPeriod;
    if (timePeriodType == null || timePeriods == null) {
        rollupPeriod = Duration.between(from, to);
    } else {
        if (truncate) {
            from = from.with(new TruncateTimePeriodAdjuster(timePeriodType.getChronoUnit(), timePeriods));
            to = to.with(new ExpandTimePeriodAdjuster(from, timePeriodType.getChronoUnit(), timePeriods));
        }
        rollupPeriod = timePeriodType.toTemporalAmount(timePeriods);
    }
    // limit is a total limit, however may as well limit per point
    var streamGenerator = rollupStream(from, to, limit, rollup, rollupPeriod, defaultMapper, aggregateMapper);
    var streams = points.stream().map(streamGenerator).collect(Collectors.toUnmodifiableList());
    // merge the streams and group by timestamp
    var mergedStream = MergingIterator.mergeStreams(streams, Comparator.comparingLong(StreamingPointValueTimeModel::getExactTimestamp));
    var grouped = TimestampGrouper.groupByTimestamp(mergedStream, defaultMapper::formatTime);
    return limit == null ? grouped : grouped.limit(limit);
}
Also used : DefaultStreamMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.DefaultStreamMapper) ExpandTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.ExpandTimePeriodAdjuster) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) TemporalAmount(java.time.temporal.TemporalAmount) TruncateTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.TruncateTimePeriodAdjuster) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AggregateValueMapper

use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper in project ma-modules-public by infiniteautomation.

the class PointValueRestController method getRollupPointValuesAsMultipleArrays.

@ApiOperation(value = "Rollup values for multiple data points, return in time ascending order", notes = "From time inclusive, To time exclusive.  Returns a map of xid to point value time arrays.", response = PointValueTimeModel.class, responseContainer = "Object")
@RequestMapping(method = RequestMethod.GET, value = "/multiple-arrays/time-period/{xids}/{rollup}")
public Map<String, Stream<StreamingPointValueTimeModel>> getRollupPointValuesAsMultipleArrays(@ApiParam(value = "Point xids", required = true, allowMultiple = true) @PathVariable String[] xids, @ApiParam(value = "Rollup type") @PathVariable(value = "rollup") RollupEnum rollup, @ApiParam(value = "From time") @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time") @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time Period Type") @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods") @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Time zone") @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Limit (per series)") @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used") @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Truncate the from time and expand to time based on the time period settings") @RequestParam(value = "truncate", required = false, defaultValue = "false") boolean truncate, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE") @RequestParam(required = false) PointValueField[] fields, Locale locale) {
    var points = Arrays.stream(xids).distinct().map(dataPointService::get).collect(Collectors.toUnmodifiableSet());
    var mapperBuilder = new StreamMapperBuilder().withDataPoints(points).withRollup(rollup).withFields(fields).withDateTimeFormat(dateTimeFormat).withTimezone(timezone, from, to).withLocale(locale);
    var defaultMapper = mapperBuilder.build(DefaultStreamMapper::new);
    var aggregateMapper = mapperBuilder.build(AggregateValueMapper::new);
    from = from.withZoneSameInstant(defaultMapper.getZoneId());
    to = to.withZoneSameInstant(defaultMapper.getZoneId());
    TemporalAmount rollupPeriod;
    if (timePeriodType == null || timePeriods == null) {
        rollupPeriod = Duration.between(from, to);
    } else {
        if (truncate) {
            from = from.with(new TruncateTimePeriodAdjuster(timePeriodType.getChronoUnit(), timePeriods));
            to = to.with(new ExpandTimePeriodAdjuster(from, timePeriodType.getChronoUnit(), timePeriods));
        }
        rollupPeriod = timePeriodType.toTemporalAmount(timePeriods);
    }
    var streamGenerator = rollupStream(from, to, limit, rollup, rollupPeriod, defaultMapper, aggregateMapper);
    return points.stream().collect(Collectors.toUnmodifiableMap(DataPointVO::getXid, streamGenerator));
}
Also used : DefaultStreamMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.DefaultStreamMapper) ExpandTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.ExpandTimePeriodAdjuster) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) TemporalAmount(java.time.temporal.TemporalAmount) TruncateTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.TruncateTimePeriodAdjuster) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AggregateValueMapper

use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper in project ma-modules-public by infiniteautomation.

the class PointValueRestController method getRollupPointValues.

@ApiOperation(value = "Rollup values For 1 Data Point, return in time ascending order", notes = "From time inclusive, To time exclusive.", response = PointValueTimeModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, value = "/time-period/{xid}/{rollup}")
public Stream<StreamingPointValueTimeModel> getRollupPointValues(@ApiParam(value = "Point xid", required = true) @PathVariable String xid, @ApiParam(value = "Rollup type") @PathVariable(value = "rollup") RollupEnum rollup, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used") @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "From time") @RequestParam(value = "from") @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time") @RequestParam(value = "to") @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time zone") @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Limit") @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Time Period Type") @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods") @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Truncate the from time and expand to time based on the time period settings") @RequestParam(value = "truncate", required = false, defaultValue = "false") boolean truncate, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE") @RequestParam(required = false) PointValueField[] fields, Locale locale) {
    DataPointVO point = dataPointService.get(xid);
    var mapperBuilder = new StreamMapperBuilder().withDataPoint(point).withRollup(rollup).withFields(fields).withDateTimeFormat(dateTimeFormat).withTimezone(timezone, from, to).withLocale(locale);
    var defaultMapper = mapperBuilder.build(DefaultStreamMapper::new);
    var aggregateMapper = mapperBuilder.build(AggregateValueMapper::new);
    from = from.withZoneSameInstant(defaultMapper.getZoneId());
    to = to.withZoneSameInstant(defaultMapper.getZoneId());
    TemporalAmount rollupPeriod;
    if (timePeriodType == null || timePeriods == null) {
        rollupPeriod = Duration.between(from, to);
    } else {
        if (truncate) {
            from = from.with(new TruncateTimePeriodAdjuster(timePeriodType.getChronoUnit(), timePeriods));
            to = to.with(new ExpandTimePeriodAdjuster(from, timePeriodType.getChronoUnit(), timePeriods));
        }
        rollupPeriod = timePeriodType.toTemporalAmount(timePeriods);
    }
    return rollupStream(from, to, limit, rollup, rollupPeriod, defaultMapper, aggregateMapper).apply(point);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DefaultStreamMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.DefaultStreamMapper) ExpandTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.ExpandTimePeriodAdjuster) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) TemporalAmount(java.time.temporal.TemporalAmount) TruncateTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.TruncateTimePeriodAdjuster) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with AggregateValueMapper

use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper in project ma-modules-public by infiniteautomation.

the class PointValueRestController method getStatistics.

@ApiOperation(value = "GET statistics for data point(s) over the given time range", notes = "From time inclusive, To time exclusive. Returns map of xid to Statistics object", response = PointValueTimeModel.class, responseContainer = "Map")
@RequestMapping(method = RequestMethod.GET, value = "/statistics/{xids}")
public Map<String, StreamingPointValueTimeModel> getStatistics(@ApiParam(value = "Point xids", required = true, allowMultiple = true) @PathVariable String[] xids, @ApiParam(value = "From time") @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time") @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time zone") @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used") @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE") @RequestParam(required = false) PointValueField[] fields, Locale locale) {
    var points = Arrays.stream(xids).distinct().map(dataPointService::get).collect(Collectors.toUnmodifiableSet());
    var mapperBuilder = new StreamMapperBuilder().withDataPoints(points).withRollup(RollupEnum.ALL).withFields(fields).withDateTimeFormat(dateTimeFormat).withTimezone(timezone, from, to).withLocale(locale).withTimestampSource(TimestampSource.STATISTIC);
    var aggregateMapper = mapperBuilder.build(AggregateValueMapper::new);
    var rollupPeriod = Duration.between(from, to);
    return points.stream().collect(Collectors.toUnmodifiableMap(DataPointVO::getXid, point -> {
        var aggregateDao = dao.getAggregateDao();
        try (var stream = aggregateDao.query(point, from, to, null, rollupPeriod)) {
            return stream.map(aggregateMapper).findAny().orElseThrow();
        }
    }));
}
Also used : Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) Duration(java.time.Duration) Map(java.util.Map) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) PointValueTimeModel(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeModel) RuntimeManager(com.serotonin.m2m2.rt.RuntimeManager) XidTimeRangeQueryModel(com.infiniteautomation.mango.rest.latest.model.pointValue.query.XidTimeRangeQueryModel) RestController(org.springframework.web.bind.annotation.RestController) ZoneId(java.time.ZoneId) Stream(java.util.stream.Stream) DateUtils(com.serotonin.m2m2.util.DateUtils) TimestampSource(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.TimestampSource) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) DataSourceService(com.infiniteautomation.mango.spring.service.DataSourceService) StreamingMultiPointModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingMultiPointModel) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) DataType(com.serotonin.m2m2.DataType) PointValueTimeCacheControl(com.infiniteautomation.mango.rest.latest.model.pointValue.query.PointValueTimeCacheControl) MergingIterator(com.infiniteautomation.mango.db.iterators.MergingIterator) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) TemporalAmount(java.time.temporal.TemporalAmount) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) Api(io.swagger.annotations.Api) TemporaryResourceWebSocketHandler(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResourceWebSocketHandler) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) PointValueField(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField) Common(com.serotonin.m2m2.Common) StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) XidLatestQueryInfoModel(com.infiniteautomation.mango.rest.latest.model.pointValue.query.XidLatestQueryInfoModel) HttpStatus(org.springframework.http.HttpStatus) SystemSettingsDao(com.serotonin.m2m2.db.dao.SystemSettingsDao) RTException(com.serotonin.m2m2.rt.RTException) RollupEnum(com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum) PointValueImportResult(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueImportResult) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) PurgePointValuesResponseModel(com.infiniteautomation.mango.rest.latest.model.pointValue.PurgePointValuesResponseModel) LoggerFactory(org.slf4j.LoggerFactory) GenericRestException(com.infiniteautomation.mango.rest.latest.exception.GenericRestException) ExpandTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.ExpandTimePeriodAdjuster) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) ApiOperation(io.swagger.annotations.ApiOperation) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) Locale(java.util.Locale) SimplifyUtility(com.goebl.simplify.SimplifyUtility) ITime(com.serotonin.m2m2.view.stats.ITime) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) URI(java.net.URI) PointValueTimePointExtractor(com.infiniteautomation.mango.rest.pointextractor.PointValueTimePointExtractor) TemporaryResourceStatusUpdate(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResourceStatusUpdate) UnitConverter(javax.measure.converter.UnitConverter) TimePeriodType(com.infiniteautomation.mango.rest.latest.model.time.TimePeriodType) PurgeDataPointValuesModel(com.infiniteautomation.mango.rest.latest.model.pointValue.PurgeDataPointValuesModel) XidRollupTimeRangeQueryModel(com.infiniteautomation.mango.rest.latest.model.pointValue.query.XidRollupTimeRangeQueryModel) TimeZone(java.util.TimeZone) HttpHeaders(org.springframework.http.HttpHeaders) SetPointSource(com.serotonin.m2m2.rt.dataImage.SetPointSource) Collection(java.util.Collection) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ISO(org.springframework.format.annotation.DateTimeFormat.ISO) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) Environment(org.springframework.core.env.Environment) Entry(java.util.Map.Entry) Optional(java.util.Optional) TimeOrder(com.serotonin.m2m2.db.dao.pointvalue.TimeOrder) LegacyXidPointValueTimeModel(com.infiniteautomation.mango.rest.latest.model.pointValue.LegacyXidPointValueTimeModel) User(com.serotonin.m2m2.vo.User) TimestampGrouper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.TimestampGrouper) NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TemporaryResourceStatus(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.TemporaryResourceStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) Function(java.util.function.Function) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) DefaultStreamMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.DefaultStreamMapper) TruncateTimePeriodAdjuster(com.infiniteautomation.mango.util.datetime.TruncateTimePeriodAdjuster) FireEvents(com.serotonin.m2m2.rt.dataImage.DataPointRT.FireEvents) ServerErrorException(com.infiniteautomation.mango.rest.latest.exception.ServerErrorException) Nullable(org.checkerframework.checker.nullness.qual.Nullable) TemporaryResource(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource) Logger(org.slf4j.Logger) MangoTaskTemporaryResourceManager(com.infiniteautomation.mango.rest.latest.temporaryResource.MangoTaskTemporaryResourceManager) LegacyPointValueTimeModel(com.infiniteautomation.mango.rest.latest.model.pointValue.LegacyPointValueTimeModel) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) ResponseEntity(org.springframework.http.ResponseEntity) AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException) Comparator(java.util.Comparator) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) AggregateValueMapper(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper) StreamMapperBuilder(com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AggregateValueMapper

use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper 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)

Aggregations

AggregateValueMapper (com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.AggregateValueMapper)5 StreamMapperBuilder (com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder)5 DefaultStreamMapper (com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.DefaultStreamMapper)4 ExpandTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.ExpandTimePeriodAdjuster)4 TruncateTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.TruncateTimePeriodAdjuster)4 ApiOperation (io.swagger.annotations.ApiOperation)4 TemporalAmount (java.time.temporal.TemporalAmount)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 PointValueField (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField)2 RollupEnum (com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum)2 TimestampSource (com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.TimestampSource)2 StreamingPointValueTimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel)2 Common (com.serotonin.m2m2.Common)2 DataType (com.serotonin.m2m2.DataType)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)2 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)2