Skip to content

DOCX report export (separate from parameter formats) for #43#50

Open
EddW1219 wants to merge 2 commits into
mainfrom
edward_branch
Open

DOCX report export (separate from parameter formats) for #43#50
EddW1219 wants to merge 2 commits into
mainfrom
edward_branch

Conversation

@EddW1219

Copy link
Copy Markdown
Collaborator

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.

EddW1219 added 2 commits May 2, 2026 13:18
- 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)
Copilot AI review requested due to automatic review settings July 10, 2026 02:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_exports to build a shared report payload from run_output and 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.docx into 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.

Comment on lines +42 to +43
with ZipFile.__new__(ZipFile) as _:
pass
Comment on lines +17 to +27
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)

Comment on lines +37 to +42
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())

@olivia-banks olivia-banks added the enhancement New feature or request label Jul 10, 2026
@olivia-banks

Copy link
Copy Markdown
Member

Hi Edward, is this ready for review?

@EddW1219

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread src/epicc/ui/export.py
st.session_state[_PRINT_REQUESTED_KEY] = False
return

trigger_token = st.session_state.get(_PRINT_TOKEN_KEY, 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/epicc/formats/docx.py


class DOCXFormat(BaseFormat):
"""Deprecated wrapper around report export functionality."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@olivia-banks

Copy link
Copy Markdown
Member

@EddW1219 Let me know if you have any questions, sorry for the late review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants