use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder 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();
}
}));
}
use of com.infiniteautomation.mango.rest.latest.streamingvalues.mapper.StreamMapperBuilder 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()));
}
Aggregations