Trying to make installable package
This commit is contained in:
commit
efc2d1c8f5
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
*.DS_Store
|
||||
pycache/
|
||||
*.pyc
|
||||
|
||||
*.log
|
||||
*.sqlite
|
||||
cache.json
|
||||
.env
|
||||
|
||||
.devcontainer/
|
||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM python:3.10
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt ./
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
64
EngieApi/Contracts.py
Normal file
64
EngieApi/Contracts.py
Normal file
@ -0,0 +1,64 @@
|
||||
import datetime
|
||||
|
||||
import numpy as np
|
||||
|
||||
from EngieApi.DistributionCosts import Capaciteitstarief
|
||||
from EngieApi.EngieAPI import EngieAPI
|
||||
|
||||
|
||||
class Dynamic:
|
||||
def __init__(self, btw=1.21):
|
||||
|
||||
self.btw = btw
|
||||
self.vast = 100.7 # EUR / jaar
|
||||
|
||||
self.groene_stroom = 0.00530 # EUR / kWh
|
||||
self.wwk = 0.02544 # EUR / kWh
|
||||
|
||||
# Supplementen
|
||||
self.energiebijdrage = 0.0020417 # EUR / kWh
|
||||
# federale accijns
|
||||
# 0 < kwh < 20000: 1.44160 cent / kWh
|
||||
# 20000 < kwh < 50000: 1.22748 cent / kWh
|
||||
# 50000 < kwh < 100000: 1.15540 cent / kWh
|
||||
self.federale_accijns = 0.0144160 # EUR / kWh
|
||||
|
||||
def calculate_price_per_kwh(self, date, peak: float):
|
||||
"""calculate_price_per_kwh
|
||||
|
||||
:param date: date to calculate for
|
||||
:type date: date
|
||||
"""
|
||||
api = EngieAPI()
|
||||
epex_spot = np.array(api.get_epex_spot(date))
|
||||
|
||||
prijs = 0.2040 + 0.1 * (epex_spot) # zonder BTW per Cent/kWh
|
||||
# cent to eur
|
||||
prijs /= 100
|
||||
prijs += self.groene_stroom + self.wwk + self.energiebijdrage + self.federale_accijns
|
||||
|
||||
# distirbution costs
|
||||
d = Capaciteitstarief()
|
||||
p, yearly = d.calculate_per_kwh(peak=peak)
|
||||
prijs += p
|
||||
|
||||
# add btw
|
||||
prijs *= self.btw
|
||||
return prijs, yearly + self.vast
|
||||
|
||||
def calculate_total_price_for_day(self, verbruik: list[int], date: datetime.date, peak: float) -> float:
|
||||
"""calculate_total_price_for_day calculate total price for given usage
|
||||
|
||||
:param verbruik: a list of hourly usage values
|
||||
:type verbruik: list[int]
|
||||
:param date: the date for the energy prices
|
||||
:type date: datetime.date
|
||||
:param peak: the monthly peak for the distribution costs
|
||||
:type peak: float
|
||||
:return: the total calculated price
|
||||
:rtype: float
|
||||
"""
|
||||
prices, yearly = self.calculate_price_per_kwh(date, peak)
|
||||
|
||||
total = np.dot(prices, np.array(verbruik).T) + yearly / 365
|
||||
return total
|
||||
28
EngieApi/DistributionCosts.py
Normal file
28
EngieApi/DistributionCosts.py
Normal file
@ -0,0 +1,28 @@
|
||||
class Capaciteitstarief:
|
||||
def __init__(self):
|
||||
self.gemiddelde_maandpiek = 38.7570 # Eur / KW / jaar
|
||||
self.kwh_tarief = 36.0218 / 1000 # EUR / kWh
|
||||
self.databeheer = 13.71 # EUR / jaar
|
||||
|
||||
def calculate(self, peak: float, usage: float, days: int):
|
||||
"""calculate distribution cost
|
||||
|
||||
:param peak: gemiddelde peak over alle maanden
|
||||
:type peak: float
|
||||
:param usage: totaal aantal kWh verbruikt
|
||||
:type usage: float
|
||||
:param days: totaal aantal dagen verbruikt
|
||||
:type days: int
|
||||
"""
|
||||
peak = max(peak, 2.5)
|
||||
return ((peak * self.gemiddelde_maandpiek) / 365 * days + usage * self.kwh_tarief + self.databeheer / 365 * days) * self.btw
|
||||
|
||||
def calculate_per_kwh(self, peak: float) -> tuple(float, float):
|
||||
"""calculate_per_kwh distribution cost
|
||||
|
||||
:param peak: gemiddelde peak over alle maanden
|
||||
:type peak: float
|
||||
:return: cost per kwh and yearly costs
|
||||
"""
|
||||
return self.kwh_tarief, self.databeheer + self.gemiddelde_maandpiek * peak
|
||||
|
||||
52
EngieApi/EngieAPI.py
Executable file
52
EngieApi/EngieAPI.py
Executable file
@ -0,0 +1,52 @@
|
||||
import json
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
import requests
|
||||
|
||||
date_format = '%Y-%m-%dT%H:%M:%S%z'
|
||||
|
||||
|
||||
class EngieAPI:
|
||||
def __init__(self):
|
||||
self.url = "https://benergy-back.azurewebsites.net/api/gateway/mercure"
|
||||
self.headers = {
|
||||
"Host": "benergy-back.azurewebsites.net",
|
||||
"Content-Type": "application/json",
|
||||
"Origin": "https://engieenergy.azurewebsites.net",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
"User-Agent": "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36",
|
||||
"Referer": "https://engieenergy.azurewebsites.net/",
|
||||
"Content-Length": "294",
|
||||
"Accept-Language": "en-GB,en;q=0.9"
|
||||
}
|
||||
|
||||
def get_epex_spot(self, date: date) -> list[float]:
|
||||
to_date = datetime(date.year, date.month, date.day, 23, 59, 59)
|
||||
from_date = to_date - timedelta(days=1, hours=23, minutes=59, seconds=59)
|
||||
|
||||
data = {
|
||||
"ApplicationDate": {
|
||||
"From": from_date.strftime(date_format),
|
||||
"To": to_date.strftime(date_format),
|
||||
"UseTime": True
|
||||
},
|
||||
"IncludeOffset": True,
|
||||
"Items": [
|
||||
{
|
||||
"IdRef": 7070
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
res = requests.post(self.url, headers=self.headers, data=json.dumps(data))
|
||||
|
||||
values = []
|
||||
for j in res.json()[0]["Points"]:
|
||||
# check if the Date is the same as the one requested, attention to the timezone
|
||||
if datetime.strptime(j["Date"], date_format).date() == date:
|
||||
values.append(j["Value"])
|
||||
|
||||
if not values:
|
||||
raise ValueError("No data found for this date")
|
||||
return values
|
||||
0
EngieApi/__init__.py
Normal file
0
EngieApi/__init__.py
Normal file
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
requests
|
||||
numpy
|
||||
Loading…
x
Reference in New Issue
Block a user