# -*- coding: utf-8 -*-
import json, pathlib, 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")
SP = BASE / "_r348_specs"

ADD = {
 "uw-stats-mmath": {
  "req": [
   ("入学准备", "录取后须按 offer letter 的 conditions of admission 完成条件（如最终成绩单、语言成绩验证），具体清单以录取信与研究生院页面为准"),
  ],
  "course": [
   ("入学准备与选课", "入学后由系里指定导师/学术顾问沟通选课；research paper 与 thesis 两种路径的学分结构见 calendar 条目"),
  ],
  "plan": [
   ("项目简介（官网原文）", "Become a leader in statistics by studying and creating new methods of collecting, analyzing, interpreting and presenting data；毕业可成为政府、医疗、科技或金融部门的统计师或数据科学家，或衔接到本校及其他顶尖大学 PhD"),
   ("灵活转轨（官网原文）", "The program gives you the flexibility to begin in the research paper option and transfer into the thesis option after the first term"),
   ("系所与学院", "统计与精算科学系隶属数学学院，授课楼为 Mathematics 3（M3）；系内同时开设统计、生物统计与精算方向，方法论课程共享"),
  ],
  "outcome": [
   ("校友与去向", "官方页面提供 Request more information 与 Supervisors 入口，可进一步查询导师方向与在读情况"),
  ],
 },
 "uw-biostat-mmath": {
  "req": [
   ("入学准备", "录取后须按 offer letter 的 conditions of admission 完成条件（最终成绩单、语言成绩验证等），以录取信与研究生院页面为准"),
  ],
  "course": [
   ("试验设计", "临床试验设计与分析（design and analysis of clinical trials）"),
   ("流行病学", "流行病学研究设计（epidemiological studies）"),
   ("纵向数据", "纵向数据分析（longitudinal data analysis）"),
   ("缺失数据", "缺失数据与测量误差处理方法（methods for dealing with incomplete data and measurement error）"),
   ("聚类数据", "聚类数据分析（clustered data）"),
   ("生命史数据", "生命史数据分析（analysis of life history data）与生物系统研究（studies of biological systems）"),
  ],
  "plan": [
   ("项目简介（官网原文）", "Learn to develop and apply statistical methods to solve problems arising in health, biology and the environment；毕业可在制药公司、合同研究组织、地区或国家卫生研究中心、学术中心与公共卫生机构就业"),
   ("灵活转轨（官网原文）", "The program gives you the flexibility to begin in the research paper option and transfer into the thesis option after the first term"),
   ("系所与学院", "统计与精算科学系隶属数学学院，授课楼 Mathematics 3（M3）；生物统计与统计方向共享方法论与师资"),
  ],
  "outcome": [
   ("行业分布", "制药企业、CRO、卫生研究中心、学术中心、公共卫生机构是官网明列的五个主要去向"),
  ],
 },
 "uw-mdsai": {
  "plan": [
   ("排名与认证（官网原文）", "QS World University Rankings by Subject 2024 数据科学与人工智能加拿大第 2；MDSAI 为 Vector Institute recognized master’s program，可获得其奖学金与专属岗位机会"),
   ("教学设施", "在校形态提供专用实验室与休息空间（dedicated lab and lounge space），便于同侪交流与项目协作"),
   ("项目定位（官网原文）", "Upgrade your theoretical knowledge in data science and artificial intelligence；面向在职者补强现职或转向新职业/晋升"),
  ],
  "outcome": [
   ("资源入口", "Graduate Data Science Job Board 为数学学院数据科学项目专属岗位板，汇集产业合作方机会"),
  ],
 },
 "uw-ds-mmath": {
  "plan": [
   ("项目简介（官网原文）", "Pursue a high-demand career in data science through the MMath in Data Science, an interdisciplinary research-based thesis program；训练学生整合计算机科学、统计学与优化三方面知识"),
   ("项目亮点", "师从国际知名研究者；可使用研究密集型实验室空间；有机会发表成果并在顶级会议报告；按滑铁卢 IP 政策，学生创建的一切成果归本人所有"),
   ("系所与学院", "数学学院数据科学系统筹，Cheriton CS、统计与精算、组合优化、应用数学四系共建；授课楼 Mathematics 3（M3）"),
   ("跨系导师", "四系共建意味着导师可来自 CS、统计、优化或应用数学，选题可跨方向组合"),
  ],
  "course": [
   ("选题口径", "thesis 选题须落在数据科学某一子领域，并能形成原创方法或模型贡献；具体方向随导师研究组合而定"),
  ],
  "req": [
   ("入学准备", "录取后须按 offer letter 的 conditions of admission 完成条件（最终成绩单、语言成绩验证等）"),
  ],
 },
 "brown-cs-scm": {
  "course": [
   ("课号与先修", "FAQ 列出建议先修：一门编程入门课、算法/数据结构、系统课与数学基础（离散数学、线性代数、概率）；课号对应见系 Course List"),
  ],
 },
 "brown-cs-scm-aiml-track": {
  "course": [
   ("课号与先修", "先修口径同 CS ScM：编程、算法、系统与数学基础，另建议至少一门高阶 CS 课；具体课号见系 Course List"),
  ],
 },
}

for sid, cards in ADD.items():
    p = SP / (sid + ".json")
    spec = json.loads(p.read_text(encoding="utf-8"))
    by_key = {c["key"]: c for c in spec["cards"]}
    for ck, rows in cards.items():
        existing = {r["k"] for r in by_key[ck]["rows"]}
        for k, v in rows:
            if k in existing:
                continue
            by_key[ck]["rows"].append({"k": k, "v": v})
    p.write_text(json.dumps(spec, ensure_ascii=False, indent=2), encoding="utf-8")
print("fix2 done")
