Files
solon/scripts/statistics-sync.ts
CatoandClaude Sonnet 5.5 568fc14323 Statistics beside the law: series, law events, timelines, maps, axes and saved views (#441)
* feat(statistics): the law beside the numbers — series, law links, timelines, axes, saved views

Implements the roadmap section {#stats} (docs/design/2026-11-freedom-laws-statistics.md):

- Series as facts: a `statistic` block on metrics (definition, publisher,
  series code); World Bank (WDI API) and OECD (SDMX) adapters; five series
  for CH, LI, EE and US, read monthly; a publisher's 5xx is retried twice.
- An append-only `statistic_records` log for law links, events and
  enforcement, written from a curated, source-checked list by
  `statistics:sync` and the daily places cron; three links checked against
  Fedlex and Riigi Teataja.
- /statistics (ranked bars, axes with reader or group weights),
  /statistics/<metric> (line chart, a timeline of linked acts' versions over
  the same years, the law, enforcement, sources), /statistics/view/<sha256>;
  on @bitbaum/chartkit; five languages.
- Saved views under the sha256 of their spec; a proposal that links one
  carries it as evidence (proposal_evidence), attached in the same
  transaction.
- Roadmap and changelog updated; what remains is listed with its reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsX15QgjkDp9MQaQ92

* feat(statistics): law event pages, clickable timelines, maps, scatter, parallel coordinates, reader-built axes

- Events: what changed (wording before/after), how it came about, votes with
  party breakdowns, who initiated/sponsored/recommended/opposed, claims and
  critiques kept apart from what happened, each line with the page it was read
  on; five loaded (Estonia 2023, US TCJA 2017, two Swiss firearms ballots,
  Kennesaw 1982). /statistics/event/<slug>, /statistics/events; timeline marks
  open them; the numbers around an event (line cut at the change, peers apart,
  a before/at/after table).
- Numbers that mean the same everywhere: central-government-only series
  retired for all-levels OECD series; a per-statistic scope sentence; central
  share of tax as a decentralisation proxy; SDMX series told apart by `match`.
- A world map per statistic on geo-kit, /statistics/compare scatter, parallel
  coordinates per axis, a reader-built axis kept in the link, saved axes.
- Fetch: four retries with backoff and a pause between a source's requests.
- Tests, roadmap, changelog and design note updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsX15QgjkDp9MQaQ92

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-09 09:15:42 +01:00

43 lines
1.5 KiB
TypeScript

/**
* Write the curated statistics records (src/lib/config/statistics/records.ts)
* into the append-only `statistic_records`.
*
* pnpm run statistics:sync apply
* pnpm run statistics:sync --check change nothing; exit 1 when the log disagrees with config
*/
import { execFileSync } from "node:child_process";
import { STATISTIC_RECORDS } from "@/lib/config/statistics/records";
import { db } from "@/lib/db/client";
import { syncStatisticRecords } from "@/lib/statistics/sync";
const check = process.argv.includes("--check");
function gitSha(): string | null {
try {
return execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf8" }).trim();
} catch {
return process.env.GIT_SHA ?? null;
}
}
async function main(): Promise<number> {
const report = await syncStatisticRecords(db, STATISTIC_RECORDS, { gitSha: gitSha(), check });
for (const key of report.asserted) console.log(`${check ? "would assert" : "asserted"} ${key}`);
for (const key of report.retracted)
console.log(`${check ? "would retract" : "retracted"} ${key}`);
for (const { key, reason } of report.skipped) console.log(`skipped ${key}: ${reason}`);
console.log(`${report.unchanged} unchanged`);
if (check && report.asserted.length + report.retracted.length > 0) {
console.error("❌ the statistics log disagrees with config; run statistics:sync");
return 1;
}
return 0;
}
main()
.then((code) => process.exit(code))
.catch((error: unknown) => {
console.error(error);
process.exit(2);
});