mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-07-21 09:18:12 +00:00
Add database support for measurements and historic prediction data. (#848)
The database supports backend selection, compression, incremental data load, automatic data saving to storage, automatic vaccum and compaction. Make SQLite3 and LMDB database backends available. Update tests for new interface conventions regarding data sequences, data containers, data providers. This includes the measurements provider and the prediction providers. Add database documentation. The fix includes several bug fixes that are not directly related to the database implementation but are necessary to keep EOS running properly and to test and document the changes. * fix: config eos test setup Make the config_eos fixture generate a new instance of the config_eos singleton. Use correct env names to setup data folder path. * fix: startup with no config Make cache and measurements complain about missing data path configuration but do not bail out. * fix: soc data preparation and usage for genetic optimization. Search for soc measurments 48 hours around the optimization start time. Only clamp soc to maximum in battery device simulation. * fix: dashboard bailout on zero value solution display Do not use zero values to calculate the chart values adjustment for display. * fix: openapi generation script Make the script also replace data_folder_path and data_output_path to hide real (test) environment pathes. * feat: add make repeated task function make_repeated_task allows to wrap a function to be repeated cyclically. * chore: removed index based data sequence access Index based data sequence access does not make sense as the sequence can be backed by the database. The sequence is now purely time series data. * chore: refactor eos startup to avoid module import startup Avoid module import initialisation expecially of the EOS configuration. Config mutation, singleton initialization, logging setup, argparse parsing, background task definitions depending on config and environment-dependent behavior is now done at function startup. * chore: introduce retention manager A single long-running background task that owns the scheduling of all periodic server-maintenance jobs (cache cleanup, DB autosave, …) * chore: canonicalize timezone name for UTC Timezone names that are semantically identical to UTC are canonicalized to UTC. * chore: extend config file migration for default value handling Extend the config file migration handling values None or nonexisting values that will invoke a default value generation in the new config file. Also adapt test to handle this situation. * chore: extend datetime util test cases * chore: make version test check for untracked files Check for files that are not tracked by git. Version calculation will be wrong if these files will not be commited. * chore: bump pandas to 3.0.0 Pandas 3.0 now performs inference on the appropriate resolution (a.k.a. unit) for the output dtype which may become datetime64[us] (before it was ns). Also numeric dtype detection is now more strict which needs a different detection for numerics. * chore: bump pydantic-settings to 2.12.0 pydantic-settings 2.12.0 under pytest creates a different behaviour. The tests were adapted and a workaround was introduced. Also ConfigEOS was adapted to allow for fine grain initialization control to be able to switch off certain settings such as file settings during test. * chore: remove sci learn kit from dependencies The sci learn kit is not strictly necessary as long as we have scipy. * chore: add documentation mode guarding for sphinx autosummary Sphinx autosummary excecutes functions. Prevent exceptions in case of pure doc mode. * chore: adapt docker-build CI workflow to stricter GitHub handling Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
@@ -15,17 +15,17 @@ from pydantic import Field, computed_field
|
||||
|
||||
from akkudoktoreos.core.coreabc import MeasurementMixin
|
||||
from akkudoktoreos.core.dataabc import (
|
||||
DataBase,
|
||||
DataABC,
|
||||
DataContainer,
|
||||
DataImportProvider,
|
||||
DataProvider,
|
||||
DataRecord,
|
||||
DataSequence,
|
||||
)
|
||||
from akkudoktoreos.utils.datetimeutil import DateTime, to_duration
|
||||
from akkudoktoreos.utils.datetimeutil import DateTime, Duration, to_duration
|
||||
|
||||
|
||||
class PredictionBase(DataBase, MeasurementMixin):
|
||||
class PredictionABC(DataABC, MeasurementMixin):
|
||||
"""Base class for handling prediction data.
|
||||
|
||||
Enables access to EOS configuration data (attribute `config`) and EOS measurement data
|
||||
@@ -95,7 +95,7 @@ class PredictionSequence(DataSequence):
|
||||
)
|
||||
|
||||
|
||||
class PredictionStartEndKeepMixin(PredictionBase):
|
||||
class PredictionStartEndKeepMixin(PredictionABC):
|
||||
"""A mixin to manage start, end, and historical retention datetimes for prediction data.
|
||||
|
||||
The starting datetime for prediction data generation is provided by the energy management
|
||||
@@ -196,6 +196,35 @@ class PredictionProvider(PredictionStartEndKeepMixin, DataProvider):
|
||||
Derived classes have to provide their own records field with correct record type set.
|
||||
"""
|
||||
|
||||
def db_keep_datetime(self) -> Optional[DateTime]:
|
||||
"""Earliest datetime from which database records should be retained.
|
||||
|
||||
Used when removing old records from database to free space.
|
||||
|
||||
Subclasses may override this method to provide a domain-specific default.
|
||||
|
||||
Returns:
|
||||
Datetime or None.
|
||||
"""
|
||||
return self.keep_datetime
|
||||
|
||||
def db_initial_time_window(self) -> Optional[Duration]:
|
||||
"""Return the initial time window used for database loading.
|
||||
|
||||
This window defines the initial symmetric time span around a target datetime
|
||||
that should be loaded from the database when no explicit search time window
|
||||
is specified. It serves as a loading hint and may be expanded by the caller
|
||||
if no records are found within the initial range.
|
||||
|
||||
Subclasses may override this method to provide a domain-specific default.
|
||||
|
||||
Returns:
|
||||
The initial loading time window as a Duration, or ``None`` to indicate
|
||||
that no initial window constraint should be applied.
|
||||
"""
|
||||
hours = max(self.config.prediction.hours, self.config.prediction_historic_hours, 24)
|
||||
return to_duration(hours * 3600)
|
||||
|
||||
def update_data(
|
||||
self,
|
||||
force_enable: Optional[bool] = False,
|
||||
@@ -219,9 +248,6 @@ class PredictionProvider(PredictionStartEndKeepMixin, DataProvider):
|
||||
# Call the custom update logic
|
||||
self._update_data(force_update=force_update)
|
||||
|
||||
# Assure records are sorted.
|
||||
self.sort_by_datetime()
|
||||
|
||||
|
||||
class PredictionImportProvider(PredictionProvider, DataImportProvider):
|
||||
"""Abstract base class for prediction providers that import prediction data.
|
||||
|
||||
Reference in New Issue
Block a user