mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-04 04:47:30 +01:00
* fix(data): correct what the quality checks and a 36-row source sample found - listings: 8 pinned home lines stored a composite FIGI that OpenFIGI cannot resolve (openfigi.com/id 404, ID_BB_GLOBAL mapping empty); pinnedLine now keeps the exchange line's own FIGI (TSMC, UMC, GlobalWafers, ASE, SMIC, Rio Tinto, NKT, TSMC Advanced Packaging) - sanctions: all 49 EU amendment dates were a day early (Brussels-midnight stamps read in UTC); 4 OFAC programmes had empty titles (menu link parsed first) - usgs-producers: wrapped workbook cells were split into bogus facilities (64 fragments -> 5); Chile's copper table had lost Escondida, Spence, Sierra Gorda and 12 more rows behind a 'Continued' commodity cell - events/dependencies: 7 paraphrased quotes replaced with the source's verbatim text; SK Siltron event names its directory company - series: 18 Cameco points get the date their MD&A states - directory: Shin-Etsu Handotai source 404 replaced; Fangyuan careers URL (domain does not resolve) set to null as its evidence already said Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(data): written quality criteria per dataset, automated checks, /data/quality - config/substrata-quality.ts: 15 datasets x 6 criteria (completeness, correctness, provenance, freshness, link health, consistency); each a rule or 'na' with a reason; freshness reuses config/substrata-freshness.ts - lib/quality: pure checks (USGS world sums, quote states the value, names resolve, cross-dataset agreement with USGS) run in verify with a failure-count ratchet (test/quality.test.ts); network checks (links with 3 tries and a blocked/broken distinction, quotes on page, SEC ticker file, OpenFIGI mapping, USGS values on the chapter PDF) run on a rotation via /api/cron/quality - migration 014: research_quality_checks + research_quality_runs (trend) - /data/quality: scores, counts, trend and every failing row with its source and a prefilled correction issue; linked from /data, footer, palette - check-series.ts shares the reader (CDATA and ' ,' fixes found by the sample) - pnpm run quality [-- --network | --all | --json out.json]; no AI anywhere Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
/**
|
|
* The data-quality checks, on demand.
|
|
*
|
|
* pnpm run quality # pure checks only (what `verify` runs), as a table
|
|
* pnpm run quality -- --network # plus one scheduled-size network slice
|
|
* pnpm run quality -- --all # plus EVERY link, quote, ticker and USGS row (~20 min)
|
|
* pnpm run quality -- --all --db # same, written to the database (DATABASE_URL)
|
|
* pnpm run quality -- --json out.json # machine-readable results with failing rows and links
|
|
*
|
|
* Without --db, network verdicts accumulate in /tmp/substrata-quality-checks.json,
|
|
* so a second run continues the rotation. No AI anywhere.
|
|
*/
|
|
import { writeFileSync } from 'node:fs';
|
|
|
|
import { buildCards, assembleResults } from '../../lib/quality/report';
|
|
import { EVERYTHING, SCHEDULED, runQuality } from '../../lib/quality/run';
|
|
import { dbStore, fileStore } from '../../lib/quality/store';
|
|
|
|
const args = process.argv.slice(2);
|
|
const flag = (name: string) => args.includes(name);
|
|
const after = (name: string) => (args.includes(name) ? args[args.indexOf(name) + 1] : undefined);
|
|
|
|
async function main() {
|
|
const store = flag('--db') ? dbStore : fileStore('/tmp/substrata-quality-checks.json');
|
|
let cards;
|
|
if (flag('--all') || flag('--network')) {
|
|
const run = await runQuality(store, flag('--all') ? EVERYTHING : SCHEDULED);
|
|
console.error(
|
|
`looked at ${run.looked}; ${run.failed} failed; ${run.cannotTell} could not tell`,
|
|
);
|
|
for (const e of run.errors) console.error(` error: ${e}`);
|
|
cards = run.cards;
|
|
} else {
|
|
cards = buildCards((await assembleResults(flag('--db') ? await store.load() : null)).results);
|
|
}
|
|
for (const card of cards) {
|
|
const scores = card.scores.map(
|
|
(s) =>
|
|
`${s.criterion.slice(0, 5)} ${s.score === null ? ' — ' : `${s.score.toFixed(1)}%`.padStart(6)}`,
|
|
);
|
|
console.log(
|
|
`${card.dataset.id.padEnd(18)} ${card.overall === null ? '—' : `${card.overall}%`.padStart(6)} ${scores.join(' ')}`,
|
|
);
|
|
for (const r of card.results.filter((x) => x.failures.length))
|
|
console.log(
|
|
` ${r.check}: ${r.failures.length} failing${r.unchecked ? `, ${r.unchecked} unchecked` : ''}`,
|
|
);
|
|
}
|
|
const out = after('--json');
|
|
if (out)
|
|
writeFileSync(
|
|
out,
|
|
JSON.stringify(
|
|
cards.map((c) => ({
|
|
dataset: c.dataset.id,
|
|
overall: c.overall,
|
|
scores: c.scores,
|
|
counts: c.counts,
|
|
results: c.results,
|
|
})),
|
|
null,
|
|
1,
|
|
),
|
|
);
|
|
}
|
|
|
|
void main();
|