diff --git a/dashboard/e2e/analytics.spec.ts b/dashboard/e2e/analytics.spec.ts index 274a8fe4..492595e4 100644 --- a/dashboard/e2e/analytics.spec.ts +++ b/dashboard/e2e/analytics.spec.ts @@ -127,7 +127,8 @@ test("the scorecard answers whether it is worth it, against the previous period" await expect(page.getByTestId("tile-merge-rate")).toContainText("▲ 10 pts"); await expect(page.getByTestId("tile-time-to-merge")).toContainText("5.2 h"); await expect(page.getByTestId("tile-time-to-merge")).toContainText("From 12 merged PRs"); - await expect(page.getByTestId("tile-cost-per-pr")).toContainText("$4.59"); + await expect(page.getByTestId("tile-tokens-per-pr")).toContainText("tokens across"); + await expect(page.getByText("$")).toHaveCount(0); await expect(page.getByTestId("tile-untouched")).toContainText("75%"); await expect(page.getByTestId("tile-ci")).toContainText("6 of 8 runs went green"); await expect(page.getByTestId("tile-findings")).toContainText("24 fixed in code, 8 settled by a person"); diff --git a/dashboard/src/app/analytics/page.tsx b/dashboard/src/app/analytics/page.tsx index b61c8b1d..0da06d57 100644 --- a/dashboard/src/app/analytics/page.tsx +++ b/dashboard/src/app/analytics/page.tsx @@ -23,8 +23,6 @@ const MINUTES_KEY = "coderhelm.analytics.minutesPerPr"; // ── Formatting ───────────────────────────────────────────────────────────── const pct = (v: number | null | undefined) => (v == null ? "—" : `${Math.round(v * 100)}%`); -const money = (v: number | null | undefined) => - v == null ? "—" : v >= 100 ? `$${Math.round(v).toLocaleString()}` : `$${v.toFixed(2)}`; const count = (v: number) => v.toLocaleString(); function hours(v: number | null | undefined) { if (v == null) return "—"; @@ -39,9 +37,13 @@ function tokens(v: number) { return String(Math.round(v)); } const plural = (n: number, one: string, many = `${one}s`) => `${count(n)} ${n === 1 ? one : many}`; +/** Tokens in and out, the measure of what Coderhelm used. */ +const totalTokens = (s: { tokens?: number; tokens_in: number; tokens_out: number }) => s.tokens ?? s.tokens_in + s.tokens_out; +const perPr = (s: { tokens?: number; tokens_in: number; tokens_out: number; prs_merged: number; tokens_per_merged_pr?: number | null }) => + s.tokens_per_merged_pr ?? (s.prs_merged ? Math.round(totalTokens(s) / s.prs_merged) : null); /** "+12% vs previous 30 days", or points for rates. Neutral ink: the reader judges. */ -function delta(cur: number | null, prev: number | null, kind: "count" | "rate" | "money" | "hours", days: number): string { +function delta(cur: number | null, prev: number | null, kind: "count" | "rate" | "hours", days: number): string { const vs = `vs previous ${days} days`; if (cur == null || prev == null) return `— ${vs}`; if (kind === "rate") { @@ -190,7 +192,7 @@ export default function AnalyticsPage() {
- What Coderhelm delivered, what it cost, and where it struggles. Every number comes from your runs, reviews and lookups; open any row to see the work behind it. + What Coderhelm delivered, the tokens it used, and where it struggles. Every number comes from your runs, reviews and lookups; open any row to see the work behind it.