24 lines
710 B
Python
24 lines
710 B
Python
from __future__ import annotations
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
import zoneinfo
|
|
|
|
from utils.time_helpers import WARSAW_TZ
|
|
|
|
@dataclass
|
|
class DistributionCostBase:
|
|
tz: zoneinfo.ZoneInfo = WARSAW_TZ
|
|
|
|
def to_local_dt(self, ts: datetime) -> datetime:
|
|
if ts.tzinfo is None:
|
|
return ts.replace(tzinfo=self.tz)
|
|
return ts.astimezone(self.tz)
|
|
|
|
def rate(self, ts: datetime) -> float:
|
|
"""Return PLN/kWh (netto) for given timestamp (override in subclasses)."""
|
|
raise NotImplementedError
|
|
|
|
def cost(self, ts: datetime, consumption_kwh: float) -> float:
|
|
return self.rate(ts) * float(consumption_kwh)
|
|
|