New smartmeter
This commit is contained in:
@@ -3,14 +3,21 @@ UNKNOWN_READING = { :total_kwh_consumed_high => nil, :total_kwh_consumed_low =>
|
||||
|
||||
|
||||
class Reading < ActiveRecord::Base
|
||||
|
||||
|
||||
# Round up with 1 (default) decimals
|
||||
def round_up(number, decimals = 1)
|
||||
factor = 10 ** decimals
|
||||
(number * factor).ceil / factor.to_f
|
||||
end
|
||||
|
||||
|
||||
def eql_reading?(reading)
|
||||
self.total_kwh_consumed_high == reading.total_kwh_consumed_high &&
|
||||
self.total_kwh_consumed_low == reading.total_kwh_consumed_low &&
|
||||
self.total_kwh_produced_high == reading.total_kwh_produced_high &&
|
||||
self.total_kwh_produced_low == reading.total_kwh_produced_low &&
|
||||
self.current_kw_consumed == reading.current_kw_consumed &&
|
||||
self.current_kw_produced == reading.current_kw_produced &&
|
||||
round_up(self.current_kw_consumed) == round_up(reading.current_kw_consumed) &&
|
||||
round_up(self.current_kw_produced) == round_up(reading.current_kw_produced) &&
|
||||
self.total_m3_gas_consumed == reading.total_m3_gas_consumed &&
|
||||
self.high_tarif == reading.high_tarif
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user