Search in sources :

Example 1 with Rollups

use of com.serotonin.m2m2.Common.Rollups in project ma-modules-public by infiniteautomation.

the class PointValueTimeWriter method writeNonNull.

/**
 * Write a Data Value that if null contains an annotation saying there is no data at this point in time
 * - useful for Rollups with gaps in the data
 * @param value
 * @param time
 * @throws ConversionException
 * @throws IOException
 */
public void writeNonNull(DataValue value, Long time, DataPointVO vo) throws ConversionException, IOException {
    if (time == null)
        throw new ShouldNeverHappenException("Time cannot be null");
    if (value == null) {
        if (useRendered) {
            this.writePointValueTime(new AlphanumericValue(""), time, this.noDataMessage, vo);
        } else {
            this.writePointValueTime(0.0D, time, this.noDataMessage, vo);
        }
    } else {
        if (useRendered) {
            // Convert to Alphanumeric Value
            String textValue = Functions.getRenderedText(vo, new PointValueTime(value, time));
            this.writePointValueTime(new AlphanumericValue(textValue), time, null, vo);
        } else if (unitConversion) {
            // Convert Value, must be numeric
            if (value instanceof NumericValue)
                this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value.getDoubleValue()), time, null, vo);
            else
                this.writePointValueTime(value, time, null, vo);
        } else {
            this.writePointValueTime(value, time, null, vo);
        }
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 2 with Rollups

use of com.serotonin.m2m2.Common.Rollups in project ma-modules-public by infiniteautomation.

the class PointValueTimeWriter method writeNonNullDouble.

/**
 * Write a Data Value that if null contains an annotation saying there is no data at this point in time
 * - useful for Rollups with gaps in the data
 * @param value
 * @param time
 * @throws ConversionException
 * @throws IOException
 */
public void writeNonNullDouble(Double value, long time, DataPointVO vo) throws ConversionException, IOException {
    if (value == null) {
        if (useRendered) {
            this.writePointValueTime(new AlphanumericValue(""), time, this.noDataMessage, vo);
        } else {
            this.writePointValueTime(0.0D, time, this.noDataMessage, vo);
        }
    } else {
        if (useRendered) {
            // Convert to Alphanumeric Value
            String textValue = Functions.getRenderedText(vo, new PointValueTime(value, time));
            this.writePointValueTime(new AlphanumericValue(textValue), time, null, vo);
        } else if (unitConversion) {
            // Convert Value, must be numeric
            this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value), time, null, vo);
        } else {
            this.writePointValueTime(value, time, null, vo);
        }
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 3 with Rollups

use of com.serotonin.m2m2.Common.Rollups in project ma-modules-public by infiniteautomation.

the class AbstractPointValueRollupCalculator method setupDates.

/**
 * Round off the period for rollups and ensure the date bounds are set
 */
private void setupDates() {
    // Determine the start and end times.
    if (from == null) {
        // Get the start and end from the point values table.
        LongPair lp = getStartEndTimes();
        from = new DateTime(lp.getL1());
        if (to == null)
            to = new DateTime(lp.getL2());
    } else if (to == null) {
        to = new DateTime();
    }
    // Round off the period if we are using periodic rollup
    if (period != null) {
        from = DateUtils.truncateDateTime(from, TimePeriodType.convertFrom(this.period.getType()), this.period.getPeriods());
        to = DateUtils.truncateDateTime(to, TimePeriodType.convertFrom(this.period.getType()), this.period.getPeriods());
    }
}
Also used : LongPair(com.serotonin.m2m2.vo.pair.LongPair) DateTime(org.joda.time.DateTime)

Aggregations

PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)2 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)1 LongPair (com.serotonin.m2m2.vo.pair.LongPair)1 DateTime (org.joda.time.DateTime)1