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