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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 (
|
||||
<TableRow key={stage.id}>
|
||||
<TableCell>
|
||||
@@ -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 (
|
||||
<Card key={stage.id}>
|
||||
<CardContent className="pt-4 space-y-3">
|
||||
@@ -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`,
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user