Search in sources :

Example 21 with DataValue

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

the class StatisticsStream method streamData.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeStream#streamData(com.fasterxml.jackson.core.JsonGenerator)
	 */
@Override
public void streamData(JsonGenerator jgen) throws IOException {
    // TODO Can't use the Facade as there is no way to perform the callback integrated with the PointValueCache
    // PointValueFacade pointValueFacade = new PointValueFacade(this.dataPointId);
    // First find the start value
    PointValueDao pvd = Common.databaseProxy.newPointValueDao();
    PointValueTime startPvt = pvd.getPointValueBefore(vo.getId(), from);
    DataValue startValue = null;
    if (startPvt != null)
        startValue = startPvt.getValue();
    StatisticsCalculator calculator = new StatisticsCalculator(jgen, vo, useRendered, unitConversion, this.from, this.to, startValue, dateTimeFormat, timezone);
    // Do the main work
    pvd.getPointValuesBetween(vo.getId(), from, to, calculator);
    // Finish
    calculator.done();
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 22 with DataValue

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

the class IdPointValueRollupCalculator method generateStream.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.AbstractPointValueRollupCalculator#generateStream(org.joda.time.DateTime, org.joda.time.DateTime, com.fasterxml.jackson.core.JsonGenerator)
	 */
@Override
protected void generateStream(DateTime from, DateTime to, JsonGenerator jgen) {
    BucketCalculator bc = this.getBucketCalculator(from, to);
    IdPointValueStatisticsQuantizerJsonCallback callback = new IdPointValueStatisticsQuantizerJsonCallback(jgen, this.voMap, this.useRendered, this.unitConversion, this.rollup, this.limit, this.dateTimeFormat, timezone);
    Iterator<Integer> it = this.voMap.keySet().iterator();
    ParentDataQuantizer quantizer = new ParentDataQuantizer(bc, callback);
    while (it.hasNext()) {
        DataPointVO vo = this.voMap.get(it.next());
        DataValue startValue = this.getStartValue(vo.getId());
        if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC) {
            quantizer.startQuantizer(vo.getId(), startValue, new AnalogStatisticsChildQuantizer(vo.getId(), quantizer));
        } else {
            quantizer.startQuantizer(vo.getId(), startValue, new ValueChangeCounterChildQuantizer(vo.getId(), quantizer));
        }
    }
    this.calculate(quantizer, from, to);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IdPointValueStatisticsQuantizerJsonCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.statistics.IdPointValueStatisticsQuantizerJsonCallback) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) AnalogStatisticsChildQuantizer(com.serotonin.m2m2.web.mvc.rest.v1.statistics.AnalogStatisticsChildQuantizer) BucketCalculator(com.serotonin.m2m2.view.quantize2.BucketCalculator) ParentDataQuantizer(com.serotonin.m2m2.web.mvc.rest.v1.statistics.ParentDataQuantizer) ValueChangeCounterChildQuantizer(com.serotonin.m2m2.web.mvc.rest.v1.statistics.ValueChangeCounterChildQuantizer)

Example 23 with DataValue

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

the class ReportPointValueTimeSerializer method getObject.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getObject(byte[], long)
	 */
@Override
public ITime getObject(ByteArrayBuilder b, long ts, String seriesId) {
    // Get the data type
    int dataType = b.getShort();
    DataValue dataValue = null;
    // Second put in the data value
    switch(dataType) {
        case DataTypes.ALPHANUMERIC:
            String s = b.getString();
            dataValue = new AlphanumericValue(s);
            break;
        case DataTypes.BINARY:
            boolean bool = b.getBoolean();
            dataValue = new BinaryValue(bool);
            break;
        case DataTypes.IMAGE:
            try {
                dataValue = new ImageValue(b.getString());
            } catch (InvalidArgumentException e1) {
            // Probably no file
            }
            break;
        case DataTypes.MULTISTATE:
            int i = b.getInt();
            dataValue = new MultistateValue(i);
            break;
        case DataTypes.NUMERIC:
            double d = b.getDouble();
            dataValue = new NumericValue(d);
            break;
        default:
            throw new ShouldNeverHappenException("Data type of " + dataType + " is not supported");
    }
    // Get the annotation
    String annotation = b.getString();
    if (annotation != null) {
        try {
            return new AnnotatedPointValueTime(dataValue, ts, TranslatableMessage.deserialize(annotation));
        } catch (Exception e) {
            throw new ShouldNeverHappenException(e);
        }
    } else {
        return new PointValueTime(dataValue, ts);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) InvalidArgumentException(com.serotonin.InvalidArgumentException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) IOException(java.io.IOException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) InvalidArgumentException(com.serotonin.InvalidArgumentException) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 24 with DataValue

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

the class IncrementMultistateChangeRT method change.

@Override
public DataValue change(DataValue currentValue) {
    // Get the current index.
    int currentInt = currentValue.getIntegerValue();
    int index = -1;
    for (int i = 0; i < vo.getValues().length; i++) {
        if (vo.getValues()[i] == currentInt) {
            index = i;
            break;
        }
    }
    if (index == -1)
        return new MultistateValue(vo.getValues()[0]);
    if (vo.isRoll()) {
        index++;
        if (index >= vo.getValues().length)
            index = 0;
    } else {
        if (decrement) {
            index--;
            if (index == -1) {
                index = 1;
                decrement = false;
            }
        } else {
            index++;
            if (index == vo.getValues().length) {
                index = vo.getValues().length - 2;
                decrement = true;
            }
        }
    }
    return new MultistateValue(vo.getValues()[index]);
}
Also used : MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Example 25 with DataValue

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

the class VirtualPointLocatorVO method createRuntime.

@Override
public PointLocatorRT<VirtualPointLocatorVO> createRuntime() {
    ChangeTypeRT changeType = getChangeType().createRuntime();
    String startValue = getChangeType().getStartValue();
    DataValue startObject;
    if (dataTypeId == DataTypes.BINARY)
        startObject = BinaryValue.parseBinary(startValue);
    else if (dataTypeId == DataTypes.MULTISTATE) {
        try {
            startObject = MultistateValue.parseMultistate(startValue);
        } catch (NumberFormatException e) {
            startObject = new MultistateValue(0);
        }
    } else if (dataTypeId == DataTypes.NUMERIC) {
        try {
            startObject = NumericValue.parseNumeric(startValue);
        } catch (NumberFormatException e) {
            startObject = new NumericValue(0);
        }
    } else {
        if (startValue == null)
            startObject = new AlphanumericValue("");
        else
            startObject = new AlphanumericValue(startValue);
    }
    return new VirtualPointLocatorRT(this, changeType, startObject, isSettable());
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) VirtualPointLocatorRT(com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT) ChangeTypeRT(com.serotonin.m2m2.virtual.rt.ChangeTypeRT) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Aggregations

DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)30 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)13 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)10 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)10 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)8 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)8 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)6 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)6 BucketCalculator (com.serotonin.m2m2.view.quantize2.BucketCalculator)6 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)5 HashMap (java.util.HashMap)5 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)4 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 AbstractDataQuantizer (com.serotonin.m2m2.view.quantize2.AbstractDataQuantizer)4 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)4 ImageSaveException (com.serotonin.m2m2.ImageSaveException)3 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)2 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)2