Send monthly reports
This commit is contained in:
@@ -45,7 +45,9 @@ class Cost
|
||||
end
|
||||
|
||||
# Assume: usage_kwh_cost, return_kwh_cost already includes vat
|
||||
def add_tax(formatted_hour,usage_kwh,usage_kwh_cost,return_kwh, return_kwh_cost)
|
||||
# calling this with only 'usage_kwh' parameter returns the tax amount for those kwh only.
|
||||
#
|
||||
def add_tax(formatted_hour,usage_kwh,usage_kwh_cost=0.0,return_kwh=0.0, return_kwh_cost=0.0)
|
||||
return nil if (usage_kwh.nil? || usage_kwh_cost.nil? || return_kwh.nil? || return_kwh_cost.nil?)
|
||||
|
||||
vat = 1 + vat_at(Date.parse(formatted_hour))
|
||||
@@ -117,6 +119,32 @@ class Cost
|
||||
g.write("plots/easy_tariff_%s.png" % date.strftime("%F"))
|
||||
end
|
||||
|
||||
# calculate the hourly cost (raw!) between start_hour and end_hour
|
||||
# raw means: entsoe prices + VAT
|
||||
def easy_energy_raw_hourly_cost_between(start_hour, end_hour)
|
||||
begin_hour = start_hour
|
||||
costs = []
|
||||
while(begin_hour < end_hour) do
|
||||
# get usage_kwh/return_kwh for one hour
|
||||
begin_hour_plus1 = begin_hour.end_of_hour
|
||||
hour_readings = Reading.where("created_at > :begin AND created_at < :end", {:begin => begin_hour, :end => begin_hour_plus1})
|
||||
hour_diff = hour_readings.last ? hour_readings.last.diff(hour_readings.first) : UNKNOWN_READING
|
||||
# helper to remove distiction between low/high tarif consumption
|
||||
usage_kwh, return_kwh = Reading.consumed_and_produced_for_diff(hour_diff)
|
||||
|
||||
formatted_hour = begin_hour.strftime("%F %H")
|
||||
# calculate RAW price (entsoe price + VAT)
|
||||
kwh_price = entsoe.price_at(formatted_hour)*(1+vat_at(Date.parse(formatted_hour)))
|
||||
hour_cost = (usage_kwh.nil? || return_kwh.nil? || kwh_price.nil?) ? nil : ((usage_kwh-return_kwh)*kwh_price)
|
||||
costs << hour_cost
|
||||
|
||||
# do the next hour
|
||||
begin_hour = begin_hour.advance(:hours => 1)
|
||||
end
|
||||
# give the result
|
||||
costs
|
||||
end
|
||||
|
||||
# calculate the hourly cost between start_hour and end_hour
|
||||
def easy_energy_hourly_cost_between(start_hour, end_hour)
|
||||
begin_hour = start_hour
|
||||
@@ -158,6 +186,26 @@ class Cost
|
||||
costs
|
||||
end
|
||||
|
||||
# calculate leveringskosten (entsoe prices + VAT) in one month
|
||||
# date = arbitrary day for the month
|
||||
def easy_energy_raw_cost_in_month(date)
|
||||
hour_start = date.beginning_of_month.in_time_zone(zone).beginning_of_day
|
||||
hour_end = date.end_of_month.in_time_zone(zone).end_of_day
|
||||
# can't get cost for the future
|
||||
hour_end = Time.now if hour_end > Time.now
|
||||
|
||||
easy_energy_raw_hourly_cost_between(hour_start,hour_end)
|
||||
end
|
||||
|
||||
def easy_energy_cost_in_month(date)
|
||||
hour_start = date.beginning_of_month.in_time_zone(zone).beginning_of_day
|
||||
hour_end = date.end_of_month.in_time_zone(zone).end_of_day
|
||||
# can't get cost for the future
|
||||
hour_end = Time.now if hour_end > Time.now
|
||||
|
||||
easy_energy_hourly_cost_between(hour_start,hour_end)
|
||||
end
|
||||
|
||||
def easy_energy_hourly_cost_for(date)
|
||||
hour_start = date.in_time_zone(zone).beginning_of_day
|
||||
day_end = hour_start.advance(days: 1)
|
||||
@@ -204,8 +252,9 @@ class Cost
|
||||
high_tariff ? 0.47758 : 0.34165
|
||||
end
|
||||
end
|
||||
|
||||
def oxxio_energy_cost(formatted_hour, normaal_kwh, dal_kwh, year_shift=0)
|
||||
|
||||
# Optional: raw! (tarif + VAT) cost
|
||||
def oxxio_energy_cost(formatted_hour, normaal_kwh, dal_kwh, with_tax=true, year_shift=0)
|
||||
return nil if (normaal_kwh.nil? || dal_kwh.nil?)
|
||||
#year = Date.parse(formatted_hour).year+year_shift
|
||||
date = Date.parse(formatted_hour).advance(years: year_shift)
|
||||
@@ -236,16 +285,24 @@ class Cost
|
||||
normaal_kwh_cost = 0.47758*vat
|
||||
dal_kwh_cost = 0.34165*vat
|
||||
else
|
||||
p "Not supported interval Oxxio for value: %d" % date.to_time.to_i
|
||||
# catch-all, incase 'formated_hour' is outside any of the cases
|
||||
normaal_kwh_cost = 0.0
|
||||
dal_kwh_cost = 0.0
|
||||
end
|
||||
normaal_cost = add_tax(formatted_hour, normaal_kwh,normaal_kwh_cost,0,0) # return_kwh already accounted for
|
||||
dal_cost = add_tax(formatted_hour, dal_kwh, dal_kwh_cost,0,0)
|
||||
|
||||
if with_tax
|
||||
normaal_cost = add_tax(formatted_hour, normaal_kwh,normaal_kwh_cost) # return_kwh already accounted for
|
||||
dal_cost = add_tax(formatted_hour, dal_kwh, dal_kwh_cost)
|
||||
else
|
||||
normaal_cost = normaal_kwh*normaal_kwh_cost
|
||||
dal_cost = dal_kwh*dal_kwh_cost
|
||||
end
|
||||
|
||||
# result
|
||||
normaal_cost + dal_cost
|
||||
return normaal_cost, dal_cost
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# Entsoe
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user