Write one JSON file per result (`` .json``) plus an aggregate. Results without a ``run_id`` fall back to `` .json`` so nothing is dropped. Returns the directory path.
(report: EvalReport, reports_dir: Path)
| 146 | |
| 147 | |
| 148 | def write_reports_dir(report: EvalReport, reports_dir: Path) -> Path: |
| 149 | """Write one JSON file per result (``<run_id>.json``) plus an aggregate. |
| 150 | |
| 151 | Results without a ``run_id`` fall back to ``<scenario_id>.json`` so |
| 152 | nothing is dropped. Returns the directory path. |
| 153 | """ |
| 154 | reports_dir = Path(reports_dir) |
| 155 | reports_dir.mkdir(parents=True, exist_ok=True) |
| 156 | |
| 157 | used: dict[str, int] = {} |
| 158 | for r in report.results: |
| 159 | stem = r.run_id or f"scenario-{r.scenario_id}" |
| 160 | suffix = used.get(stem, 0) |
| 161 | used[stem] = suffix + 1 |
| 162 | name = stem if suffix == 0 else f"{stem}-{suffix}" |
| 163 | (reports_dir / f"{name}.json").write_text( |
| 164 | r.model_dump_json(indent=2), encoding="utf-8" |
| 165 | ) |
| 166 | |
| 167 | (reports_dir / _AGGREGATE_FILENAME).write_text( |
| 168 | report.model_dump_json(indent=2), encoding="utf-8" |
| 169 | ) |
| 170 | return reports_dir |
| 171 | |
| 172 | |
| 173 | def render_summary(report: EvalReport) -> str: |