use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class XidPointValueTimeMapDatabaseStream method streamData.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.ObjectStream#streamData(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
*/
@Override
public void streamData(CSVPojoWriter<Map<String, List<PointValueTime>>> writer) throws IOException {
Iterator<Integer> it = this.pointMap.keySet().iterator();
boolean writeHeaders = true;
while (it.hasNext()) {
DataPointVO vo = this.pointMap.get(it.next());
PointValueTimeCsvStreamCallback callback = new PointValueTimeCsvStreamCallback(writer.getWriter(), vo, useRendered, unitConversion, true, writeHeaders, limit, dateTimeFormat, timezone);
this.dao.getPointValuesBetween(vo.getId(), from, to, callback);
writeHeaders = false;
}
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime 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.PointValueTime 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.PointValueTime in project ma-modules-public by infiniteautomation.
the class SerialDataSourceTest method testReadPointValue.
@Test
public void testReadPointValue() {
// Connect
try {
assertTrue(rt.connect());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
for (String s : testCases.keySet()) {
SerialDataSourceTestCase stc = testCases.get(s);
rt.addDataPoint(stc.getTargetPoint());
if (stc.getCondition().equals("terminator")) {
vo.setMessageTerminator(stc.getTerminator());
vo.setUseTerminator(true);
} else if (stc.getCondition().equals("timeout")) {
vo.setUseTerminator(false);
}
// load a test input
proxy.getTestInputStream().pushToMockStream(s);
// Create an event to force the Data Source to read the port
SerialPortProxyEvent evt = new SerialPortProxyEvent(timer.currentTimeMillis());
rt.serialEvent(evt);
// Fast Forward to fire any events
time = time + 5;
timer.fastForwardTo(time);
List<PointValueTime> pvts = Lists.reverse(stc.getTargetPoint().getLatestPointValues(stc.getNewValueCount()));
boolean found;
for (int k = 0; k < stc.getResults().length; k += 1) {
found = false;
for (int i = 0; i < pvts.size(); i += 1) {
if (stc.getResult(k).equals(pvts.get(i).getStringValue()))
found = true;
}
if (!found)
fail("No value match found for: '" + stc.getResult(k) + "' point value");
}
// Remove the point for the next test
rt.removeDataPoint(stc.getTargetPoint());
}
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.
the class VMStatDataSourceRT method readParts.
private void readParts(String[] parts) {
TranslatableMessage error = null;
long time = System.currentTimeMillis();
pointListChangeLock.readLock().lock();
try {
for (DataPointRT dp : dataPoints) {
VMStatPointLocatorVO locator = ((VMStatPointLocatorRT) dp.getPointLocator()).getVo();
Integer position = attributePositions.get(locator.getAttributeId());
if (position == null) {
if (error != null)
error = new TranslatableMessage("event.vmstat.attributeNotFound", locator.getConfigurationDescription());
} else {
try {
String data = parts[position];
Double value = new Double(data);
dp.updatePointValue(new PointValueTime(value, time));
} catch (NumberFormatException e) {
log.error("Weird. We couldn't parse the value " + parts[position] + " into a double. attribute=" + locator.getAttributeId());
} catch (ArrayIndexOutOfBoundsException e) {
log.error("Weird. We need element " + position + " but the vmstat data is only " + parts.length + " elements long. The statistic " + Common.translate(VMStatPointLocatorVO.ATTRIBUTE_CODES.getKey(locator.getAttributeId())) + " is missing from the vmstat output.");
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.vmstat.process", "The statistic " + Common.translate(VMStatPointLocatorVO.ATTRIBUTE_CODES.getKey(locator.getAttributeId())) + " is missing from the vmstat output."));
}
}
}
} finally {
pointListChangeLock.readLock().unlock();
}
if (error == null)
returnToNormal(PARSE_EXCEPTION_EVENT, time);
else
raiseEvent(PARSE_EXCEPTION_EVENT, time, true, error);
}
Aggregations