#!/usr/bin/env python3 """Split data/catalog.json into per-region research assignments. Usage: python3 -I scripts/make_assignments.py Writes research/assignments/.json - one file per research agent. Grouping by region lets one researcher reuse city/country context. """ import json from collections import Counter GROUPS = { "germany": ["Germany"], "alps-benelux": ["Austria", "Switzerland", "Belgium", "Netherlands"], "france": ["France"], "nordic-atlantic": ["Sweden", "Norway", "Denmark", "Finland", "Iceland", "Ireland"], "central-east-europe": ["Croatia", "Slovenia", "Slovakia", "Hungary", "Poland", "Romania", "Bulgaria", "Ukraine", "Estonia", "Lithuania"], "south-europe": ["Spain", "Italy", "Portugal", "Greece", "Türkiye"], "korea": ["Korea (the Republic of)"], "taiwan-china": ["Taiwan", "China"], "asia-other": ["Japan", "Singapore", "Thailand", "Viet Nam", "Indonesia", "India"], "anglo-overseas": ["United States of America", "Canada", "Australia"], "latin-america": ["Mexico", "Brazil", "Argentina", "Chile", "Colombia", "Costa Rica", "Peru", "Uruguay", "Venezuela"], } catalog = json.load(open("data/catalog.json", encoding="utf-8")) by_country = {c: g for g, cs in GROUPS.items() for c in cs} missing = {s["country"] for s in catalog["schools"]} - set(by_country) assert not missing, f"countries without a group: {missing}" counts = Counter() for group in GROUPS: schools = [s for s in catalog["schools"] if by_country[s["country"]] == group] counts[group] = len(schools) with open(f"research/assignments/{group}.json", "w", encoding="utf-8") as f: json.dump({"group": group, "schools": schools}, f, ensure_ascii=False, indent=1) f.write("\n") print(dict(counts), "total", sum(counts.values()))