(episodes_path: Path, reports_path: Path)
| 79 | |
| 80 | |
| 81 | def evaluate_reports(episodes_path: Path, reports_path: Path) -> Dict[str, Any]: |
| 82 | expected = expected_report_keys(episodes_path) |
| 83 | seen: set[Tuple[str, str, str]] = set() |
| 84 | duplicate_count = 0 |
| 85 | report_count = 0 |
| 86 | matched_count = 0 |
| 87 | nonempty_matched_count = 0 |
| 88 | full_text_count = 0 |
| 89 | evidence_count = 0 |
| 90 | structure_scores: list[float] = [] |
| 91 | length_scores: list[float] = [] |
| 92 | char_counts: list[int] = [] |
| 93 | source_counts: Counter[str] = Counter() |
| 94 | |
| 95 | for report in iter_jsonl(reports_path): |
| 96 | report_count += 1 |
| 97 | key = report_key(report) |
| 98 | if key: |
| 99 | if key in seen: |
| 100 | duplicate_count += 1 |
| 101 | seen.add(key) |
| 102 | is_expected = key in expected if key else False |
| 103 | if is_expected: |
| 104 | matched_count += 1 |
| 105 | |
| 106 | content = str(report.get("report_content") or "").strip() |
| 107 | char_count = len(content) |
| 108 | char_counts.append(char_count) |
| 109 | length_scores.append(length_fit_score(char_count)) |
| 110 | if is_expected and content: |
| 111 | nonempty_matched_count += 1 |
| 112 | |
| 113 | source = str(report.get("analysis_source") or "unknown").strip() or "unknown" |
| 114 | source_counts[source] += 1 |
| 115 | if source in {"pdf", "full_text"} and not report.get("pdf_error"): |
| 116 | full_text_count += 1 |
| 117 | |
| 118 | payload = report.get("report_payload") or {} |
| 119 | if payload.get("retrieved_evidence") or payload.get("report_evidence_anchors"): |
| 120 | evidence_count += 1 |
| 121 | |
| 122 | filled = 0 |
| 123 | for field in REQUIRED_REPORT_FIELDS: |
| 124 | value = payload.get(field) |
| 125 | if isinstance(value, (list, dict)): |
| 126 | filled += 1 if value else 0 |
| 127 | else: |
| 128 | filled += 1 if str(value or "").strip() else 0 |
| 129 | structure_scores.append(filled / len(REQUIRED_REPORT_FIELDS)) |
| 130 | |
| 131 | expected_count = len(expected) |
| 132 | coverage = matched_count / expected_count if expected_count else None |
| 133 | success_rate = nonempty_matched_count / expected_count if expected_count else None |
| 134 | full_text_rate = full_text_count / report_count if report_count else None |
| 135 | evidence_rate = evidence_count / report_count if report_count else None |
| 136 | structure_score = sum(structure_scores) / len(structure_scores) if structure_scores else None |
| 137 | length_score = sum(length_scores) / len(length_scores) if length_scores else None |
| 138 | avg_chars = sum(char_counts) / len(char_counts) if char_counts else None |
no test coverage detected