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();
}
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);
}
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);
}
}
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]);
}
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());
}
Aggregations