use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by MangoAutomation.
the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesInRange.
@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesInRange() {
DataPointWithEventDetectors dp = createDisabledPoint(1.0, null, TimePeriods.SECONDS, false, CalculationMode.INSTANTANEOUS, 0, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN, 0, TimePeriods.SECONDS);
// Save some values
PointValueDao dao = Common.getBean(PointValueDao.class);
dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.001, 0));
dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.0003, 100));
timer.fastForwardTo(timer.currentTimeMillis() + 200);
dp.getDataPoint().setEnabled(true);
Common.runtimeManager.startDataPoint(dp);
DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
ensureSetPointValue(rt, new PointValueTime(0.0005, timer.currentTimeMillis()));
timer.fastForwardTo(timer.currentTimeMillis() + 500);
ensureSetPointValue(rt, new PointValueTime(0.0009, timer.currentTimeMillis()));
timer.fastForwardTo(timer.currentTimeMillis() + 4500);
assertEquals(0, listener.raised.size());
assertEquals(0, listener.rtn.size());
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by MangoAutomation.
the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeReset.
@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeReset() {
DataPointWithEventDetectors dp = createDisabledPoint(1.0, 0.9, TimePeriods.SECONDS, false, CalculationMode.INSTANTANEOUS, 0, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN, 0, TimePeriods.SECONDS);
// Save some values
PointValueDao dao = Common.getBean(PointValueDao.class);
dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.0, 0));
dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(1.1, 100));
timer.fastForwardTo(1000);
dp.getDataPoint().setEnabled(true);
Common.runtimeManager.startDataPoint(dp);
DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
assertEquals(0, listener.raised.size());
assertEquals(0, listener.rtn.size());
timer.fastForwardTo(1500);
ensureSetPointValue(rt, new PointValueTime(2.1, timer.currentTimeMillis()));
timer.fastForwardTo(1501);
assertEquals(0, listener.raised.size());
assertEquals(0, listener.rtn.size());
timer.fastForwardTo(1600);
ensureSetPointValue(rt, new PointValueTime(3.2, timer.currentTimeMillis()));
timer.fastForwardTo(1601);
assertEquals(1, listener.raised.size());
assertEquals(1600, listener.raised.get(0).getActiveTimestamp());
assertEquals(0, listener.rtn.size());
timer.fastForwardTo(2000);
ensureSetPointValue(rt, new PointValueTime(0.5, timer.currentTimeMillis()));
timer.fastForwardTo(2001);
assertEquals(1, listener.raised.size());
assertEquals(1, listener.rtn.size());
assertEquals(2000, (long) listener.rtn.get(0).getRtnTimestamp());
// See RoC Return to 0
timer.fastForwardTo(4500);
ensureSetPointValue(rt, new PointValueTime(0.9, timer.currentTimeMillis()));
timer.fastForwardTo(5000);
assertEquals(1, listener.raised.size());
assertEquals(1, listener.rtn.size());
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by MangoAutomation.
the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesInRangeAverage.
@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesInRangeAverage() {
DataPointWithEventDetectors dp = createDisabledPoint(1.0, null, TimePeriods.SECONDS, false, CalculationMode.AVERAGE, 1, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN, 0, TimePeriods.SECONDS);
// Save some values
PointValueDao dao = Common.getBean(PointValueDao.class);
dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.001, 0));
dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.0003, 100));
timer.fastForwardTo(timer.currentTimeMillis() + 200);
dp.getDataPoint().setEnabled(true);
Common.runtimeManager.startDataPoint(dp);
DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
ensureSetPointValue(rt, new PointValueTime(0.0005, timer.currentTimeMillis()));
timer.fastForwardTo(timer.currentTimeMillis() + 500);
ensureSetPointValue(rt, new PointValueTime(0.0009, timer.currentTimeMillis()));
timer.fastForwardTo(timer.currentTimeMillis() + 4500);
assertEquals(0, listener.raised.size());
assertEquals(0, listener.rtn.size());
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by MangoAutomation.
the class DataPointService method getWithEventDetectors.
/**
* Get a data point and its detectors from the database
*/
public DataPointWithEventDetectors getWithEventDetectors(String xid) throws PermissionException, NotFoundException {
DataPointVO vo = get(xid);
List<AbstractPointEventDetectorVO> detectors = eventDetectorDao.getWithSource(vo.getId(), vo);
return new DataPointWithEventDetectors(vo, detectors);
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by MangoAutomation.
the class DataPointService method insert.
@Override
public DataPointVO insert(DataPointVO vo) throws PermissionException, ValidationException {
PermissionHolder user = Common.getUser();
// Ensure they can create
ensureCreatePermission(user, vo);
// Ensure id is not set
if (vo.getId() != Common.NEW_ID) {
ProcessResult result = new ProcessResult();
result.addContextualMessage("id", "validate.invalidValue");
throw new ValidationException(result);
}
// Generate an Xid if necessary
if (StringUtils.isEmpty(vo.getXid()))
vo.setXid(dao.generateUniqueXid());
for (DataPointChangeDefinition def : changeDefinitions) {
def.preInsert(vo);
}
ensureValid(vo);
dao.insert(vo);
List<AbstractPointEventDetectorVO> detectors = new ArrayList<>();
for (DataPointChangeDefinition def : changeDefinitions) {
for (var detector : def.postInsert(vo)) {
if (detector.isNew()) {
log.warn("Detector added via postInsert hook was not saved");
} else if (detector.getDataPoint().getId() != vo.getId()) {
log.warn("Detector added via postInsert hook was for a different data point");
} else {
detectors.add(detector);
}
}
}
if (vo.isEnabled()) {
// the data point cannot have detectors if it was just inserted, don't query for detectors
getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
}
return vo;
}
Aggregations