Fix2 electricity price prediction. (#296)

Normalize electricity price prediction to €/Wh.
Provide electricity price prediction by €/kWh for convenience.

Allow to configure electricity price charges by €/kWh.

Also added error page to fastapi rest server to get rid of annoying
unrelated fault messages during testing.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte
2024-12-30 21:29:50 +01:00
committed by GitHub
parent 45079ca29c
commit c0ea13d0f4
13 changed files with 178 additions and 52 deletions

View File

@@ -7,7 +7,7 @@ Notes:
from abc import abstractmethod
from typing import List, Optional
from pydantic import Field
from pydantic import Field, computed_field
from akkudoktoreos.prediction.predictionabc import PredictionProvider, PredictionRecord
from akkudoktoreos.utils.logutil import get_logger
@@ -23,10 +23,22 @@ class ElecPriceDataRecord(PredictionRecord):
"""
elecprice_marketprice: Optional[float] = Field(
None, description="Electricity market price (€/KWh)"
elecprice_marketprice_wh: Optional[float] = Field(
None, description="Electricity market price per Wh (€/Wh)"
)
# Computed fields
@computed_field # type: ignore[prop-decorator]
@property
def elecprice_marketprice_kwh(self) -> Optional[float]:
"""Electricity market price per kWh (€/kWh).
Convenience attribute calculated from `elecprice_marketprice_wh`.
"""
if self.elecprice_marketprice_wh is None:
return None
return self.elecprice_marketprice_wh * 1000.0
class ElecPriceProvider(PredictionProvider):
"""Abstract base class for electricity price providers.