Search in sources :

Example 6 with DataPointWithEventDetectors

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());
}
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 7 with DataPointWithEventDetectors

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());
}
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 8 with DataPointWithEventDetectors

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());
}
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 9 with DataPointWithEventDetectors

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

Example 10 with DataPointWithEventDetectors

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;
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

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