Commit d0592b22 d0592b22804d997f55b1df9b92894cc4ddfb7d24 by 沈秋雨

优化fix脚本

1 parent cddc9bdd
...@@ -69,17 +69,18 @@ def should_remove(row: dict, main_durations: dict[str, float], threshold: float) ...@@ -69,17 +69,18 @@ def should_remove(row: dict, main_durations: dict[str, float], threshold: float)
69 def compute_summary(rows: list[dict], threshold: float, out_path: str) -> dict: 69 def compute_summary(rows: list[dict], threshold: float, out_path: str) -> dict:
70 """计算评测指标。""" 70 """计算评测指标。"""
71 tp = fp = tn = fn = 0 71 tp = fp = tn = fn = 0
72 upload_ms = poll_ms = total_ms = [] 72 upload_ms, poll_ms, total_ms = [], [], []
73 by_variant: dict[str, dict] = {} 73 by_variant: dict[str, dict] = {}
74 74
75 for r in rows: 75 for r in rows:
76 pred = r.get("predicted_duplicate", "").lower() == "true" 76 pred = r.get("predicted_duplicate", "").lower() == "true"
77 exp = r.get("expected_duplicate", "").lower() == "true" 77 exp = r.get("expected_duplicate", "").lower() == "true"
78 correct = r.get("correct", "").lower() == "true" 78 correct = r.get("correct", "").lower() == "true"
79 sample_class = r.get("sample_class", "unknown")
79 80
80 variant = r.get("variant", "unknown") 81 variant = r.get("variant", "unknown")
81 if variant not in by_variant: 82 if variant not in by_variant:
82 by_variant[variant] = {"correct": 0, "total": 0} 83 by_variant[variant] = {"correct": 0, "total": 0, "sample_class": sample_class}
83 by_variant[variant]["total"] += 1 84 by_variant[variant]["total"] += 1
84 if correct: 85 if correct:
85 by_variant[variant]["correct"] += 1 86 by_variant[variant]["correct"] += 1
...@@ -137,9 +138,23 @@ def compute_summary(rows: list[dict], threshold: float, out_path: str) -> dict: ...@@ -137,9 +138,23 @@ def compute_summary(rows: list[dict], threshold: float, out_path: str) -> dict:
137 "query_time_ms": _stats(total_ms), 138 "query_time_ms": _stats(total_ms),
138 "upload_time_ms": _stats(upload_ms), 139 "upload_time_ms": _stats(upload_ms),
139 "poll_time_ms": _stats(poll_ms), 140 "poll_time_ms": _stats(poll_ms),
141 "by_sample_class": {
142 cls: {
140 "by_variant": { 143 "by_variant": {
141 v: {"accuracy": round(d["correct"] / d["total"], 4), "total": d["total"]} 144 v: {"accuracy": round(d["correct"] / d["total"], 4), "total": d["total"]}
142 for v, d in sorted(by_variant.items()) 145 for v, d in sorted(by_variant.items())
146 if d["sample_class"] == cls
147 }
148 }
149 for cls in ("positive", "negative")
150 },
151 "by_variant": {
152 v: {
153 "sample_class": d["sample_class"],
154 "accuracy": round(d["correct"] / d["total"], 4),
155 "total": d["total"],
156 }
157 for v, d in sorted(by_variant.items())
143 }, 158 },
144 "out": out_path, 159 "out": out_path,
145 } 160 }
...@@ -237,9 +252,13 @@ def main(): ...@@ -237,9 +252,13 @@ def main():
237 print(f"Recall: {summary['recall']}") 252 print(f"Recall: {summary['recall']}")
238 print(f"F1: {summary['f1']}") 253 print(f"F1: {summary['f1']}")
239 print(f"TP={summary['tp']} FP={summary['fp']} TN={summary['tn']} FN={summary['fn']}") 254 print(f"TP={summary['tp']} FP={summary['fp']} TN={summary['tn']} FN={summary['fn']}")
240 print() 255
241 print("按变体:") 256 for cls in ("positive", "negative"):
242 for v, d in summary["by_variant"].items(): 257 variants = summary["by_sample_class"][cls]["by_variant"]
258 if not variants:
259 continue
260 print(f"\n[{cls}]")
261 for v, d in variants.items():
243 print(f" {v:20s} acc={d['accuracy']:.4f} n={d['total']}") 262 print(f" {v:20s} acc={d['accuracy']:.4f} n={d['total']}")
244 263
245 # 打印被移除的样本明细 264 # 打印被移除的样本明细
......