adds constants and class variables
This commit is contained in:
@@ -1,7 +1,14 @@
|
|||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
|
||||||
|
UNKNOWN_READING = { :total_kwh_consumed_high => nil, :total_kwh_consumed_low => nil, :total_kwh_produced_high => nil, :total_kwh_produced_low => nil, :total_m3_gas_consumed => nil}
|
||||||
|
EASY_ENERGY_TARIFFS = {}
|
||||||
|
BATTERY_MAX_KWH = 10.0
|
||||||
|
MAX_CHARGE_KWH = 5.0
|
||||||
|
|
||||||
class Reading < ActiveRecord::Base
|
class Reading < ActiveRecord::Base
|
||||||
|
|
||||||
|
@@battery_kwh = 0.0
|
||||||
|
|
||||||
def eql_reading?(reading)
|
def eql_reading?(reading)
|
||||||
self.total_kwh_consumed_high == reading.total_kwh_consumed_high &&
|
self.total_kwh_consumed_high == reading.total_kwh_consumed_high &&
|
||||||
self.total_kwh_consumed_low == reading.total_kwh_consumed_low &&
|
self.total_kwh_consumed_low == reading.total_kwh_consumed_low &&
|
||||||
@@ -65,10 +72,7 @@ class Reading < ActiveRecord::Base
|
|||||||
def day(date)
|
def day(date)
|
||||||
Reading.where("created_at > :begin AND created_at < :end", { :begin => date.to_date.beginning_of_day, :end => date.to_date.end_of_day})
|
Reading.where("created_at > :begin AND created_at < :end", { :begin => date.to_date.beginning_of_day, :end => date.to_date.end_of_day})
|
||||||
end
|
end
|
||||||
|
|
||||||
EASY_ENERGY_TARIFFS = {}
|
|
||||||
|
|
||||||
|
|
||||||
# returns a hash with keys formatted "yyyy-mm-dd-hr" and values [usage, return]
|
# returns a hash with keys formatted "yyyy-mm-dd-hr" and values [usage, return]
|
||||||
# e.g. { 2021-12-16-06"=>[0.36058, 0.298] }
|
# e.g. { 2021-12-16-06"=>[0.36058, 0.298] }
|
||||||
def easy_energy_tariffs(date)
|
def easy_energy_tariffs(date)
|
||||||
@@ -166,45 +170,37 @@ class Reading < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
UNKNOWN_READING = { :total_kwh_consumed_high => nil, :total_kwh_consumed_low => nil, :total_kwh_produced_high => nil, :total_kwh_produced_low => nil, :total_m3_gas_consumed => nil}
|
|
||||||
|
|
||||||
def format_cost(cost)
|
def format_cost(cost)
|
||||||
cost ? "EUR %0.03f" % cost : "EUR ?"
|
cost ? "EUR %0.03f" % cost : "EUR ?"
|
||||||
end
|
end
|
||||||
|
|
||||||
@battery_kwh = 0.0
|
|
||||||
BATTERY_MAX_KWH = 10.0
|
|
||||||
|
|
||||||
def charge_battery(kwh)
|
def charge_battery(kwh)
|
||||||
return 0.0 if kwh.nil?
|
return 0.0 if kwh.nil?
|
||||||
if @battery_kwh + kwh <= BATTERY_MAX_KWH
|
if @@battery_kwh + kwh <= BATTERY_MAX_KWH
|
||||||
@battery_kwh += kwh.to_f
|
@@battery_kwh += kwh.to_f
|
||||||
p "Battery is now at %s kwh" % @battery_kwh
|
p "Battery is now at %s kwh" % @@battery_kwh
|
||||||
return kwh
|
return kwh
|
||||||
else
|
else
|
||||||
old_kwh = @battery_kwh
|
old_kwh = @battery_kwh
|
||||||
@battery_kwh = BATTERY_MAX_KWH
|
@@battery_kwh = BATTERY_MAX_KWH
|
||||||
p "Battery is now at %s kwh" % @battery_kwh
|
p "Battery is now at %s kwh" % @@battery_kwh
|
||||||
return (BATTERY_MAX_KWH-old_kwh)
|
return (BATTERY_MAX_KWH-old_kwh)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def discharge_battery(kwh)
|
def discharge_battery(kwh)
|
||||||
return 0.0 if kwh.nil?
|
return 0.0 if kwh.nil?
|
||||||
if @battery_kwh > kwh.to_f
|
if @@battery_kwh > kwh.to_f
|
||||||
@battery_kwh -= kwh.to_f
|
@@battery_kwh -= kwh.to_f
|
||||||
p "Battery is now at %s kwh" % @battery_kwh
|
p "Battery is now at %s kwh" % @@battery_kwh
|
||||||
return kwh
|
return kwh
|
||||||
else
|
else
|
||||||
old_kwh = @battery_kwh
|
old_kwh = @@battery_kwh
|
||||||
@battery_kwh = 0.0
|
@@battery_kwh = 0.0
|
||||||
p "Battery is now at %s kwh" % @battery_kwh
|
p "Battery is now at %s kwh" % @@battery_kwh
|
||||||
return old_kwh
|
return old_kwh
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
MAX_CHARGE_KWH = 7.0
|
|
||||||
|
|
||||||
def hours(date, year_shift=0)
|
def hours(date, year_shift=0)
|
||||||
hour_start = date.beginning_of_day
|
hour_start = date.beginning_of_day
|
||||||
|
|||||||
Reference in New Issue
Block a user