Skip to content

Delete all original data that resample-data resamples within a window - #2927

Open
SajalDevX wants to merge 3 commits into
FlexMeasures:mainfrom
SajalDevX:fix/resample-data-window
Open

SajalDevX wants to merge 3 commits into
FlexMeasures:mainfrom
SajalDevX:fix/resample-data-window

Conversation

@SajalDevX

Copy link
Copy Markdown
Contributor

Description

  • flexmeasures edit resample-data with --from or --until now deletes the original data with the same bounds that search_beliefs used to select it (events that occur at least in part within the window), using the sensor's original resolution
  • Added changelog item in documentation/changelog.rst (and in documentation/cli/change_log.rst)

The delete query was built after sensor.event_resolution was already set to the new resolution, and used event_start + resolution <= until and event_start >= from. So when downsampling, the original events in the last new step of the window were kept, and a --from within an event kept that event. They stayed next to the resampled data, and with the sensor's new resolution they read as extra events.

Look & Feel

A kW sensor with a 15-minute resolution and 12 values (1 to 12) from 2026-01-01 00:00+01:00:

flexmeasures edit resample-data --sensor 7 --event-resolution 60 \
    --from 2026-01-01T00:00+01:00 --until 2026-01-01T02:00+01:00 --skip-integrity-check

Before, the 15-minute rows at 01:15, 01:30 and 01:45 (values 6, 7 and 8) stayed in the window next to the hourly beliefs at 00:00 and 01:00. After, only the hourly beliefs at 00:00 and 01:00 are in the window, and the data from 02:00 onwards is untouched.

With --from 2026-01-01T01:10+01:00, the original 01:00 row (value 5) used to stay next to the resampled 01:00 beliefs; now it is replaced.

How to test

pytest flexmeasures/cli/tests/test_data_edit_fresh_db.py flexmeasures/cli/tests/test_data_edit.py

test_resample_sensor_data_within_window resamples the epex_da test data within a window to 30 minutes and back to an hour, once with a window on the hour and once with a window starting and ending within an event, and checks that only the hourly event starts are left. Both cases fail without the fix (an extra row at 15:30) and pass with it. I also ran the command above against a local database before and after the fix, and the full test suite.

Further Improvements

...

Related Items

Closes #2926


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

…indow

Context:
- With --from or --until, the resampled data came from search_beliefs, which selects the events that occur at least in part within the window,
  but the original data was deleted with other bounds, so some of it stayed next to the resampled data.

Change:
- Delete the original data with the bounds that search_beliefs used, and with the original resolution,
  by building the delete query before setting the sensor's new resolution.

Signed-off-by: Sajal Kumar Jana <[email protected]>
…d to the data

Context:
- Resampling to 30 minutes and back to an hour within a window left a 30-minute event at the end of the window.

Change:
- Resample the epex_da test data within a window and back, and check that only hourly event starts are left.

Signed-off-by: Sajal Kumar Jana <[email protected]>
Context:
- Bugfix to flexmeasures edit resample-data with --from or --until.

Change:
- Add entries to the main changelog and the CLI changelog.

Signed-off-by: Sajal Kumar Jana <[email protected]>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #36265495 | 📁 Comparing 98f648b against latest (f329a88)

  🔍 Preview build  

3 files changed
± changelog.html
± api/v3_0.html
± cli/change_log.html

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flexmeasures edit resample-data --until leaves original data in the window when downsampling

1 participant