Search in sources :

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

Example 12 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 13 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 14 with DataPointWithEventDetectors

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

the class DataPointRTTest method testIntervalOnChangeLogging.

/**
 * Test Interval Logged Values w/ On Change Option
 */
@Test
public void testIntervalOnChangeLogging() {
    MockDataSourceVO dsVo = new MockDataSourceVO();
    MockDataSourceRT dataSource = dsVo.createDataSourceRT();
    dataSource.initialize(false);
    PointValueDao dao = Common.getBean(PointValueDao.class);
    MockPointLocatorVO plVo = new MockPointLocatorVO(DataType.NUMERIC, true);
    DataPointVO dpVo = new DataPointVO();
    dpVo.setId(1);
    dpVo.setDataSourceId(dsVo.getId());
    // Configure Interval on change logging
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
    dpVo.setTolerance(0.5);
    dpVo.setIntervalLoggingPeriod(5);
    dpVo.setIntervalLoggingPeriodType(TimePeriods.SECONDS);
    dpVo.setPointLocator(plVo);
    dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
    MockPointLocatorRT plRt = new MockPointLocatorRT(plVo);
    // Setup some initial data
    List<PointValueTime> initialCache = new ArrayList<>();
    initialCache.add(new PointValueTime(1.0, 0));
    SimulationTimer timer = new SimulationTimer();
    DataPointWithEventDetectors dp = new DataPointWithEventDetectors(dpVo, new ArrayList<>());
    DataPointRT rt = new DataPointRT(dp, plRt, dataSource, initialCache, dao, Common.getBean(PointValueCache.class), timer);
    rt.initialize(false);
    // Test no changes
    timer.fastForwardTo(5001);
    PointValueTime value = dao.getLatestPointValue(dpVo).orElse(null);
    // Ensure database has interval logged value
    assertEquals(1.0, value.getDoubleValue(), 0.0001);
    assertEquals(5000, value.getTime());
    // Ensure cache does not have interval logged value
    assertEquals(1.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(0, rt.getPointValue().getTime());
    // Next interval
    timer.fastForwardTo(6000);
    rt.setPointValue(new PointValueTime(2.0, 6000), null);
    // Check Log On Change
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(6000, value.getTime());
    assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(6000, rt.getPointValue().getTime());
    // Interval is reset for 5000ms from now
    timer.fastForwardTo(11001);
    // Check Interval Log
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(11000, value.getTime());
    assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(6000, rt.getPointValue().getTime());
    // Test Tolerance (Should not get logged)
    timer.fastForwardTo(12000);
    rt.setPointValue(new PointValueTime(2.20, 12000), null);
    // Check Log On Change
    value = dao.getLatestPointValue(dpVo).orElse(null);
    assertEquals(2.0, value.getDoubleValue(), 0.0001);
    assertEquals(11000, value.getTime());
    // Cache will have the set value
    assertEquals(2.2, rt.getPointValue().getDoubleValue(), 0.0001);
    assertEquals(12000, rt.getPointValue().getTime());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) SimulationTimer(com.serotonin.timer.SimulationTimer) ArrayList(java.util.ArrayList) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) BasicSQLPointValueDao(com.serotonin.m2m2.db.dao.BasicSQLPointValueDao) MockPointLocatorRT(com.serotonin.m2m2.rt.dataSource.MockPointLocatorRT) MockDataSourceRT(com.serotonin.m2m2.rt.dataSource.MockDataSourceRT) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) Test(org.junit.Test)

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

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