Search in sources :

Example 1 with RollupEnum

use of com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum in project ma-modules-public by infiniteautomation.

the class AggregateValueMapper method apply.

@Override
public StreamingPointValueTimeModel apply(SeriesValueTime<? extends AggregateValue> value) {
    DataPointVO point = lookupPoint(value.getSeriesId());
    RollupEnum rollup = rollup(point);
    AggregateValue aggregate = value.getValue();
    StreamingPointValueTimeModel model = new StreamingPointValueTimeModel(point.getXid(), value.getTime());
    if (rollup == RollupEnum.ALL) {
        AllStatisticsModel allStatisticsModel = getAllRollup(point, aggregate);
        model.setAllStatistics(allStatisticsModel);
    } else {
        ValueTimeModel rollupValue = getRollupValue(point, aggregate, rollup);
        model.setValueModel(rollupValue);
    }
    if (fields.contains(PointValueField.CACHED)) {
        model.setCached(false);
    }
    if (fields.contains(PointValueField.BOOKEND)) {
        model.setBookend(false);
    }
    return copyPointPropertiesToModel(point, model);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AggregateValue(com.serotonin.m2m2.db.dao.pointvalue.AggregateValue) AllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel) MultistateAllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel) StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) ValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.ValueTimeModel) RollupEnum(com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum)

Example 2 with RollupEnum

use of com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum in project ma-modules-public by infiniteautomation.

the class PointValueTimeStreamCsvMessageConverter method writeInternal.

@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    MediaType contentType = outputMessage.getHeaders().getContentType();
    JsonEncoding encoding = getJsonEncoding(contentType);
    try {
        PointValueTimeStream<?, ?> stream = (PointValueTimeStream<?, ?>) object;
        stream.setContentType(StreamContentType.CSV);
        JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
        // Set the schema
        CsvSchema.Builder builder = CsvSchema.builder();
        builder.setUseHeader(true);
        // Setup our rendering parameters
        LatestQueryInfo info = stream.getQueryInfo();
        if (stream instanceof MultiPointTimeRangeDatabaseStream || stream instanceof MultiPointLatestDatabaseStream) {
            if (info.isSingleArray()) {
                if (info.isMultiplePointsPerArray()) {
                    Map<Integer, DataPointVO> voMap = stream.getVoMap();
                    Iterator<Integer> it = voMap.keySet().iterator();
                    boolean firstTimestamp = true;
                    while (it.hasNext()) {
                        String xid = voMap.get(it.next()).getXid();
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.TIMESTAMP) {
                                if (firstTimestamp)
                                    field.createColumn(builder, xid);
                                firstTimestamp = false;
                            } else
                                field.createColumn(builder, xid);
                        }
                    }
                } else {
                    for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                }
            } else {
                for (PointValueField field : info.getFields()) field.createColumn(builder, null);
            }
        } else if (stream instanceof MultiDataPointStatisticsQuantizerStream || stream instanceof MultiDataPointDefaultRollupStatisticsQuantizerStream) {
            if (stream.getQueryInfo().isSingleArray()) {
                if (stream.getQueryInfo().isMultiplePointsPerArray()) {
                    Map<Integer, DataPointVO> voMap = stream.getVoMap();
                    Iterator<Integer> it = voMap.keySet().iterator();
                    boolean firstTimestamp = true;
                    while (it.hasNext()) {
                        String xid = voMap.get(it.next()).getXid();
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.TIMESTAMP) {
                                if (firstTimestamp)
                                    field.createColumn(builder, xid);
                                firstTimestamp = false;
                            } else if (field == PointValueField.VALUE) {
                                if (info.getRollup() == RollupEnum.ALL) {
                                    for (RollupEnum rollup : getAllRollups()) {
                                        builder.addColumn(xid + PointValueTimeWriter.DOT + rollup.name(), ColumnType.NUMBER_OR_STRING);
                                    }
                                } else {
                                    field.createColumn(builder, xid);
                                }
                            } else {
                                field.createColumn(builder, xid);
                            }
                        }
                    }
                } else {
                    // Single array
                    if (info.getRollup() == RollupEnum.ALL) {
                        for (RollupEnum rollup : getAllRollups()) {
                            builder.addColumn(rollup.name(), ColumnType.NUMBER_OR_STRING);
                        }
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.VALUE)
                                continue;
                            field.createColumn(builder, null);
                        }
                    } else {
                        for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                    }
                }
            } else {
                if (info.getRollup() == RollupEnum.ALL) {
                    for (RollupEnum rollup : getAllRollups()) {
                        builder.addColumn(rollup.name(), ColumnType.NUMBER_OR_STRING);
                    }
                    for (PointValueField field : info.getFields()) {
                        if (field == PointValueField.VALUE)
                            continue;
                        field.createColumn(builder, null);
                    }
                } else {
                    for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                }
            }
        }
        generator.setSchema(builder.build());
        PointValueTimeWriter writer = new PointValueTimeCsvWriter(stream.getQueryInfo(), stream.getVoMap().size(), generator);
        try {
            stream.start(writer);
            stream.streamData(writer);
            stream.finish(writer);
            generator.flush();
        } catch (QueryCancelledException e) {
            throw new HttpMessageNotWritableException("Query Cancelled");
        }
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
    }
}
Also used : PointValueTimeStream(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeStream) MultiDataPointStatisticsQuantizerStream(com.infiniteautomation.mango.rest.latest.model.pointValue.quantize.MultiDataPointStatisticsQuantizerStream) MultiDataPointDefaultRollupStatisticsQuantizerStream(com.infiniteautomation.mango.rest.latest.model.pointValue.quantize.MultiDataPointDefaultRollupStatisticsQuantizerStream) LatestQueryInfo(com.infiniteautomation.mango.rest.latest.model.pointValue.query.LatestQueryInfo) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) PointValueTimeCsvWriter(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeCsvWriter) JsonEncoding(com.fasterxml.jackson.core.JsonEncoding) MultiPointTimeRangeDatabaseStream(com.infiniteautomation.mango.rest.latest.model.pointValue.query.MultiPointTimeRangeDatabaseStream) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) Iterator(java.util.Iterator) MediaType(org.springframework.http.MediaType) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RollupEnum(com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MultiPointLatestDatabaseStream(com.infiniteautomation.mango.rest.latest.model.pointValue.query.MultiPointLatestDatabaseStream) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) PointValueTimeWriter(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeWriter) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException) Map(java.util.Map) PointValueField(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField)

Aggregations

RollupEnum (com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 JsonEncoding (com.fasterxml.jackson.core.JsonEncoding)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 QueryCancelledException (com.infiniteautomation.mango.db.query.QueryCancelledException)1 PointValueField (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueField)1 PointValueTimeCsvWriter (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeCsvWriter)1 PointValueTimeStream (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeStream)1 PointValueTimeWriter (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeWriter)1 MultiDataPointDefaultRollupStatisticsQuantizerStream (com.infiniteautomation.mango.rest.latest.model.pointValue.quantize.MultiDataPointDefaultRollupStatisticsQuantizerStream)1 MultiDataPointStatisticsQuantizerStream (com.infiniteautomation.mango.rest.latest.model.pointValue.quantize.MultiDataPointStatisticsQuantizerStream)1 LatestQueryInfo (com.infiniteautomation.mango.rest.latest.model.pointValue.query.LatestQueryInfo)1 MultiPointLatestDatabaseStream (com.infiniteautomation.mango.rest.latest.model.pointValue.query.MultiPointLatestDatabaseStream)1 MultiPointTimeRangeDatabaseStream (com.infiniteautomation.mango.rest.latest.model.pointValue.query.MultiPointTimeRangeDatabaseStream)1 AllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel)1 MultistateAllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel)1 StreamingPointValueTimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel)1