Search in sources :

Example 1 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.

the class XidPointValueMapRollupCalculator method generateStream.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream#streamData(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
	 */
@Override
protected void generateStream(DateTime from, DateTime to, CSVPojoWriter<Map<String, List<PointValueTime>>> writer) {
    Iterator<Integer> it = this.voMap.keySet().iterator();
    boolean writeHeaders = true;
    while (it.hasNext()) {
        DataPointVO vo = this.voMap.get(it.next());
        DataValue startValue = this.getStartValue(vo.getId());
        BucketCalculator bc = this.getBucketCalculator(from, to);
        final AbstractDataQuantizer quantizer = createQuantizer(vo, startValue, bc, writer, true, writeHeaders);
        this.calculate(quantizer, vo.getId(), from, to);
        // Only write the headers on the first iteration
        writeHeaders = false;
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BucketCalculator(com.serotonin.m2m2.view.quantize2.BucketCalculator) AbstractDataQuantizer(com.serotonin.m2m2.view.quantize2.AbstractDataQuantizer)

Example 2 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.fasterxml.jackson.core.JsonGenerator)
	 */
@Override
public void streamData(JsonGenerator jgen) {
    Iterator<Integer> it = this.pointMap.keySet().iterator();
    while (it.hasNext()) {
        try {
            DataPointVO vo = this.pointMap.get(it.next());
            PointValueFacade pointValueFacade = new PointValueFacade(vo.getId(), useCache);
            PointValueTimeJsonStreamCallback callback = new PointValueTimeJsonStreamCallback(jgen, vo, useRendered, unitConversion, null, dateTimeFormat, timezone);
            jgen.writeArrayFieldStart(vo.getXid());
            List<PointValueTime> pvts = pointValueFacade.getLatestPointValues(limit);
            for (int i = 0; i < pvts.size(); i++) callback.row(pvts.get(i), i);
            jgen.writeEndArray();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) IOException(java.io.IOException)

Example 3 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.

the class PointValueTimeWriter method writeNonNull.

/**
 * Write a Data Value that if null contains an annotation saying there is no data at this point in time
 * - useful for Rollups with gaps in the data
 * @param value
 * @param time
 * @throws ConversionException
 * @throws IOException
 */
public void writeNonNull(DataValue value, Long time, DataPointVO vo) throws ConversionException, IOException {
    if (time == null)
        throw new ShouldNeverHappenException("Time cannot be null");
    if (value == null) {
        if (useRendered) {
            this.writePointValueTime(new AlphanumericValue(""), time, this.noDataMessage, vo);
        } else {
            this.writePointValueTime(0.0D, time, this.noDataMessage, vo);
        }
    } else {
        if (useRendered) {
            // Convert to Alphanumeric Value
            String textValue = Functions.getRenderedText(vo, new PointValueTime(value, time));
            this.writePointValueTime(new AlphanumericValue(textValue), time, null, vo);
        } else if (unitConversion) {
            // Convert Value, must be numeric
            if (value instanceof NumericValue)
                this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value.getDoubleValue()), time, null, vo);
            else
                this.writePointValueTime(value, time, null, vo);
        } else {
            this.writePointValueTime(value, time, null, vo);
        }
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 4 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.

the class PointValueTimeWriter method writeNonNullDouble.

/**
 * Write a Data Value that if null contains an annotation saying there is no data at this point in time
 * - useful for Rollups with gaps in the data
 * @param value
 * @param time
 * @throws ConversionException
 * @throws IOException
 */
public void writeNonNullDouble(Double value, long time, DataPointVO vo) throws ConversionException, IOException {
    if (value == null) {
        if (useRendered) {
            this.writePointValueTime(new AlphanumericValue(""), time, this.noDataMessage, vo);
        } else {
            this.writePointValueTime(0.0D, time, this.noDataMessage, vo);
        }
    } else {
        if (useRendered) {
            // Convert to Alphanumeric Value
            String textValue = Functions.getRenderedText(vo, new PointValueTime(value, time));
            this.writePointValueTime(new AlphanumericValue(textValue), time, null, vo);
        } else if (unitConversion) {
            // Convert Value, must be numeric
            this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value), time, null, vo);
        } else {
            this.writePointValueTime(value, time, null, vo);
        }
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 5 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.

the class SerialDataSourceRT method matchPointValue.

/**
 * Match for 1 point Helper for DWR and here
 * @param msg
 * @param messageRegex
 * @param pointIdentifierIndex
 * @param plVo
 * @param callback
 * @param log
 */
public static void matchPointValue(String msg, String messageRegex, int pointIdentifierIndex, SerialPointLocatorVO plVo, boolean isHex, Log log, MatchCallback callback) throws Exception {
    Pattern messagePattern = Pattern.compile(messageRegex);
    Matcher messageMatcher = messagePattern.matcher(msg);
    if (messageMatcher.find()) {
        if (log.isDebugEnabled())
            log.debug("Message matched regex: " + messageRegex);
        // Parse out the Identifier
        String pointIdentifier = null;
        try {
            pointIdentifier = messageMatcher.group(pointIdentifierIndex);
        } catch (Exception e) {
            callback.pointNotIdentified(msg, messageRegex, pointIdentifierIndex);
            return;
        }
        if (plVo.getPointIdentifier().equals(pointIdentifier)) {
            if (log.isDebugEnabled())
                log.debug("Point Identified: " + pointIdentifier);
            Pattern pointValuePattern = Pattern.compile(plVo.getValueRegex());
            // Use the index from the above message
            Matcher pointValueMatcher = pointValuePattern.matcher(msg);
            if (pointValueMatcher.find()) {
                String value = pointValueMatcher.group(plVo.getValueIndex());
                if (log.isDebugEnabled()) {
                    log.debug("Point Value matched regex: " + plVo.getValueRegex() + " and extracted value " + value);
                }
                PointValueTime pvt = convertToPointValue(value, plVo.getDataTypeId(), isHex);
                callback.onMatch(pointIdentifier, pvt);
            } else {
                callback.pointPatternMismatch(msg, plVo.getValueRegex());
            }
        } else {
            callback.pointNotIdentified(msg, messageRegex, pointIdentifierIndex);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) IOException(java.io.IOException)

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