diff --git a/app/models/entsoe.rb b/app/models/entsoe.rb index 394b03a..7d9f3b5 100644 --- a/app/models/entsoe.rb +++ b/app/models/entsoe.rb @@ -40,15 +40,23 @@ class Entsoe def high_low_hours(date) sorted_prices = prices_at(date).to_a.sort_by(&:last) # sort according to price - lowest_hour = sorted_prices.first[0] highest_hour = sorted_prices.last[0] - # calculate hours where rate > charge_rate + storage_cost (typically 0.05) - charge_rate = sorted_prices.first[1] # assume we charge at lowest hour - high_hours = sorted_prices.select{|p| p[1] > charge_rate + storage_cost}.to_h.keys - # reset lowest_hour (effectively not charging), when price difference smaller than storage_cost - highest_price = sorted_prices.last[1] - lowest_hour = "" if (highest_price-charge_rate) < storage_cost + # From Apr-Oct: do not charge; every hour that has cost > charge_rate is a high_hour + if [4,5,6,7,8,9,10].include?(date.month) + lowest_hour = "" # effectively no charging from grid + high_hours = sorted_prices.select{|p| p[1] > storage_cost} + else + lowest_hour = sorted_prices.first[0] + + # calculate hours where rate > charge_rate + storage_cost (typically 0.05) + charge_rate = sorted_prices.first[1] # assume we charge at lowest hour + high_hours = sorted_prices.select{|p| p[1] > charge_rate + storage_cost}.to_h.keys + + # reset lowest_hour (effectively not charging), when price difference smaller than storage_cost + highest_price = sorted_prices.last[1] + lowest_hour = "" if (highest_price-charge_rate) < storage_cost + end return lowest_hour,highest_hour,high_hours end