Skip to content

feat(sld): the SLD overlay follows the Loading % view - #232

Open
marota wants to merge 1 commit into
ainetus:mainfrom
marota:feat/sld-loading-view
Open

marota wants to merge 1 commit into
ainetus:mainfrom
marota:feat/sld-loading-view

Conversation

@marota

@marota marota commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #230 (Loading % view). The SLD overlay followed Flows | Impacts but always read in MW. It now also follows the main window's MW | Loading % toggle, on its N, N-1 and action sub-tabs.

Flows Impacts
MW pypowsybl's own values (unchanged) ΔP / ΔQ, arrows turned (unchanged)
Loading % each branch feeder: the loading of the end it draws each branch feeder: the branch's change (+12%), as on the NAD

In Loading %:

  • The end it draws: pypowsybl's SLD metadata gives each branch feeder's arrows a side (ONE / TWO), and the feeder reads that end's loading. A transformer's side without a limit reads the other end's loading. For example, in the 400 kV voltage level, a 400/225 kV transformer limited on its 225 kV side shows its loading, not a dash.
  • Colours:
    • Flows: the feeder cell takes the NAD's loading scale (grey below 50 %). From 50 %, the value sits on a pill of that colour, with dark text in both themes.
    • Impacts: the value and the cell are coloured like the MW deltas.
  • One figure per end: the Q arrow and its value are hidden. The P arrow stays.
  • Loads and generators have no limit, so they keep their MW in Flows and their MW change in Impacts. A shed load still shows its shed MW.
  • Header: it shows Loading % beside Flows / Impacts. The N sub-tab reads Flows, since it is the Impacts' reference, as on the N tab.

Backend

  • /api/n-sld, /api/contingency-sld and /api/action-variant-sld carry branch_loading; the N-1 and action ones also carry loading_deltas.
  • They reuse the NAD helpers (_safe_branch_loading, _attach_loading_vs_base, _attach_action_loading) and follow the same variant discipline: the action loading is read before the switch to the contingency variant.
  • The tables are read grid-wide, so a branch's Impacts category is the same as on the NAD. They are then narrowed to the voltage level's branches (_keep_sld_branches).
  • No OpenAPI change: these endpoints return bespoke responses.

Frontend

  • The painting moved out of SldOverlay (1420 → 1070 lines, the ceiling is 1450) into utils/svg/sldFlowVisuals.ts plus hooks/useSldFlowVisuals.ts.
  • The MW Impacts algorithm is carried over unchanged.
  • The hook is still a self-gated layout effect, so there is still no blink during a pan. It now gates on its inputs' identity plus a DOM probe, instead of a per-render JSON signature of the sorted keys of the grid-wide delta tables.
  • VisualizationPanel passes the main window's metric to the overlay, as it already did for actionViewMode.

Fixes on the way (found while checking on the fr225_400 situation)

  • Thousands-grouped values: pypowsybl prints -1,297, and parseFloat read it as -1.
  • apply_threshold classified an exact zero change as negative when nothing changed at all (0 < 0 is false). It now reads grey, like the vectorised and scalar categorisers already did.
  • Loading changes round to 0.1 point, like the loadings themselves. Float noise between two equal states is no longer "the largest delta".
  • A change under one unit keeps a decimal (-0.4%). Before, it read 0% in a decrease's colour. Shared by the NAD labels and the SLD.

Test plan

  • Backend:
    • test_diagram_mixin.py: the three SLD payloads, the narrowing to the voltage level's branches, and the variant restored.
    • test_diagram_helpers.py: equal states read grey; a zero change is grey.
    • Full suite: 1470 passed. The 2 local failures (test_combined_actions_scenario::test_independent_actions_simulation, test_stream_pdf_integration) fail the same way without this change and depend on the local recommender install.
  • Frontend:
    • sldFlowVisuals.test.ts: each view, the feeder's end, the transformer fallback, pills, hidden Q, loads in MW, grouped values, clearing.
    • SldOverlay.test.tsx: follows the toggles, the header, the N sub-tab.
    • useSldOverlay.test.ts, plus grouped values in branchLabels and loadingVisuals.
    • Full suite: 2307 passed. tsc -b and eslint are clean.
  • Gates replicated locally: ruff, check_code_quality.py, check_docs_tree.py, mypy 1.19, OpenAPI contract, and the four parity layers against a freshly built standalone.
  • Checked in the browser on pypsa_eur_fr225_400 (2025-07-01 11:00), contingency ATTAQL72MANDA:
    • MANDARINS 400kV, N-1, Loading % Flows: WARANDE shows 105% on a vivid orange pill under its overload halo, ATTAQUES (the contingency) reads 0%, and the transformer without a limit reads —.
    • MASTAING 400kV, action open_coupler, Loading % Impacts: CAPELLE +2% in orange, LONNY -1% and AVELIN -0.4% in blue; the injections show ΔMW.
    • Dark theme: the pill text stays dark.

🤖 Generated with Claude Code

The single line diagram followed Flows | Impacts but always read in MW.
It now follows the main window's MW | Loading % toggle too:

- Loading % Flows: each branch feeder reads the loading of the end it
  draws (pypowsybl's feeder-info side; a transformer's side without a
  limit reads the other end's), its cell in the NAD's loading scale, the
  value on a pill of that colour from 50 %.
- Loading % Impacts: the branch's loading change (+12%), coloured like
  the deltas, as on the NAD.
- The Q arrow is hidden (one figure per end); loads and generators keep
  their MW. The header says Loading % beside Flows / Impacts; the N
  sub-tab reads Flows, the Impacts' reference.

Backend: the three SLD endpoints carry branch_loading (and, N-1 /
action, loading_deltas), read grid-wide like the NAD's so the Impacts
categories match, then narrowed to the voltage level's branches.

The painting moved out of SldOverlay (1420 -> 1070 lines) into
utils/svg/sldFlowVisuals.ts + hooks/useSldFlowVisuals.ts, self-gated on
its inputs' identity instead of a per-render JSON signature of the
grid-wide deltas.

Fixes on the way:
- values pypowsybl prints with their thousands grouped (-1,297) read as
  numbers: a 1 297 MW branch read -1 in the NAD's MW labels and hover,
  and a >= 1 000 MW SLD feeder kept its flow in MW Impacts;
- apply_threshold greys a zero change even when nothing changed at all;
  a loading change rounds to 0.1 point like the loadings;
- a change under one unit keeps a decimal (-0.4%) instead of reading 0
  in a decrease's colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Antoine Marot <amarot91@gmail.com>
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.

1 participant