mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-10-20 21:01:57 +00:00
fix: move data management to async (#1015)
FAstAPI is an async framework. Data may be imported and exported, load and save, set and get asynchronously. Prevent interleaving data operations to corrupt the data. In the previous design sync and async data access was intermixed leading to data corruption. The basic data classes DataSequence and DataContainer and the derived classes like Provider and Measurement now are async. Data access is protected by several async locks. To support the async design of the data classes the database interface became async. The energy management is also adapted to the new async design. Optimization is still off-loaded to another thread, but the prepration for the optimization and the post optimization actions now follow the async design. Adapter operations are now also protected by async locks. Tests were adapted to the async design and new tests were created. Besides this major fix several other improvements and fixes are included in this PR. * fix: key_to_dict/list/array only regard data records with key value set. Before the exclusion of no value data records was only done if the dropna flag was set. * fix: test for visual result pdf generation Due to updates in the library the generated charts text was a little bit different. Adapt the test to create the comaprison pdf in the test data durectory and update the reference pdf. * chore: Remove MutableMapping from DataSequence and DataContainer. Mutable Mapping does not fit to the now async design. * chore: Add NoDB database backend This backend implements the full database backend interface but performs no actual persistence. It is intended for configurations where database persistence is disabled (`provider=None`). * chore: Improve measurement data import testing with real world scenarios. Added two new endpoints to support testing. * chore: Add mermaid to supported documentation tools * chore: Add documentation about async design * chore: Add documentation about generic data handling Covers the basics of measurement and prediction time series data handling. * chore: Add empty lines around markdown lists. * chore: sync pre-commit config to updated package versions Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
@@ -147,7 +147,7 @@ class GeneticOptimizationParameters(
|
||||
return start_solution
|
||||
|
||||
@classmethod
|
||||
def prepare(cls) -> "Optional[GeneticOptimizationParameters]":
|
||||
async def prepare(cls) -> "Optional[GeneticOptimizationParameters]":
|
||||
"""Prepare optimization parameters from config, forecast and measurement data.
|
||||
|
||||
Fills in values needed for optimization from available configuration, predictions and
|
||||
@@ -231,11 +231,11 @@ class GeneticOptimizationParameters(
|
||||
raise ValueError(error_msg)
|
||||
|
||||
# Assure predictions are uptodate
|
||||
cls.prediction.update_data()
|
||||
await cls.prediction.update_data()
|
||||
|
||||
try:
|
||||
pvforecast_ac_power = (
|
||||
cls.prediction.key_to_array(
|
||||
await cls.prediction.key_to_array(
|
||||
key="pvforecast_ac_power",
|
||||
start_datetime=parameter_start_datetime,
|
||||
end_datetime=parameter_end_datetime,
|
||||
@@ -290,7 +290,7 @@ class GeneticOptimizationParameters(
|
||||
# Retry
|
||||
continue
|
||||
try:
|
||||
elecprice_marketprice_wh = cls.prediction.key_to_array(
|
||||
elecprice_marketprice_wh = await cls.prediction.key_to_array(
|
||||
key="elecprice_marketprice_wh",
|
||||
start_datetime=parameter_start_datetime,
|
||||
end_datetime=parameter_end_datetime,
|
||||
@@ -306,7 +306,7 @@ class GeneticOptimizationParameters(
|
||||
# Retry
|
||||
continue
|
||||
try:
|
||||
loadforecast_power_w = cls.prediction.key_to_array(
|
||||
loadforecast_power_w = await cls.prediction.key_to_array(
|
||||
key="loadforecast_power_w",
|
||||
start_datetime=parameter_start_datetime,
|
||||
end_datetime=parameter_end_datetime,
|
||||
@@ -331,7 +331,7 @@ class GeneticOptimizationParameters(
|
||||
# Retry
|
||||
continue
|
||||
try:
|
||||
feed_in_tariff_wh = cls.prediction.key_to_array(
|
||||
feed_in_tariff_wh = await cls.prediction.key_to_array(
|
||||
key="feed_in_tariff_wh",
|
||||
start_datetime=parameter_start_datetime,
|
||||
end_datetime=parameter_end_datetime,
|
||||
@@ -358,7 +358,7 @@ class GeneticOptimizationParameters(
|
||||
# Retry
|
||||
continue
|
||||
try:
|
||||
weather_temp_air = cls.prediction.key_to_array(
|
||||
weather_temp_air = await cls.prediction.key_to_array(
|
||||
key="weather_temp_air",
|
||||
start_datetime=parameter_start_datetime,
|
||||
end_datetime=parameter_end_datetime,
|
||||
@@ -418,7 +418,7 @@ class GeneticOptimizationParameters(
|
||||
battery_lcos_kwh = battery_config.levelized_cost_of_storage_kwh
|
||||
# Initial SOC
|
||||
try:
|
||||
initial_soc_factor = cls.measurement.key_to_value(
|
||||
initial_soc_factor = await cls.measurement.key_to_value(
|
||||
key=battery_config.measurement_key_soc_factor,
|
||||
target_datetime=ems.start_datetime,
|
||||
time_window=to_duration(to_duration("48 hours")),
|
||||
@@ -490,7 +490,7 @@ class GeneticOptimizationParameters(
|
||||
continue
|
||||
# Initial SOC
|
||||
try:
|
||||
initial_soc_factor = cls.measurement.key_to_value(
|
||||
initial_soc_factor = await cls.measurement.key_to_value(
|
||||
key=electric_vehicle_config.measurement_key_soc_factor,
|
||||
target_datetime=ems.start_datetime,
|
||||
time_window=to_duration(to_duration("48 hours")),
|
||||
|
||||
@@ -344,7 +344,7 @@ class GeneticSolution(ConfigMixin, GeneticParametersBaseModel):
|
||||
|
||||
return effective_ac, effective_dc, effective_dis
|
||||
|
||||
def optimization_solution(self) -> OptimizationSolution:
|
||||
async def optimization_solution(self) -> OptimizationSolution:
|
||||
"""Provide the genetic solution as a general optimization solution.
|
||||
|
||||
The battery modes are controlled by the grid control triggers:
|
||||
@@ -612,7 +612,7 @@ class GeneticSolution(ConfigMixin, GeneticParametersBaseModel):
|
||||
),
|
||||
]:
|
||||
if pred_key in pred.record_keys:
|
||||
array = pred.key_to_array(
|
||||
array = await pred.key_to_array(
|
||||
key=pred_key,
|
||||
start_datetime=start_datetime,
|
||||
end_datetime=end_datetime,
|
||||
|
||||
Reference in New Issue
Block a user