fix(api): adjust gate week handling to use campaign weeks

This commit is contained in:
Prad Nukala
2026-08-27 11:05:03 -04:00
parent 6ebca68ff8
commit 72a8399e6d
+7 -1
View File
@@ -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<object>
const ladder: Record<string, number> = { 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 }[] = [];