use of com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel in project ma-modules-public by infiniteautomation.
the class AggregateValueMapper method apply.
@Override
public StreamingPointValueTimeModel apply(SeriesValueTime<? extends AggregateValue> value) {
DataPointVO point = lookupPoint(value.getSeriesId());
RollupEnum rollup = rollup(point);
AggregateValue aggregate = value.getValue();
StreamingPointValueTimeModel model = new StreamingPointValueTimeModel(point.getXid(), value.getTime());
if (rollup == RollupEnum.ALL) {
AllStatisticsModel allStatisticsModel = getAllRollup(point, aggregate);
model.setAllStatistics(allStatisticsModel);
} else {
ValueTimeModel rollupValue = getRollupValue(point, aggregate, rollup);
model.setValueModel(rollupValue);
}
if (fields.contains(PointValueField.CACHED)) {
model.setCached(false);
}
if (fields.contains(PointValueField.BOOKEND)) {
model.setBookend(false);
}
return copyPointPropertiesToModel(point, model);
}
use of com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel in project ma-modules-public by infiniteautomation.
the class DefaultStreamMapper method apply.
@Override
public StreamingPointValueTimeModel apply(IdPointValueTime valueTime) {
DataPointVO point = lookupPoint(valueTime.getSeriesId());
StreamingPointValueTimeModel model = new StreamingPointValueTimeModel(point.getXid(), valueTime.getTime());
model.setValueModel(getValue(point, valueTime));
if (fields.contains(PointValueField.CACHED)) {
model.setCached(valueTime.isFromCache());
}
if (fields.contains(PointValueField.BOOKEND)) {
model.setBookend(valueTime.isBookend());
}
if (fields.contains(PointValueField.ANNOTATION)) {
if (valueTime instanceof IAnnotated) {
model.setAnnotation(((IAnnotated) valueTime).getSourceMessage());
}
}
return copyPointPropertiesToModel(point, model);
}
use of com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel 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.model.StreamingPointValueTimeModel 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