victron-shedule-generator/EnergyPriceProvider/TauronG13Provider.py
Bartosz Wieczorek aadcd4a193 init
2025-09-04 09:25:21 +02:00

73 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 (XIII):
medium: 0713
high: 1621
low: 1316, 2107; weekend/święta = low
Lato (IVIX):
medium: 0713
high: 1922
low: 1319, 2207; 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": { # IVIX
"workday": {"low": tarcza_rates, "medium": tarcza_rates, "high": tarcza_rates},
"dayoff": {"low": tarcza_rates, "medium": tarcza_rates, "high": tarcza_rates},
},
"winter": { # XIII
"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]