use of com.serotonin.m2m2.rt.dataImage.types.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]);
}
use of com.serotonin.m2m2.rt.dataImage.types.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());
}
use of com.serotonin.m2m2.rt.dataImage.types.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);
}
use of com.serotonin.m2m2.rt.dataImage.types.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);
}
}
}
use of com.serotonin.m2m2.rt.dataImage.types.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;
}
Aggregations