money series: /admin/money-series (revenue/spend/OC balance) + daily OC balance snapshot

- /admin/money-series (X-Admin-Token, 30/min): three series for the admin
  panel's Money chart, hourly in-memory cache with stale-on-error fallback.
  revenue = OC contribution transactions (CREDIT/CONTRIBUTION/non-refund,
  monthly + one-time, org-backed included), cumulative from 2026-09-06;
  spend = one GROUP BY day pass over the full LiteLLM SpendLogs (no team
  filter, same definition as metrics_snapshot.spend_by_day); balance = OC
  current balance + daily snapshots.
- OC exposes only the CURRENT balance — no historical series exists — so
  metrics_snapshot.py now writes oc_balance_usd into metrics_daily daily
  (from 2026-11-08 onward; balance history cannot be backfilled). The
  endpoint seeds an existing row's balance with the live value without
  touching the snapshot's other columns.
- Aggregate totals only: no member emails or names selected or returned.
This commit is contained in:
inference-bot committed 2026-11-08 01:50:17 +00:00
1 parent 3cc2fad1dd
commit dcce9fcb35
3 files changed
+417 -6

No files matched your search

+7 -3
View File
@@ -125,13 +125,17 @@ Three jobs run inside the container via `CloudronManifest.json` → `addons.sche
State persists in `/app/data/rag_refresh_state.json`.
- **metrics_snapshot** (daily 3:15am UTC) — `metrics_snapshot.py` records one row per
day into the `metrics_daily` table: members, newsletter subscribers, Matrix
membership, spend, request counts, and energy/CO₂. A source that cannot be read
membership, spend, request counts, energy/CO₂, and the Open Collective
balance. A source that cannot be read
yields NULL for that metric rather than a zero. `spend_usd` is the co-op-wide
total and deliberately spans every team, the co-op's own operator accounts
included; `operator_spend_usd` is the breakout of that portion, served through
`/broker/metrics` so the member dashboard can show the co-op's own share
alongside the total. `--backfill` rebuilds history idempotently. Methodology:
[Energy and carbon metrics](docs/energy-metrics.md).
alongside the total. `oc_balance_usd` is a daily snapshot of the collective's
OC balance (the OC API has no historical series, so balance history accrues
from these snapshots only — 2026-11-08 onward). `--backfill` rebuilds history
idempotently (balance history cannot be backfilled: past balances were never
recorded). Methodology: [Energy and carbon metrics](docs/energy-metrics.md).
Verify after any manifest change: the deploy log must show
`setupAddons: ... scheduler ...` listing all three tasks, and each script must