Skip to content

Add MW Start column to action score tables - #62

Merged
marota merged 7 commits into
mainfrom
claude/add-mw-start-column-8C0ZD
Mar 26, 2026
Merged

marota merged 7 commits into
mainfrom
claude/add-mw-start-column-8C0ZD

Conversation

@marota

@marota marota commented Mar 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a MW Start column to the scored actions tables (ActionFeed manual selection dropdown, CombinedActionsModal explore tab, and standalone interface)
  • Backend computes mw_start per action in _compute_mw_start_for_scores() using the N-1 observation:
    • Line disconnection: abs(p_or) of the disconnected line
    • PST tap change: abs(p_or) of the PST line
    • Load shedding: load_p of the shed load(s)
    • Open coupling (node splitting): sum of abs(p_or) of lines moved between buses (virtual line MW)
    • Line reconnection / Close coupling: N/A
  • Session save/restore preserves mw_start data automatically via action_scores

Test plan

  • Frontend TypeScript build passes
  • All 69 ActionFeed, CombinedActionsModal, and sessionUtils tests pass
  • Manual test: run analysis and verify MW Start values appear in score tables
  • Manual test: verify N/A shown for reconnection and close coupling actions
  • Manual test: save and reload session, verify MW Start values persist

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz

claude added 7 commits March 25, 2026 20:16
Display the initial MW value for each action in the score tables:
- Line disconnection/PST: active power (p_or) on the line in N-1 state
- Load shedding: active power (load_p) of the load in N-1 state
- Open coupling: sum of active power on lines moved between buses
- Line reconnection/close coupling: N/A

Backend computes mw_start per action type in _compute_mw_start_for_scores().
Frontend displays the column in ActionFeed, CombinedActionsModal, and
standalone_interface.html. Session save/restore preserves the data.

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
Backend (pytest, 17 tests):
- _compute_mw_start_for_scores: no-context guards, line disco abs(p_or),
  PST p_or, load shedding load_p, open coupling summed lines, N/A for
  reco/close-coupling, multi-type in one call

Frontend (vitest, 8 tests):
- ActionFeed: MW Start header, numeric value, N/A for reco/missing,
  load shedding value
- CombinedActionsModal: explore tab numeric value, null value N/A,
  missing mw_start map N/A

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
Load shedding: add fallback to extract load name from action_id pattern
(load_shedding_<name>) when content.set_bus.loads_id is missing, which
happens with library-enriched actions.

Open coupling: replace incorrect sum of abs(p_or) with algebraic net
injection at the moved bus using Kirchhoff's law:
  - lines_or_id: injection = -p_or (origin at sub, positive leaves)
  - lines_ex_id: injection = +p_or (power arriving from origin)
  - generators_id: injection = +gen_p
  - loads_id: injection = -load_p
  Virtual line MW = |net injection|

Updated tests: 21 backend tests now cover both fixes including
action_id pattern fallback, net injection algebra, and gen/load
contributions.

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
Partition set_bus elements by bus number and compute KCL at bus 1 only
(matching the reference get_virtual_line_flow implementation). Previously
all elements were summed regardless of bus assignment, giving ~0 instead
of the virtual line flow.

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
set_bus can contain elements with bus=-1 (disconnected). Previously
min(all_buses) picked -1 as bus 1, computing KCL only for disconnected
elements (0 flow) → result was always 0. Now filters out bus <= 0
before determining bus 1.

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
Tests use the exact set_bus from reduced_model_actions_test.json with
p_or values derived from the N-1 diagrams shown in the issue screenshots.
Covers: disconnected elements (bus=-1), mix of or/ex side lines, expected
virtual line flows of 63 MW and 29 MW respectively.

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
The onChange handler was calling changeConfigFilePath (which makes an
API call and resets state from the response), so by Apply time the
displayed value was already overwritten by the mock response '/mock/config.json'.

Now onChange only updates the local display state via setConfigFilePath.
The API call still happens on blur and on Apply (which already had the
configFilePath !== lastActiveConfigFilePath guard).

https://claude.ai/code/session_01AH3KFQG3oMHczWhuc2htgz
@marota
marota merged commit e93f71a into main Mar 26, 2026
2 checks passed
@marota marota mentioned this pull request Mar 27, 2026
5 tasks done
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