Skip to content

test: multi-session same-sensor schedules accumulate (sum) - #2344

Open
sankalpsthakur wants to merge 4 commits into
FlexMeasures:mainfrom
sankalpsthakur:test-1947-multi-session-same-sensor
Open

test: multi-session same-sensor schedules accumulate (sum)#2344
sankalpsthakur wants to merge 4 commits into
FlexMeasures:mainfrom
sankalpsthakur:test-1947-multi-session-same-sensor

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #1947

Completes the regression-test slice discussed after #1948. Documentation example deferred pending product discussion (nhoening).

Core fix was #1948 (storage_schedule[sensor] += ...). This PR only locks that in with focused tests maintainers asked for (high value / low effort).

Impact

Severity: silent schedule loss — with multiple flex-model entries on one power sensor (common for EV sessions on a single charge point), only the last session's schedule was kept. Earlier sessions were overwritten with no error.

Before #1948: two non-overlapping 2 kWh sessions on one sensor → ~2 kWh delivered (first half zeros). After: ~4 kWh (both halves active).

Look & Feel

N/A (test-only).

Non-overlapping

Window Session Power
hours 0–1 session 1 1 kW
hours 2–3 session 2 1 kW

Overlapping (capacity pre-split)

Both sessions active all 4 hours at 0.5 kW each (pre-allocation per Flix6x on #1947):

  • Correct (sum): [1, 1, 1, 1] kW (~4 kWh)
  • Overwrite: ~0.5 kW (~2 kWh)

How to test

pytest \
  flexmeasures/data/models/planning/tests/test_storage.py::test_multiple_sessions_same_sensor_accumulate_schedules \
  flexmeasures/data/models/planning/tests/test_storage.py::test_multiple_sessions_same_sensor_accumulate_overlapping_windows \
  -v

Further Improvements

Related Items


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

@sankalpsthakur
sankalpsthakur force-pushed the test-1947-multi-session-same-sensor branch 3 times, most recently from d446240 to 6632b8a Compare July 22, 2026 19:03
@Flix6x
Flix6x requested a review from Ahmad-Wahid July 22, 2026 19:06
@sankalpsthakur
sankalpsthakur force-pushed the test-1947-multi-session-same-sensor branch from 6632b8a to c59ede3 Compare July 28, 2026 10:14
Comment on lines +2123 to +2125
power_sensor = _shared_evse_power_sensor(
db, building, resolution, name="shared EVSE power non-overlap"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic asset for an EVSE(connector) should be a charge point and not a building. A charge point can have a single or more connectors.

Comment on lines +2192 to +2203
def test_multiple_sessions_same_sensor_accumulate_overlapping_windows(db, building):
"""Overlapping same-sensor sessions still sum after pre-allocating capacity.

Companion to ``test_multiple_sessions_same_sensor_accumulate_schedules``: when
two sessions share hours, power capacity must be pre-split in the flex-models
(Flix6x on #1947). The returned sensor schedule must still be the sum of both
device schedules, not the last session alone.

Setup: both sessions active all 4 hours at 0.5 kW each, each needing 2 kWh.
Sum → [1, 1, 1, 1] kW (~4 kWh). Overwrite would keep only one session at
0.5 kW (~2 kWh).
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlapping sessions on the same power sensor would never happen. For example: we cannot charge two different cars from a single connector at the same time. This is applicable only in the terms of a charge point. A charge point has one or more connectors and that leads to overlapping sessions which then decrease the power capacity of the individual connector.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test case, we should have different power sensors.

Comment on lines +2208 to +2210
power_sensor = _shared_evse_power_sensor(
db, building, resolution, name="shared EVSE power overlap"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above. Use charge point asset

@sankalpsthakur

Copy link
Copy Markdown
Contributor Author

switching the asset to a charge point makes sense — there's no charge point fixture in the planning conftest yet (flexible_devices has it as a todo), so i'll add one.

on the overlapping test: the point of this pr is that two sessions on one sensor sum instead of overwrite (#1947). if that case moves to different power sensors it stops covering that. do you want the overlapping test dropped as unrealistic, or rewritten as a charge point with two connectors on separate sensors? happy either way, just don't want to guess.

@Ahmad-Wahid

Copy link
Copy Markdown
Contributor

Thanks for pointing to the issue. The overlapping sessions example is wrong there. We should have separate power sensors.

@Ahmad-Wahid

Copy link
Copy Markdown
Contributor

The main goal of that issue is to fix the non-overlapping sessions on the same power sensor. I have corrected the test case, maybe that helps you.

@sankalpsthakur

Copy link
Copy Markdown
Contributor Author

switched to a charge point fixture with two separate connectors for the overlap case (site-power-capacity is the shared constraint across them), kept the single shared sensor for the non-overlap test since that's the actual #1947 case. pushed in 813ce6e.

@sankalpsthakur

Copy link
Copy Markdown
Contributor Author

the two-connector test exercises the charge point's site-capacity sharing, not the same-sensor accumulation from #1947/#1948 (that's still covered by the non-overlap test, but never with both sessions non-zero on the same tick). want a same-sensor overlap case added alongside it, or is the non-overlap coverage enough?

Regression for FlexMeasures#1947 after core fix FlexMeasures#1948: two flex-model sessions
sharing one power sensor must return a summed schedule, not overwrite.

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
Strengthen the non-overlap regression with per-half assertions and add
a companion case where capacity is pre-split across concurrent sessions
on one power sensor (sum, not overwrite).

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
Per review: an EVSE session's generic asset should be a charge point, not
a building, and two sessions cannot physically overlap on the same
connector's power sensor. Add a charge_point fixture and rewrite the
overlapping-sessions test to use two connectors (separate power sensors)
on one charge point, sharing its site-power-capacity - which is what
actually makes overlap physically meaningful. The non-overlapping test
keeps the single shared sensor, since that's the actual FlexMeasures#1947 regression,
just moved onto the charge_point asset.

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
@sankalpsthakur
sankalpsthakur force-pushed the test-1947-multi-session-same-sensor branch from 813ce6e to ff465b9 Compare August 1, 2026 10:37
@sankalpsthakur

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. Per #1947 and review: same-sensor non-overlap remains the regression (#1948 sum); same-sensor overlap is intentionally not added (unrealistic on one connector — corrected in the issue). Overlap coverage stays on two connectors sharing site capacity. Ready for re-review.

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.

StorageScheduler overwrites schedules when multiple sessions use the same sensor

2 participants