"""sources/klasifikacija.csv no partijām: tools/batch1.py (1. partija) + sources/batches/*.csv (point,type,function,rationale). Visas partijas — MI priekšlikums (status ai_proposed), līdz cilvēks tās pārskata. python3 tools/merge_batches.py → sources/klasifikacija.csv; pēc tam python3 tools/generate.py""" import csv import glob import os import sys sys.path.insert(0, os.path.dirname(__file__)) import batch1 # noqa: E402 BY, DATE = "claude-opus-5-5", "2026-10-24" TYPES = {"function", "procedural", "residual"} def main(out="sources/klasifikacija.csv"): rows, seen = [], {} for point, t, fn, why in batch1.ROWS: rows.append((point, t, fn, why, "batch1")) for path in sorted(glob.glob("sources/batches/*.csv")): for r in csv.DictReader(open(path, encoding="utf-8")): rows.append((r["point"].strip(), r["type"].strip(), (r["function"] or "").strip(), (r["rationale"] or "").strip(), os.path.basename(path))) # sources/remap.csv: point (exact id, or institution prefix ending with ".") from → to, after a catalogue split if os.path.exists("sources/remap.csv"): rules = list(csv.DictReader(open("sources/remap.csv", encoding="utf-8"))) used = {i: 0 for i in range(len(rules))} remapped = [] for point, t, fn, why, src in rows: for i, r in enumerate(rules): k = r["point"] if t == "function" and fn == r["from"] and (point == k or (k.endswith(".") and point.startswith(k))): fn, used[i] = r["to"], used[i] + 1 break remapped.append((point, t, fn, why, src)) rows = remapped idle = [rules[i]["point"] for i, n in used.items() if not n] if idle: sys.exit("remap.csv: neizmantoti noteikumi " + ", ".join(idle)) print("remap:", sum(used.values()), "punkti pārvietoti") bad = [] for point, t, fn, why, src in rows: if point in seen: bad.append(f"{point}: divreiz ({seen[point]}, {src})") seen[point] = src if t not in TYPES: bad.append(f"{point}: type {t!r}") if (t == "function") != bool(fn): bad.append(f"{point}: type {t} un function {fn!r} nesader") if not why: bad.append(f"{point}: nav pamatojuma") if bad: sys.exit("\n".join(bad[:40])) with open(out, "w", encoding="utf-8", newline="") as f: w = csv.writer(f) w.writerow(["point", "type", "function", "status", "by", "date", "rationale"]) for point, t, fn, why, _src in sorted(rows): w.writerow([point, t, fn, "ai_proposed", BY, DATE, why]) print(out, len(rows), "punkti no", len({r[4] for r in rows}), "partijām") if __name__ == "__main__": main()