use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointValueRestController method createRecentPointValueTimeModel.
/**
* @param vo
* @param pvt
* @param useRendered
* @param unitConversion
* @param b
* @return
*/
private RecentPointValueTimeModel createRecentPointValueTimeModel(DataPointVO vo, PointValueTime pvt, UriComponentsBuilder imageServletBuilder, boolean useRendered, boolean unitConversion, boolean cached) {
RecentPointValueTimeModel model;
if (useRendered) {
// Render the values as Strings with the suffix and or units
model = new RecentPointValueTimeModel(pvt, cached);
model.setType(DataTypeEnum.convertTo(pvt.getValue().getDataType()));
model.setValue(Functions.getRenderedText(vo, pvt));
model.setTimestamp(pvt.getTime());
if (pvt.isAnnotated())
model.setAnnotation(((AnnotatedPointValueTime) pvt).getAnnotation(Common.getTranslations()));
} else if (unitConversion) {
// Convert the numeric value using the unit and rendered unit
model = new RecentPointValueTimeModel(pvt, cached);
model.setType(DataTypeEnum.convertTo(pvt.getValue().getDataType()));
model.setValue(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(pvt.getValue().getDoubleValue()));
model.setTimestamp(pvt.getTime());
if (pvt.isAnnotated())
model.setAnnotation(((AnnotatedPointValueTime) pvt).getAnnotation(Common.getTranslations()));
} else {
model = new RecentPointValueTimeModel(pvt, cached);
}
if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
model.setValue(imageServletBuilder.buildAndExpand(model.getTimestamp(), vo.getId()).toUri());
return model;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class AbstractPointValueRollupCalculator method getStartValue.
/**
* Get the value at the start of the period or if there isn't one then return the closest value.
* @param dataPointId
* @return
*/
protected DataValue getStartValue(int dataPointId) {
PointValueTime startPvt = pvd.getPointValueAt(dataPointId, from.getMillis());
if (startPvt == null)
startPvt = pvd.getPointValueBefore(dataPointId, from.getMillis());
DataValue startValue = PointValueTime.getValue(startPvt);
return startValue;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointValueTimeJsonStreamCallback method row.
/* (non-Javadoc)
* @see com.serotonin.db.MappedRowCallback#row(java.lang.Object, int)
*/
@Override
public void row(PointValueTime pvt, int index) {
if (this.limiter.limited())
return;
try {
String annotation = null;
if (pvt.isAnnotated())
annotation = ((AnnotatedPointValueTime) pvt).getAnnotation(translations);
if (useRendered) {
// Convert to Alphanumeric Value
String textValue = Functions.getRenderedText(vo, pvt);
this.writePointValueTime(new AlphanumericValue(textValue), pvt.getTime(), annotation, vo);
} else if (unitConversion) {
if (pvt.getValue() instanceof NumericValue)
this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(pvt.getValue().getDoubleValue()), pvt.getTime(), annotation, vo);
else
this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
} else {
this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
}
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class XidPointValueTimeLatestPointFacadeStream method streamData.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.ObjectStream#streamData(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
*/
@Override
public void streamData(CSVPojoWriter<Map<String, List<PointValueTime>>> writer) throws IOException {
Iterator<Integer> it = this.pointMap.keySet().iterator();
boolean writeHeaders = true;
while (it.hasNext()) {
DataPointVO vo = this.pointMap.get(it.next());
PointValueFacade pointValueFacade = new PointValueFacade(vo.getId(), useCache);
PointValueTimeCsvStreamCallback callback = new PointValueTimeCsvStreamCallback(writer.getWriter(), vo, useRendered, unitConversion, true, writeHeaders, null, dateTimeFormat, timezone);
List<PointValueTime> pvts = pointValueFacade.getLatestPointValues(limit);
for (int i = 0; i < pvts.size(); i++) callback.row(pvts.get(i), i);
writeHeaders = false;
}
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class PointLinkRT method execute.
private void execute(PointValueTime newValue) {
// Bail out if already running a point link operation
synchronized (ready) {
if (!ready) {
SystemEventType.raiseEvent(alreadyRunningEvent, newValue.getTime(), true, new TranslatableMessage("event.pointLink.duplicateRuns"));
return;
} else {
// Stop anyone else from using this
ready = false;
SystemEventType.returnToNormal(alreadyRunningEvent, System.currentTimeMillis());
}
}
// Propagate the update to the target point. Validate that the target point is available.
DataPointRT targetPoint = Common.runtimeManager.getDataPoint(vo.getTargetPointId());
if (targetPoint == null) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.targetUnavailable"));
ready = true;
return;
}
if (!targetPoint.getPointLocator().isSettable()) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.targetNotSettable"));
ready = true;
return;
}
int targetDataType = targetPoint.getVO().getPointLocator().getDataTypeId();
if (!StringUtils.isBlank(vo.getScript())) {
Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
context.put(CONTEXT_SOURCE_VAR_NAME, Common.runtimeManager.getDataPoint(vo.getSourcePointId()));
context.put(CONTEXT_TARGET_VAR_NAME, Common.runtimeManager.getDataPoint(vo.getTargetPointId()));
try {
if (!compiled) {
compiledScript = CompiledScriptExecutor.compile(vo.getScript());
compiled = true;
}
PointValueTime pvt = CompiledScriptExecutor.execute(compiledScript, context, null, newValue.getTime(), targetDataType, newValue.getTime(), vo.getScriptPermissions(), new PrintWriter(new NullWriter()), scriptLog, setCallback, importExclusions, false);
if (pvt.getValue() == null) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.nullResult"));
ready = true;
return;
} else if (pvt.getValue() == CompiledScriptExecutor.UNCHANGED) {
ready = true;
return;
}
newValue = pvt;
} catch (ScriptException e) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("pointLinks.validate.scriptError", e.getMessage()));
ready = true;
return;
} catch (ScriptPermissionsException e) {
raiseFailureEvent(newValue.getTime(), e.getTranslatableMessage());
ready = true;
return;
} catch (ResultTypeException e) {
raiseFailureEvent(newValue.getTime(), e.getTranslatableMessage());
ready = true;
return;
}
}
if (DataTypes.getDataType(newValue.getValue()) != targetDataType) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.convertError"));
ready = true;
return;
}
// Queue a work item to perform the update.
Common.backgroundProcessing.addWorkItem(new PointLinkSetPointWorkItem(vo.getTargetPointId(), newValue, this));
returnToNormal();
}
Aggregations