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