use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class MultiPointLatestDatabaseStream method buildCache.
/**
* Build the cache based on our Query Info
* @param voMap
* @param limit
* @return
*/
protected Map<Integer, List<IdPointValueTime>> buildCache() {
Map<Integer, List<IdPointValueTime>> map = new HashMap<>();
for (Integer id : voMap.keySet()) {
DataPointRT rt = Common.runtimeManager.getDataPoint(id);
if (rt != null) {
List<PointValueTime> cache;
if (info.getLimit() != null)
cache = rt.getCacheCopy(info.getLimit());
else
cache = rt.getCacheCopy();
List<IdPointValueTime> idPvtCache = new ArrayList<>(cache.size());
for (PointValueTime pvt : cache) {
if (includeCachedPoint(pvt)) {
if (pvt.isAnnotated())
idPvtCache.add(new AnnotatedIdPointValueTime(id, pvt.getValue(), pvt.getTime(), ((AnnotatedPointValueTime) pvt).getSourceMessage()));
else
idPvtCache.add(new IdPointValueTime(id, pvt.getValue(), pvt.getTime()));
}
}
if (!idPvtCache.isEmpty()) {
sortCache(idPvtCache);
map.put(id, idPvtCache);
}
}
}
return map;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointValueRestController method getRollupPointValuesAsMultipleArrays.
@ApiOperation(value = "Rollup values for multiple data points, return in time ascending order", notes = "From time inclusive, To time exclusive. Returns a map of xid to point value time arrays.", response = PointValueTimeModel.class, responseContainer = "Object")
@RequestMapping(method = RequestMethod.GET, value = "/multiple-arrays/time-period/{xids}/{rollup}")
public ResponseEntity<PointValueTimeStream<Map<String, List<PointValueTime>>, ZonedDateTimeRangeQueryInfo>> getRollupPointValuesAsMultipleArrays(HttpServletRequest request, @ApiParam(value = "Point xids", required = true, allowMultiple = true) @PathVariable String[] xids, @ApiParam(value = "Rollup type", required = false, allowMultiple = false) @PathVariable(value = "rollup") RollupEnum rollup, @ApiParam(value = "From time", required = false, allowMultiple = false) @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time", required = false, allowMultiple = false) @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time Period Type", required = false, allowMultiple = false) @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods", required = false, allowMultiple = false) @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Time zone", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Limit (per series)", required = false, allowMultiple = false) @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used", required = false, allowMultiple = false) @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Truncate the from time and expand to time based on the time period settings", required = false, allowMultiple = false) @RequestParam(value = "truncate", required = false, defaultValue = "false") boolean truncate, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE", required = false, allowMultiple = false) @RequestParam(required = false) PointValueField[] fields, @AuthenticationPrincipal User user) {
TimePeriod timePeriod = null;
if ((timePeriodType != null) && (timePeriods != null)) {
timePeriod = new TimePeriod(timePeriods, timePeriodType);
}
ZonedDateTimeRangeQueryInfo info = new ZonedDateTimeRangeQueryInfo(from, to, dateTimeFormat, timezone, rollup, timePeriod, limit, true, false, false, PointValueTimeCacheControl.NONE, null, null, truncate, fields);
return generateStream(user, info, xids);
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class MBusDataSourceRT method setValue.
protected boolean setValue(DataBlock db, boolean pointError, long time, DataPointRT point, final MBusPointLocatorRT locatorRT, final MBusPointLocatorVO locatorVo) {
try {
if ((db instanceof BcdValue) && ((BcdValue) db).isBcdError()) {
pointError = true;
LOG.fatal("BCD Error : " + ((BcdValue) db).getBcdError());
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "BCD error value: " + ((BcdValue) db).getBcdError()));
pointError = true;
} else if (db instanceof ByteDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ByteDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof ShortDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ShortDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof IntegerDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((IntegerDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof LongDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((LongDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof RealDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((RealDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof BigDecimalDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((BigDecimalDataBlock) db).getValue().doubleValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof StringDataBlock) {
point.updatePointValue(new PointValueTime(((StringDataBlock) db).getValue(), time));
} else {
LOG.fatal("Dont know how to save: " + point.getVO().getExtendedName());
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Dont know how to save"));
pointError = true;
}
} catch (Exception ex) {
LOG.fatal("Error during saving: " + vo.getName(), ex);
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Ex: " + ex));
pointError = true;
}
return pointError;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointValueImportResult method saveValue.
public void saveValue(XidPointValueTimeModel model) {
if (valid) {
// Validate the model against our point
long timestamp = model.getTimestamp();
if (timestamp == 0)
timestamp = Common.timer.currentTimeMillis();
int dataTypeId = DataTypeEnum.convertFrom(model.getType());
if (dataTypeId != vo.getPointLocator().getDataTypeId()) {
result.addContextualMessage("dataType", "event.ds.dataType");
return;
}
DataValue value;
switch(model.getType()) {
case ALPHANUMERIC:
value = new AlphanumericValue((String) model.getValue());
break;
case BINARY:
value = new BinaryValue((Boolean) model.getValue());
break;
case MULTISTATE:
if (model.getValue() instanceof String) {
try {
value = vo.getTextRenderer().parseText((String) model.getValue(), dataTypeId);
} catch (Exception e) {
// Lots can go wrong here so let the user know
result.addContextualMessage("value", "event.valueParse.textParse", e.getMessage());
return;
}
} else {
value = new MultistateValue(((Number) model.getValue()).intValue());
}
break;
case NUMERIC:
value = new NumericValue(((Number) model.getValue()).doubleValue());
break;
case IMAGE:
default:
result.addContextualMessage("dataType", "common.default", model.getType() + " data type not supported yet");
return;
}
PointValueTime pvt;
if (model.getAnnotation() == null) {
pvt = new PointValueTime(value, timestamp);
} else {
pvt = new AnnotatedPointValueTime(value, timestamp, new TranslatableMessage("common.default", model.getAnnotation()));
}
if (rt == null) {
dao.savePointValueAsync(vo.getId(), pvt, null);
} else {
rt.savePointValueDirectToCache(pvt, null, true, true);
}
total++;
}
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class AsciiFileEditDwr method testString.
@DwrPermission(user = true)
public ProcessResult testString(int dsId, String raw) {
final ProcessResult pr = new ProcessResult();
// Message we will work with
String msg;
if (dsId == -1) {
pr.addContextualMessage("testString", "dsEdit.file.test.needsSave");
return pr;
}
msg = StringEscapeUtils.unescapeJava(raw);
// Map to store the values vs the points they are for
final List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
pr.addData("results", results);
DataPointDao dpd = DataPointDao.instance;
List<DataPointVO> points = dpd.getDataPoints(dsId, null);
for (final DataPointVO vo : points) {
final Map<String, Object> result = new HashMap<String, Object>();
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
result.put("success", "true");
result.put("name", vo.getName());
result.put("identifier", pointIdentifier);
result.put("value", value != null ? value.toString() : "null");
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noPointRegexMatch").translate(Common.getTranslations()));
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noIdentifierFound").translate(Common.getTranslations()));
}
@Override
public void matchGeneralFailure(Exception e) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("common.default", e.getMessage()).translate(Common.getTranslations()));
}
};
AsciiFilePointLocatorVO locator = vo.getPointLocator();
AsciiFileDataSourceRT.matchPointValueTime(msg, Pattern.compile(locator.getValueRegex()), locator.getPointIdentifier(), locator.getPointIdentifierIndex(), locator.getDataTypeId(), locator.getValueIndex(), locator.getHasTimestamp(), locator.getTimestampIndex(), locator.getTimestampFormat(), callback);
if (result.size() > 0) {
results.add(result);
}
}
return pr;
}
Aggregations