# -*- coding: utf-8 -*-
"""Round 210: add 5 remaining ECE PhDs - Northwestern / Rice / Vanderbilt / WashU / Notre."""
import os, re

BASE = os.path.dirname(os.path.abspath(__file__))
INDEX = os.path.join(BASE, "index_main.html")
DETAILS_DIR = os.path.join(BASE, "details")

new_programs = [
    {
        "id": "nu-ece-phd",
        "s": "nu",
        "n": "Electrical and Computer Engineering (PhD)",
        "en": "PhD in Electrical and Computer Engineering (Northwestern University, Robert R. McCormick School of Engineering, Department of Electrical and Computer Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "On-campus research PhD, Evanston IL; Fall quarter admission (Winter/Spring only by special exception); typical applicant has B.S. in computer engineering, computer science, electrical engineering, or related discipline; highly qualified candidates from other backgrounds considered; research areas: systems/control, communications/signal processing, photonics, electronics, ML, MLSP, micro/nano, robotics, VLSI, wireless.",
        "ddl": "December 15, 2026 (for Fall 2027 quarter admission; MS deadline late February; PhD requests reviewed during Winter Quarter).",
        "lang": "TOEFL iBT or IELTS Academic required for international applicants per The Graduate School (TGS) at Northwestern.",
        "test": "GRE General: OPTIONAL per TGS / McCormick ECE admissions. Required: TGS online application; transcripts; 3 letters of recommendation; SOP; CV; English proficiency. Funding: University Fellowship (first-year) + TA + RA (faculty research grant); stipend + tuition + health insurance. Score distributions reflect admitted cohort, not minimum thresholds.",
        "tui": "Full support: tuition + stipend + health insurance via University Fellowship (year 1) + TA + RA.",
        "url": "details/nu-ece-phd.html",
    },
    {
        "id": "rice-ece-phd",
        "s": "rice",
        "n": "Electrical and Computer Engineering (PhD)",
        "en": "PhD in Electrical and Computer Engineering (Rice University, George R. Brown School of Engineering, Department of Electrical and Computer Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "On-campus research PhD, Houston TX; Fall admission only (no Spring for PhD); students with a prior non-thesis MS may be waived from obtaining a Rice MS; research areas: signals/systems, photonics, nanotechnology, integrated circuits, VLSI, ML, communications, robotics, energy.",
        "ddl": "December 21, 2026 (late deadline January 1, 2027; decisions mid-February through late March; April 15 response resolution).",
        "lang": "TOEFL iBT or IELTS Academic required per Rice Graduate and Postdoctoral Studies.",
        "test": "GRE General: OPTIONAL but strongly recommended. Required: Rice ECE online application (application fee WAIVED for PhD); transcripts from every institution including senior-year first semester; at least 3 letters of recommendation from faculty familiar with applicant; SOP; CV; English proficiency. All PhD students receive full tuition waiver + stipend; first-year supported by department fellowship, thereafter by advisor RA (paid bi-weekly). External fellowships (NSF GRFP, etc.) encouraged. Score distributions reflect admitted cohort, not minimum thresholds.",
        "tui": "Full tuition + stipend; first-year department fellowship, thereafter advisor RA; external fellowships encouraged.",
        "url": "details/rice-ece-phd.html",
    },
    {
        "id": "vanderbilt-ece-phd",
        "s": "vanderbilt",
        "n": "Electrical and Computer Engineering (PhD)",
        "en": "PhD in Electrical and Computer Engineering (Vanderbilt University, School of Engineering, Department of Electrical and Computer Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "On-campus research PhD, Nashville TN; Fall admission (Spring by international early deadline November 1); first-year students typically serve as teaching assistants; continuation contingent on academic/research progress; research areas: computer architecture, VLSI, photonics, RF/mmWave, control, robotics, ML, biomedical electronics, energy.",
        "ddl": "December 1, 2026 (fee-waiver deadline for Fall 2027); January 8, 2027 (final PhD application deadline, 11:59 PM ET; encouraged to submit by December 15 for material completion).",
        "lang": "TOEFL iBT or IELTS Academic required per Vanderbilt Graduate School.",
        "test": "GRE General: not required per Vanderbilt School of Engineering graduate admissions. Required: Vanderbilt Graduate School online application; transcripts; 3 letters; SOP; CV; English proficiency. Funding: Engineering Graduate Fellowship - full tuition waiver, monthly stipend, student service fees, health insurance premium; all PhD students receive comprehensive package up to 5 years: annual stipend $40,000, $2,000 one-time student success allowance, additional merit awards up to $10,000/year. Score distributions reflect admitted cohort, not minimum thresholds.",
        "tui": "Comprehensive package up to 5 years: full tuition + annual stipend $40,000 + health insurance + $2,000 success allowance + merit awards up to $10,000/yr.",
        "url": "details/vanderbilt-ece-phd.html",
    },
    {
        "id": "wustl-ee-phd",
        "s": "wustl",
        "n": "Electrical Engineering (PhD)",
        "en": "PhD in Electrical Engineering (Washington University in St. Louis, McKelvey School of Engineering, Department of Electrical and Systems Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "On-campus research PhD, St. Louis MO; Fall semester entry only (Spring admission only by specific faculty invitation); research areas: communications, signal processing, control systems, robotics, photonics, energy, ML, systems science; 36 credits coursework + 30 credits dissertation minimum.",
        "ddl": "December 15, 2026 (application opens September 1; decisions by March 15; reply by April 15; Early Decision December 31 with notification January 31).",
        "lang": "TOEFL iBT required for international applicants (composite 95+ typical admitted cohort per ESE admissions); IELTS Academic accepted per WashU Graduate School.",
        "test": "GRE General: OPTIONAL (test-optional since COVID-era policy; admitted cohort typically Q >90th percentile and AW >=3.5). Required: WashU graduate application; transcripts; 3 letters; SOP; CV; English proficiency; research experience strongly preferred. Fully funded: full tuition + health insurance + competitive stipend (guaranteed with satisfactory progress). Top fellowships: Ann W. and Spencer T. Olin-Chancellor's Fellowship; McDonnell International Scholars Academy. Score distributions reflect admitted cohort, not minimum thresholds.",
        "tui": "Fully funded: full tuition + health insurance + competitive stipend; top awards include Olin-Chancellor's Fellowship and McDonnell International Scholars Academy.",
        "url": "details/wustl-ee-phd.html",
    },
    {
        "id": "notre-ee-phd",
        "s": "notre",
        "n": "Electrical Engineering (PhD)",
        "en": "PhD in Electrical Engineering (University of Notre Dame, College of Engineering, Department of Electrical Engineering)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "On-campus research PhD, Notre Dame IN; Fall admission (Spring only by faculty invitation); open to applicants with B.S. or M.S. in engineering or physical sciences; minimum residency 4 semesters; research areas: electronic circuits/systems, electronic materials/devices, wireless, photonics, control, power, RF/mmWave, communications.",
        "ddl": "December 15, 2026 (priority for internal select fellowships; Spring admission November 1 by faculty invitation only).",
        "lang": "TOEFL iBT, IELTS Academic, or Duolingo English Test required for non-native English speakers per Notre Dame Graduate School.",
        "test": "GRE General: RECOMMENDED but not required. Required: Notre Dame Graduate School online application; unofficial transcripts from every post-secondary institution (official upon enrollment); 3 letters of recommendation from faculty who can judge academic/research potential; CV; statement of intent; English proficiency. All admitted PhD students receive full financial support: full tuition scholarship + 12-month living stipend + 100% health insurance premium + conference/travel funding. Score distributions reflect admitted cohort, not minimum thresholds.",
        "tui": "Fully funded: full tuition scholarship + 12-month stipend + 100% health insurance + conference/travel funding; fellowship top-ups available.",
        "url": "details/notre-ee-phd.html",
    },
]

def detail_html(p, school_cn, tagline):
    stem_badge = "STEM" if p["stem"] else "Non-STEM"
    lvl_badge = "PhD" if p["lvl"] == "d" else "Master's"
    return f"""<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8">
<title>{p['en']} - {school_cn}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',sans-serif;max-width:980px;margin:24px auto;padding:0 20px;color:#222;line-height:1.6}}
h1{{font-size:22px;border-bottom:2px solid #8c641a;padding-bottom:8px}}
h2{{font-size:16px;color:#8c641a;margin-top:24px}}
.grid{{display:grid;grid-template-columns:1fr 1fr;gap:12px}}
.card{{border:1px solid #ddd;border-radius:8px;padding:14px;background:#fafafa}}
.card h3{{margin:0 0 6px;font-size:14px;color:#444}}
.badge{{display:inline-block;background:#8c641a;color:#fff;padding:2px 8px;border-radius:10px;font-size:12px;margin-left:8px}}
.back{{display:inline-block;margin-bottom:16px;color:#8c641a;text-decoration:none}}
</style></head><body>
<a class="back" href="../index_main.html">&larr; Back to Program Library</a>
<h1>{p['en']}<span class="badge">{stem_badge}</span><span class="badge">{lvl_badge}</span></h1>
<p><strong>{school_cn}</strong> &middot; {p['deg']} &middot; {tagline}</p>
<div class="grid">
<div class="card"><h3>Degree / Format</h3>{p['deg']}, on-campus. {p['dur']}.</div>
<div class="card"><h3>Application Deadline</h3>{p['ddl']}.</div>
<div class="card"><h3>English Proficiency</h3>{p['lang']}.</div>
<div class="card"><h3>Standardized Tests</h3>{p['test']}.</div>
<div class="card"><h3>Tuition / Funding</h3>{p['tui']}.</div>
<div class="card"><h3>Curriculum</h3>待补 - qualifying exam, course distribution, dissertation handbook to be filled from graduate program guide.</div>
</div>
<h2>Notes</h2>
<ul>
<li>Source: Northwestern ECE / Rice ECE / Vanderbilt ECE / WashU ESE / Notre EE official admissions pages.</li>
<li>All five are US research PhDs fully funded; none require GRE for the current cycle (Rice optional-but-recommended, Notre recommended, others optional/not required).</li>
<li>Vanderbilt is the only school publishing an explicit $40,000 annual stipend plus $2,000 one-time success allowance; Rice ECE PhD application fee is waived.</li>
<li>WashU ESE and Notre EE are distinct departments from the previously added CSE/CPE PhDs (WashU CSE and Notre CSE).</li>
<li>Fields marked 待补 will be filled when the official graduate handbook PDF is reachable.</li>
<li>Official pages may update; always confirm on the school's admissions site before applying.</li>
</ul>
</body></html>"""

details_meta = [
    ("nu-ece-phd.html", "Northwestern University (McCormick School of Engineering)", "PhD in Electrical and Computer Engineering"),
    ("rice-ece-phd.html", "Rice University (George R. Brown School of Engineering)", "PhD in Electrical and Computer Engineering"),
    ("vanderbilt-ece-phd.html", "Vanderbilt University (School of Engineering)", "PhD in Electrical and Computer Engineering"),
    ("wustl-ee-phd.html", "Washington University in St. Louis (McKelvey School of Engineering)", "PhD in Electrical Engineering"),
    ("notre-ee-phd.html", "University of Notre Dame (College of Engineering)", "PhD in Electrical Engineering"),
]

for fname, scn, tag in details_meta:
    p = next(p for p in new_programs if p["url"].endswith(fname))
    out = os.path.join(DETAILS_DIR, fname)
    with open(out, "w", encoding="utf-8") as f:
        f.write(detail_html(p, scn, tag))
    print("Wrote:", fname)

with open(INDEX, "r", encoding="utf-8") as f:
    html = f.read()

def fmt_prog(p):
    return (
        '{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},'
        'dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test}"}},tui:"{tui}",url:"{url}"}}'
    ).format(**p)

new_block = ",\n" + ",\n".join(fmt_prog(p) for p in new_programs)

m = re.search(r'const\s+PROGRAMS\s*=\s*\[', html)
if not m:
    raise SystemExit("PROGRAMS array not found")
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[':
        depth += 1
    elif c == ']':
        depth -= 1
    i += 1
insert_at = i - 1
new_html = html[:insert_at] + new_block + "\n" + html[insert_at:]

vd_new = [p["url"] for p in new_programs]
m2 = re.search(r'const\s+VERIFIED_DETAILS\s*=\s*new\s+Set\(\s*\[', new_html)
if not m2:
    raise SystemExit("VD Set not found")
start2 = m2.end()
depth2 = 1
j = start2
while j < len(new_html) and depth2 > 0:
    c = new_html[j]
    if c == '[':
        depth2 += 1
    elif c == ']':
        depth2 -= 1
    j += 1
insert_at2 = j - 1
vd_block = "," + ",".join('"{}"'.format(u) for u in vd_new)
new_html = new_html[:insert_at2] + vd_block + new_html[insert_at2:]

with open(INDEX, "w", encoding="utf-8") as f:
    f.write(new_html)

print("Appended {} PROGRAMS entries and {} VD entries".format(len(new_programs), len(vd_new)))
print("Done. File size:", os.path.getsize(INDEX))
