Search in sources :

Example 1 with StartsAndRuntimeAggregate

use of com.serotonin.m2m2.db.dao.pointvalue.StartsAndRuntimeAggregate in project ma-modules-public by infiniteautomation.

the class AggregateValueMapper method getAllRollup.

private AllStatisticsModel getAllRollup(DataPointVO point, AggregateValue stats) {
    AllStatisticsModel all;
    if (stats instanceof NumericAggregate) {
        NumericAllModel model = new NumericAllModel();
        model.setAccumulator(getRollupValue(point, stats, RollupEnum.ACCUMULATOR));
        model.setAverage(getRollupValue(point, stats, RollupEnum.AVERAGE));
        model.setDelta(getRollupValue(point, stats, RollupEnum.DELTA));
        model.setIntegral(getRollupValue(point, stats, RollupEnum.INTEGRAL));
        model.setMaximum(getRollupValue(point, stats, RollupEnum.MAXIMUM));
        model.setMinimum(getRollupValue(point, stats, RollupEnum.MINIMUM));
        model.setSum(getRollupValue(point, stats, RollupEnum.SUM));
        model.setMaximumInPeriod(getRollupValue(point, stats, RollupEnum.MAXIMUM_IN_PERIOD));
        model.setMinimumInPeriod(getRollupValue(point, stats, RollupEnum.MINIMUM_IN_PERIOD));
        model.setArithmeticMean(getRollupValue(point, stats, RollupEnum.ARITHMETIC_MEAN));
        all = model;
    } else if (stats instanceof StartsAndRuntimeAggregate) {
        MultistateAllStatisticsModel model = new MultistateAllStatisticsModel();
        var startsStats = ((StartsAndRuntimeAggregate) stats);
        var startsModel = startsStats.getData().stream().map(start -> {
            String rendered = renderValue(point, start.getDataValue());
            return new StartsAndRuntimeModel(start.getDataValue(), rendered, start.getStarts(), start.getRuntime(), start.getProportion());
        }).collect(Collectors.toUnmodifiableList());
        model.setStartsAndRuntimes(startsModel);
        all = model;
    } else {
        all = new AllStatisticsModel();
    }
    if (fields.contains(PointValueField.TIMESTAMP)) {
        all.setTimestamp(formatTime(stats.getPeriodStartTime()));
    }
    all.setCount(stats.getCount());
    all.setFirst(getRollupValue(point, stats, RollupEnum.FIRST));
    all.setLast(getRollupValue(point, stats, RollupEnum.LAST));
    all.setStart(getRollupValue(point, stats, RollupEnum.START));
    return all;
}
Also used : AllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel) MultistateAllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel) MultistateAllStatisticsModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel) StartsAndRuntimeAggregate(com.serotonin.m2m2.db.dao.pointvalue.StartsAndRuntimeAggregate) NumericAllModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.NumericAllModel) StartsAndRuntimeModel(com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel.StartsAndRuntimeModel) NumericAggregate(com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate)

Aggregations

AllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.AllStatisticsModel)1 MultistateAllStatisticsModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel)1 StartsAndRuntimeModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.MultistateAllStatisticsModel.StartsAndRuntimeModel)1 NumericAllModel (com.infiniteautomation.mango.rest.latest.streamingvalues.model.NumericAllModel)1 NumericAggregate (com.serotonin.m2m2.db.dao.pointvalue.NumericAggregate)1 StartsAndRuntimeAggregate (com.serotonin.m2m2.db.dao.pointvalue.StartsAndRuntimeAggregate)1