Search in sources :

Example 81 with PointValueTime

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;
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO)

Example 82 with PointValueTime

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();
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 83 with PointValueTime

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);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) InvalidArgumentException(com.serotonin.InvalidArgumentException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) IOException(java.io.IOException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) InvalidArgumentException(com.serotonin.InvalidArgumentException) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 84 with PointValueTime

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());
    }
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) SerialDataSourceTestCase(com.infiniteautomation.serial.SerialDataSourceTestCase) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) SerialPortProxyEvent(com.infiniteautomation.mango.io.serial.SerialPortProxyEvent) Test(org.junit.Test)

Example 85 with PointValueTime

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);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)104 ArrayList (java.util.ArrayList)33 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)29 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)24 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)23 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)23 IOException (java.io.IOException)18 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)17 HashMap (java.util.HashMap)17 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)15 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)12 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)11 ScriptException (javax.script.ScriptException)10 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)9 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)9 LogStopWatch (com.serotonin.log.LogStopWatch)8 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)8 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)8 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8