Skip to content

Add SLD impact highlights for contingencies, actions, and overloads - #63

Merged
marota merged 7 commits into
mainfrom
claude/sld-highlight-impacted-assets-Dh1w2
Mar 27, 2026
Merged

marota merged 7 commits into
mainfrom
claude/sld-highlight-impacted-assets-Dh1w2

Conversation

@marota

@marota marota commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds visual highlighting of impacted assets on Single Line Diagrams (SLDs) to help users quickly identify which equipment is affected by contingencies, remedial actions, and overloaded lines. Four distinct visual styles are applied: orange glow for contingency elements, yellow glow for action targets, dashed orange for overloaded lines, and purple glow for affected breakers/switches.

Key Changes

  • CSS Styling (App.css and standalone_interface.html):

    • Added four new highlight classes with distinct visual styles:
      • .sld-highlight-contingency: Orange glow (#ff9800) for N-1 contingency elements
      • .sld-highlight-action: Yellow glow (#fffb00) for action target equipment
      • .sld-highlight-overloaded: Dashed orange (#ff8c00) for overloaded lines
      • .sld-highlight-breaker: Purple glow (#e040fb) for affected breakers/switches
    • Each style includes drop-shadow filters and stroke styling for SVG elements
  • Frontend Logic (VisualizationPanel.tsx):

    • Added new useEffect hook to manage SLD impact highlights independently of delta flow coloring
    • Implemented equipment ID lookup with multiple fallback strategies:
      • Exact metadata lookup with dot/underscore sanitization variants
      • Substring matching against metadata equipment IDs
      • Fallback substring search against SVG element IDs
    • Highlights contingency element when viewing N-1 or action tabs
    • Highlights action targets (lines, generators, loads, PST taps) when viewing action tab
    • Highlights affected breakers/switches from action topology with fallback parsing of action descriptions
    • Highlights overloaded lines when viewing N-1 or action tabs
    • Prevents duplicate highlighting of the same cell element
  • Backend Enhancement (recommender_service.py):

    • Extended action topology enrichment to include pst_tap, substations, and switches fields
    • Added logic to supplement missing switches data from the original action dictionary entry, since grid2op Action objects may not carry this attribute
    • Applied same supplementation in both _enrich_actions() and get_action_detail() methods
  • Type Updates:

    • Added ActionDetail import to component type definitions
    • Updated SldOverlayProps interface to include selectedBranch, result, and selectedActionId props

Implementation Details

  • The highlight logic uses vlOverlay.actionId (set when overlay opens) rather than component-level selectedActionId to ensure consistency
  • Equipment ID matching handles common naming variations (dots vs underscores) to accommodate different naming conventions
  • Action description parsing extracts breaker/switch names from French text patterns like "Ouverture/Fermeture" and "OC ' DJ_OC'"
  • Highlights are cleared and recomputed whenever SLD metadata, tab, or action details change

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX

claude added 7 commits March 26, 2026 08:34
Add visual highlighting on Single Line Diagrams for contingency elements
(orange glow on N-1 tab), action targets (yellow glow on action tab),
overloaded lines (dashed orange), and affected breakers/switches (purple
glow). Uses SLD metadata to map equipment IDs to SVG elements and walks
up to cell ancestors for consistent highlighting.

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX
Mirror the SLD highlight logic from the React app into the standalone
HTML interface: contingency element (orange), action targets (yellow),
overloaded lines (dashed orange), and affected breakers (purple).

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX
…ction

Three root causes for highlights not appearing on SLD diagrams:

1. Frontend used selectedActionId prop instead of vlOverlay.actionId to
   look up the action detail — these can differ. Fixed to use the overlay's
   own actionId.

2. Backend: grid2op Action objects don't carry a 'switches' attribute, so
   action_topology.switches was always empty. Added fallback to extract
   switches from the original action dictionary entry (self._dict_action).
   Also fixed simulate_manual_action path which only extracted 4 of 7
   topology fields.

3. Added substring matching for equipment IDs in SLD metadata (e.g.
   switch ID "COUCHP6_COUCH6COUPL DJ_OC" containing metadata equipmentId
   "COUCH6COUPL DJ_OC"). Also added description-based breaker name parsing
   as fallback for coupling/line opening actions.

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX
… detection

SLD highlights now use background clones instead of directly styling original
elements, preserving normal SLD rendering in Flows/Impacts modes. For coupling
actions, only the coupling breaker is highlighted (not branches).

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX
…highlight on action tab

- Backend: compare pypowsybl switch states between N-1 and action variants
  in get_action_variant_sld() to robustly detect changed switches (works for
  coupling/node-merging actions where grid2op action object lacks switch data)
- Frontend: use changed_switches from SLD response as primary source for
  breaker highlighting, falling back to action_topology.switches
- Fix: only show overloaded lines (dashed orange) highlight on N-1 tab,
  not on action tab where it incorrectly altered non-action branches

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX
…kers; 18 new tests

- Fix highlights disappearing on pan/zoom: replace CTM-based background-layer
  approach with sibling-clone insertion (clone inserted immediately before its
  source element, same SVG parent group, so it moves with the source naturally)
- Coupling action breaker highlights now use yellow (sld-highlight-action) to
  match standard action color, instead of purple (sld-highlight-breaker)
- Add test_sld_highlight.py: 18 unit tests covering changed_switches diff
  logic, _enrich_actions switch fallback, coupling detection heuristic, and
  action_topology field completeness

https://claude.ai/code/session_01CWNLrpSw2HRn1qURUo8cYX
@marota
marota merged commit 708cf14 into main Mar 27, 2026
2 checks passed
@marota marota mentioned this pull request Mar 27, 2026
10 of 11 tasks
marota pushed a commit that referenced this pull request Apr 30, 2026
Reconciliation of section 2 (0.5.0):
- Drop misattributed PRs that were actually pre-rebrand: save/reload
  (#49/#52), MW Start (#62), interaction-logging (#64), SLD highlights
  (#63), load shedding initial integration (#61). All now properly
  cited in section 1.5–1.6.
- Disambiguate App.tsx refactor history: PR #56 (hooks, 2100 → 800,
  pre-rebrand) vs PR #74 (components, 1000 → 650, 0.5.0) vs PR #75
  (memoization Phase 2, same LoC).
- Add accurate 0.5.0 PRs: #66 (vectorization w/ benchmark table),
  #69/#70/#71 (UI polish), #72 (curtailment), #73 (loads_p/gens_p
  format + configurable MW), #74/#75 (App.tsx decomposition),
  #78 (PST tap re-simulation), #84/#86/#87/#90 (detachable tabs).
- Add a recap table summarizing what's truly new in 0.5.0.

Diagrams added (Mermaid, GitHub-rendered):
- Gantt timeline of all 4 phases (top of doc).
- High-level architecture (frontend / backend / data).
- Two-step analysis sequence diagram (section 1.6).
- App.tsx LoC evolution flow (section 2.4).
- Backend mixin decomposition before/after PR #104/#106 (section 3).
- PyPSA-EUR pipeline flowchart (section 4).

https://claude.ai/code/session_01Pg7fuCUG2edfm5PyHS6SbN
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.

2 participants