Search in sources :

Example 36 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)

Example 37 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 38 with DataPointWithEventDetectors

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

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());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HashMap(java.util.HashMap) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Field(org.jooq.Field) SortField(org.jooq.SortField) DataPointsRecord(com.infiniteautomation.mango.db.tables.records.DataPointsRecord) Record(org.jooq.Record)

Example 40 with DataPointWithEventDetectors

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);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

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