Search in sources :

Example 1 with ValueTimeModel

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

the class AggregateValueMapper method getRollupValue.

private ValueTimeModel getRollupValue(DataPointVO point, AggregateValue aggregate, RollupEnum rollup) {
    Object rawValue;
    Long timestamp = aggregate.getPeriodStartTime();
    switch(rollup) {
        case FIRST:
            rawValue = aggregate.getFirstValue();
            if (timestampSource == TimestampSource.STATISTIC) {
                timestamp = aggregate.getFirstTime();
            }
            break;
        case LAST:
            rawValue = aggregate.getLastValue();
            if (timestampSource == TimestampSource.STATISTIC) {
                timestamp = aggregate.getLastTime();
            }
            break;
        case COUNT:
            rawValue = aggregate.getCount();
            break;
        case START:
            rawValue = aggregate.getStartValue();
            break;
        case AVERAGE:
            rawValue = extractNumeric(aggregate, NumericAggregate::getAverage);
            break;
        case DELTA:
            rawValue = extractNumeric(aggregate, NumericAggregate::getDelta);
            break;
        case ACCUMULATOR:
            rawValue = extractNumeric(aggregate, NumericAggregate::getAccumulator);
            break;
        case MINIMUM:
            rawValue = extractNumeric(aggregate, NumericAggregate::getMinimumValue);
            if (timestampSource == TimestampSource.STATISTIC) {
                timestamp = extractNumeric(aggregate, NumericAggregate::getMinimumTime);
            }
            break;
        case MAXIMUM:
            rawValue = extractNumeric(aggregate, NumericAggregate::getMaximumValue);
            if (timestampSource == TimestampSource.STATISTIC) {
                timestamp = extractNumeric(aggregate, NumericAggregate::getMaximumTime);
            }
            break;
        case SUM:
            rawValue = extractNumeric(aggregate, NumericAggregate::getSum);
            break;
        case INTEGRAL:
            rawValue = extractNumeric(aggregate, NumericAggregate::getIntegral);
            break;
        case ARITHMETIC_MEAN:
            rawValue = extractNumeric(aggregate, NumericAggregate::getArithmeticMean);
            break;
        case MINIMUM_IN_PERIOD:
            rawValue = extractNumeric(aggregate, NumericAggregate::getMinimumInPeriod);
            break;
        case MAXIMUM_IN_PERIOD:
            rawValue = extractNumeric(aggregate, NumericAggregate::getMaximumInPeriod);
            break;
        case ALL:
        // fall through, not supported here
        default:
            throw new IllegalArgumentException("Unsupported rollup: " + rollup);
    }
    ValueTimeModel model = new ValueTimeModel();
    if (fields.contains(PointValueField.TIMESTAMP)) {
        model.setTimestamp(formatTime(timestamp));
    }
    if (fields.contains(PointValueField.VALUE)) {
        Object convertedValue;
        if (rollup == RollupEnum.INTEGRAL && rawValue != null) {
            convertedValue = point.getIntegralConverter().convert((double) rawValue);
        } else {
            convertedValue = convertValue(point, rawValue);
        }
        model.setValue(convertedValue);
    }
    if (fields.contains(PointValueField.RAW)) {
        model.setRaw(rawValue);
    }
    if (fields.contains(PointValueField.RENDERED)) {
        String rendered;
        if (rollup == RollupEnum.INTEGRAL && rawValue != null) {
            rendered = point.createIntegralRenderer().getText((double) rawValue, TextRenderer.HINT_FULL, locale);
        } else {
            rendered = getRenderedValue(point, rawValue);
        }
        model.setRendered(rendered);
    }
    return model;
}
Also used : StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) ValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.ValueTimeModel)

Example 2 with ValueTimeModel

use of com.infiniteautomation.mango.rest.latest.streamingvalues.model.ValueTimeModel 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 3 with ValueTimeModel

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

the class DefaultStreamMapper method getValue.

private ValueTimeModel getValue(DataPointVO point, PointValueTime valueTime) {
    DataValue rawValue = valueTime.getValue();
    ValueTimeModel model = new ValueTimeModel();
    if (fields.contains(PointValueField.TIMESTAMP)) {
        model.setTimestamp(formatTime(valueTime.getTime()));
    }
    if (fields.contains(PointValueField.VALUE)) {
        Object convertedValue = convertValue(point, rawValue);
        model.setValue(convertedValue);
    }
    if (fields.contains(PointValueField.RAW)) {
        model.setRaw(rawValue);
    }
    if (fields.contains(PointValueField.RENDERED)) {
        model.setRendered(renderValue(point, rawValue));
    }
    return model;
}
Also used : StreamingPointValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel) ValueTimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.ValueTimeModel) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue)

Aggregations

StreamingPointValueTimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.StreamingPointValueTimeModel)3 ValueTimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.ValueTimeModel)3 RollupEnum (com.infiniteautomation.mango.rest.latest.model.pointValue.RollupEnum)1 AllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel)1 MultistateAllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel)1 AggregateValue (com.serotonin.m2m2.db.dao.pointvalue.AggregateValue)1 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1