stats: new public stats schema (source/series/obs/region/fetch_run + raw CBS, Eurostat, FRED, BIS tables) and the stats collector (scripts/stats-fetch.ts); preflight checks the stats tables
Some checks failed
Deploy production / deploy (push) Failing after 54s

This commit is contained in:
2026-10-25 20:27:04 +00:00
parent 902b1cadd5
commit 8ef291f586
14 changed files with 33128 additions and 2 deletions

44
scripts/stats-fetch.ts Normal file
View File

@@ -0,0 +1,44 @@
// /stats collector. Pulls open statistics into the `stats` schema; every job is logged in
// stats.fetch_run. Run on the host by systemd user timers (deploy/stats-collector), with DB_URL
// read from the app container (app role personal_app).
//
// bun scripts/stats-fetch.ts cbs [--force] [--only=86141NED,85592NED]
// bun scripts/stats-fetch.ts eurostat [--only=nrg_pc_204]
// bun scripts/stats-fetch.ts fred [--only=DCOILBRENTEU]
// bun scripts/stats-fetch.ts bis
// bun scripts/stats-fetch.ts normalise-cbs rebuild CBS chart series from the raw rows
import { ensureMeta, sql } from './stats/common';
import { cbs, normaliseCbs } from './stats/cbs';
import { eurostat } from './stats/eurostat';
import { fred } from './stats/fred';
import { bis } from './stats/bis';
const [source, ...args] = process.argv.slice(2);
const flag = (name: string) => args.includes(`--${name}`);
const value = (name: string) => args.find((a) => a.startsWith(`--${name}=`))?.split('=')[1];
const job = flag('backfill') ? 'backfill' : value('only') ? `only:${value('only')}` : 'refresh';
try {
await ensureMeta();
switch (source) {
case 'cbs':
await cbs({ force: flag('force') || flag('backfill'), only: value('only'), job });
break;
case 'normalise-cbs':
console.log(`${await normaliseCbs()} CBS observations normalised`);
break;
case 'eurostat':
await eurostat({ only: value('only'), job });
break;
case 'fred':
await fred({ only: value('only'), job });
break;
case 'bis':
await bis({ job });
break;
default:
throw new Error(`Unknown source "${source}" (cbs, eurostat, fred, bis, normalise-cbs)`);
}
} finally {
await sql.end({ timeout: 5 });
}