diff --git a/static/adwright.js b/static/adwright.js index c0fb1c3..b00659a 100644 --- a/static/adwright.js +++ b/static/adwright.js @@ -320,11 +320,20 @@ ).join("") + ''; } + // Backend proto field for cycle budget is `budget_total` (decimal string, + // e.g. "200.00"). Spend lives in cycle_metric (fetched via GetCycleMetrics + // — not in ListCycles), so it stays 0 until that wire lands. + function _cycleBudget(x) { + return parseFloat(x.budget_total || x.budget || 0) || 0; + } + function _cycleSpend(x) { + return parseFloat(x.spend || 0) || 0; + } function _deriveKpis(cycles, recipes) { const c = cycles || []; const r = recipes || []; - const spend = c.reduce((s, x) => s + (x.spend || 0), 0); - const budget = c.reduce((s, x) => s + (x.budget || 0), 0) || 6000; + const spend = c.reduce((s, x) => s + _cycleSpend(x), 0); + const budget = c.reduce((s, x) => s + _cycleBudget(x), 0) || 6000; const impressions = c.reduce((s, x) => s + (x.impressions || 0), 0); const ctrs = c.map((x) => x.ctr || 0).filter((v) => v > 0); const ctr = ctrs.length ? (ctrs.reduce((s, x) => s + x, 0) / ctrs.length) : 0; @@ -374,7 +383,7 @@ '