diff --git a/Gemfile b/Gemfile index a847c88..0ba5c40 100644 --- a/Gemfile +++ b/Gemfile @@ -12,3 +12,4 @@ gem 'ruby-gr' gem 'gr-plot' gem 'histogram' gem 'numo-narray' +gem 'gruff' diff --git a/Gemfile.lock b/Gemfile.lock index b9cfff9..0232c94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,6 +21,9 @@ GEM raabro (~> 1.4) gr-plot (0.0.1) ruby-gr + gruff (0.19.0) + histogram + rmagick (>= 4.2) histogram (0.2.4.1) i18n (1.8.11) concurrent-ruby (~> 1.0) @@ -37,6 +40,7 @@ GEM pkg-config (1.4.9) raabro (1.4.0) racc (1.6.0) + rmagick (5.0.0) ruby-gr (0.66.0.0) fiddle numo-narray @@ -55,6 +59,7 @@ DEPENDENCIES activerecord daemons gr-plot + gruff histogram mail mysql2 diff --git a/app/models/cost.rb b/app/models/cost.rb index c928344..42b47ff 100644 --- a/app/models/cost.rb +++ b/app/models/cost.rb @@ -4,8 +4,8 @@ EASY_ENERGY_TARIFFS = {} # See https://www.belastingdienst.nl/wps/wcm/connect/bldcontentnl/belastingdienst/zakelijk/overige_belastingen/belastingen_op_milieugrondslag/tarieven_milieubelastingen/tabellen_tarieven_milieubelastingen # Without VAT -ENERGY_TAX_KWH = { 2020 => 0.09770, 2021 => 0.09428, 2022 => 0.03679} -ODE_KWH = { 2020 => 0.0273, 2021 => 0.0300, 2022 => 0.0305} +ENERGY_TAX_KWH = { 2020 => 0.09770, 2021 => 0.09428, 2022 => 0.03679, 2023 => 0.12599 } +ODE_KWH = { 2020 => 0.0273, 2021 => 0.0300, 2022 => 0.0305, 2023 => 0.0} # merge by adding values TAX_KWH = ENERGY_TAX_KWH.merge(ODE_KWH){|key, energy_tax, ode| energy_tax + ode} @@ -151,6 +151,9 @@ class Cost high_tariff ? 0.06782 : 0.05259 when 2022 high_tariff ? 0.23665 : 0.19408 + when 2023 + # rate excl. VAT + high_tariff ? 0.47758 : 0.34165 end end @@ -175,10 +178,15 @@ class Cost # normaal_kwh * (0.23665 + 0.04452 + 0.03691) + dal_kwh * (0.19408 + 0.04452 + 0.03691) normaal_kwh_cost = 0.23665 dal_kwh_cost = 0.19408 - # From 8 Sept 2022 until 31 December 2025 (may need to extend this) - when 1662595200..1767139200 + # From 8 Sept 2022 until 31 December 2022 + when 1662595200..1672527599 normaal_kwh_cost = 0.60824 dal_kwh_cost = 0.43701 + # From 1 Jan 2023 until 31 December 2023 + when 1672527600..1704063599 + vat = 1 + vat_at(Date.parse(formatted_hour)) + normaal_kwh_cost = 0.47758*vat + dal_kwh_cost = 0.34165*vat else # catch-all, incase 'formated_hour' is outside any of the cases normaal_kwh_cost = 0.0 diff --git a/frankenergy.py b/frankenergy.py new file mode 100644 index 0000000..ade0eef --- /dev/null +++ b/frankenergy.py @@ -0,0 +1,46 @@ +import requests +from datetime import datetime, timedelta +import csv + +def FrankEnergy(): + now = datetime.now() + + yesterday = datetime.now() + timedelta(days=-1) + startdate = yesterday.strftime("%Y-%m-%d") + enddate = now.strftime("%Y-%m-%d") + + if int(now.strftime("%H")) > 15: + tomorrow = datetime.now() + timedelta(days=2) + startdate = now.strftime("%Y-%m-%d") + enddate = tomorrow.strftime("%Y-%m-%d") + + headers = { "content-type":"application/json" } + + query = f"""query MarketPrices {{ + marketPricesGas(startDate: "{startdate}", endDate: "{enddate}") {{ + from + till + marketPrice + priceIncludingMarkup + }} + }}""" + + response = requests.post('https://graphcdn.frankenergie.nl', json={'query': query}, headers=headers) + data = response.json() + + frank_gas_file = "frank_gas.csv" + + frank_headers = ['till', 'from', 'marketPrice', 'priceIncludingMarkup'] + + with open(frank_gas_file, 'w') as csvfile: + writer = csv.DictWriter(csvfile, fieldnames = frank_headers) + writer.writeheader() + writer.writerows(data['data']['marketPricesGas']) + + for gas in data['data']['marketPricesGas']: + print(gas['till'], gas['from'],gas['marketPrice'], gas['priceIncludingMarkup']) + + +if __name__ == "__main__": + FrankEnergy() + diff --git a/stacked_bar.png b/stacked_bar.png new file mode 100644 index 0000000..99dbbde Binary files /dev/null and b/stacked_bar.png differ