# -*- coding: utf-8 -*- """逐会话从转录 rawUsage 汇总真实积分(递归找 rawUsage.credit)。""" import io, json, glob HOME = "E:/ProgramData/.workbuddy" SIDS = { "3814f5fb": "覆盖网络线·归档接续(自动 @10:20)", "e265f0cd": "覆盖网络线·接续优化版(自动 @10:45)", "478eef8c": "决策方法-2(自动 @11:10)", "d48a9be8": "覆盖网络线·S1 落地(自动 @14:32)", "b08b1c35": "确认覆盖网络任务待办事项(手动新会话,基线)", } def walk(o, hits, path=""): if isinstance(o, dict): for k, v in o.items(): if k == "rawUsage" and isinstance(v, dict): hits.append(v) else: walk(v, hits, path + "/" + str(k)) elif isinstance(o, list): for x in o: walk(x, hits, path) print("%-38s %6s %8s %8s" % ("会话", "计费次", "积分合计", "均值")) for short, label in SIDS.items(): hits = glob.glob(HOME + "/projects/*/" + short + "*.jsonl") if not hits: print(short, "无转录") continue ru = [] with io.open(hits[0], "r", encoding="utf-8", errors="replace", newline="") as f: for line in f: line = line.strip() if not line: continue try: d = json.loads(line) except Exception: continue walk(d, ru) cr = [r.get("credit") for r in ru if isinstance(r.get("credit"), (int, float))] tot = sum(cr) print("%-38s %6d %8.2f %8s" % (label[:36], len(cr), tot, ("%.3f" % (tot / len(cr))) if cr else "-")) if cr: s = sorted(cr) print(" min=%.2f 中位=%.2f max=%.2f | 首=%.2f 末=%.2f" % (s[0], s[len(s)//2], s[-1], cr[0], cr[-1]))