diff --git a/app/helpers/ReadingsMailer.rb b/app/helpers/ReadingsMailer.rb index fbdef4c..5a4fa73 100644 --- a/app/helpers/ReadingsMailer.rb +++ b/app/helpers/ReadingsMailer.rb @@ -25,6 +25,9 @@ class ReadingsMailer # Fetch today's usage usage_today = Reading.diff_on(Date.today) + c = Cost.new + oxxio_cost = c.oxxio_energy_cost(Date.today.to_s,usage_today[:total_kwh_consumed_high]-usage_today[:total_kwh_produced_high], usage_today[:total_kwh_consumed_low]-usage_today[:total_kwh_produced_low]) + easy_cost = c.easy_energy_cost_barplot(Date.today) # side effect: generates a PNG mail = Mail.new do delivery_method :smtp, smtp_opts @@ -37,7 +40,9 @@ class ReadingsMailer -------------------------------\n\n Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}\n Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}\n - Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}\n + Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}\n\n + kWH cost (Oxxio): EUR #{ oxxio_cost }\n + kWH cost (EasyEnergy): EUR #{ easy_cost }\n " end @@ -46,7 +51,10 @@ class ReadingsMailer body "
Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}
" + "Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}
" + - "Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}
" + "Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}
" + + "" + + "kWH cost (Oxxio): EUR #{ oxxio_cost}
" + + "kWH cost (EasyEnergy): EUR #{ easy_cost}
" end end diff --git a/app/models/cost.rb b/app/models/cost.rb index 25f5eef..44c1967 100644 --- a/app/models/cost.rb +++ b/app/models/cost.rb @@ -118,8 +118,10 @@ class Cost 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) + GR.savefig("plots/easy_cost_%s.png" % date.strftime("%F"), title: title, xlabel: xlabel, ylabel: ylabel) + # return the sum cost + costs.sum end