Files
EOS/src/akkudoktoreos/prediction/feedintariffabc.py
7tobias 6933b33542
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
feat: rename genetic optimization API fields to English (#675)
Rename the German field names of the genetic optimization API to
English with full backward compatibility:

- English names are canonical and documented in the OpenAPI schema;
  the German names are still accepted on input via validation aliases
  and re-emitted in responses as deprecated computed fields
- fix visualization receiving the raw German-keyed simulation dict
  (KeyError: load_wh_per_hour)
- rename internal German identifiers (optimize_ems, total_balance,
  battery_residual_value, self_consumption, extra_data keys)
- use amount instead of currency/euro in chart labels and schema
  descriptions; document currency handling (whole currency units,
  never cents) in the API description
- regenerate openapi.json and generated docs

Co-authored-by: Tobias Welz <tobias.wizneteu@gmail.com>
2026-07-18 08:08:25 +02:00

62 lines
1.8 KiB
Python

"""Abstract and base classes for feed in tariff predictions.
Notes:
- Ensure appropriate API keys or configurations are set up if required by external data sources.
"""
from abc import abstractmethod
from typing import List, Optional
from pydantic import Field, computed_field
from akkudoktoreos.prediction.predictionabc import PredictionProvider, PredictionRecord
class FeedInTariffDataRecord(PredictionRecord):
"""Represents a feed in tariff data record containing various price attributes at a specific datetime.
Attributes:
date_time (Optional[AwareDatetime]): The datetime of the record.
"""
feed_in_tariff_wh: Optional[float] = Field(
None, json_schema_extra={"description": "Feed in tariff per Wh [amount/Wh]"}
)
# Computed fields
@computed_field # type: ignore[prop-decorator]
@property
def feed_in_tariff_kwh(self) -> Optional[float]:
"""Feed in tariff per kWh [amount/kWh].
Convenience attribute calculated from `feed_in_tariff_wh`.
"""
if self.feed_in_tariff_wh is None:
return None
return self.feed_in_tariff_wh * 1000.0
class FeedInTariffProvider(PredictionProvider):
"""Abstract base class for feed in tariff providers.
FeedInTariffProvider is a thread-safe singleton, ensuring only one instance of this class is created.
Configuration variables:
feed in tariff_provider (str): Prediction provider for feed in tarif.
"""
# overload
records: List[FeedInTariffDataRecord] = Field(
default_factory=list,
json_schema_extra={"description": "List of FeedInTariffDataRecord records"},
)
@classmethod
@abstractmethod
def provider_id(cls) -> str:
return "FeedInTariffProvider"
def enabled(self) -> bool:
return self.provider_id() == self.config.feedintariff.provider