# -*- coding: utf-8 -*-
import json, pathlib, re, sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = pathlib.Path(r"D:\work buddy\2026-11-05-14-15-52")
html = (BASE / "index_main.html").read_text(encoding="utf-8", errors="replace")
seg = html[html.index("const PROGRAMS=["):html.index("const CATD=[")]
disc = {}
for blk in re.findall(r'\{id:"([^"]+)"', seg):
    pass
blocks = seg.split('{id:"')[1:]
for b in blocks:
    pid = b[:b.index('"')]
    m = re.search(r'disc:"([^"]*)"', b)
    disc[pid] = m.group(1) if m else ""
rows = json.load(open(BASE / "_density_report.json", encoding="utf-8"))["rows"]
PRI = ["CS", "EE", "FIN", "ECON", "BA", "DS", "STAT", "ME", "BIO", "MGMT"]
non = [r for r in rows if r["grade"] != "A"]
print("非A总数", len(non))
for p in PRI:
    hit = [r for r in non if disc.get(r["id"], "") == p]
    print(f"== {p} nonA {len(hit)}")
    for r in sorted(hit, key=lambda x: -x["score"])[:10]:
        print(f"  {r['grade']}{r['score']} {r['id']} | {r['n'][:40]} | {r['url'][:70]} | cards{r['m']['cards']} chars{r['m']['chars']} codes{r['m']['codes']}")
print("== 其他高价值(non A, score>=7)")
oth = [r for r in non if disc.get(r["id"], "") not in PRI and r["score"] >= 7]
for r in sorted(oth, key=lambda x: -x["score"])[:15]:
    print(f"  {r['s']} {r['grade']}{r['score']} {r['id']} | {r['n'][:40]} | disc={disc.get(r['id'],'')}")
