mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-06-27 08:26:53 +00:00
Optimization of the Inverter class to speed up scr calculation (#607)
Some checks are pending
docker-build / platform-excludes (push) Waiting to run
docker-build / build (push) Blocked by required conditions
docker-build / merge (push) Blocked by required conditions
pre-commit / pre-commit (push) Waiting to run
Run Pytest on Pull Request / test (push) Waiting to run
Some checks are pending
docker-build / platform-excludes (push) Waiting to run
docker-build / build (push) Blocked by required conditions
docker-build / merge (push) Blocked by required conditions
pre-commit / pre-commit (push) Waiting to run
Run Pytest on Pull Request / test (push) Waiting to run
* fix(ElecPriceEnergyCharts): get history series, update docs Signed-off-by: redmoon2711 <redmoon2711@gmx.de> * feat(inverter): using lookup table for calculate scr Signed-off-by: redmoon2711 <redmoon2711@gmx.de> --------- Signed-off-by: redmoon2711 <redmoon2711@gmx.de>
This commit is contained in:
parent
eb23123bba
commit
ba4f5ecbb5
@ -25,6 +25,22 @@ class Inverter(DeviceBase):
|
||||
self.parameters: Optional[InverterParameters] = None
|
||||
super().__init__(parameters)
|
||||
|
||||
self.scr_lookup: dict = {}
|
||||
|
||||
def _calculate_scr(self, consumption: float, generation: float) -> float:
|
||||
"""Check if the consumption and production is in the lookup table. If not, calculate and store the value."""
|
||||
if consumption not in self.scr_lookup:
|
||||
self.scr_lookup[consumption] = {}
|
||||
|
||||
if generation not in self.scr_lookup[consumption]:
|
||||
scr = self.self_consumption_predictor.calculate_self_consumption(
|
||||
consumption, generation
|
||||
)
|
||||
self.scr_lookup[consumption][generation] = scr
|
||||
return scr
|
||||
|
||||
return self.scr_lookup[consumption][generation]
|
||||
|
||||
def _setup(self) -> None:
|
||||
if self.parameters is None:
|
||||
raise ValueError(f"Parameters not set: {self.parameters}")
|
||||
@ -60,9 +76,8 @@ class Inverter(DeviceBase):
|
||||
grid_import = -remaining_power # Negative indicates feeding into the grid
|
||||
self_consumption = self.max_power_wh
|
||||
else:
|
||||
scr = self.self_consumption_predictor.calculate_self_consumption(
|
||||
consumption, generation
|
||||
)
|
||||
# Calculate scr with lookup table
|
||||
scr = self._calculate_scr(consumption, generation)
|
||||
|
||||
# Remaining power after consumption
|
||||
remaining_power = (generation - consumption) * scr # EVQ
|
||||
|
Loading…
x
Reference in New Issue
Block a user