use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.
the class RateOfChangeDetectorTest method testNoValuesSetTwoInitialValues.
/**
* Two initial values before point starts, no values set during test
*/
@Test
public void testNoValuesSetTwoInitialValues() {
DataPointWithEventDetectors dp = createDisabledPoint(1.0, 1.1, TimePeriods.SECONDS, false, CalculationMode.INSTANTANEOUS, 0, TimePeriods.SECONDS, ComparisonMode.LESS_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(0.5, 500));
timer.fastForwardTo(1000);
dp.getDataPoint().setEnabled(true);
Common.runtimeManager.startDataPoint(dp);
DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
// An event will not be active as the RoC is uncomputable with no value at the period start
assertEquals(0, listener.raised.size());
assertEquals(0, listener.rtn.size());
ensureSetPointValue(rt, new PointValueTime(0.9, timer.currentTimeMillis()));
timer.fastForwardTo(1200);
// An event will active as the RoC is (0.9 - 0.5)/500 < 1/s
assertEquals(1, listener.raised.size());
assertEquals(1000, listener.raised.get(0).getActiveTimestamp());
ensureSetPointValue(rt, new PointValueTime(2.2, timer.currentTimeMillis()));
timer.fastForwardTo(1500);
assertEquals(1, listener.raised.size());
assertEquals(1, listener.rtn.size());
assertEquals(1200, (long) listener.rtn.get(0).getRtnTimestamp());
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.
the class RateOfChangeDetectorTest method createRunningPoint.
// TODO Test no values set, 1 initial value
// TODO Test no values set, 0 initial values
/**
* Create a running datapoint with no initial values
*
* NOTE: The poll period is 1s for the data source
*
* @param durationPeriods - duration for RoC to match its comparison before event will go active
* @param durationPeriodType - duration for RoC to match its comparison before event will go active
*/
protected DataPointRT createRunningPoint(double rocThreshold, Double resetThreshold, int rocThresholdPeriodType, boolean useAbsoluteValue, CalculationMode calculationMode, int rocDuration, int rocDurationType, ComparisonMode comparisonMode, int durationPeriods, int durationPeriodType) {
DataPointWithEventDetectors dp = createDisabledPoint(rocThreshold, resetThreshold, rocThresholdPeriodType, useAbsoluteValue, calculationMode, rocDuration, rocDurationType, comparisonMode, durationPeriods, durationPeriodType);
dp.getDataPoint().setEnabled(true);
Common.runtimeManager.startDataPoint(dp);
return Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.
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 infiniteautomation.
the class DataPointDao method getDataPointsForDataSourceStart.
/**
* Get points for runtime in an efficient manner by joining with the event detectors and only returning
* data points that are enabled
*/
public List<DataPointWithEventDetectors> getDataPointsForDataSourceStart(int dataSourceId) {
List<Field<?>> fields = new ArrayList<>(this.getSelectFields());
fields.addAll(Arrays.asList(eventDetectors.fields()));
Select<Record> select = this.joinTables(this.getSelectQuery(fields), null).leftOuterJoin(eventDetectors).on(table.id.eq(eventDetectors.dataPointId)).where(table.dataSourceId.eq(dataSourceId).and(table.enabled.eq(boolToChar(true))));
Map<Integer, DataPointWithEventDetectors> result = new HashMap<>();
try (Cursor<Record> cursor = select.fetchLazy()) {
for (Record record : cursor) {
int id = record.get(table.id);
DataPointWithEventDetectors dp = result.computeIfAbsent(id, (i) -> {
DataPointVO dpvo = this.mapRecord(record);
loadRelationalData(dpvo);
return new DataPointWithEventDetectors(dpvo, new ArrayList<>());
});
AbstractPointEventDetectorVO detector = eventDetectorDao.mapPointEventDetector(record, dp.getDataPoint());
if (detector != null) {
dp.getEventDetectors().add(detector);
}
}
}
return new ArrayList<>(result.values());
}
use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.
the class RuntimeManagerImpl method startDataPoint.
@Override
public void startDataPoint(DataPointWithEventDetectors vo, @Nullable List<PointValueTime> initialCache) {
DataPointVO dataPointVO = vo.getDataPoint();
// Ensure that the data point is saved and enabled.
Assert.isTrue(dataPointVO.getId() > 0, "Data point must be saved");
Assert.isTrue(dataPointVO.isEnabled(), "Data point not enabled");
ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
// Only add the data point if its data source is enabled.
DataSourceRT<? extends DataSourceVO> ds = runningDataSources.get(dataPointVO.getDataSourceId());
if (ds != null) {
DataPointRT dataPoint = dataPointCache.computeIfAbsent(dataPointVO.getId(), k -> new DataPointRT(vo, dataPointVO.getPointLocator().createRuntime(), ds, initialCache, pointValueDao, pointValueCache));
// Initialize it, will fail if data point is already initializing or running
dataPoint.initialize(false);
}
}
Aggregations