mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-05 01:38:18 +01:00
- The row's value is "≥100%" when named capacity covers the national figure (capacity can exceed output), the percentage only below it; the exact ratio stays in the opened working and in coverage_of. - Above 3× the national figure, the row names the printed figure that dominates (Canada nickel: Lac des Iles; China cobalt: Jinchuan) as a source-table question. No figure is altered or excluded. - A "Locations:" cell is a collapsed "Locations (N)" list, one place per line; operators are a separate short line. Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE Co-authored-by: Claude <noreply@anthropic.com>
171 lines
6.5 KiB
TypeScript
171 lines
6.5 KiB
TypeScript
import { coverageOf, RATIO_CAVEAT, RATIO_LABEL, type Coverage } from '../../coverage/ratio';
|
|
import { dominantRow, exactRatio, headline, splitLocations } from '../../coverage/display';
|
|
import type { RowWorking } from '../../coverage/rows';
|
|
import { codeHref } from '../../methods';
|
|
import { formatValue } from '../../resources/format';
|
|
import { UNIT_LABEL } from '../../resources/usgs';
|
|
import { t } from '../../i18n/messages';
|
|
import type { ProfileModule } from '../types';
|
|
|
|
// The mass balance (lib/coverage): for each resource, how much of the national
|
|
// figure the facilities with a named operator account for, with the working
|
|
// one tap away — or exactly why it cannot be computed. Stated rows only.
|
|
|
|
// A paragraph of the working: plain flowing text (measure-lines is a grid, which
|
|
// split a sentence and its link onto separate lines).
|
|
const PARA = 'coverage-working';
|
|
const unitOf = (unit: string) => UNIT_LABEL[unit] ?? unit;
|
|
const amount = (value: number, unit: string) => `${formatValue(value)} ${unitOf(unit)}`;
|
|
|
|
function RowLine({ row }: { row: RowWorking }) {
|
|
const printed = row.printed.trim() ? `${row.printed.trim()} ${row.unit}` : 'no capacity printed';
|
|
const places = splitLocations(row.location);
|
|
const counted =
|
|
row.compared !== true
|
|
? `not compared: ${row.compared}`
|
|
: row.figure && 'reason' in row.figure
|
|
? `not added: ${row.figure.reason}`
|
|
: row.operators.length
|
|
? 'counted as named'
|
|
: 'listed, not named';
|
|
return (
|
|
<li>
|
|
<p>
|
|
<span className="text-fg-primary">
|
|
{places.length > 1
|
|
? `${places.length} places, one capacity printed for all`
|
|
: places[0] || 'no place printed'}
|
|
</span>{' '}
|
|
— {row.commodity}; {printed}. <span className="text-fg-tertiary">{counted}.</span>
|
|
</p>
|
|
<p className="coverage-operators">
|
|
{row.operators.length
|
|
? `Operator${row.operators.length === 1 ? '' : `s (${row.operators.length})`}: ${row.operators.map((o) => o.name).join(' · ')}`
|
|
: 'No stated operator'}
|
|
</p>
|
|
{places.length > 1 && (
|
|
<details className="coverage-places">
|
|
<summary>Locations ({places.length})</summary>
|
|
<ul>
|
|
{places.map((place, i) => (
|
|
<li key={i}>{place}</li>
|
|
))}
|
|
</ul>
|
|
</details>
|
|
)}
|
|
</li>
|
|
);
|
|
}
|
|
|
|
function Working({ c }: { c: Coverage }) {
|
|
const a = c.attribution;
|
|
return (
|
|
<div className="measure-groups">
|
|
{c.status === 'computed' ? (
|
|
<>
|
|
<p className={PARA}>
|
|
{amount(c.named.capacity, c.unit)} named ÷ {amount(c.national.value, c.unit)} national ={' '}
|
|
{exactRatio(c.ratio)} (exact). All rows of this basis, named or not:{' '}
|
|
{amount(c.listed.capacity, c.unit)} ({c.listed.rows} row{c.listed.rows === 1 ? '' : 's'}
|
|
).
|
|
{c.yearGap > 0 &&
|
|
` The facility table is for ${c.table?.year} and the national figure for ${c.national.year}: ${c.yearGap} year${c.yearGap === 1 ? '' : 's'} apart.`}
|
|
</p>
|
|
{dominantRow(c) && (
|
|
<p className="coverage-working coverage-flag">{dominantRow(c)!.note}</p>
|
|
)}
|
|
</>
|
|
) : null}
|
|
{c.national && (
|
|
<p className={PARA}>
|
|
National figure:{' '}
|
|
<a href={c.national.url} rel="noopener noreferrer" target="_blank">
|
|
{c.national.source}, {c.national.table} ↗
|
|
</a>{' '}
|
|
— {c.national.series}, {c.national.year}: “{c.national.printed}” ({c.national.unitQuote}
|
|
{c.national.estimated ? ', estimated' : ''}).
|
|
</p>
|
|
)}
|
|
{c.table && (
|
|
<p className={PARA}>
|
|
Facilities:{' '}
|
|
<a href={c.table.url} rel="noopener noreferrer" target="_blank">
|
|
USGS Minerals Yearbook {c.table.year}, {c.table.table} ↗
|
|
</a>
|
|
. {a.rowsWithOperator.count} of {a.rowsWithOperator.of} rows name an operator;{' '}
|
|
{a.operatorsWithOwner.count} of {a.operatorsWithOwner.of} named operators have a stated
|
|
owner. Flows: {a.flows.status === 'cannot' ? a.flows.reason : 'computed'}.
|
|
</p>
|
|
)}
|
|
{c.rows.length > 0 && (
|
|
<ul className="coverage-rows">
|
|
{c.rows.map((row, i) => (
|
|
<RowLine key={`${row.location}-${i}`} row={row} />
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const coverage: ProfileModule<Coverage[]> = {
|
|
id: 'coverage',
|
|
title: t('profile.coverage.title'),
|
|
appliesTo: ['country'],
|
|
importance: 87,
|
|
load(entity) {
|
|
const rows = coverageOf(entity.id.slice(entity.id.indexOf(':') + 1));
|
|
return rows.length ? rows : null;
|
|
},
|
|
evidence: (rows) => {
|
|
const done = rows.filter((c) => c.status === 'computed').length;
|
|
return `${done} of ${rows.length} computed · ${RATIO_LABEL}, stated rows only`;
|
|
},
|
|
Render({ data }) {
|
|
return (
|
|
<>
|
|
<p className="resource-line">
|
|
For each resource: the capacity of facilities with a named operator, over the national
|
|
production figure. Open a row for the working. {RATIO_CAVEAT}
|
|
</p>
|
|
<ul className="measure-countries">
|
|
{data.map((c) => (
|
|
<li key={c.resource}>
|
|
<details className="measure-country">
|
|
<summary>
|
|
<span className="measure-country-name">
|
|
{c.label}
|
|
<span className="coverage-line">
|
|
{c.status === 'computed'
|
|
? `${headline(c.ratio).note ?? RATIO_LABEL} · ${c.basis}`
|
|
: `Cannot be computed: ${c.reason}`}
|
|
</span>
|
|
{dominantRow(c) && (
|
|
<span className="coverage-line coverage-flag">
|
|
Check the row: one printed figure dominates —{' '}
|
|
{splitLocations(dominantRow(c)!.row.location)[0]}
|
|
</span>
|
|
)}
|
|
</span>
|
|
<span className="measure-country-meta">
|
|
{c.status === 'computed' ? headline(c.ratio).value : 'n/a'}
|
|
</span>
|
|
</summary>
|
|
<Working c={c} />
|
|
</details>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p className="resource-source">
|
|
Derived and lead relations are never counted here.{' '}
|
|
<a href={codeHref('lib/coverage/README.md')} rel="noopener noreferrer">
|
|
How the ratio is computed
|
|
</a>
|
|
</p>
|
|
</>
|
|
);
|
|
},
|
|
};
|
|
|
|
export { coverage };
|