A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
tools: event timeline, print every event by date (fixes #324) (#327)
agamrafaeli-instinct52abdfe8c165
diff --git a/docs/dev-setup.md b/docs/dev-setup.mdindex 006eea875..c50bfee48 100644--- a/docs/dev-setup.md+++ b/docs/dev-setup.md@@ -23,6 +23,7 @@ Unity, a Unity licence and macOS are only needed for `unity/`. The sim, the cont| Policy checker tests | `uv run --with pytest==9.1.1 --with pyyaml==6.0.3 --with requests==2.32.5 pytest scripts/oss/tests -q` | Repo policy || Data tool tests (one runs the sim's release gate, so they need the .NET SDK too) | `uv run --with pytest==9.1.1 --with rasterio==1.5.2 --with numpy==2.5.3 --with pyyaml==6.0.3 --with pillow==12.3.0 --with requests==2.32.5 --with pyproj==3.8.0 pytest tools/tests -q` | Tools (pytest) || GDD feature sections (also run by the policy checker tests) | `uv run scripts/oss/gdd_lint.py` | Repo policy |+| Every event by date, with era, anchor and review status | `uv run scripts/event_timeline.py [--status draft]` | none (helper) || Dead relative links in Markdown files (also run by the policy checker tests) | `uv run scripts/oss/md_links.py` | Repo policy || New event file (skeleton with every required field) | `uv run scripts/new_event.py <id> [--from D] [--to D]` | none (helper) || Changelog line | `uv run scripts/oss/changelog_check.py --base origin/main` | Changelog |diff --git a/scripts/event_timeline.py b/scripts/event_timeline.pynew file mode 100644index 000000000..853474be9--- /dev/null+++ b/scripts/event_timeline.py@@ -0,0 +1,60 @@+#!/usr/bin/env python3+# /// script+# requires-python = ">=3.10"+# dependencies = ["pyyaml==6.0.3"]+# ///+"""Print every event sorted by window (#324): `uv run scripts/event_timeline.py [--root DIR] [--status draft]`.++One line per event: from, to, era, anchor, status, id, tags. An event with no `to` shows `open`. A final line counts+events per status, so unreviewed ones stand out. Reads content/events/*.yaml and content/eras.yaml; writes nothing."""+import argparse+import sys+from pathlib import Path++import yaml++ROOT = Path(__file__).resolve().parents[1]+# The sim's defaults for a missing key (GameEvent in sim/Statecraft.Sim/Content.cs; a test keeps them equal).+DEFAULT_ANCHOR = "soft"+DEFAULT_STATUS = "draft"+++def load(root: Path) -> list[dict]:+ eras = yaml.safe_load((root / "content/eras.yaml").read_text(encoding="utf-8"))["eras"]+ rows = []+ for f in sorted((root / "content/events").glob("*.yaml")):+ e = yaml.safe_load(f.read_text(encoding="utf-8"))+ start = str(e["from"])+ era = next((x["id"] for x in eras+ if str(x["from"]) <= start and (not x.get("to") or start < str(x["to"]))), "-")+ rows.append({"from": start, "to": str(e["to"]) if e.get("to") else "open", "era": era,+ "anchor": e.get("anchor", DEFAULT_ANCHOR), "status": e.get("status", DEFAULT_STATUS),+ "id": e["id"], "tags": ",".join(e.get("tags") or [])})+ return sorted(rows, key=lambda r: (r["from"], r["id"]))+++def render(rows: list[dict]) -> str:+ lines = [f"{r['from']} {r['to']:<10} {r['era']:<10} {r['anchor']:<4} {r['status']:<20} {r['id']}"+ + (f" [{r['tags']}]" if r["tags"] else "") for r in rows]+ counts: dict[str, int] = {}+ for r in rows:+ counts[r["status"]] = counts.get(r["status"], 0) + 1+ summary = ", ".join(f"{n} {s}" for s, n in sorted(counts.items()))+ lines.append(f"{len(rows)} events: {summary}" if summary else "0 events")+ return "\n".join(lines)+++def main(argv: list[str] | None = None) -> int:+ p = argparse.ArgumentParser(description=__doc__.split("\n")[0])+ p.add_argument("--root", type=Path, default=ROOT)+ p.add_argument("--status", help="only events with this review status")+ a = p.parse_args(argv)+ rows = load(a.root)+ if a.status:+ rows = [r for r in rows if r["status"] == a.status]+ print(render(rows))+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/scripts/oss/tests/test_event_timeline.py b/scripts/oss/tests/test_event_timeline.pynew file mode 100644index 000000000..ebdd7b2c2--- /dev/null+++ b/scripts/oss/tests/test_event_timeline.py@@ -0,0 +1,50 @@+"""Event timeline (#324): sorting, era lookup, open windows, status filter and the real content."""+import importlib.util+from pathlib import Path++ROOT = Path(__file__).resolve().parents[3]+SPEC = importlib.util.spec_from_file_location('event_timeline', ROOT / 'scripts/event_timeline.py')+m = importlib.util.module_from_spec(SPEC)+SPEC.loader.exec_module(m)+++def repo(tmp_path):+ (tmp_path / 'content/events').mkdir(parents=True)+ (tmp_path / 'content/eras.yaml').write_text(+ "eras:\n - { id: a, from: 1948-05-15, to: 1950-01-01 }\n - { id: b, from: 1950-01-01, to: 1957-01-01 }\n")+ (tmp_path / 'content/events/late.yaml').write_text("id: late\nfrom: 1951-01-01\nstatus: fact-checked\n")+ (tmp_path / 'content/events/early.yaml').write_text("id: early\nfrom: 1948-06-01\nto: 1948-07-01\ntags: [security]\nanchor: hard\n")+ # named so that id order is not date order; this one starts on the era boundary, so it belongs to era b+ (tmp_path / 'content/events/a_edge.yaml').write_text("id: a_edge\nfrom: 1950-01-01\nstatus: fact-checked\n")+ return tmp_path+++def test_sorted_with_era_open_window_and_default_status(tmp_path):+ rows = m.load(repo(tmp_path))+ assert [r['id'] for r in rows] == ['early', 'a_edge', 'late']+ assert [r['era'] for r in rows] == ['a', 'b', 'b']+ assert rows[2]['to'] == 'open' and rows[0]['status'] == 'draft' and rows[0]['anchor'] == 'hard'+ out = m.render(rows)+ assert '[security]' in out and out.splitlines()[-1] == '3 events: 1 draft, 2 fact-checked'+++def test_status_filter(tmp_path, capsys):+ assert m.main(['--root', str(repo(tmp_path)), '--status', 'draft']) == 0+ out = capsys.readouterr().out+ assert 'early' in out and 'late' not in out.split('\n')[0]+ assert m.main(['--root', str(tmp_path), '--status', 'historian-reviewed']) == 0+ assert capsys.readouterr().out.strip() == '0 events'+++def test_defaults_match_the_sim():+ # a missing anchor or status must show as the sim reads it (GameEvent in Content.cs)+ cs = (ROOT / 'sim/Statecraft.Sim/Content.cs').read_text()+ game_event = cs[cs.index('class GameEvent'):]+ game_event = game_event[:game_event.index('\n }')]+ assert f'Anchor {{ get; set; }} = "{m.DEFAULT_ANCHOR}";' in game_event+ assert f'Status {{ get; set; }} = "{m.DEFAULT_STATUS}";' in game_event+++def test_real_content_every_event_lands_in_an_era():+ rows = m.load(ROOT)+ assert rows and all(r['era'] != '-' for r in rows)