Prevent low-value export and freeze-export slots leaking into Predbat plans#4088
Open
nickgee31 wants to merge 13 commits into
Open
Prevent low-value export and freeze-export slots leaking into Predbat plans#4088nickgee31 wants to merge 13 commits into
nickgee31 wants to merge 13 commits into
Conversation
Add threshold-based pruning and trimming for optimiser-selected export windows. Plan: introduce export_threshold_for_window, export_window_is_manual, export_window_above_threshold, trim_export_window_to_threshold and prune_export_windows_below_threshold; call pruning during plan filtering and recompute. Execute: respect export_window_above_threshold to avoid starting export (or scheduling freeze-only) when window rates are below the final threshold, log decisions and disable forced export. Tests: add unit tests and setup changes covering pruning, trimming of low-rate edges, preservation of manual overrides, and execute behavior when below threshold.
Set my_predbat.rate_export = {} in the test fixture to ensure the attribute exists for tests. This prevents errors when tests or code expect a dict for rate_export and makes the setup explicit about the default test state.
…1/batpred into export-planning-changes
Compute original_window_size from the window's original start and use it when scaling metric_min_improvement_export. Previously the scaled minimum improvement used window_size (based on adjusted start), which could mis-scale the threshold; this change preserves the original window duration so min_improvement_scaled is calculated correctly relative to plan_interval_minutes.
Add logic to undo optimiser tail-trimming for export windows when the skipped original start period remains above the final export threshold. Hook restore_export_windows_above_threshold into the full optimisation flow (guarded by calculate_best_export and export_window_best). The new method checks the export threshold, skips fully-exported windows, inspects per-minute rate_export (using PREDICT_STEP) or window average, logs the restoration, and resets the window start to start_orig when appropriate. Also add unit tests verifying restoration when skipped rates are above threshold and non-restoration when there are below-threshold rates.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines Predbat’s export-window handling so that optimiser-selected export and freeze-export slots do not “leak” into the plan/execution when their rates fall below the optimiser’s final export threshold, while still honoring explicit manual overrides.
Changes:
- Added final post-optimisation pruning/trimming of export windows against the effective export threshold.
- Added restoration logic to undo optimiser tail-trimming when skipped minutes are still above the threshold.
- Updated execution and tests to ensure below-threshold export does not remain active unless manually requested.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/predbat/plan.py | Adds export-threshold helpers plus pruning/trimming/restoration of export windows below the final threshold. |
| apps/predbat/execute.py | Prevents executing/scheduling export when the current export window is below the final threshold. |
| apps/predbat/tests/test_execute.py | Adds execution coverage for below-threshold export vs manual override behavior. |
| apps/predbat/tests/test_discard_unused_export_slots.py | Adds unit tests for pruning/trimming/restoring export windows around the final threshold. |
Comment on lines
+2396
to
+2406
| if skipped_above_threshold: | ||
| self.log( | ||
| "Restore export window start {} - {} to {} using optimisation threshold {}{}".format( | ||
| self.time_abs_str(window_start), | ||
| self.time_abs_str(window["end"]), | ||
| self.time_abs_str(window_start_orig), | ||
| dp2(threshold), | ||
| self.currency_symbols[1], | ||
| ) | ||
| ) | ||
| window["start"] = window_start_orig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR tightens how Predbat handles export windows around the optimiser’s final export threshold.
Previously, Predbat could still plan or continue export behaviour in slots that were below the effective export threshold. This showed up in a few ways:
Changes
Predbat should now avoid planning or executing export/freeze-export actions below the optimiser’s final export threshold, unless the user explicitly requested them manually. This makes export behaviour more consistent with the intended meaning of the threshold and avoids low-value export periods being pulled into otherwise profitable export windows.