import json, re
from collections import Counter

todo = json.load(open('todo_upgrade.json', encoding='utf-8'))
html = open('index_main.html', encoding='utf-8').read()

# 已在 PROGRAMS 中的 id
existing_ids = set(re.findall(r'\{id:"([^"]+)"', html))
print('PROGRAMS 已有 id 数:', len(existing_ids))

# 只抓 VERIFIED_DETAILS 集合里的 det
m = re.search(r'VERIFIED_DETAILS\s*=\s*new Set\(\[([\s\S]*?)\]\)', html)
vd_raw = m.group(1) if m else ''
vd_set = set(re.findall(r'"(details/[^"]+\.html)"', vd_raw))
print('VD 集合大小:', len(vd_set))

# 热门方向关键词
hot = ['computer', 'data', 'statistic', 'finance', 'econom', 'analytic',
       'electrical', 'engineering', 'biostat', 'business', 'machine learning',
       'AI', 'information system']

candidates = []
for t in todo:
    if t['s'] == 'ucsd':
        continue
    en_lower = t['en'].lower()
    if not any(k.lower() in en_lower for k in hot):
        continue
    det = t.get('det', '')
    if det and det in vd_set:
        continue
    candidates.append(t)

print(f'\n非UCSD热门方向候选: {len(candidates)}')
by_school = Counter(c['s'] for c in candidates)
for s, c in by_school.most_common(15):
    print(f'  {s}: {c}')

print('\n=== 前 25 条候选 ===')
for c in candidates[:25]:
    print(f"  [{c['s']}] {c['cn']} ({c['en']}) - {c['deg']} - {c.get('det','')}")
