Search in sources :

Example 11 with MultistateValue

use of com.serotonin.m2m2.view.text.MultistateValue 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 12 with MultistateValue

use of com.serotonin.m2m2.view.text.MultistateValue 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)

Example 13 with MultistateValue

use of com.serotonin.m2m2.view.text.MultistateValue in project ma-core-public by infiniteautomation.

the class DataPointEditDwr method setMultistateRenderer.

@DwrPermission(user = true)
public void setMultistateRenderer(List<MultistateValue> values) {
    MultistateRenderer r = new MultistateRenderer();
    for (MultistateValue v : values) r.addMultistateValue(v.getKey(), v.getText(), v.getColour());
    setTextRenderer(r);
}
Also used : MultistateRenderer(com.serotonin.m2m2.view.text.MultistateRenderer) MultistateValue(com.serotonin.m2m2.view.text.MultistateValue) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 14 with MultistateValue

use of com.serotonin.m2m2.view.text.MultistateValue in project ma-core-public by infiniteautomation.

the class DataPointRT method scheduleTimeoutImpl.

public void scheduleTimeoutImpl(long fireTime) {
    synchronized (intervalLoggingLock) {
        DataValue value;
        if (vo.getLoggingType() == DataPointVO.LoggingTypes.INTERVAL) {
            if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.INSTANT)
                value = PointValueTime.getValue(pointValue);
            else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MAXIMUM || vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MINIMUM) {
                value = PointValueTime.getValue(intervalValue);
                intervalValue = pointValue;
            } else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {
                // If we don't have enough averaging values then we will bail and wait for more
                if (vo.isOverrideIntervalLoggingSamples() && (averagingValues.size() != vo.getIntervalLoggingSampleWindowSize()))
                    return;
                if (vo.getPointLocator().getDataTypeId() == DataTypes.MULTISTATE) {
                    StartsAndRuntimeList stats = new StartsAndRuntimeList(intervalStartTime, fireTime, intervalValue, averagingValues);
                    double maxProportion = -1;
                    Object valueAtMax = null;
                    for (StartsAndRuntime sar : stats.getData()) {
                        if (sar.getProportion() > maxProportion) {
                            maxProportion = sar.getProportion();
                            valueAtMax = sar.getValue();
                        }
                    }
                    if (valueAtMax != null)
                        value = new MultistateValue(DataValue.objectToValue(valueAtMax).getIntegerValue());
                    else
                        value = null;
                } else {
                    AnalogStatistics stats = new AnalogStatistics(intervalStartTime, fireTime, intervalValue, averagingValues);
                    if (stats.getAverage() == null || (stats.getAverage() == Double.NaN && stats.getCount() == 0))
                        value = null;
                    else if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC)
                        value = new NumericValue(stats.getAverage());
                    else if (vo.getPointLocator().getDataTypeId() == DataTypes.BINARY)
                        value = new BinaryValue(stats.getAverage() >= 0.5);
                    else
                        throw new ShouldNeverHappenException("Unsupported average interval logging data type.");
                }
                // Compute the center point of our average data, starting by finding where our period started
                long sampleWindowStartTime;
                if (vo.isOverrideIntervalLoggingSamples())
                    sampleWindowStartTime = averagingValues.get(0).getTime();
                else
                    sampleWindowStartTime = intervalStartTime;
                intervalStartTime = fireTime;
                // Fix to simulate center tapped filter (un-shift the average)
                fireTime = sampleWindowStartTime + (fireTime - sampleWindowStartTime) / 2L;
                intervalValue = pointValue;
                if (!vo.isOverrideIntervalLoggingSamples())
                    averagingValues.clear();
            } else
                throw new ShouldNeverHappenException("Unknown interval logging type: " + vo.getIntervalLoggingType());
        } else if (vo.getLoggingType() == DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL) {
            // Okay, no changes rescheduled the timer. Get a value, reschedule
            if (pointValue != null) {
                value = pointValue.getValue();
                if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC)
                    toleranceOrigin = pointValue.getDoubleValue();
            } else
                value = null;
            rescheduleChangeInterval(Common.getMillis(vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod()));
        } else
            value = null;
        if (value != null) {
            PointValueTime newValue = new PointValueTime(value, fireTime);
            valueCache.logPointValueAsync(newValue, null);
            // Fire logged Events
            fireEvents(null, newValue, null, false, false, true, false, false);
        }
    }
}
Also used : StartsAndRuntime(com.infiniteautomation.mango.statistics.StartsAndRuntime) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) StartsAndRuntimeList(com.infiniteautomation.mango.statistics.StartsAndRuntimeList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnalogStatistics(com.infiniteautomation.mango.statistics.AnalogStatistics) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Example 15 with MultistateValue

use of com.serotonin.m2m2.view.text.MultistateValue in project ma-core-public by infiniteautomation.

the class PointValueDaoSQL method createDataValue.

DataValue createDataValue(ResultSet rs, int firstParameter) throws SQLException {
    int dataType = rs.getInt(firstParameter);
    DataValue value;
    switch(dataType) {
        case (DataTypes.NUMERIC):
            value = new NumericValue(rs.getDouble(firstParameter + 1));
            break;
        case (DataTypes.BINARY):
            value = new BinaryValue(rs.getDouble(firstParameter + 1) == 1);
            break;
        case (DataTypes.MULTISTATE):
            value = new MultistateValue(rs.getInt(firstParameter + 1));
            break;
        case (DataTypes.ALPHANUMERIC):
            String s = rs.getString(firstParameter + 2);
            if (s == null)
                s = rs.getString(firstParameter + 3);
            value = new AlphanumericValue(s);
            break;
        case (DataTypes.IMAGE):
            value = new ImageValue(Integer.parseInt(rs.getString(firstParameter + 2)), rs.getInt(firstParameter + 1));
            break;
        default:
            value = null;
    }
    return value;
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Aggregations

MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)23 IOException (java.io.IOException)15 NextTimePeriodAdjuster (com.infiniteautomation.mango.util.datetime.NextTimePeriodAdjuster)14 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)14 ZonedDateTime (java.time.ZonedDateTime)14 MutableInt (org.apache.commons.lang3.mutable.MutableInt)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 StartsAndRuntime (com.infiniteautomation.mango.statistics.StartsAndRuntime)8 StartsAndRuntimeList (com.infiniteautomation.mango.statistics.StartsAndRuntimeList)8 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)8 ValueChangeCounter (com.infiniteautomation.mango.statistics.ValueChangeCounter)7 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)7 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)7 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)7 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2