RFTSystems commited on
Commit
c71f147
·
verified ·
1 Parent(s): 69ba747

Create drp/report.py

Browse files
Files changed (1) hide show
  1. drp/report.py +69 -0
drp/report.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from typing import Any, Dict, List
3
+
4
+
5
+ def render_report_markdown(diff: Dict[str, Any]) -> str:
6
+ s = diff["summary"]
7
+ counts = diff.get("class_counts", {})
8
+
9
+ lines: List[str] = []
10
+ lines.append("# DRP Differential Report")
11
+ lines.append("")
12
+ lines.append("## Summary")
13
+ lines.append(f"- Run A: `{s.get('run_a')}`")
14
+ lines.append(f"- Run B: `{s.get('run_b')}`")
15
+ lines.append(f"- Framework A/B: `{s.get('framework_a')}` / `{s.get('framework_b')}`")
16
+ lines.append(f"- Model A/B: `{s.get('model_a')}` / `{s.get('model_b')}`")
17
+ lines.append(f"- Events A/B: `{s.get('events_a')}` / `{s.get('events_b')}`")
18
+ lines.append(f"- First divergence index: `{s.get('first_divergence_index')}`")
19
+ lines.append("")
20
+
21
+ lines.append("## Divergence classes")
22
+ if counts:
23
+ for k in sorted(counts.keys()):
24
+ lines.append(f"- **{k}**: {counts[k]}")
25
+ else:
26
+ lines.append("- (no diffs)")
27
+ lines.append("")
28
+
29
+ lines.append("## First divergence detail (if any)")
30
+ first = s.get("first_divergence_index")
31
+ diffs = diff.get("differences", [])
32
+ first_item = None
33
+ if first is not None:
34
+ for item in diffs:
35
+ if item.get("i") == first:
36
+ first_item = item
37
+ break
38
+
39
+ if not first_item:
40
+ lines.append("- No divergence found (or divergence is only length mismatch).")
41
+ return "\n".join(lines)
42
+
43
+ lines.append(f"- Index: `{first_item.get('i')}`")
44
+ lines.append(f"- Class: `{first_item.get('class')}`")
45
+ lines.append(f"- Kind A/B: `{first_item.get('kind_a')}` / `{first_item.get('kind_b')}`")
46
+ lines.append(f"- Step A/B: `{first_item.get('step_a')}` / `{first_item.get('step_b')}`")
47
+ lines.append("")
48
+ lines.append("### Key diffs (first 25)")
49
+ for d in (first_item.get("diffs") or [])[:25]:
50
+ lines.append(f"- `{d.get('path')}` ({d.get('kind')}): A={_short(d.get('a'))} | B={_short(d.get('b'))}")
51
+
52
+ if "text_unified_diff" in first_item:
53
+ lines.append("")
54
+ lines.append("### Text unified diff (truncated)")
55
+ lines.append("```diff")
56
+ lines.append(first_item["text_unified_diff"][:8000])
57
+ lines.append("```")
58
+
59
+ return "\n".join(lines)
60
+
61
+
62
+ def _short(x: Any, n: int = 180) -> str:
63
+ try:
64
+ s = json.dumps(x, ensure_ascii=False)
65
+ except Exception:
66
+ s = str(x)
67
+ if len(s) > n:
68
+ return s[:n] + "…"
69
+ return s