From 6d4ee93ab3f79923a216d8f31b72a5c3b4c90264 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 21 Feb 2026 01:34:42 +0100 Subject: [PATCH] Fix round completion rate: use evaluations/assignments, closed rounds=100% The round breakdown was showing 200% for active rounds (assignments/projects) and 0% for closed rounds. Now correctly computes evaluations/assignments for active rounds and shows 100% for closed/archived rounds. Co-Authored-By: Claude Opus 4.6 --- src/app/(observer)/observer/reports/page.tsx | 20 ++++++++++++++++---- src/server/routers/program.ts | 7 +++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/app/(observer)/observer/reports/page.tsx b/src/app/(observer)/observer/reports/page.tsx index a7a8aae..05fc125 100644 --- a/src/app/(observer)/observer/reports/page.tsx +++ b/src/app/(observer)/observer/reports/page.tsx @@ -72,7 +72,7 @@ type Stage = { status: string roundType: string windowCloseAt: Date | null - _count: { projects: number; assignments: number } + _count: { projects: number; assignments: number; evaluations: number } programId: string programName: string } @@ -288,7 +288,13 @@ function ProgressTab({ selectedValue, stages, stagesLoading, selectedRound }: { {stages.map((stage) => { const projects = stage._count.projects const assignments = stage._count.assignments - const rate = assignments > 0 && projects > 0 ? Math.round((assignments / projects) * 100) : 0 + const evaluations = stage._count.evaluations + const isClosed = stage.status === 'ROUND_CLOSED' || stage.status === 'ROUND_ARCHIVED' + const rate = isClosed + ? 100 + : assignments > 0 + ? Math.min(100, Math.round((evaluations / assignments) * 100)) + : 0 return ( @@ -335,7 +341,13 @@ function ProgressTab({ selectedValue, stages, stagesLoading, selectedRound }: { {stages.map((stage) => { const projects = stage._count.projects const assignments = stage._count.assignments - const rate = assignments > 0 && projects > 0 ? Math.round((assignments / projects) * 100) : 0 + const evaluations = stage._count.evaluations + const isClosed = stage.status === 'ROUND_CLOSED' || stage.status === 'ROUND_ARCHIVED' + const rate = isClosed + ? 100 + : assignments > 0 + ? Math.min(100, Math.round((evaluations / assignments) * 100)) + : 0 return ( @@ -770,7 +782,7 @@ function ReportsPageContent() { const { data: programs, isLoading: stagesLoading } = trpc.program.list.useQuery({ includeStages: true }) const stages: Stage[] = programs?.flatMap(p => - ((p.stages || []) as { id: string; name: string; status: string; roundType: string; windowCloseAt: Date | null; _count: { projects: number; assignments: number } }[]).map(s => ({ + ((p.stages || []) as { id: string; name: string; status: string; roundType: string; windowCloseAt: Date | null; _count: { projects: number; assignments: number; evaluations: number } }[]).map(s => ({ ...s, programId: p.id, programName: `${p.year} Edition`, diff --git a/src/server/routers/program.ts b/src/server/routers/program.ts index 267e810..61a786c 100644 --- a/src/server/routers/program.ts +++ b/src/server/routers/program.ts @@ -34,6 +34,10 @@ export const programRouter = router({ _count: { select: { assignments: true, projectRoundStates: true }, }, + assignments: { + where: { evaluation: { status: 'SUBMITTED' } }, + select: { id: true }, + }, }, }, }, @@ -52,9 +56,11 @@ export const programRouter = router({ // Provide `stages` as alias for backward compatibility stages: allRounds.map((round: any) => ({ ...round, + assignments: undefined, // don't leak raw assignments array _count: { projects: round._count?.projectRoundStates || 0, assignments: round._count?.assignments || 0, + evaluations: round.assignments?.length || 0, }, })), // Main rounds array @@ -68,6 +74,7 @@ export const programRouter = router({ _count: { projects: round._count?.projectRoundStates || 0, assignments: round._count?.assignments || 0, + evaluations: round.assignments?.length || 0, }, })), }