This commit is contained in:
Aart van Halteren
2013-08-07 22:55:01 +02:00
parent 894932b726
commit 6fd8b79e1c

View File

@@ -34,11 +34,11 @@ class Reading < ActiveRecord::Base
# calculate difference with another reading
# return a hash with differences (self - reading)
def diff(reading)
{ :total_kwh_consumed_high => self.total_kwh_consumed_high - reading.total_kwh_consumed_high,
:total_kwh_consumed_low => self.total_kwh_consumed_low - reading.total_kwh_consumed_low,
:total_kwh_produced_high => self.total_kwh_produced_high - reading.total_kwh_produced_high,
:total_kwh_produced_low => self.total_kwh_produced_low - reading.total_kwh_produced_low,
:total_m3_gas_consumed => self.total_m3_gas_consumed - reading.total_m3_gas_consumed }
{ :total_kwh_consumed_high => (self.total_kwh_consumed_high - reading.total_kwh_consumed_high).round(1),
:total_kwh_consumed_low => (self.total_kwh_consumed_low - reading.total_kwh_consumed_low).round(1),
:total_kwh_produced_high => (self.total_kwh_produced_high - reading.total_kwh_produced_high).round(1),
:total_kwh_produced_low => (self.total_kwh_produced_low - reading.total_kwh_produced_low).round(1),
:total_m3_gas_consumed => (self.total_m3_gas_consumed - reading.total_m3_gas_consumed).round(3) }
end
#