from __future__ import annotations import json import sys from pathlib import Path from openpyxl import load_workbook HERE = Path(__file__).resolve().parent ROOT = HERE.parents[3] sys.path.insert(0, str(HERE.parents[1])) from charting import save_chart YEARS = list(range(2019, 2025)) NATIONAL = "Worldwide total" CHINA = "Mainland China" COUNTRIES = ["India", CHINA, "Nepal", "Vietnam", "South Korea", "Japan", "Nigeria", "Bangladesh", "Brazil"] COLOR = ("#fbf7ef", "#142334", "#21615e", "#9c3930", "#2b527f", "#5d7831") SEVIS = "https://www.ice.gov/doclib/sevis/btn/25_0605_2024-sevis-btn.pdf" def main(): archive = ROOT / "research/launch_payloads_2026-12-01.json" record = next(r for r in json.loads(archive.read_text(encoding="utf-8"))["items"] if r["id"] == "launch_state_nonimmigrant_visas_1997_2024") wb = load_workbook(ROOT / record["local_path"], data_only=True, read_only=True) groups = {"Grand Total": NATIONAL, "Grand Totals": NATIONAL, "China - mainland": CHINA, "Korea, South": "South Korea"} counts = {} try: for year in YEARS: rows = list(wb[f"FY{year % 100}"].values) fields = [str(key).replace("-", "").strip() for key in rows[0]] i, j = (fields.index(name) for name in ("F1", "F2")) values = {} for row in rows[1:]: if isinstance(row[0], str): name = groups.get(row[0].strip(), row[0].strip()) if name in (NATIONAL, *COUNTRIES): if name in values or not all(isinstance(row[n], int) for n in (i, j)): raise ValueError(f"Duplicate or nonnumeric count for {name} in FY{year}") values[name] = {"F-1": row[i], "F-2": row[j]} assert set(values) == {NATIONAL, *COUNTRIES} counts[year] = values finally: wb.close() def series(name, visa="F-1"): return [counts[yr][name][visa] for yr in YEARS] nat = series(NATIONAL) recent = {k: series(k)[-1] - series(k)[-2] for k in COUNTRIES} chart_plan = [] def add(tag, title, question, unit, labels, values, summary, *, kind="bar", source=None, source_note=None): stem = f"chart-{len(chart_plan) + 1:02d}-{tag}" save_chart(HERE / "charts", stem, title=title, unit=unit, labels=labels, series=values, source=source_note or "U.S. Department of State, nonimmigrant visa issuance detail workbook", palette=COLOR, kind=kind) chart_plan.append({"asset": f"charts/{stem}.png", "data": f"charts/{stem}.csv", "question": question, "source": source or record["source_url"], "population": "U.S. student visa issuances; SEVIS records are marked separately", "period": "Federal fiscal years 2019–24 except the marked calendar-year SEVIS counts", "unit": unit, "takeaway": summary}) add("worldwide", "F-1 issuance fell after the rebound peak", "What happened to worldwide F-1 issuance from 2019 to 2024?", "Visas issued, thousands", YEARS, {"F-1": [x / 1000 for x in nat]}, "The 2024 figure was higher than 2019 and lower than 2023.", kind="line") subset = ["India", CHINA, "Nepal", "Vietnam"] net = nat[-1] - nat[-2] add("net-change", "India accounted for nearly all of the net drop", "Which large movements offset each other in the FY2024 total?", "Change in visas issued from FY2023", [*subset, "All other nationalities", "Worldwide net"], {"Change": [*[recent[k] for k in subset], net - sum(recent[k] for k in subset), net]}, "India's decline of 44,663 nearly equals the worldwide net decline of 44,681.") add("two-markets", "A smaller combined share for two large sources", "What share of F-1 issuances went to India and mainland China?", "Share of worldwide F-1 issuances (%)", YEARS, {"India": [100 * x / v for x, v in zip(series("India"), nat)], CHINA: [100 * x / v for x, v in zip(series(CHINA), nat)], "Combined": [100 * (a + b) / v for a, b, v in zip(series("India"), series(CHINA), nat)]}, "The combined share fell from roughly 49 to 42 percent in the latest comparison.", kind="line") others = ["Japan", "South Korea", "Vietnam", "Nepal"] add("index", "Other Asian markets recovered at different rates", "Which selected nationality counts exceeded FY2019?", "F-1 issuance index, FY2019 = 100", YEARS, {k: [100 * value / series(k)[0] for value in series(k)] for k in others}, "Nepal's count rose from a small base while Japan and South Korea were still below their FY2019 levels.", kind="line") five = ["South Korea", "Bangladesh", "Nigeria", "Brazil", "Japan"] add("other-declines", "Several smaller decreases accompanied the India shift", "How much did selected other nationality counts fall?", "Change in visas issued from FY2023", five, {"Change": [recent[k] for k in five]}, "The selected markets moved down in absolute counts, although each shift was smaller than India's.") add("before-pandemic", "The longer comparison tells a different story", "How does FY2024 compare with FY2019 across the main components?", "Change in F-1 visas issued from FY2019", ["India", CHINA, "All remaining rows", "Worldwide net"], {"Change": [series("India")[-1] - series("India")[0], series(CHINA)[-1] - series(CHINA)[0], (nat[-1] - nat[0]) - sum(series(k)[-1] - series(k)[0] for k in ("India", CHINA)), nat[-1] - nat[0]]}, "The FY2024 worldwide count exceeded FY2019 even though mainland China's reported count was below it.") add("dependent-class", "The dependent visa class has its own pattern", "How many F-2 issuances occurred per 100 F-1 issuances?", "F-2 issuances per 100 F-1 issuances", YEARS, {k: [100 * a / b for a, b in zip(series(k, "F-2"), series(k))] for k in (NATIONAL, "India", CHINA)}, "The age, application timing and visa status of specific families cannot be recovered from these ratios.", kind="line") sevis_counts = [1503649, 1582808] add("sevis-countercheck", "Active student records and F-1 issuances diverged", "Did the separate SEVIS measure move in the same direction?", "Index, each measure’s 2023 count = 100", [2023, 2024], {"State Department fiscal-year F-1 visas": [100, 100 * nat[-1] / nat[-2]], "ICE calendar-year active F-1 and M-1 records": [100, 100 * sevis_counts[-1] / sevis_counts[0]]}, "The active-record count grew while F-1 issuances fell; units and year definitions differ.", kind="line", source=[record["source_url"], SEVIS], source_note="U.S. Department of State NIV detail and ICE 2024 SEVIS by the Numbers") summary = {"snapshot": {k: record.get(k) for k in ("id", "source_url", "local_path", "sha256")}, "issuances": counts, "recent_f1_changes": recent, "sevis_calendar_active_records": dict(zip((2023, 2024), sevis_counts)), "sevis_source": SEVIS} for name, value in (("CHART-PLAN.json", chart_plan), ("evidence.json", summary)): (HERE / name).write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") if __name__ == "__main__": main()