DOCX report export (separate from parameter formats) for #43#50
DOCX report export (separate from parameter formats) for #43#50EddW1219 wants to merge 2 commits into
Conversation
- Add docx.py format implementation - Register DOCX in format registry - Update export UI - Add tests for DOCX format - Verification: 1. Content and format of docx file exported. 2. Save parameter button(support DOCX or not)
There was a problem hiding this comment.
Pull request overview
This PR adds a dedicated DOCX report export path for EPICC simulation results (separate from the parameter format system), updates the Streamlit UI to expose “Save report as DOCX”, and leaves PDF export as print-dialog based.
Changes:
- Added
epicc.ui.report_exportsto build a shared report payload fromrun_outputand generate minimal DOCX bytes. - Updated export UI/app wiring to include a DOCX download button and adjusted print-trigger timing for PDF.
- Added DOCX export tests and converted
epicc.formats.docxinto a deprecated compatibility shim.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/epicc/test_loader.py | Removes unused import in loader tests. |
| tests/epicc/test_interpreted_model.py | Removes unused imports from interpreted-model tests. |
| tests/epicc/test_formats_docx.py | Adds tests for generating DOCX bytes and validating ZIP/doc XML contents. |
| src/epicc/ui/report_exports.py | New module: builds report payload from simulation output and writes a minimal DOCX package. |
| src/epicc/ui/export.py | Adds DOCX export button; refactors PDF export button/print trigger to use inline JS. |
| src/epicc/formats/docx.py | New deprecated shim format that only supports writing __report__ payloads. |
| src/epicc/main.py | Integrates DOCX export button into the results column; adjusts parameter action button layout and print trigger call site. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| with ZipFile.__new__(ZipFile) as _: | ||
| pass |
| model_def = model.get_model_definition() | ||
| scenario_results: dict[str, dict[str, Any]] = run_output.get("scenario_results_by_id", {}) | ||
| label_overrides = run_output.get("label_overrides", {}) | ||
|
|
||
| scenario_labels: dict[str, str] = {} | ||
| for s in getattr(model_def, "scenarios", []) or []: | ||
| sid = getattr(s, "id", None) | ||
| lbl = getattr(s, "label", None) | ||
| if sid: | ||
| scenario_labels[sid] = label_overrides.get(sid, lbl or sid) | ||
|
|
| item_columns = getattr(item, "columns", None) or [] | ||
| if item_columns: | ||
| selected_scenario_ids = [sid for sid in item_columns if sid in scenario_results] | ||
| else: | ||
| selected_scenario_ids = list(scenario_results.keys()) | ||
|
|
|
Hi Edward, is this ready for review? |
Hi Olivia, I'm thinking to fix the issues the Copilot mentioned so far, but yes I already tested before I made the PR, feel free to review. |
| st.session_state[_PRINT_REQUESTED_KEY] = False | ||
| return | ||
|
|
||
| trigger_token = st.session_state.get(_PRINT_TOKEN_KEY, 0) |
There was a problem hiding this comment.
We should keep the comment contained within here, or at least some version of it, to explain why we're doing this to the Javascript payload.
|
|
||
|
|
||
| class DOCXFormat(BaseFormat): | ||
| """Deprecated wrapper around report export functionality.""" |
There was a problem hiding this comment.
This should be removed, there should be no place in the software where we need to use this since DOCX reports aren't structured, nested-tabular data.
| from epicc.ui.report_exports import build_report_docx_bytes | ||
|
|
||
|
|
||
| def _make_report_payload(title: str = "Test Report") -> dict: |
There was a problem hiding this comment.
Just out of curiosity, can you upload a DOCX of what a report generated this way looks like? I'm curious as to the visuals of this but I'm away from my computer for the next bit to run it myself.
|
@EddW1219 Let me know if you have any questions, sorry for the late review! |
This PR implements DOCX report export for issue #43.
Changes:
Added a dedicated report-export module
-Builds a shared report payload from simulation output
-Generates DOCX bytes from report content (markdown, tables, and graph metadata)
Updated export UI
-Save report as DOCX now exports simulation results
-DOCX export uses the shared payload
-Save report as PDF remains browser-print based
Removed DOCX from parameter format registry, so .docx is no longer treated as a parameter file type.
Converted docx.py into a deprecated compatibility shim.
Updated app integration in main.py for export button flow and print trigger timing.
Notes
This keeps DOCX export separate from the structured parameter format system, as discussed in #43.
PDF is still print-based for now, while DOCX logic is now cleanly separated.