# -*- coding: utf-8 -*-
import io, sys, os, re, json, datetime
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
os.chdir(r"D:\work buddy\2026-11-05-14-15-52")
idx=open("index_main.html",encoding="utf-8").read()
seg=idx[idx.find("const PROGRAMS="):idx.find("const CATD=")]
plvl=re.findall(r'lvl:"([^"]+)"',seg)
master=plvl.count("m"); phd=plvl.count("d"); programs=len(plvl)
vd=re.search(r'const VERIFIED_DETAILS=new Set\(\[(.*?)\]\);',idx,re.S).group(1)
vd_n=len(re.findall(r'"([^"]+)"',vd))
det_n=len([f for f in os.listdir("details") if f.endswith(".html")])
mtime=datetime.datetime.fromtimestamp(os.path.getmtime("index_main.html")).strftime("%Y-%m-%d %H:%M:%S")
print("实测 programs",programs,"master",master,"phd",phd,"VD",vd_n,"details",det_n,"mtime",mtime)

b=json.load(open("_heartbeat_baseline.json",encoding="utf-8"))
b["updated_at"]=mtime; b["index_main_mtime"]=mtime
b["schools"]=36; b["programs"]=programs; b["programs_master"]=master; b["programs_phd"]=phd
b["catd"]=2676; b["dead_links"]=0; b["excluded_residue"]=0
b["vd_set"]=vd_n; b["details_html"]=det_n; b["node_check"]="exit 0"

new=[
 ("jhu-ds-mse","details/jhu-cd967c0.html","JHU MSE Data Science"),
 ("jhu-finfe-ms","details/jhu-cb6c788.html","JHU MS Finance Financial Econometrics"),
 ("jhu-hcm-ms","details/jhu-c2babcf.html","JHU MS Health Care Management"),
 ("jhu-hfm-mhs","details/jhu-cab39af.html","JHU MHS Health Finance and Management"),
 ("jhu-ahsi-ms","details/jhu-cfe2f27.html","JHU MS Applied Health Sciences Informatics"),
]
for _,det,_ in new:
    tag=det+" 浏览器实开待后端会话恢复后补核（六卡静态核对已通过）"
    if det not in b["pending_browser_check"]:
        b["pending_browser_check"].append(tag)

notes=[
 "JHU MSE Data Science（jhu-ds-mse）：半核验入库。WSE 应用数学与统计系；fully residential 在校；核心 + 5 附加课 + 4 选修；Capstone EN.553.806 6cr 研究导向（研究主管 + Oversight Committee 批准）+ 海报 + 论文；硬指标待补；STEM 未明示标 0。排除在线/part-time、PhD、其他 AMS 学位、MBA 双学位。",
 "JHU MS Finance Financial Econometrics Concentration（jhu-finfe-ms）：半核验入库。Carey 商院；36cr；全日制三学期 12 个月（fall/spring/summer）或 15 个月（fall/spring/fall）；不接受课程豁免；catalogue 明示 F-1 可申 STEM OPT Extension，标 stem:1。系站 403，硬指标待补。排除 Finance 其他方向另页、PhD、在线 part-time、MBA 双学位。",
 "JHU MS Health Care Management（jhu-hcm-ms）：半核验入库。Carey 商院健康管理；30cr；全日制两学期 fall/spring；Business Communication/Leadership/Statistical Analysis/分析框架；硬指标待补；STEM 未明示标 0。排除在线/part-time、PhD、MBA 双学位、纯临床执业。",
 "JHU MHS Health Finance and Management（jhu-hfm-mhs）：半核验入库。BSPH 卫生政策与管理系；64cr；全校 Introduction to Online Learning 为在线学习入门必修（非项目在线形态）；Economic Evaluation 3cr + 选修 7cr；授课形态见 BSPH 站（不可达待补）；硬指标待补；STEM 未明示标 0。排除在线/part-time、其他公卫学位、PhD/DrPH、MBA 双学位。",
 "JHU MS Applied Health Sciences Informatics（jhu-ahsi-ms）：半核验入库。医学院；onsite 全日制 12 个月通道；核心 Biomedical Informatics/Precision Medicine Data Analysis/Seminar Grand Rounds/Database + 选修 + capstone；方向生物医学/临床信息/健康信息系统/数据科学；硬指标待补；STEM 未明示标 0。仅录在校通道，排除 online 36 个月在职通道、PhD、临床执业学位、MBA 双学位。",
 "JHU 剩余候选（下轮）：BMB ScM（ca597d7，研究型论文）、Biophysical Chemistry and Design for Biotechnology MS（c03ef7d，in-person 10–24 个月，full-time/part-time 在校）、BID MSE（c064173，46–48cr）、Economics MA（c529fb8，full-time residential）、EHE MA/MS/MSE、GILE MS；AAP 三条（Applied Economics/Bioinformatics/Financial Economics）待正文定性 part-time/在线。",
]
for n in notes:
    if n[:40] not in " ".join(b["blocked_notes"]):
        b["blocked_notes"].append(n)

b["note"]=b["note"]+" 2026-11-19 心跳第二十二轮入库 5 条：JHU Data Science MSE + Finance-FE MS + HCM MS + HFM MHS + AHSI MS。重探：Rice CS 200；Stanford/USC Viterbi/JHU Eng 403；NYU GSAS 202 0B；UT Stat/Math 小字节 challenge 页待浏览器确认。"
json.dump(b,open("_heartbeat_baseline.json","w",encoding="utf-8"),ensure_ascii=False,indent=2)
print("基线已刷新：programs",b["programs"],"master",master,"phd",phd,"VD",vd_n,"details",det_n,"pending",len(b["pending_browser_check"]),"blocked",len(b["blocked_notes"]))
