import re, os, sys, io, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
base = os.path.dirname(os.path.abspath(__file__))
html = open(os.path.join(base, 'index_main.html'), encoding='utf-8').read()
m = re.search(r'const PROGRAMS\s*=\s*\[(.*?)\];', html, re.S)
body = m.group(1)
blocks = dict(re.findall(r'\{id:"([^"]+)"([\s\S]*?)(?=\{id:"|$)', body))

def g(rest, key):
    mm = re.search(key+r':"([^"]*)"', rest)
    return mm.group(1) if mm else ''

def missing(v):
    return v=='' or v=='待补' or v.startswith('待补')

only_tui=[]; only_test=[]; other=[]
for tid, rest in blocks.items():
    s=g(rest,'s'); tui=g(rest,'tui'); ddl=g(rest,'ddl'); lang=g(rest,'lang'); n=g(rest,'n'); en=g(rest,'en'); deg=g(rest,'deg'); url=g(rest,'url')
    testm=re.search(r'test:\{cls:"([^"]*)"\}', rest); cls=testm.group(1) if testm else ''
    miss=[]
    if missing(tui): miss.append('tui')
    if missing(ddl): miss.append('ddl')
    if missing(lang): miss.append('lang')
    if missing(cls): miss.append('test')
    if not miss: continue
    row=(tid,s,n,en,deg,url,cls,ddl,lang)
    if miss==['tui']: only_tui.append(row)
    elif miss==['test']: only_test.append(row)
    else: other.append((tid,s,miss,n))

print("=== 仅缺学费 tui（lang/ddl/test 齐）共", len(only_tui), "条 ===")
for r in sorted(only_tui, key=lambda x:(x[1],x[0])):
    print(f"  [{r[1]}] {r[0]} | {r[2][:38]} | {r[4]} | {r[5]}")
print()
print("=== 仅缺标化 test 共", len(only_test), "条 ===")
for r in sorted(only_test, key=lambda x:(x[1],x[0])):
    print(f"  [{r[1]}] {r[0]} | {r[2][:38]} | {r[4]}")
print()
print("=== 多字段缺口 共", len(other), "条（按校聚合）===")
agg={}
for tid,s,miss,n in other:
    agg.setdefault(s,[]).append((tid,miss,n))
for s in sorted(agg,key=lambda x:-len(agg[x])):
    print(f"  [{s}] {len(agg[s])} 条")
