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