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()));
}
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);
}
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);
}
Aggregations