take yearshift into account

This commit is contained in:
Aart van Halteren
2022-09-15 22:22:27 +02:00
parent e0f5865cd8
commit 754a7d3997
2 changed files with 4 additions and 2 deletions

View File

@@ -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
#

View File

@@ -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