Fewer no grid charge months

This commit is contained in:
Aart van Halteren
2022-01-10 22:27:25 +01:00
parent 8725c12a68
commit 28a806f584
2 changed files with 9 additions and 7 deletions

View File

@@ -3,8 +3,8 @@ EASY_ENERGY_TARIFFS = {}
class Cost
attr_reader :battery, :max_charge_kwh, :entsoe
attr_accessor :max_charge_kwh
attr_reader :battery, :entsoe
def initialize(battery_capacity=10.0, max_charge=5.0)
@entsoe = Entsoe.new
@@ -161,8 +161,8 @@ class Cost
# charge battery with return_kwh
return_kwh -= battery.charge(return_kwh)
if lowest_hour.eql?(formatted_hour) # lowest_hour = "" if small difference between high/low
# charge battery during lowest hour
if (lowest_hour.eql?(formatted_hour) || entsoe.price_at(formatted_hour) < 0) # lowest_hour = "" if small difference between high/low
# charge battery during lowest hour, or when prices are negative
usage_kwh += battery.charge(max_charge_kwh)
else
# if during expensive hours || more than <max_charge_kwh> kwh then discharge_battery
@@ -197,7 +197,7 @@ class Cost
oxxio_rate,
oxxio_cost]
p "%s,%s,%s,%s,%s,%s,%s,%03f,%s,%s,%s,%s,%s" % (one_hour[0..7] + one_hour[8..12].map{|c| format_cost(c)})
p "%s,%s,%s,%s,%s,%s,%s,%0.02f,%s,%s,%s,%s,%s" % (one_hour[0..7] + one_hour[8..12].map{|c| format_cost(c)})
result << one_hour
hour_start = hour_start.advance(:hours => 1)