From 90294df4c6aa096193abce6d504e71de1779f60a Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Sun, 8 Nov 2026 01:50:26 +0000 Subject: [PATCH] money chart: cumulative OC revenue, token spend, and OC balance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New Money tab beside Trends, fed by the portal's /admin/money-series (hourly-cached server-side). One fetch at full range; period (30/90/all) and spend-mode (cumulative/daily) toggles re-render client-side. - Cumulative mode: three lines — Revenue (OC contributions, green), Token spend (blue), OC balance (amber). NULL balance days render as a gap (the OC API exposes only the CURRENT balance; history accrues from daily snapshots from the deploy date onward — stated in the caption and in the balance legend key). - Daily mode: token spend per day as bars (spend-only; the other series are cumulative and would need a second axis). - Money ticks use the 1/2/5 x 10^k rule; tooltips reuse the shared chart-tip helper (all three series listed per day). - The caption is a deliberate exception to the no-caption chart rule: the operator asked for the honest data-history limits in the UI. - Harness: tests/money-chart-harness.js (axis invariants, gap handling, daily bars, period slice, single-point balance). --- app/main.py | 253 ++++++++++++++++++++++++++++++++++- tests/money-chart-harness.js | 91 +++++++++++++ 2 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 tests/money-chart-harness.js diff --git a/app/main.py b/app/main.py index 4d30fff..36a65c8 100644 --- a/app/main.py +++ b/app/main.py @@ -139,6 +139,22 @@ async def api_metrics(request: Request, days: int = 730): return JSONResponse({"error": e.detail}, status_code=e.status_code) +@app.get("/api/money-series") +async def api_money_series(request: Request): + """Revenue / token spend / OC balance series (portal /admin/money-series). + + The portal owns this data and caches it hourly (the OC queries are slow); + the panel only reads it. The full history comes back in one payload — the + period and spend-mode toggles slice client-side and never refetch. + """ + if not is_admin(request): + return JSONResponse({"error": "forbidden"}, status_code=403) + try: + return await portal_get("/admin/money-series") + except HTTPException as e: + return JSONResponse({"error": e.detail}, status_code=e.status_code) + + @app.post("/api/set-balance") async def api_set_balance(request: Request): if not is_admin(request): @@ -291,6 +307,13 @@ PAGE_HTML = """ .chart-tip .tip-row { display: flex; justify-content: space-between; gap: 14px; } .chart-tip .tip-row span { color: var(--muted); } .chart-tip .tip-row b { color: var(--ink); font-variant-numeric: tabular-nums; } + /* Money chart: legend keys + the honest-data caption. The caption is a + deliberate exception to the no-caption rule for the Trends charts: the + operator asked for the data-history limits to be stated IN this chart. */ + .money-legend { display: inline-flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-weight: 600; } + .money-legend .key { display: inline-flex; align-items: center; gap: 5px; } + .money-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; } + .money-caption { color: var(--muted); font-size: 11px; margin: 8px 0 0; } @media (max-width: 600px) { .trend-controls { gap: 10px; } .trend-card { padding: 12px 10px; } } .num { font-variant-numeric: tabular-nums; } .remaining-col { font-weight: 700; color: var(--green-deep); background: #eaf3ea; } @@ -345,6 +368,7 @@ PAGE_HTML = """ + @@ -401,6 +425,30 @@ PAGE_HTML = """ + +