Commit Graph

2 Commits

Author SHA1 Message Date
Bobby Noelte
2ed04d5573 fix: db compaction run (#1156)
These fixes were taken from https://github.com/arneman/EOS/tree/refactor/economic-objective.

1. Fix compaction job registration bug in eos.py:
   - compact_eos_database was registered with save_eos_database function
   - Now correctly calls compact_eos_database()
   - Root cause: compaction/vacuum never ran, allowing records to grow unbounded

2. Optimize db_iterate_records() from O(n) to O(log n):
   - Previous: linear scan from index 0 for every key_to_array() call
   - Now: uses bisect_left on _db_sorted_timestamps to skip to start position
   - Critical for large datasets: 9400 measurement records → 94s/call overhead → 5 calls/optimization

3. Reduce compaction_interval_sec default from 604800s (7 days) to 3600s (1 hour):
   - With 7-day interval: 65000 records accumulate before first cleanup
   - Bridge pushes ~1 record/9s (grid_export_emr)
   - Hourly compaction + 2h data window → stable ~950 records

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2026-07-20 12:59:08 +02:00
Bobby Noelte
eb9e966de9 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>
2026-07-15 16:38:53 +02:00