Files
CatoandClaude Opus 5 9f9464ca63 feat(data): numbers with a year and a source, and the difference between a law and a schedule (#65)
The corpus could say a material was concentrated and could not say how
concentrated. Severity was a 0-12 judgement and everything around it was prose,
so the first question anyone asks — how much, where, how much is left — had no
answer on the page.

Helium and gallium now have real figures, from USGS Mineral Commodity Summaries
2025, a public-domain source, read and quoted rather than summarised. Helium:
United States 68 million m3 and 37.8% of world output, Qatar 64, Russia 17,
Algeria 11, against a published world total of 180. Gallium: China 750,000 kg of
760,000, which is 98.7%.

Every figure carries the year it is FOR, the basis it was arrived at, and its
source. A number without a year is a lie with a decimal point, and an estimate
rendered as a measurement is the failure this project exists to avoid, so
`basis` is on every row and is shown on the page.

Nothing derived is stored. Share, Herfindahl concentration and
reserves-to-production are functions of the rows, so they cannot drift from the
figures they claim to summarise — the mistake this codebase has already made
twice, with entity ids and with relation labels. Concentration is worth the
trouble: gallium comes out at 0.97 and helium at 0.28, which is the arithmetic
companion to "how few suppliers qualify" and can be argued with.

Absences are kept as absences. USGS does not publish gallium reserves, because
it is a byproduct of bauxite and zinc processing, so the field is missing and
says why — a zero would assert something false. Qatar's helium reserves are
recorded by USGS as "Large" rather than a number, and the page says that.

And substitution stops being a 0-3 score. An alternative existing is not the
same as it being available, and the reasons differ in kind: helium below 4 K is
blocked by PHYSICS — USGS states plainly that nothing substitutes for it — while
gallium outside China is blocked by capacity and price, which is a schedule.
Germany, Hungary and Kazakhstan all produced gallium and stopped, in 2016, 2015
and 2013; the plants were not destroyed by physics but closed on price. Today
both of those read as a 3.

The new gate found the directory fault in miniature: Algeria was missing from
the country directory entirely while holding the second-largest recorded helium
reserve and producing 11 million m3 a year. Timor-Leste's oil was in it. Algeria
is in now, and Qatar is finally linked to the helium it supplies a third of.


Claude-Session: https://claude.ai/code/session_01Y6ecRd91ZsPPcjuNkKTFV2

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 09:39:08 -07:00

102 lines
3.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Everything the figures imply, computed rather than stored.
*
* Share, concentration and reserves-to-production are all functions of the rows
* in `config/substrata-quantities.ts`. Storing them would create a second copy
* of the same fact, free to drift from the first — which is the failure this
* codebase has already had twice, with entity ids and with relation labels.
*
* Each read says what it is made of, because a derived number that cannot be
* traced back to its inputs is indistinguishable from an assertion.
*/
import {
ENDOWMENTS,
WORLD_TOTALS,
type Endowment,
type Quantity,
type Unit,
} from '@/config/substrata-quantities';
export interface PlaceShare {
place: string;
production: Quantity;
/** Fraction of the published world total, 0–1. Undefined when no total exists. */
share?: number;
}
export function endowmentsFor(material: string): Endowment[] {
return ENDOWMENTS.filter((row) => row.material === material).sort(
(a, b) => (b.production?.value ?? 0) - (a.production?.value ?? 0),
);
}
export function worldTotalFor(material: string) {
return WORLD_TOTALS.find((row) => row.material === material);
}
/** Producers of a material, largest first, with each one's share of the world total. */
export function sharesFor(material: string): PlaceShare[] {
const total = worldTotalFor(material);
return endowmentsFor(material)
.filter((row): row is Endowment & { production: Quantity } => Boolean(row.production))
.map((row) => ({
place: row.place,
production: row.production,
share:
total && total.total.unit === row.production.unit && total.total.value > 0
? row.production.value / total.total.value
: undefined,
}));
}
/**
* Concentration, on the Herfindahl index the competition authorities use.
*
* The corpus already judges "how few suppliers qualify" on a 0–3 scale. This is
* the arithmetic companion to that judgement: computed from published shares
* rather than asserted, so the two can be compared and the judgement argued
* with. 1.0 is a single supplier; 0.1 is a fragmented market.
*
* Returns undefined rather than a number when shares are unknown — an index
* computed over partial data reads as precision that is not there.
*/
export function concentrationOf(material: string): { hhi: number; from: number } | undefined {
const shares = sharesFor(material).filter((row) => row.share !== undefined);
if (shares.length === 0) return undefined;
const hhi = shares.reduce((sum, row) => sum + (row.share ?? 0) ** 2, 0);
return { hhi, from: shares.length };
}
/**
* How long the current rate can continue, in years.
*
* Reserves divided by annual production. A blunt measure — reserves are
* re-estimated as prices and technology move, so this is "at today's rate with
* today's reserves", not a countdown.
*/
export function reservesToProduction(
material: string,
place: string,
): { years: number; reserves: Quantity; production: Quantity } | undefined {
const row = endowmentsFor(material).find((entry) => entry.place === place);
if (!row?.reserves || !row.production || row.reserves.unit !== row.production.unit)
return undefined;
if (row.production.value <= 0) return undefined;
return {
years: row.reserves.value / row.production.value,
reserves: row.reserves,
production: row.production,
};
}
/** Whether a material has any figures at all, so a module can decline to render. */
export function hasQuantities(material: string): boolean {
return ENDOWMENTS.some((row) => row.material === material);
}
export function formatQuantity(quantity: Quantity, unitLabel: Record<Unit, string>): string {
const value =
quantity.value >= 10_000 ? quantity.value.toLocaleString('en') : String(quantity.value);
return `${value} ${unitLabel[quantity.unit]}`;
}