# -*- coding: utf-8 -*-
import io, sys, os, re, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
todo = json.load(open("todo_upgrade.json", encoding="utf-8"))
html = open("index_main.html", encoding="utf-8").read()
m = re.search(r"const PROGRAMS=\[(.*?)\n\];", html, re.S).group(1)
prog_det = set(re.findall(r'url:"(details/[^"]+)"', m))

def cls(t):
    en = (t.get("en","") or "").lower()
    d = t.get("disc","")
    if "data science" in en or "dsai" in en: return "DS"
    if "statistic" in en or "biostat" in en: return "统计"
    if "finance" in en or "quant" in en: return "金融"
    if "economic" in en: return "经济"
    if any(k in en for k in ["analytics","analytic","business analytics","business analytics"]): return "BA"
    if "electrical" in en or "electronic" in en or "computer engineering" in en: return "EE"
    if "mechanical" in en or "mech" in en: return "机械"
    if any(k in en for k in ["biology","biomedical","biochem","biological","bioengineering","bioe"]): return "生物"
    if "management" in en: return "管理"
    if d=="cs" or "computer" in en or "machine" in en or "artificial intelligence" in en or "information system" in en or "computational" in en: return "CS"
    return None

from collections import Counter
buckets = Counter()
remain_by_bucket = {}
for t in todo:
    if t.get("det") in prog_det: continue
    c = cls(t)
    if c:
        buckets[c]+=1
        remain_by_bucket.setdefault(c, []).append(t)

print("=== 剩余待核验·按热门十类（已去重已入库）===")
tot=0
for k,v in buckets.most_common():
    print(f"  {k}: {v}")
    tot+=v
print("  热门小计:", tot)

# 非热门剩余
nonhot = [t for t in todo if t.get("det") not in prog_det and cls(t) is None]
print("  非热门(工程其他/理科其他/社科/医学/人文/教育):", len(nonhot))

# 卡点/排除清单（det 命中关键词）
block_kw = ["rice-cs","ut-c6a54a2","statistics.utoronto"]
blocked = [t for t in remain_by_bucket.get("统计",[]) if "ut" in t.get("s","")]
print("\nUT 统计类剩余(Cloudflare 卡点):", len(blocked))
