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