Search in sources :

Example 31 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-modules-public by infiniteautomation.

the class SerialDataSourceTestData method getNewlineTerminated.

public static DataPointRT getNewlineTerminated(DataSourceRT<? extends DataSourceVO> ds) {
    DataPointVO vo = new DataPointVO();
    vo.setName("newlineTerminated");
    vo.setXid("newlineTerminated");
    vo.setId(currentId++);
    vo.setDataSourceId(ds.getId());
    SerialPointLocatorVO plVo = new SerialPointLocatorVO();
    plVo.setDataType(DataType.ALPHANUMERIC);
    plVo.setValueRegex(PATTERNS.get(vo.getName()));
    plVo.setValueIndex(2);
    plVo.setPointIdentifier("");
    vo.setPointLocator(plVo);
    return new DataPointRT(new DataPointWithEventDetectors(vo, new ArrayList<>()), plVo.createRuntime(), ds, null, Common.getBean(PointValueDao.class), Common.getBean(PointValueCache.class), null);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ArrayList(java.util.ArrayList) SerialPointLocatorVO(com.infiniteautomation.serial.vo.SerialPointLocatorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache)

Example 32 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class RateOfChangeDetectorTest method testDifferentThresholdPeriodToAverage.

/**
 * Change of 1.0/s in 10 seconds
 */
@Test
public void testDifferentThresholdPeriodToAverage() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, 0.5, TimePeriods.SECONDS, false, CalculationMode.AVERAGE, 10, 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(0.1, 1000));
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.2, 2000));
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.3, 3000));
    timer.fastForwardTo(10000);
    dp.getDataPoint().setEnabled(true);
    Common.runtimeManager.startDataPoint(dp);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
    timer.fastForwardTo(10999);
    assertEquals(0, listener.raised.size());
    assertEquals(0, listener.rtn.size());
    ensureSetPointValue(rt, new PointValueTime(10.3, timer.currentTimeMillis()));
    timer.fastForwardTo(11000);
    assertEquals(1, listener.raised.size());
    assertEquals(10999, listener.raised.get(0).getActiveTimestamp());
    assertEquals(0, listener.rtn.size());
    ensureSetPointValue(rt, new PointValueTime(11.3, timer.currentTimeMillis()));
    timer.fastForwardTo(13000);
    // Nothing raised as our change is only 1 in the last 10s
    assertEquals(1, listener.raised.size());
    assertEquals(0, listener.rtn.size());
    ensureSetPointValue(rt, new PointValueTime(21.4, timer.currentTimeMillis()));
    timer.fastForwardTo(13999);
    assertEquals(1, listener.raised.size());
    assertEquals(0, listener.rtn.size());
    // Allow reset of alarm after 10s and no change
    timer.fastForwardTo(26000);
    assertEquals(1, listener.rtn.size());
    assertEquals(23000, (long) listener.rtn.get(0).getRtnTimestamp());
    ensureSetPointValue(rt, new PointValueTime(41.4, timer.currentTimeMillis()));
    timer.fastForwardTo(33000);
    assertEquals(2, listener.raised.size());
    assertEquals(26000, listener.raised.get(1).getActiveTimestamp());
    assertEquals(1, listener.rtn.size());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Test(org.junit.Test)

Example 33 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

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());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Test(org.junit.Test)

Example 34 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesOneValueOutOfRangeForOneSecondAverage.

/**
 * Settings:
 *   RoC Threshold: 1.0/Second
 *   reset Threshold: none
 *   RoC Averaging Period: 1 Second
 *   useAbsoluteValue: false
 *   calculationMode: AVERAGE
 *   comparisonMode: GREATER_THAN
 *   duration: 1 Seconds
 *
 * Initial value(s): 0.1 at 0, 1.101 at 100
 *
 * Test:
 *   advance to 1000 and start point, ensure no events raised
 *   set value to 2.5 at 1000
 *   advance to 1001 ensure no events raised
 *   advance to 2000
 *
 * Result: No events raised
 */
@Test
public void testOneSecondPeriodTwoInitialValuesOneValueOutOfRangeForOneSecondAverage() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, null, TimePeriods.SECONDS, false, CalculationMode.AVERAGE, 1, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN, 1, TimePeriods.SECONDS);
    // Save some values
    PointValueDao dao = Common.getBean(PointValueDao.class);
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.1, 0));
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(1.101, 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());
    ensureSetPointValue(rt, new PointValueTime(2.5, timer.currentTimeMillis()));
    timer.fastForwardTo(1001);
    assertEquals(0, listener.raised.size());
    assertEquals(0, listener.rtn.size());
    timer.fastForwardTo(2000);
    assertEquals(1, listener.raised.size());
    assertEquals(2000, listener.raised.get(0).getActiveTimestamp());
    assertEquals(1, listener.rtn.size());
    assertEquals(2000, (long) listener.rtn.get(0).getRtnTimestamp());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Test(org.junit.Test)

Example 35 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeResetAverage.

@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeResetAverage() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, 0.9, 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.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());
    timer.fastForwardTo(1500);
    assertEquals(1, listener.raised.size());
    assertEquals(1000, listener.raised.get(0).getActiveTimestamp());
    assertEquals(1, listener.rtn.size());
    assertEquals(1100, (long) listener.rtn.get(0).getRtnTimestamp());
    ensureSetPointValue(rt, new PointValueTime(0.5, timer.currentTimeMillis()));
    timer.fastForwardTo(2000);
    ensureSetPointValue(rt, new PointValueTime(0.9, timer.currentTimeMillis()));
    timer.fastForwardTo(4500);
    assertEquals(1, listener.rtn.size());
    assertEquals(1, listener.raised.size());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Test(org.junit.Test)

Aggregations

DataPointWithEventDetectors (com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)54 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)29 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)25 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)24 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)22 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)20 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)18 PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)7 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)6 JsonException (com.serotonin.json.JsonException)6 HashMap (java.util.HashMap)5 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 JsonArray (com.serotonin.json.type.JsonArray)4 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)4 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)4 SerialPointLocatorVO (com.infiniteautomation.serial.vo.SerialPointLocatorVO)3 DataPointChangeDefinition (com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition)3