* fix(law): a recut keeps the mark of a text read by OCR The weekly recut wrote every cantonal version it examined back with the plain importer version, so a text read from a scan by OCR (`…+ocr`) lost the mark that says how it was read, and an older version so marked was examined again at the head of every run. Any version carrying this reader's version with a mark (+archive, +ocr, or both) is now current, and a version brought up to date keeps every mark it had. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJdjaMYdbLjujoC3k * feat(places): a pack of its own takes a country over from the world pack Adding a pack is how a country gets places in depth, and the path had never run: a new pack's root resolved to the world pack's row, which kept its pack and path; the new pack's places hung under world/...; and a world file still stating the country would set the root's level back and give it a parent. - A pack may `yield` (the world pack does): it holds a place only until a pack of the place's own names it. - Then the place moves: same row (its figures and records stay), new pack and path, the new path canonical in place_paths and the old one redirecting, and the parents other sources stated for it superseded. - What the world pack held under a moved place that the batch does not restate ends that day; restated later, it moves and is current again. - A batch of a yielding pack leaves alone a place another pack holds and every place it states under one, so a world file not yet regenerated, the countries' or the subdivisions', cannot take a country back. - An integration test adds Quuxland, a made-up country the world pack holds first, and checks all of it, rerun-safe on one database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJdjaMYdbLjujoC3k * feat(data): one command refreshes every generated dataset, and a monthly workflow opens the PR The world's profiles, its countries, every country's subdivisions, the world list's photographs and the law plan were refreshed only when someone ran three to five commands on a laptop, in an order nobody wrote down; all were last read on 2026-11-10. - `pnpm run data:refresh [--only a,b] [--list]` (scripts/data-refresh.ts) runs the generators in the order they build on each other. One that fails keeps its old files and is reported; the rest still run. A new generator is one entry. - .github/workflows/data-refresh.yml runs it on the 4th of each month (or on dispatch, for some), and opens a pull request when anything changed, as bitbaum/substrata's recheck-data.yml does; the sweep merges it on green CI and the deploy's places-data job imports it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJdjaMYdbLjujoC3k --------- Co-authored-by: Claude <noreply@anthropic.com>
10 KiB
Adding statistics, events and dimensions
How to add content to the statistics layer. The design is in
docs/design/2026-11-freedom-framework.md; this is the checklist. Every step
has a test or a command that fails when it is done wrong, so a mistake is found
by a program and not by a reader.
Commands (all under pnpm run):
| Command | What it does |
|---|---|
places:sync-config |
Writes the metric and source registries (config) to the database |
places:fetch <source> / places:import <source> <file> |
Reads a source (by its adapter) and loads its figures |
statistics:sync |
Writes the curated records (links, events) into the append-only log |
statistics:quality |
Reports gaps, large steps, stale and provisional figures per series |
statistics:verify |
Fetches every page the curated records cite and checks the words each is expected to hold |
verify |
The whole gate: format, lint, types, design, tests |
1. Add a series
-
Find the publisher's series and read its terms. Note the series code, what it measures in the publisher's own words, what it covers (which levels of government, which people), its unit, and its licence. If the licence is not on
src/lib/config/places/licences.ts, stop: a Register decision admits it first. -
Add a metric to
src/lib/config/places/metrics.tswith astatisticblock:definition: what it measures, in the publisher's terms, in every language (do not describe methods you have not read);scope: what it covers, in one sentence (a series that counts only central government must say so; a federal country will otherwise look small beside a unitary one);series:publisher,code,url,read(the adapter that reads it:worldbank_indicatorsoroecd_sdmx), and for SDMXmeasure,key(with{iso3}where a country goes) andmatchwhere a flow holds several series under one measure; a World Bank series outside the WDI names itsdatabase(3for the Worldwide Governance Indicators);unitand aplausibleband: values outside it are quarantined at import.
A metric of a known family is a few lines:
wgiMetric({ key, code, name })for a governance indicator, and the shared words insrc/lib/config/places/statistic-templates.ts(ALL_LEVELS_SCOPE,PERCEPTION_SCOPE,sentence()for a label put into a sentence in each language). Give a name whole in each language; never assemble one from parts. A metric whose series is not comparable across countries is not charted: leavestatisticoff, or retire it withretired: true(never delete one that has data). -
Name the source. For a World Bank or OECD series there is nothing more to write: its
readputs it in that publisher's one source (src/lib/config/places/sources.ts), which asks for every country in one request per series, and the next run reads it. For a new publisher add an adapter insrc/lib/places/adapters/(format only: it names no country), register it inadapters/index.ts, and add one source for it that lists the countries it covers and the packs it serves (packs). A pack's own list of sources is computed from the sources that name it; never write it by hand. If a source's key changes, keep the old one informerKeys: what it read under that key stays credited to it. -
Test it against a real response saved as a fixture (
src/lib/places/__tests__/fixtures/). Check the mapping, that a missing value is never stored and is reported (each year, for a source of one country; for a source of many, one line a series naming the countries it has no value for:adapters/gaps.ts), and that the plausible band holds. -
Load it twice.
places:sync-config, thenplaces:fetch <source>; the second run must reportunchangedfor every retrieval (nothing re-read). A retrieval that left out figures for a country not held here is read again on every run instead, and its report names the country: load the country's places, and the figures land. -
Look at it.
statistics:qualitylists gaps and large steps; open the statistic's page. Read the numbers against the publisher's page. If two countries look alike or unlike for a reason of scope, the scope sentence is wrong or missing. -
Place it. Add the metric key to a layer of a dimension in
src/lib/config/statistics/dimensions.ts, or leave it unplaced on purpose.
2. Add an event
An event is something that happened to the law of a place: a statute, a
referendum, an ordinance. Add it to src/lib/config/statistics/events.ts.
- Read the primary pages first. Official gazettes, parliaments' own records, the roll call. Do not write from memory or from a summary. If a site refuses programs, do not disguise the request; use another official source (the US Senate's vote was taken from GovInfo's bill record for this reason).
- Every line carries evidence: publisher,
url,read(the day you read it) andexpect: the words the page must still hold (a figure, a name, a quoted sentence). A page a program cannot read (a JavaScript app) is markedunchecked: trueand the record also cites a copy a program can read. - What changed: the wording before and after, in its own language, with a
translation, each with its evidence. If you have only one side, say
before: null; do not invent the other. - How it came about: dated steps. Votes: counts or a share; a breakdown by party must add up to the totals (the loader fails otherwise).
- Who stood where:
actorswith a role (initiator, sponsor, responsible, voted for or against, recommended yes or no, supported, opposed, said) and what the source says they did. Name only what a source names: if no sponsor is named, say none is. - Claims are
reported, never facts:kindclaim, critique or context,bywhoever said it, with evidence. An effect is never stated in Solon's voice. series: the statistics to chart around it, by metric key; none where Solon holds no series (the page then says so and shows the claims).caveat: what a reader should keep in mind before reading a cause into a line.- Run
pnpm run statistics:verify; thenpnpm run statistics:sync; open/statistics/event/<slug>.
A large step flagged by statistics:quality in a rate series is a candidate
law-change year: look for the act behind it.
3. Link a series to the law
Add a law_link record to src/lib/config/statistics/records.ts: the metric,
the place, the act (authority, identifier scheme, value), the provision, why
the series is about it, and evidence with the words read. Cite the version of the
text you read; the human page may be unreadable by a program (unchecked).
4. Add or change a dimension or an axis
- A dimension (
src/lib/config/statistics/dimensions.ts) has three layers. A layer with no series must say what would fill it; the loader fails otherwise. A metric sits on one layer of one dimension. - An axis (
src/lib/config/statistics/axes.ts) lists measures, each with a direction (sign) and a weight, adirectionsentence saying what a higher score means (never which end is better) and anauthor. Use only series whose scope is the same in every country shown.
4a. Code a legal feature
A coding reads one feature of a law onto a written scale.
- Write the rubric in
src/lib/config/statistics/rubrics.ts: the question, every point of the scale with a definition, and the edge cases decided so far. Changing a point's meaning means a newversion; old codings keep the version they were made under. - Add the coding to
src/lib/config/statistics/assessments.ts: the place, the rubric and its current version, the value, the provisions (act and article) and the quoted wording with where it was read, aconfidenceand, below high, what isopen. Code only from a text you opened. - Put the rubric on a layer of a dimension (
rubrics: [...]). reviewedBystarts empty. The page says "awaiting a second reader" until a person other thancodedByis named there; the loader refuses the coder as their own reviewer.pnpm run statistics:sync, thenpnpm run statistics:verifyto check the cited words.
5. Add a country
A country is a pack and its sources (see docs/design/2026-09-places-and-jurisdictions.md).
Every country is already a place of the world pack; adding a pack of its own
takes it over. Write the pack (src/lib/config/places/countries/<key>.ts, with
its region) and run pnpm run places:world-countries (verify fails until
you do). The first import of the pack's own register moves the country and the
places it restates into the pack: same rows, so its figures stay, and its old
/places/world/... path redirects. What the world pack held under it that the
pack does not restate ends that day. For the statistics: add its ISO 3166-1 numeric code to
src/lib/config/statistics/world.ts (a test fails if a pack's country is
missing). The World Bank's source already reads every country; add it to
OECD_MEMBERS (src/lib/config/places/world.ts) or EUROSTAT_GOV_COUNTRIES
(src/lib/config/budgets/eurostat.ts) if it is in either, and its figures come
with the next run.
6. What the page checks for you
- Every metric needs a
plausibleband; a figure outside it is left out of every chart. pnpm run statistics:qualityprints the chart warnings (!lines) beside the series notes. A warning on data you know is right means the check is wrong: narrow or remove it insrc/lib/statistics/sanity.tswith a test, never explain it away in a caveat.- The AI explanation reads only what
brief.ts(metric pages) anddimension-brief.ts(dimension pages) list as facts. A new kind of thing a page shows needs a fact kind there, its English line inexplain.tsand its template inStatistics.explain.facts.
Before you open the pull request
pnpm run verify, pnpm run statistics:verify, pnpm run statistics:quality,
and the page opened at 390 px wide in light and dark. Nothing is described as
built until it is.