Search in sources :

Example 16 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 17 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)

Example 18 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 19 with DataPointWithEventDetectors

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());
}
Also used : DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)

Example 20 with DataPointWithEventDetectors

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());
}
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)29 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)16 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)14 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)13 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)12 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)9 PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)5 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)3 SerialPointLocatorVO (com.infiniteautomation.serial.vo.SerialPointLocatorVO)3 JsonException (com.serotonin.json.JsonException)3 HashMap (java.util.HashMap)3 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)2 JsonArray (com.serotonin.json.type.JsonArray)2 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 DataPointChangeDefinition (com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition)2 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)2 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)2