Search in sources :

Example 26 with DataPointWithEventDetectors

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

the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeForOneSecond.

@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeForOneSecond() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, null, TimePeriods.SECONDS, false, CalculationMode.INSTANTANEOUS, 0, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN_OR_EQUALS, 0, 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(200);
    dp.getDataPoint().setEnabled(true);
    Common.runtimeManager.startDataPoint(dp);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
    ensureSetPointValue(rt, new PointValueTime(1.5, timer.currentTimeMillis()));
    timer.fastForwardTo(500);
    ensureSetPointValue(rt, new PointValueTime(2.5, timer.currentTimeMillis()));
    // 1s after the change of grater than 1
    timer.fastForwardTo(1100);
    assertEquals(1, listener.raised.size());
    assertEquals(200, listener.raised.get(0).getActiveTimestamp());
    assertEquals(0, listener.rtn.size());
    ensureSetPointValue(rt, new PointValueTime(2.2, timer.currentTimeMillis()));
    // Well after we have had no changes and our RoC has dropped to RTN the event
    timer.fastForwardTo(4500);
    assertEquals(1, listener.raised.size());
    assertEquals(1, listener.rtn.size());
    assertEquals(1100, (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 27 with DataPointWithEventDetectors

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

the class RateOfChangeDetectorTest method createDisabledPoint.

/**
 * Create a point in the database that is not running.
 *
 * NOTE: The poll period is 1s for the data source
 */
protected DataPointWithEventDetectors createDisabledPoint(double rocThreshold, Double resetThreshold, int rocThresholdPeriodType, boolean useAbsoluteValue, CalculationMode calculationMode, int rocDuration, int rocDurationType, ComparisonMode comparisonMode, int durationPeriods, int durationPeriodType) {
    // Create point locator
    MockPointLocatorVO plVo = new MockPointLocatorVO(DataType.NUMERIC, true);
    // Setup Data Point VO
    DataPointVO dpVo = new DataPointVO();
    dpVo.setName("Test");
    dpVo.setXid("DP_1");
    dpVo.setEnabled(false);
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ALL);
    dpVo.setPointLocator(plVo);
    dpVo.setDataSourceId(dsVo.getId());
    // Setup our ROC Detector
    RateOfChangeDetectorVO rocVo = new RateOfChangeDetectorVO(dpVo);
    rocVo.setXid(EventDetectorDao.getInstance().generateUniqueXid());
    rocVo.setDefinition(new RateOfChangeDetectorDefinition());
    rocVo.setRateOfChangeThreshold(rocThreshold);
    rocVo.setRateOfChangeThresholdPeriodType(rocThresholdPeriodType);
    if (resetThreshold != null) {
        rocVo.setUseResetThreshold(true);
        rocVo.setResetThreshold(resetThreshold);
    }
    rocVo.setRateOfChangePeriods(rocDuration);
    rocVo.setRateOfChangePeriodType(rocDurationType);
    rocVo.setComparisonMode(comparisonMode);
    rocVo.setCalculationMode(calculationMode);
    rocVo.setUseAbsoluteValue(useAbsoluteValue);
    rocVo.setDuration(durationPeriods);
    rocVo.setDurationType(durationPeriodType);
    validate(rocVo);
    DataPointService service = Common.getBean(DataPointService.class);
    validate(dpVo);
    service.insert(dpVo);
    rocVo.setSourceId(dpVo.getId());
    EventDetectorDao.getInstance().insert(rocVo);
    List<AbstractPointEventDetectorVO> eventDetectors = new ArrayList<>();
    eventDetectors.add(rocVo);
    return new DataPointWithEventDetectors(dpVo, eventDetectors);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) RateOfChangeDetectorVO(com.serotonin.m2m2.vo.event.detector.RateOfChangeDetectorVO) RateOfChangeDetectorDefinition(com.serotonin.m2m2.module.definitions.event.detectors.RateOfChangeDetectorDefinition) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)

Example 28 with DataPointWithEventDetectors

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

the class RateOfChangeDetectorTest method testNoValuesSetTwoInitialValuesAverage.

@Test
public void testNoValuesSetTwoInitialValuesAverage() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, 1.1, TimePeriods.SECONDS, false, CalculationMode.AVERAGE, 1, 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());
    timer.fastForwardTo(1499);
    assertEquals(1, listener.raised.size());
    assertEquals(1000, listener.raised.get(0).getActiveTimestamp());
    assertEquals(0, listener.rtn.size());
    ensureSetPointValue(rt, new PointValueTime(2.2, timer.currentTimeMillis()));
    timer.fastForwardTo(2000);
    assertEquals(1, listener.raised.size());
    assertEquals(1, listener.rtn.size());
    assertEquals(1499, (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 29 with DataPointWithEventDetectors

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

the class InternalLifecycle method maybeCreatePoints.

/**
 */
private void maybeCreatePoints(boolean safe, DataSourceVO vo) {
    Map<String, ValueMonitor<?>> monitors = getAllHomePageMonitors();
    Iterator<String> it = monitors.keySet().iterator();
    while (it.hasNext()) {
        String xid = it.next();
        ValueMonitor<?> monitor = monitors.get(xid);
        if (monitor != null) {
            DataPointVO dp = DataPointDao.getInstance().getByXid(xid);
            if (dp == null) {
                dp = new DataPointVO();
                InternalPointLocatorVO pl = new InternalPointLocatorVO();
                pl.setMonitorId(monitor.getId());
                dp.setPointLocator(pl);
                dp.setXid(xid);
                dp.setName(monitor.getName().translate(Common.getTranslations()));
                dp.setDataSourceId(vo.getId());
                dp.setDeviceName(vo.getName());
                dp.defaultTextRenderer();
                dp.setEnabled(true);
                dp.setChartColour("");
                if (pl.getDataType() == DataType.NUMERIC) {
                    dp.setRollup(Rollups.AVERAGE);
                    switch(xid) {
                        case SQL_DATABASE_PARTITION_USABLE_SPACE_POINT_XID:
                        case NOSQL_DATABASE_PARTITION_USABLE_SPACE_POINT_XID:
                        case MA_HOME_PARTITION_TOTAL_SPACE_XID:
                        case MA_HOME_PARTITION_USED_SPACE_XID:
                        case MA_HOME_PARTITION_USABLE_SPACE_XID:
                        case SQL_DATABASE_SIZE_POINT_XID:
                        case NOSQL_DATABASE_SIZE_POINT_XID:
                            dp.setUnit(Common.GIBI(NonSI.BYTE));
                            dp.setLoggingType(LoggingTypes.ON_CHANGE);
                            dp.setTextRenderer(new AnalogRenderer("0.0", " GiB", false));
                            break;
                        case CPU_SYSTEM_LOAD_XID:
                        case CPU_PROCESS_LOAD_XID:
                            dp.setLoggingType(LoggingTypes.ON_CHANGE);
                            dp.setTextRenderer(new AnalogRenderer("0", " %", false));
                            break;
                        case JVM_USED_MEMORY_XID:
                        case JVM_MAX_MEMORY_XID:
                        case JVM_FREE_MEMORY_XID:
                            dp.setUnit(Common.MEBI(NonSI.BYTE));
                            dp.setLoggingType(LoggingTypes.ON_CHANGE);
                            dp.setTextRenderer(new AnalogRenderer("0", " MiB", false));
                            break;
                        case SYSTEM_UPTIME_POINT_XID:
                            dp.setUnit(NonSI.HOUR);
                            // This value changes often, log interval instance
                            dp.setLoggingType(LoggingTypes.INTERVAL);
                            dp.setIntervalLoggingPeriodType(TimePeriods.MINUTES);
                            dp.setIntervalLoggingPeriod(5);
                            dp.setIntervalLoggingType(IntervalLoggingTypes.INSTANT);
                            dp.setTextRenderer(new AnalogRenderer("0.0", " hrs", false));
                            break;
                        default:
                            // If we are numeric then we want to log on change
                            dp.setLoggingType(LoggingTypes.ON_CHANGE);
                            dp.setTextRenderer(new AnalogRenderer("0", "", false));
                            break;
                    }
                }
                DataPointDao.getInstance().insert(dp);
                if (!safe) {
                    Common.runtimeManager.startDataPoint(new DataPointWithEventDetectors(dp, new ArrayList<>()));
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor)

Example 30 with DataPointWithEventDetectors

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

the class SerialDataSourceTestData method getMatchAllPoint.

// ========== POINT CREATION METHODS ===========
public static DataPointRT getMatchAllPoint(DataSourceRT<? extends DataSourceVO> ds) {
    DataPointVO vo = new DataPointVO();
    vo.setName("matchAll");
    vo.setXid("matchAll");
    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)

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