Adds actual cost barplot
This commit is contained in:
@@ -82,15 +82,44 @@ class Cost
|
||||
result
|
||||
end
|
||||
|
||||
def easy_energy_barplot(date)
|
||||
def easy_energy_tariff_barplot(date)
|
||||
hours = (0..23).to_a
|
||||
costs = easy_energy_hours(date)
|
||||
GR.barplot(hours,costs)
|
||||
# make sure you have set GKS_WSTYPE=100 in the environment (for headless setup)
|
||||
title = "Kosten per kwH (incl. belastingen en BTW) - %s" % date.strftime("%A, %e %B %Y")
|
||||
title = "Tarief per kwH (incl. belastingen en BTW) - %s" % date.strftime("%A, %e %B %Y")
|
||||
xlabel = "uur"
|
||||
ylabel = "EUR"
|
||||
GR.savefig("easy_%s.png" % date.strftime("%F"), title: title, xlabel: xlabel, ylabel: ylabel)
|
||||
GR.savefig("easy_tariff_%s.png" % date.strftime("%F"), title: title, xlabel: xlabel, ylabel: ylabel)
|
||||
end
|
||||
|
||||
def easy_energy_cost_barplot(date)
|
||||
hour_start = date.in_time_zone(zone).beginning_of_day
|
||||
day_end = hour_start.advance(days: 1)
|
||||
costs = []
|
||||
while(hour_start < day_end) do
|
||||
# get usage_kwh/return_kwh for one hour
|
||||
hour_end = hour_start.end_of_hour
|
||||
hour_readings = Reading.where("created_at > :begin AND created_at < :end", {:begin => hour_start, :end => hour_end})
|
||||
hour_diff = hour_readings.last ? hour_readings.last.diff(hour_readings.first) : UNKNOWN_READING
|
||||
usage_kwh = hour_diff[:total_kwh_consumed_high] + hour_diff[:total_kwh_consumed_low]
|
||||
return_kwh = hour_diff[:total_kwh_produced_high] + hour_diff[:total_kwh_produced_low]
|
||||
|
||||
formatted_hour = hour_start.strftime("%F %H")
|
||||
costs << easy_energy_cost(formatted_hour, usage_kwh, return_kwh)
|
||||
# do the next hour
|
||||
hour_start = hour_start.advance(:hours => 1)
|
||||
end
|
||||
|
||||
# create plot
|
||||
hours = (0..23).to_a
|
||||
GR.barplot(hours,costs)
|
||||
# make sure you have set GKS_WSTYPE=100 in the environment (for headless setup)
|
||||
title = "Verbruikskosten (incl. belastingen en BTW) - %s" % date.strftime("%A, %e %B %Y")
|
||||
xlabel = "uur"
|
||||
ylabel = "EUR"
|
||||
GR.savefig("easy_cost_%s.png" % date.strftime("%F"), title: title, xlabel: xlabel, ylabel: ylabel)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user