Skip to content

Add session save functionality with JSON export and PDF archival - #49

Merged
marota merged 19 commits into
claude/clear-contingency-state-7G5HCfrom
claude/save-session-results-OgL2W
Mar 11, 2026
Merged

marota merged 19 commits into
claude/clear-contingency-state-7G5HCfrom
claude/save-session-results-OgL2W

Conversation

@marota

@marota marota commented Mar 11, 2026 •

Copy link
Copy Markdown
Collaborator

PR: ExpertAssist UI Refinements, PDF Export Fix, and Save Session Feedback

Goal

Improve user feedback during and after analysis, fix the missing PDF in session exports, and ensure UI consistency across the main application and standalone interface.

Proposed Changes

1. Save Session & PDF Export

  • PDF Preservation: Updated App.tsx and standalone_interface.html to store the pdf_path from analysis results. This allows the backend to find and copy the overflow graph PDF when a session is saved.
  • Backend Status: Modified the save_session endpoint in main.py to return a pdf_copied boolean, indicating success or failure of the PDF export.
  • Enhanced Feedback:
    • Implemented a prominent success message (bright green background) that appears after saving, explicitly stating the output path and PDF inclusion.
    • Message automatically fades out after 3 seconds.

2. UI Aesthetic Refinements (Yellow Theme)

  • Visual Consistency: Applied the requested yellow theme (#fff3cd background) to:
    • The "Action Dictionary" warning banner in the Action Feed.
    • The processing/loading banner that appears at the top of the Action Feed during analysis.
    • The "Run Analysis" button (turns yellow while active).
    • The overflow tab placeholder in VisualizationPanel.
  • Timing: Warnings are now synchronized to appear only when relevant and hide after analysis finishes.

3. Logic & Robustness

  • Auto-Fading Messages: Implemented a 3-second setTimeout hook for infoMessage state to ensure notifications like "Analysis completed" don't clutter the UI indefinitely.
  • Standalone Fix: Restored missing infoMessage rendering in standalone_interface.html.

Verification Results

  • Automated: Added expert_backend/tests/test_save_session.py to verify the full save flow and PDF copying.
  • Manual: Verified the auto-fade logic and yellow theme consistency across both interfaces.

marota and others added 19 commits March 10, 2026 21:03
Add confirmation dialogs for contingency and study reload
This commit updates RecommenderService to extract and include PST tap information in the action_topology field of enriched actions, ensuring visibility in the UI.
Adds a '💾 Save Results' button in the header that assembles the full
analysis session into a structured JSON file and triggers a browser
download. The exported file includes:

- Configuration: all settings (network/action paths, thresholds,
  monitoring factor, flags, etc.)
- Contingency: disconnected element, selected overloads, monitor_deselected flag
- Overload lists: N overloads, N-1 overloads, and resolved overloads
- Overflow graph: PDF URL and path
- Analysis: message, DC fallback flag, action score table, and all
  action cards with rho_before/rho_after arrays, max_rho, topology,
  convergence status, plus per-action status tags:
    - is_selected (starred by user)
    - is_suggested (recommended by the expert_op4grid engine)
    - is_rejected (explicitly rejected)
    - is_manually_simulated (added via manual search)

Also adds a new `SessionResult` TypeScript type hierarchy in types.ts
(`SessionResult`, `SavedActionEntry`, `SavedActionStatus`).

The button is disabled until at least a contingency is selected.
The filename includes the contingency name and an ISO timestamp.

https://claude.ai/code/session_01JgtV5Uj3vk9J41XbDSFc7g
## is_suggested fix

Replaces `is_suggested: !manuallyAddedIds.has(id)` with a dedicated
`suggestedByRecommenderIds` Set that accumulates every action ID ever
returned by the recommender for the current contingency.

This fixes the edge case where a user manually simulates an action
*before* running the recommender, and the recommender later returns the
same action as a suggestion — previously the action was incorrectly
marked as `is_suggested: false` because it was in `manuallyAddedIds`.
Both flags can now be true independently.

The set is populated in the step-2 streaming handler and cleared on
contingency change, Load Study, and Apply Settings resets.

## Refactor

Extracts the JSON-building logic from `handleSaveResults` into a new
pure function `buildSessionResult(input: SessionInput)` in
`utils/sessionUtils.ts`. This separates the serialisation logic from
React state and makes it directly unit-testable.

## Tests

- `utils/sessionUtils.test.ts` (27 new tests):
  - All configuration, contingency, overload, and analysis fields
  - All four status tags independently verified
  - Edge cases: manually-added-then-suggested, only-manual, re-run accumulation
- `App.test.tsx` (6 new UI tests):
  - Button presence, disabled/enabled state
  - Download triggered with correct filename pattern
  - JSON structure validated against downloaded Blob

## Docs

`docs/save-results.md` documents the full JSON schema, field reference,
status tag semantics, implementation notes, and test coverage.

https://claude.ai/code/session_01JgtV5Uj3vk9J41XbDSFc7g
## Session folder save

Replace browser-only JSON download with a full session folder saved to
the backend filesystem via POST /api/save-session:
  - session.json  — full analysis snapshot
  - <overflow>.pdf — copy of the overflow graph PDF

When "Output Folder Path" is not configured, falls back to browser JSON
download (previous behaviour).

## New Settings → Paths tab

Settings modal gains a third tab "Paths" (shown first) with:
  - Network File Path — synchronized with the banner input
  - Action Dictionary File Path — moved here from the banner
  - Output Folder Path — new field for session save destination

All three fields are backed up on settings open and restored on Cancel.

## Banner simplification

The Action File Path input/picker is removed from the banner; only the
Network Path remains (plus Load Study, Save Results, Settings gear).

## Backend

New POST /api/save-session endpoint:
  - Creates <output_folder_path>/<session_name>/ directory
  - Writes session.json
  - Copies overflow PDF if pdf_path is provided and file exists
  - Returns { "session_folder": "<absolute_path>" }

## Standalone interface

standalone_interface.html receives the same changes:
  - outputFolderPath state + localStorage persistence
  - suggestedByRecommenderIds state (was referenced but not declared)
  - handleSaveSession function (new — mirrors App.tsx logic)
  - Save Results button added to banner
  - Action File Path removed from banner
  - Settings Paths tab added

## Docs

docs/save-results.md updated to describe session folder behaviour,
output folder configuration, and the banner restructuring.

https://claude.ai/code/session_01JgtV5Uj3vk9J41XbDSFc7g
…or disconnection simply of the related network branch
…t primary action categories like Disconnections take precedence. I've also resolved all frontend lint errors and mirrored these improvements to the standalone interface for consistency. Verification was completed with 13 tests passing and logic hardening in both interfaces.
feat: include pst_tap in enriched action topology
- Switched folder icons to file icons for path-based fields.
- Added placeholder to network file input in settings and main banner.
- Fixed 'Change in settings' link in standalone interface.
- Updated frontend tests to 33 passing tests with UI verification.
@marota
marota merged commit d870fdb into claude/clear-contingency-state-7G5HC Mar 11, 2026
@marota marota mentioned this pull request Mar 16, 2026
9 of 17 tasks
@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