use of com.webstart.model.NumericValue in project FarmCloud by vratsasg.
the class MeasuresServiceImpl method saveMeasure.
public void saveMeasure(AutomaticWater automaticWater) {
try {
Long seriesid = seriesJpaRepository.findSeriesIdByEndDevice(automaticWater.getIdentifier()).get(0);
BigDecimal waterCons = featureofinterestJpaRepository.getWaterConsumption(automaticWater.getIdentifier()).get(0);
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMddHHmmss");
// DateTime Convertable
Featureofinterest featureofinterest = featureofInterestService.getFeatureofinterestByIdentifier(automaticWater.getIdentifier());
DateTimeFormatter dtfInput = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
HelperCls.ConvertToDateTime convertable = new HelperCls.ConvertToDateTime();
DateTime from = convertable.GetUTCDateTime(automaticWater.getFromtime(), dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
DateTime to = convertable.GetUTCDateTime(automaticWater.getUntiltime(), dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
int offset = DateTimeZone.getDefault().getOffset(new Instant());
//
Observation observation = new Observation();
observation.setSeriesid(seriesid);
observation.setPhenomenontimestart(new Timestamp(from.getMillis() - offset));
observation.setPhenomenontimeend(new Timestamp(to.getMillis() - offset));
observation.setIdentifier(dtf.print(new DateTime(DateTimeZone.UTC)) + "-" + java.util.UUID.randomUUID());
observation.setUnitid((long) 22);
//
logger.debug("params: FROM dt_from={}, ts_from={} TO dt_to={}, ts_to={}", from, observation.getPhenomenontimestart(), to, observation.getPhenomenontimeend());
//
observationJpaRepository.save(observation);
NumericValue numericValue = new NumericValue();
numericValue.setObservationid(observation.getObservationid());
float diffmilliSec = to.getMillis() - from.getMillis();
numericValue.setValue(new BigDecimal((diffmilliSec / 1000.0 / 3600.0) * waterCons.doubleValue()));
numericValueJpaRepository.save(numericValue);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.webstart.model.NumericValue in project FarmCloud by vratsasg.
the class MeasuresServiceImpl method saveMeasure.
public void saveMeasure(Long seriesId, EmbeddedData embeddedData) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
// DateTime Convertable
Featureofinterest featureofinterest = featureofInterestService.getFeatureofinterestByIdentifier(embeddedData.getZigbeeAddress());
DateTimeFormatter dtfInput = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
HelperCls.ConvertToDateTime convertable = new HelperCls.ConvertToDateTime();
DateTime dt = convertable.GetUTCDateTime(embeddedData.getDatetimeMeasure(), dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
Timestamp ts = new Timestamp(dt.getMillis());
Observation observation = new Observation();
observation.setSeriesid(seriesId);
observation.setPhenomenontimestart(ts);
observation.setPhenomenontimeend(ts);
// observation.setIdentifier(dtf.print(new DateTime(DateTimeZone.UTC)) + "-" + java.util.UUID.randomUUID());
observation.setIdentifier(sdf.format(ts) + "-" + java.util.UUID.randomUUID());
observation.setUnitid((long) embeddedData.getUnitId());
observationJpaRepository.save(observation);
NumericValue numericValue = new NumericValue();
numericValue.setObservationid(observation.getObservationid());
numericValue.setValue(embeddedData.getMeasureValue());
numericValueJpaRepository.save(numericValue);
logger.debug("params: dt={}, ts={}", dt, ts);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations