From 754a7d3997b4be3b5930d4632f3cab84507aeb9c Mon Sep 17 00:00:00 2001 From: Aart van Halteren Date: Thu, 15 Sep 2022 22:22:27 +0200 Subject: [PATCH] take yearshift into account --- app/models/cost.rb | 5 +++-- app/models/entsoe.rb | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/cost.rb b/app/models/cost.rb index 97c1c0b..238eb13 100644 --- a/app/models/cost.rb +++ b/app/models/cost.rb @@ -177,11 +177,10 @@ class Cost hour_start = date.in_time_zone("Amsterdam").beginning_of_day day_end = hour_start.advance(days: 1) result = [] - lowest_hour, highest_hour,high_hours = entsoe.high_low_hours(date) + lowest_hour, highest_hour,high_hours = entsoe.high_low_hours(date.advance(years: year_shift)) while(hour_start < day_end) do hour_end = hour_start.end_of_hour - formatted_hour = hour_start.strftime("%F %H") #p "Fetching meter readings between %s and %s" % [hour_start,hour_end] hour_readings = Reading.where("created_at > :begin AND created_at < :end", {:begin => hour_start, :end => hour_end}) @@ -189,6 +188,8 @@ class Cost # calculate cost of this hour usage_kwh = hour_diff[:total_kwh_consumed_high] + hour_diff[:total_kwh_consumed_low] rescue nil return_kwh = hour_diff[:total_kwh_produced_high] + hour_diff[:total_kwh_produced_low] rescue nil + + formatted_hour = hour_start.advance(years: year_shift).strftime("%F %H") entsoe_cost = entsoe_energy_cost(formatted_hour, usage_kwh, return_kwh) # without battery use # diff --git a/app/models/entsoe.rb b/app/models/entsoe.rb index f180f20..cec44eb 100644 --- a/app/models/entsoe.rb +++ b/app/models/entsoe.rb @@ -114,6 +114,7 @@ class Entsoe prices.map{|p| [start_time.advance(hours: (p[0]-1)), p[1]]}.to_h rescue Date::Error => e p e.message + {} end end end