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;
}
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);
}
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;
}
Aggregations