73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
from __future__ import annotations
|
||
from datetime import time, datetime
|
||
from EnergyPrice import EnergyPriceBase
|
||
from utils.time import in_range_local
|
||
from utils.calendar_pl import is_weekend_or_holiday, gov_energy_prices_shield
|
||
|
||
class TauronG13Provider(EnergyPriceBase):
|
||
"""
|
||
Energy cost – Tauron G13 (NET PLN/kWh).
|
||
Zima (X–III):
|
||
medium: 07–13
|
||
high: 16–21
|
||
low: 13–16, 21–07; weekend/święta = low
|
||
Lato (IV–IX):
|
||
medium: 07–13
|
||
high: 19–22
|
||
low: 13–19, 22–07; weekend/święta = low
|
||
"""
|
||
def __init__(self, **kwargs):
|
||
super().__init__(**kwargs)
|
||
|
||
self.w_med = (time(7,0), time(13,0))
|
||
self.w_high = (time(16,0), time(21,0))
|
||
self.w_low1 = (time(13,0), time(16,0))
|
||
self.w_low2 = (time(21,0), time(7,0))
|
||
|
||
self.s_med = (time(7,0), time(13,0))
|
||
self.s_high = (time(19,0), time(22,0))
|
||
self.s_low1 = (time(13,0), time(19,0))
|
||
self.s_low2 = (time(22,0), time(7,0))
|
||
|
||
@staticmethod
|
||
def _rates(ts: datetime):
|
||
if gov_energy_prices_shield(ts):
|
||
tarcza_rates = 0.62/1.23
|
||
return {
|
||
"summer": { # IV–IX
|
||
"workday": {"low": tarcza_rates, "medium": tarcza_rates, "high": tarcza_rates},
|
||
"dayoff": {"low": tarcza_rates, "medium": tarcza_rates, "high": tarcza_rates},
|
||
},
|
||
"winter": { # X–III
|
||
"workday": {"low": tarcza_rates, "medium": tarcza_rates, "high": tarcza_rates},
|
||
"dayoff": {"low": tarcza_rates, "medium": tarcza_rates, "high": tarcza_rates},
|
||
},
|
||
}
|
||
else:
|
||
raise RuntimeError("brak danych dla nie tarczy, trzeba ogarnąć")
|
||
|
||
@staticmethod
|
||
def _is_winter(month: int) -> bool:
|
||
return month in (10, 11, 12, 1, 2, 3)
|
||
|
||
def rate(self, ts):
|
||
dt = self.to_local_dt(ts)
|
||
d, t = dt.date(), dt.time()
|
||
rates = self._rates(ts)
|
||
|
||
if is_weekend_or_holiday(d):
|
||
return rates["low"]
|
||
|
||
if self._is_winter(d.month):
|
||
if in_range_local(t, self.w_high): key = "high"
|
||
elif in_range_local(t, self.w_med): key = "medium"
|
||
elif in_range_local(t, self.w_low1) or in_range_local(t, self.w_low2): key = "low"
|
||
else: key = "low"
|
||
else:
|
||
if in_range_local(t, self.s_high): key = "high"
|
||
elif in_range_local(t, self.s_med): key = "medium"
|
||
elif in_range_local(t, self.s_low1) or in_range_local(t, self.s_low2): key = "low"
|
||
else: key = "low"
|
||
|
||
return rates[key]
|