Search in sources :

Example 1 with ITime

use of com.serotonin.m2m2.view.stats.ITime in project ma-modules-public by infiniteautomation.

the class ReportPointValueTimeSerializer method putBytes.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getBytes(com.serotonin.m2m2.db.dao.nosql.NoSQLDataEntry)
	 */
@Override
public void putBytes(ByteArrayBuilder b, ITime obj, long timestamp, String seriesId) {
    PointValueTime value = (PointValueTime) obj;
    // First put in the data type
    b.putShort((short) value.getValue().getDataType());
    // Second put in the data value
    switch(value.getValue().getDataType()) {
        case DataTypes.ALPHANUMERIC:
            b.putString(value.getStringValue());
            break;
        case DataTypes.BINARY:
            b.putBoolean(value.getBooleanValue());
            break;
        case DataTypes.IMAGE:
            ImageValue imageValue = (ImageValue) value.getValue();
            if (!imageValue.isSaved()) {
                throw new ImageSaveException(new IOException("Image not saved."));
            }
            b.putString(imageValue.getFilename());
            break;
        case DataTypes.MULTISTATE:
            b.putInt(value.getIntegerValue());
            break;
        case DataTypes.NUMERIC:
            b.putDouble(value.getDoubleValue());
            break;
        default:
            throw new ShouldNeverHappenException("Data type of " + value.getValue().getDataType() + " is not supported");
    }
    // Put in annotation
    if (value.isAnnotated()) {
        AnnotatedPointValueTime apv = (AnnotatedPointValueTime) value;
        b.putString(apv.getSourceMessage().serialize());
    } else
        b.putString(null);
}
Also used : AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) IOException(java.io.IOException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 2 with ITime

use of com.serotonin.m2m2.view.stats.ITime in project ma-modules-public by infiniteautomation.

the class ReportDao method reportInstanceDataNoSQL.

public void reportInstanceDataNoSQL(int instanceId, final ExportDataStreamHandler handler) {
    // Retrieve point information.
    List<ExportPointInfo> pointInfos = query(REPORT_INSTANCE_POINT_SELECT + "where reportInstanceId=?", new Object[] { instanceId }, new RowMapper<ExportPointInfo>() {

        @Override
        public ExportPointInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            int i = 0;
            ExportPointInfo rp = new ExportPointInfo();
            rp.setReportPointId(rs.getInt(++i));
            rp.setDeviceName(rs.getString(++i));
            rp.setPointName(rs.getString(++i));
            rp.setXid(rs.getString(++i));
            rp.setDataType(rs.getInt(++i));
            String startValue = rs.getString(++i);
            if (startValue != null)
                rp.setStartValue(DataValue.stringToValue(startValue, rp.getDataType()));
            rp.setTextRenderer((TextRenderer) SerializationHelper.readObjectInContext(rs.getBlob(++i).getBinaryStream()));
            rp.setColour(rs.getString(++i));
            rp.setWeight(rs.getFloat(++i));
            rp.setConsolidatedChart(charToBool(rs.getString(++i)));
            rp.setPlotType(rs.getInt(++i));
            return rp;
        }
    });
    final ExportDataValue edv = new ExportDataValue();
    for (final ExportPointInfo point : pointInfos) {
        if (point.getDataType() == DataTypes.IMAGE) {
            DataPointVO vo = DataPointDao.instance.getByXid(point.getXid());
            if (vo != null)
                point.setDataPointId(vo.getId());
            else
                point.setDataPointId(-1);
        }
        handler.startPoint(point);
        edv.setReportPointId(point.getReportPointId());
        final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
        final String pointStore = instanceId + "_" + point.getReportPointId();
        dao.getData(pointStore, 0, Long.MAX_VALUE, -1, false, new NoSQLQueryCallback() {

            @Override
            public void entry(String storeName, long timestamp, ITime entry) {
                PointValueTime pvt = (PointValueTime) entry;
                edv.setValue(pvt.getValue());
                edv.setTime(pvt.getTime());
                if (pvt instanceof AnnotatedPointValueTime)
                    edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
                handler.pointData(edv);
            }
        });
    }
    handler.done();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLException(java.sql.SQLException) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) NoSQLQueryCallback(com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback) NoSQLDao(com.serotonin.m2m2.db.dao.nosql.NoSQLDao) ResultSet(java.sql.ResultSet) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) ITime(com.serotonin.m2m2.view.stats.ITime) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 3 with ITime

use of com.serotonin.m2m2.view.stats.ITime 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)

Aggregations

AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 ImageSaveException (com.serotonin.m2m2.ImageSaveException)2 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)2 IOException (java.io.IOException)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 NoSQLDao (com.serotonin.m2m2.db.dao.nosql.NoSQLDao)1 NoSQLQueryCallback (com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback)1 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)1 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)1 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)1 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)1 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)1 ITime (com.serotonin.m2m2.view.stats.ITime)1 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)1 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)1