Use gruff gem to generate bar graphs
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
require 'open-uri'
|
||||
require 'gr/plot'
|
||||
require 'i18n'
|
||||
require 'gruff'
|
||||
|
||||
EASY_ENERGY_TARIFFS = {}
|
||||
|
||||
# See https://www.belastingdienst.nl/wps/wcm/connect/bldcontentnl/belastingdienst/zakelijk/overige_belastingen/belastingen_op_milieugrondslag/tarieven_milieubelastingen/tabellen_tarieven_milieubelastingen
|
||||
@@ -20,6 +22,11 @@ class Cost
|
||||
@entsoe = Entsoe.new(zone, storage_cost)
|
||||
@max_charge_kwh = max_charge
|
||||
@battery = Battery.new(battery_capacity)
|
||||
|
||||
# Allow for Dutch titles in graphs
|
||||
I18n.load_path += Dir[File.expand_path("config/locales") + "/*.yml"]
|
||||
I18n.available_locales = [:en, :nl]
|
||||
I18n.locale = :nl
|
||||
end
|
||||
|
||||
# Government reduced VAT to 9% from 1 July 2022 until 31 Dec 2022
|
||||
@@ -98,12 +105,16 @@ class Cost
|
||||
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 = "Tarief per kwH (incl. belastingen en BTW) - %s" % date.strftime("%A, %e %B %Y")
|
||||
xlabel = "uur"
|
||||
ylabel = "EUR"
|
||||
GR.savefig("plots/easy_tariff_%s.png" % date.strftime("%F"), title: title, xlabel: xlabel, ylabel: ylabel)
|
||||
g = Gruff::StackedBar.new()
|
||||
g.title = "Tarief per kwH (incl. belastingen en BTW) - %s" % I18n.localize(date, format: "%A, %e %B %Y")
|
||||
g.x_axis_label = "uur"
|
||||
#g.y_axis_label = "EUR"
|
||||
g.y_axis_label_format = lambda do |value|
|
||||
"€ %.2f" % value
|
||||
end
|
||||
g.labels = hours
|
||||
g.data :costs, costs
|
||||
g.write("plots/easy_tariff_%s.png" % date.strftime("%F"))
|
||||
end
|
||||
|
||||
def easy_energy_cost_barplot(date)
|
||||
@@ -126,13 +137,17 @@ class Cost
|
||||
|
||||
# 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("plots/easy_cost_%s.png" % date.strftime("%F"), title: title, xlabel: xlabel, ylabel: ylabel)
|
||||
|
||||
g = Gruff::StackedBar.new()
|
||||
g.title = "Verbruikskosten (incl. belastingen en BTW) - %s" % I18n.localize(date, format: "%A, %e %B %Y")
|
||||
g.x_axis_label = "uur"
|
||||
#g.y_axis_label = "EUR"
|
||||
g.y_axis_label_format = lambda do |value|
|
||||
"€ %.2f" % value
|
||||
end
|
||||
g.labels = hours
|
||||
g.data :costs, costs
|
||||
g.write("plots/easy_tariff_%s.png" % date.strftime("%F"))
|
||||
|
||||
# return the sum cost
|
||||
costs.sum
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user