use of com.infiniteautomation.mango.statistics.ValueChangeCounter in project ma-core-public by infiniteautomation.
the class ValueChangeCounterQuantizerTest method testStartValueOneValuePerPeriod.
@Test
public void testStartValueOneValuePerPeriod() throws IOException {
// Generate data at 12 noon for every day in the period
NextTimePeriodAdjuster adjuster = new NextTimePeriodAdjuster(TimePeriods.DAYS, 1);
time = ZonedDateTime.of(2017, 01, 01, 12, 00, 00, 0, zoneId);
List<IdPointValueTime> data = new ArrayList<>();
int value = 1;
while (time.toInstant().isBefore(to.toInstant())) {
data.add(new IdPointValueTime(1, new MultistateValue(value), time.toInstant().toEpochMilli()));
time = (ZonedDateTime) adjuster.adjustInto(time);
}
// Reset time to track periods
time = ZonedDateTime.of(2017, 01, 01, 00, 00, 00, 0, zoneId);
MutableInt counter = new MutableInt(0);
BucketCalculator bc = new TimePeriodBucketCalculator(from, to, TimePeriods.DAYS, 1);
ValueChangeCounterQuantizer quantizer = new ValueChangeCounterQuantizer(bc, new StatisticsGeneratorQuantizerCallback<ValueChangeCounter>() {
@Override
public void quantizedStatistics(ValueChangeCounter statisticsGenerator) throws IOException {
counter.increment();
ValueChangeCounter stats = (ValueChangeCounter) statisticsGenerator;
// Test periodStart
Assert.assertEquals(time.toInstant().toEpochMilli(), stats.getPeriodStartTime());
// Test periiodEnd
Assert.assertEquals(time.plusDays(1).toInstant().toEpochMilli(), stats.getPeriodEndTime());
ZonedDateTime sampleTime = time.plusHours(12);
// Test first
Assert.assertEquals(1, stats.getFirstValue().getIntegerValue());
Assert.assertEquals((long) sampleTime.toInstant().toEpochMilli(), (long) stats.getFirstTime());
// Test last
Assert.assertEquals(1, stats.getLastValue().getIntegerValue());
Assert.assertEquals((long) sampleTime.toInstant().toEpochMilli(), (long) stats.getLastTime());
// Test start (the first start value will be null
Assert.assertEquals(1, stats.getStartValue().getIntegerValue());
// Test count
Assert.assertEquals(1, stats.getCount());
// Test Changes
Assert.assertEquals(0, stats.getChanges());
// Move to next period time
time = (ZonedDateTime) adjuster.adjustInto(time);
}
});
quantizer.firstValue(new IdPointValueTime(1, new MultistateValue(1), time.minusHours(3).toInstant().toEpochMilli()), 0, true);
for (int count = 0; count < data.size(); count++) quantizer.row(data.get(count), count + 1);
quantizer.lastValue(data.get(data.size() - 1), data.size() + 1, true);
quantizer.done();
Assert.assertEquals(new Integer(31), counter.getValue());
}
Aggregations