Search in sources :

Example 76 with PointValueTime

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;
}
Also used : RecentPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)

Example 77 with PointValueTime

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;
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 78 with PointValueTime

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);
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) IOException(java.io.IOException) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 79 with PointValueTime

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;
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 80 with PointValueTime

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();
}
Also used : HashMap(java.util.HashMap) NullWriter(org.apache.commons.io.output.NullWriter) ScriptException(javax.script.ScriptException) ResultTypeException(com.serotonin.m2m2.rt.script.ResultTypeException) ScriptPermissionsException(com.serotonin.m2m2.rt.script.ScriptPermissionsException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) IDataPointValueSource(com.serotonin.m2m2.rt.dataImage.IDataPointValueSource) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PrintWriter(java.io.PrintWriter)

Aggregations

PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)104 ArrayList (java.util.ArrayList)33 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)29 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)24 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)23 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)23 IOException (java.io.IOException)18 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)17 HashMap (java.util.HashMap)17 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)15 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)12 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)11 ScriptException (javax.script.ScriptException)10 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)9 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)9 LogStopWatch (com.serotonin.log.LogStopWatch)8 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)8 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)8 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8