diff --git a/apps/api/src/stats.ts b/apps/api/src/stats.ts index 7a44e76..6be0400 100644 --- a/apps/api/src/stats.ts +++ b/apps/api/src/stats.ts @@ -10,6 +10,7 @@ import { addDays, campaignDay, campaignWeek, + isoWeek, streak, } from "./srs.ts"; @@ -61,9 +62,14 @@ export async function buildStats(db: D1Database, today: string): Promise const ladder: Record = { new: 0, "+2": 0, "+5": 0, "+10": 0, retired: 0 }; for (const row of ladderRows) ladder[row.stage] = row.n; - const { results: gates } = await db + // gates rows are keyed by ISO week (that's the digest/gate contract), but + // the page speaks campaign weeks. The campaign never crosses a year + // boundary, so a plain offset converts safely. + const isoWeekOffset = isoWeek(CAMPAIGN_START) - 1; + const { results: gateRows } = await db .prepare("SELECT week, issue, pass_rate, closed_on FROM gates ORDER BY week") .all<{ week: number; issue: number | null; pass_rate: number | null; closed_on: string | null }>(); + const gates = gateRows.map((g) => ({ ...g, week: g.week - isoWeekOffset })); // Review-queue depth for the next 14 days: everything due by that day. const queue: { date: string; due: number }[] = [];