From 55e81bfff9151fd23347eb07414483497983062a Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Mon, 2 Nov 2026 15:44:34 +0000 Subject: [PATCH] dashboard: show the co-op's own share in Co-op usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Co-op usage view charted the co-op-wide spend (which spans the co-op's own operator accounts) with nothing saying so. Adds a stats pair — co-op spend all time, and of which the co-op's own accounts — summed from the series' new operator_spend_usd (NULL days skipped, not counted as zero), and labels the spend chart and the model board as including the co-op's own accounts. --- app/main.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index bb98c7c..d69cd55 100644 --- a/app/main.py +++ b/app/main.py @@ -415,6 +415,9 @@ PAGE_HTML = """ .coop-trend-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; } .coop-trend-title { font-weight: 700; font-size: 15px; color: var(--ink, #2d3327); } .coop-trend-controls { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; } + .coop-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin: 2px 0 12px; } + .coop-stats .num { font-size: 20px; font-weight: 700; color: var(--ink, #2d3327); } + .coop-stats .lbl { font-size: 12px; color: var(--muted); } .trend-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; } .coop-trend-body svg { display: block; width: 100%; height: auto; overflow: visible; } .board-row { @@ -600,6 +603,10 @@ PAGE_HTML = """
The co-op over time
+
+
—
co-op spend, all time
+
—
of which the co-op's own accounts
+
Show @@ -618,7 +625,7 @@ PAGE_HTML = """
Loading
-
Usage across the co-op, last 30 days
+
Usage across the co-op, including the co-op's own accounts, last 30 days
Sort by @@ -854,13 +861,13 @@ let trendDays = 90; // 0 = all time const TREND_CONF = { members: { kind: "line", title: "The co-op over time" }, requests: { kind: "bar", title: "Requests the co-op served" }, - spend: { kind: "bar", title: "What the co-op spent" }, + spend: { kind: "bar", title: "What the co-op spent (members + the co-op's own accounts)" }, energy: { kind: "bar", title: "Energy the co-op used" }, co2e: { kind: "bar", title: "Carbon the co-op emitted" } }; async function loadMetrics() { - if (trendsData) { renderTrends(); return; } + if (trendsData) { renderCoopTotals(); renderTrends(); return; } const host = $("trend-body"); try { const r = await fetch("/api/metrics"); @@ -868,12 +875,27 @@ async function loadMetrics() { const d = await r.json(); if (d.error) { host.innerHTML = "
" + d.error + "
"; return; } trendsData = d.series || []; + renderCoopTotals(); renderTrends(); } catch (e) { host.innerHTML = "
Could not load the co-op chart
"; } } +// The co-op total spans the members AND the co-op's own (operator) accounts — +// spend_usd is the whole co-op. operator_spend_usd is the co-op's own share of +// it (NULL where a day was not measured, so it is skipped rather than counted +// as zero). Both summed over the widest range the series carries (all time). +function renderCoopTotals() { + let total = 0, own = 0; + (trendsData || []).forEach(row => { + if (typeof row.spend_usd === "number") total += row.spend_usd; + if (typeof row.operator_spend_usd === "number") own += row.operator_spend_usd; + }); + $("coop-total").textContent = fmtMoney(total); + $("coop-own").textContent = fmtMoney(own); +} + function setTrendMetric(m) { trendMetric = m; $("tm-members").className = "mode-btn" + (m === "members" ? " active" : "");