feat: admin evaluation editing, ranking improvements, status transition fix
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m26s
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m26s
- Add adminEditEvaluation mutation and getJurorEvaluations query - Create shared EvaluationEditSheet component with inline feedback editing - Add Evaluations tab to member detail page (grouped by round) - Make jury group member names clickable (link to member detail) - Replace inline EvaluationDetailSheet on project page with shared component - Fix project status transition validation (skip when status unchanged) - Fix frontend to not send status when unchanged on project edit - Ranking dashboard improvements and boolean decision converter fixes - Backfill script updates for binary decisions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,9 +8,11 @@
|
|||||||
* 1. Finds all rounds with a boolean criterion labeled "Move to the Next Stage?"
|
* 1. Finds all rounds with a boolean criterion labeled "Move to the Next Stage?"
|
||||||
* 2. For evaluations in those rounds where binaryDecision IS NULL,
|
* 2. For evaluations in those rounds where binaryDecision IS NULL,
|
||||||
* copies the boolean value from criterionScoresJson into binaryDecision
|
* copies the boolean value from criterionScoresJson into binaryDecision
|
||||||
|
*
|
||||||
|
* Safe to re-run: only updates evaluations where binaryDecision is still null.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { PrismaClient } from '@prisma/client'
|
import { PrismaClient, Prisma } from '@prisma/client'
|
||||||
|
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ async function main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let totalUpdated = 0
|
let totalUpdated = 0
|
||||||
|
let totalSkipped = 0
|
||||||
|
|
||||||
for (const round of rounds) {
|
for (const round of rounds) {
|
||||||
const config = round.configJson as Record<string, unknown> | null
|
const config = round.configJson as Record<string, unknown> | null
|
||||||
@@ -47,36 +50,55 @@ async function main() {
|
|||||||
console.log(`Round "${round.name}" (${round.id}): found criterion "${boolCriterion.label}" (${boolCriterion.id})`)
|
console.log(`Round "${round.name}" (${round.id}): found criterion "${boolCriterion.label}" (${boolCriterion.id})`)
|
||||||
|
|
||||||
// Find evaluations in this round where binaryDecision is null
|
// Find evaluations in this round where binaryDecision is null
|
||||||
|
// Use Prisma.JsonNull for proper null filtering
|
||||||
const evaluations = await prisma.evaluation.findMany({
|
const evaluations = await prisma.evaluation.findMany({
|
||||||
where: {
|
where: {
|
||||||
assignment: { roundId: round.id },
|
assignment: { roundId: round.id },
|
||||||
binaryDecision: null,
|
binaryDecision: null,
|
||||||
status: 'SUBMITTED',
|
status: 'SUBMITTED',
|
||||||
criterionScoresJson: { not: undefined },
|
|
||||||
},
|
},
|
||||||
select: { id: true, criterionScoresJson: true },
|
select: { id: true, criterionScoresJson: true },
|
||||||
})
|
})
|
||||||
|
|
||||||
let updated = 0
|
let updated = 0
|
||||||
|
let skipped = 0
|
||||||
for (const ev of evaluations) {
|
for (const ev of evaluations) {
|
||||||
const scores = ev.criterionScoresJson as Record<string, unknown> | null
|
const scores = ev.criterionScoresJson as Record<string, unknown> | null
|
||||||
if (!scores) continue
|
if (!scores) {
|
||||||
|
skipped++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const value = scores[boolCriterion.id]
|
const value = scores[boolCriterion.id]
|
||||||
if (typeof value !== 'boolean') continue
|
let resolved: boolean | null = null
|
||||||
|
|
||||||
|
if (typeof value === 'boolean') {
|
||||||
|
resolved = value
|
||||||
|
} else if (value === 'true' || value === 1) {
|
||||||
|
resolved = true
|
||||||
|
} else if (value === 'false' || value === 0) {
|
||||||
|
resolved = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resolved === null) {
|
||||||
|
console.log(` Skipping eval ${ev.id}: criterion value is ${JSON.stringify(value)}`)
|
||||||
|
skipped++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
await prisma.evaluation.update({
|
await prisma.evaluation.update({
|
||||||
where: { id: ev.id },
|
where: { id: ev.id },
|
||||||
data: { binaryDecision: value },
|
data: { binaryDecision: resolved },
|
||||||
})
|
})
|
||||||
updated++
|
updated++
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(` Updated ${updated}/${evaluations.length} evaluations`)
|
console.log(` Updated ${updated}/${evaluations.length} evaluations (skipped ${skipped})`)
|
||||||
totalUpdated += updated
|
totalUpdated += updated
|
||||||
|
totalSkipped += skipped
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\nDone. Total evaluations updated: ${totalUpdated}`)
|
console.log(`\nDone. Total updated: ${totalUpdated}, Total skipped: ${totalSkipped}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -289,7 +289,9 @@ export default function JuryGroupDetailPage({ params }: JuryGroupDetailPageProps
|
|||||||
{group.members.map((member) => (
|
{group.members.map((member) => (
|
||||||
<TableRow key={member.id}>
|
<TableRow key={member.id}>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{member.user.name || 'Unnamed'}
|
<Link href={`/admin/members/${member.user.id}` as Route} className="hover:underline text-primary">
|
||||||
|
{member.user.name || 'Unnamed'}
|
||||||
|
</Link>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-sm text-muted-foreground">
|
<TableCell className="text-sm text-muted-foreground">
|
||||||
{member.user.email}
|
{member.user.email}
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ import {
|
|||||||
TableRow,
|
TableRow,
|
||||||
} from '@/components/ui/table'
|
} from '@/components/ui/table'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||||
import { TagInput } from '@/components/shared/tag-input'
|
import { TagInput } from '@/components/shared/tag-input'
|
||||||
import { UserActivityLog } from '@/components/shared/user-activity-log'
|
import { UserActivityLog } from '@/components/shared/user-activity-log'
|
||||||
|
import { EvaluationEditSheet } from '@/components/admin/evaluation-edit-sheet'
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -53,6 +55,10 @@ import {
|
|||||||
Shield,
|
Shield,
|
||||||
Loader2,
|
Loader2,
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
|
ClipboardList,
|
||||||
|
Eye,
|
||||||
|
ThumbsUp,
|
||||||
|
ThumbsDown,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
|
||||||
export default function MemberDetailPage() {
|
export default function MemberDetailPage() {
|
||||||
@@ -73,6 +79,16 @@ export default function MemberDetailPage() {
|
|||||||
{ enabled: user?.role === 'MENTOR' }
|
{ enabled: user?.role === 'MENTOR' }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Juror evaluations (only fetched for jury members)
|
||||||
|
const isJuror = user?.role === 'JURY_MEMBER' || user?.roles?.includes('JURY_MEMBER')
|
||||||
|
const { data: jurorEvaluations } = trpc.evaluation.getJurorEvaluations.useQuery(
|
||||||
|
{ userId },
|
||||||
|
{ enabled: !!user && !!isJuror }
|
||||||
|
)
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const [selectedEvaluation, setSelectedEvaluation] = useState<any>(null)
|
||||||
|
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState('')
|
||||||
const [email, setEmail] = useState('')
|
const [email, setEmail] = useState('')
|
||||||
const [role, setRole] = useState<string>('JURY_MEMBER')
|
const [role, setRole] = useState<string>('JURY_MEMBER')
|
||||||
@@ -207,6 +223,26 @@ export default function MemberDetailPage() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Tabs defaultValue="profile" className="space-y-6">
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="profile">
|
||||||
|
<User className="h-4 w-4 mr-1" />
|
||||||
|
Profile
|
||||||
|
</TabsTrigger>
|
||||||
|
{isJuror && (
|
||||||
|
<TabsTrigger value="evaluations">
|
||||||
|
<ClipboardList className="h-4 w-4 mr-1" />
|
||||||
|
Evaluations
|
||||||
|
{jurorEvaluations && jurorEvaluations.length > 0 && (
|
||||||
|
<Badge variant="secondary" className="ml-1.5 text-xs px-1.5 py-0">
|
||||||
|
{jurorEvaluations.length}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</TabsTrigger>
|
||||||
|
)}
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent value="profile" className="space-y-6">
|
||||||
<div className="grid gap-6 md:grid-cols-2">
|
<div className="grid gap-6 md:grid-cols-2">
|
||||||
{/* Basic Info */}
|
{/* Basic Info */}
|
||||||
<Card>
|
<Card>
|
||||||
@@ -430,6 +466,121 @@ export default function MemberDetailPage() {
|
|||||||
Save Changes
|
Save Changes
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
{/* Evaluations Tab */}
|
||||||
|
{isJuror && (
|
||||||
|
<TabsContent value="evaluations" className="space-y-4">
|
||||||
|
{!jurorEvaluations || jurorEvaluations.length === 0 ? (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
||||||
|
<ClipboardList className="h-12 w-12 text-muted-foreground/30" />
|
||||||
|
<p className="mt-2 text-muted-foreground">No evaluations submitted yet</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
) : (
|
||||||
|
(() => {
|
||||||
|
// Group evaluations by round
|
||||||
|
const byRound = new Map<string, typeof jurorEvaluations>()
|
||||||
|
for (const ev of jurorEvaluations) {
|
||||||
|
const key = ev.roundName
|
||||||
|
if (!byRound.has(key)) byRound.set(key, [])
|
||||||
|
byRound.get(key)!.push(ev)
|
||||||
|
}
|
||||||
|
return Array.from(byRound.entries()).map(([roundName, evals]) => (
|
||||||
|
<Card key={roundName}>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="text-base">{roundName}</CardTitle>
|
||||||
|
<CardDescription>{evals.length} evaluation{evals.length !== 1 ? 's' : ''}</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Project</TableHead>
|
||||||
|
<TableHead>Score</TableHead>
|
||||||
|
<TableHead>Decision</TableHead>
|
||||||
|
<TableHead>Status</TableHead>
|
||||||
|
<TableHead>Submitted</TableHead>
|
||||||
|
<TableHead className="w-10"></TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{evals.map((ev) => (
|
||||||
|
<TableRow key={ev.assignmentId}>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
<Link
|
||||||
|
href={`/admin/projects/${ev.projectId}`}
|
||||||
|
className="hover:underline text-primary"
|
||||||
|
>
|
||||||
|
{ev.projectTitle}
|
||||||
|
</Link>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{ev.evaluation.globalScore !== null && ev.evaluation.globalScore !== undefined
|
||||||
|
? <span className="font-medium">{ev.evaluation.globalScore}/10</span>
|
||||||
|
: <span className="text-muted-foreground">-</span>}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{ev.evaluation.binaryDecision !== null && ev.evaluation.binaryDecision !== undefined ? (
|
||||||
|
ev.evaluation.binaryDecision ? (
|
||||||
|
<div className="flex items-center gap-1 text-green-600">
|
||||||
|
<ThumbsUp className="h-4 w-4" />
|
||||||
|
<span className="text-sm">Yes</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center gap-1 text-red-600">
|
||||||
|
<ThumbsDown className="h-4 w-4" />
|
||||||
|
<span className="text-sm">No</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground">-</span>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Badge variant={ev.evaluation.status === 'SUBMITTED' ? 'default' : 'secondary'}>
|
||||||
|
{ev.evaluation.status.replace('_', ' ')}
|
||||||
|
</Badge>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-sm text-muted-foreground">
|
||||||
|
{ev.evaluation.submittedAt
|
||||||
|
? new Date(ev.evaluation.submittedAt).toLocaleDateString()
|
||||||
|
: '-'}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setSelectedEvaluation({
|
||||||
|
...ev,
|
||||||
|
user: user,
|
||||||
|
evaluation: ev.evaluation,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Eye className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
))
|
||||||
|
})()
|
||||||
|
)}
|
||||||
|
|
||||||
|
<EvaluationEditSheet
|
||||||
|
assignment={selectedEvaluation}
|
||||||
|
open={!!selectedEvaluation}
|
||||||
|
onOpenChange={(open) => { if (!open) setSelectedEvaluation(null) }}
|
||||||
|
onSaved={() => utils.evaluation.getJurorEvaluations.invalidate({ userId })}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
)}
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
{/* Super Admin Confirmation Dialog */}
|
{/* Super Admin Confirmation Dialog */}
|
||||||
<AlertDialog open={showSuperAdminConfirm} onOpenChange={setShowSuperAdminConfirm}>
|
<AlertDialog open={showSuperAdminConfirm} onOpenChange={setShowSuperAdminConfirm}>
|
||||||
|
|||||||
@@ -267,12 +267,13 @@ function EditProjectContent({ projectId }: { projectId: string }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const statusChanged = data.status !== previousStatus
|
||||||
await updateProject.mutateAsync({
|
await updateProject.mutateAsync({
|
||||||
id: projectId,
|
id: projectId,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
teamName: data.teamName || null,
|
teamName: data.teamName || null,
|
||||||
description: data.description || null,
|
description: data.description || null,
|
||||||
status: data.status,
|
...(statusChanged && { status: data.status }),
|
||||||
tags: data.tags,
|
tags: data.tags,
|
||||||
competitionCategory: (data.competitionCategory || null) as 'STARTUP' | 'BUSINESS_CONCEPT' | null,
|
competitionCategory: (data.competitionCategory || null) as 'STARTUP' | 'BUSINESS_CONCEPT' | null,
|
||||||
oceanIssue: (data.oceanIssue || null) as 'POLLUTION_REDUCTION' | 'CLIMATE_MITIGATION' | 'TECHNOLOGY_INNOVATION' | 'SUSTAINABLE_SHIPPING' | 'BLUE_CARBON' | 'HABITAT_RESTORATION' | 'COMMUNITY_CAPACITY' | 'SUSTAINABLE_FISHING' | 'CONSUMER_AWARENESS' | 'OCEAN_ACIDIFICATION' | 'OTHER' | null,
|
oceanIssue: (data.oceanIssue || null) as 'POLLUTION_REDUCTION' | 'CLIMATE_MITIGATION' | 'TECHNOLOGY_INNOVATION' | 'SUSTAINABLE_SHIPPING' | 'BLUE_CARBON' | 'HABITAT_RESTORATION' | 'COMMUNITY_CAPACITY' | 'SUSTAINABLE_FISHING' | 'CONSUMER_AWARENESS' | 'OCEAN_ACIDIFICATION' | 'OTHER' | null,
|
||||||
|
|||||||
@@ -28,13 +28,7 @@ import { FileUpload } from '@/components/shared/file-upload'
|
|||||||
import { ProjectLogoWithUrl } from '@/components/shared/project-logo-with-url'
|
import { ProjectLogoWithUrl } from '@/components/shared/project-logo-with-url'
|
||||||
import { UserAvatar } from '@/components/shared/user-avatar'
|
import { UserAvatar } from '@/components/shared/user-avatar'
|
||||||
import { EvaluationSummaryCard } from '@/components/admin/evaluation-summary-card'
|
import { EvaluationSummaryCard } from '@/components/admin/evaluation-summary-card'
|
||||||
import {
|
import { EvaluationEditSheet } from '@/components/admin/evaluation-edit-sheet'
|
||||||
Sheet,
|
|
||||||
SheetContent,
|
|
||||||
SheetDescription,
|
|
||||||
SheetHeader,
|
|
||||||
SheetTitle,
|
|
||||||
} from '@/components/ui/sheet'
|
|
||||||
import { AnimatedCard } from '@/components/shared/animated-container'
|
import { AnimatedCard } from '@/components/shared/animated-container'
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
@@ -56,7 +50,6 @@ import {
|
|||||||
Loader2,
|
Loader2,
|
||||||
ScanSearch,
|
ScanSearch,
|
||||||
Eye,
|
Eye,
|
||||||
MessageSquare,
|
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import { formatDate, formatDateOnly } from '@/lib/utils'
|
import { formatDate, formatDateOnly } from '@/lib/utils'
|
||||||
@@ -742,10 +735,11 @@ function ProjectDetailContent({ projectId }: { projectId: string }) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Evaluation Detail Sheet */}
|
{/* Evaluation Detail Sheet */}
|
||||||
<EvaluationDetailSheet
|
<EvaluationEditSheet
|
||||||
assignment={selectedEvalAssignment}
|
assignment={selectedEvalAssignment}
|
||||||
open={!!selectedEvalAssignment}
|
open={!!selectedEvalAssignment}
|
||||||
onOpenChange={(open) => { if (!open) setSelectedEvalAssignment(null) }}
|
onOpenChange={(open) => { if (!open) setSelectedEvalAssignment(null) }}
|
||||||
|
onSaved={() => utils.project.getFullDetail.invalidate({ id: projectId })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* AI Evaluation Summary */}
|
{/* AI Evaluation Summary */}
|
||||||
@@ -830,173 +824,6 @@ function AnalyzeDocumentsButton({ projectId, onComplete }: { projectId: string;
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function EvaluationDetailSheet({
|
|
||||||
assignment,
|
|
||||||
open,
|
|
||||||
onOpenChange,
|
|
||||||
}: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
assignment: any
|
|
||||||
open: boolean
|
|
||||||
onOpenChange: (open: boolean) => void
|
|
||||||
}) {
|
|
||||||
if (!assignment?.evaluation) return null
|
|
||||||
|
|
||||||
const ev = assignment.evaluation
|
|
||||||
const criterionScores = (ev.criterionScoresJson || {}) as Record<string, number | boolean | string>
|
|
||||||
const hasScores = Object.keys(criterionScores).length > 0
|
|
||||||
|
|
||||||
// Try to get the evaluation form for labels
|
|
||||||
const roundId = assignment.roundId as string | undefined
|
|
||||||
const { data: activeForm } = trpc.evaluation.getStageForm.useQuery(
|
|
||||||
{ roundId: roundId ?? '' },
|
|
||||||
{ enabled: !!roundId }
|
|
||||||
)
|
|
||||||
|
|
||||||
// Build label lookup from form criteria
|
|
||||||
const criteriaMap = new Map<string, { label: string; type: string; trueLabel?: string; falseLabel?: string }>()
|
|
||||||
if (activeForm?.criteriaJson) {
|
|
||||||
for (const c of activeForm.criteriaJson as Array<{ id: string; label: string; type?: string; trueLabel?: string; falseLabel?: string }>) {
|
|
||||||
criteriaMap.set(c.id, {
|
|
||||||
label: c.label,
|
|
||||||
type: c.type || 'numeric',
|
|
||||||
trueLabel: c.trueLabel,
|
|
||||||
falseLabel: c.falseLabel,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
||||||
<SheetContent className="sm:max-w-lg overflow-y-auto">
|
|
||||||
<SheetHeader>
|
|
||||||
<SheetTitle className="flex items-center gap-2">
|
|
||||||
<UserAvatar user={assignment.user} avatarUrl={assignment.user.avatarUrl} size="sm" />
|
|
||||||
{assignment.user.name || assignment.user.email}
|
|
||||||
</SheetTitle>
|
|
||||||
<SheetDescription>
|
|
||||||
{ev.submittedAt
|
|
||||||
? `Submitted ${formatDate(ev.submittedAt)}`
|
|
||||||
: 'Evaluation details'}
|
|
||||||
</SheetDescription>
|
|
||||||
</SheetHeader>
|
|
||||||
|
|
||||||
<div className="space-y-6 mt-6">
|
|
||||||
{/* Global stats */}
|
|
||||||
<div className="grid grid-cols-2 gap-3">
|
|
||||||
<div className="p-3 rounded-lg bg-muted">
|
|
||||||
<p className="text-xs text-muted-foreground">Score</p>
|
|
||||||
<p className="text-2xl font-bold">
|
|
||||||
{ev.globalScore !== null ? `${ev.globalScore}/10` : '-'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="p-3 rounded-lg bg-muted">
|
|
||||||
<p className="text-xs text-muted-foreground">Decision</p>
|
|
||||||
<div className="mt-1">
|
|
||||||
{ev.binaryDecision !== null ? (
|
|
||||||
ev.binaryDecision ? (
|
|
||||||
<div className="flex items-center gap-1.5 text-emerald-600">
|
|
||||||
<ThumbsUp className="h-5 w-5" />
|
|
||||||
<span className="font-semibold">Yes</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="flex items-center gap-1.5 text-red-600">
|
|
||||||
<ThumbsDown className="h-5 w-5" />
|
|
||||||
<span className="font-semibold">No</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<span className="text-2xl font-bold">-</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Criterion Scores */}
|
|
||||||
{hasScores && (
|
|
||||||
<div>
|
|
||||||
<h4 className="text-sm font-medium mb-3 flex items-center gap-2">
|
|
||||||
<BarChart3 className="h-4 w-4" />
|
|
||||||
Criterion Scores
|
|
||||||
</h4>
|
|
||||||
<div className="space-y-2.5">
|
|
||||||
{Object.entries(criterionScores).map(([key, value]) => {
|
|
||||||
const meta = criteriaMap.get(key)
|
|
||||||
const label = meta?.label || key
|
|
||||||
const type = meta?.type || (typeof value === 'boolean' ? 'boolean' : typeof value === 'string' ? 'text' : 'numeric')
|
|
||||||
|
|
||||||
if (type === 'section_header') return null
|
|
||||||
|
|
||||||
if (type === 'boolean' || type === 'advance') {
|
|
||||||
return (
|
|
||||||
<div key={key} className="flex items-center justify-between p-2.5 rounded-lg border">
|
|
||||||
<span className="text-sm">{label}</span>
|
|
||||||
{value === true ? (
|
|
||||||
<Badge className="bg-emerald-100 text-emerald-700 border-emerald-200" variant="outline">
|
|
||||||
<ThumbsUp className="mr-1 h-3 w-3" />
|
|
||||||
{meta?.trueLabel || 'Yes'}
|
|
||||||
</Badge>
|
|
||||||
) : (
|
|
||||||
<Badge className="bg-red-100 text-red-700 border-red-200" variant="outline">
|
|
||||||
<ThumbsDown className="mr-1 h-3 w-3" />
|
|
||||||
{meta?.falseLabel || 'No'}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'text') {
|
|
||||||
return (
|
|
||||||
<div key={key} className="space-y-1">
|
|
||||||
<span className="text-sm font-medium">{label}</span>
|
|
||||||
<div className="text-sm text-muted-foreground p-2.5 rounded-lg border bg-muted/50 whitespace-pre-wrap">
|
|
||||||
{typeof value === 'string' ? value : String(value)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Numeric
|
|
||||||
return (
|
|
||||||
<div key={key} className="flex items-center gap-3 p-2.5 rounded-lg border">
|
|
||||||
<span className="text-sm flex-1 truncate">{label}</span>
|
|
||||||
<div className="flex items-center gap-2 shrink-0">
|
|
||||||
<div className="w-20 h-2 rounded-full bg-muted overflow-hidden">
|
|
||||||
<div
|
|
||||||
className="h-full rounded-full bg-primary"
|
|
||||||
style={{ width: `${(Number(value) / 10) * 100}%` }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<span className="text-sm font-bold tabular-nums w-8 text-right">
|
|
||||||
{typeof value === 'number' ? value : '-'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Feedback Text */}
|
|
||||||
{ev.feedbackText && (
|
|
||||||
<div>
|
|
||||||
<h4 className="text-sm font-medium mb-2 flex items-center gap-2">
|
|
||||||
<MessageSquare className="h-4 w-4" />
|
|
||||||
Feedback
|
|
||||||
</h4>
|
|
||||||
<div className="text-sm text-muted-foreground p-3 rounded-lg border bg-muted/30 whitespace-pre-wrap leading-relaxed">
|
|
||||||
{ev.feedbackText}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</SheetContent>
|
|
||||||
</Sheet>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ProjectDetailPage({ params }: PageProps) {
|
export default function ProjectDetailPage({ params }: PageProps) {
|
||||||
const { id } = use(params)
|
const { id } = use(params)
|
||||||
|
|
||||||
|
|||||||
305
src/components/admin/evaluation-edit-sheet.tsx
Normal file
305
src/components/admin/evaluation-edit-sheet.tsx
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { trpc } from '@/lib/trpc/client'
|
||||||
|
import { Badge } from '@/components/ui/badge'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
|
import {
|
||||||
|
Sheet,
|
||||||
|
SheetContent,
|
||||||
|
SheetDescription,
|
||||||
|
SheetHeader,
|
||||||
|
SheetTitle,
|
||||||
|
} from '@/components/ui/sheet'
|
||||||
|
import { UserAvatar } from '@/components/shared/user-avatar'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { formatDate } from '@/lib/utils'
|
||||||
|
import {
|
||||||
|
BarChart3,
|
||||||
|
ThumbsUp,
|
||||||
|
ThumbsDown,
|
||||||
|
MessageSquare,
|
||||||
|
Pencil,
|
||||||
|
Loader2,
|
||||||
|
Check,
|
||||||
|
X,
|
||||||
|
} from 'lucide-react'
|
||||||
|
|
||||||
|
type EvaluationEditSheetProps = {
|
||||||
|
/** The assignment object with user, evaluation, and roundId */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
assignment: any
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
/** Called after a successful feedback edit */
|
||||||
|
onSaved?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EvaluationEditSheet({
|
||||||
|
assignment,
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
onSaved,
|
||||||
|
}: EvaluationEditSheetProps) {
|
||||||
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
|
const [editedFeedback, setEditedFeedback] = useState('')
|
||||||
|
|
||||||
|
const editMutation = trpc.evaluation.adminEditEvaluation.useMutation({
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('Feedback updated')
|
||||||
|
setIsEditing(false)
|
||||||
|
onSaved?.()
|
||||||
|
},
|
||||||
|
onError: (err) => toast.error(err.message),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!assignment?.evaluation) return null
|
||||||
|
|
||||||
|
const ev = assignment.evaluation
|
||||||
|
const criterionScores = (ev.criterionScoresJson || {}) as Record<string, number | boolean | string>
|
||||||
|
const hasScores = Object.keys(criterionScores).length > 0
|
||||||
|
|
||||||
|
const roundId = assignment.roundId as string | undefined
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sheet open={open} onOpenChange={(v) => {
|
||||||
|
if (!v) setIsEditing(false)
|
||||||
|
onOpenChange(v)
|
||||||
|
}}>
|
||||||
|
<SheetContent className="sm:max-w-lg overflow-y-auto">
|
||||||
|
<SheetHeader>
|
||||||
|
<SheetTitle className="flex items-center gap-2">
|
||||||
|
{assignment.user && (
|
||||||
|
<UserAvatar user={assignment.user} avatarUrl={assignment.user.avatarUrl} size="sm" />
|
||||||
|
)}
|
||||||
|
{assignment.user?.name || assignment.user?.email || 'Juror'}
|
||||||
|
</SheetTitle>
|
||||||
|
<SheetDescription>
|
||||||
|
{ev.submittedAt
|
||||||
|
? `Submitted ${formatDate(ev.submittedAt)}`
|
||||||
|
: 'Evaluation details'}
|
||||||
|
</SheetDescription>
|
||||||
|
</SheetHeader>
|
||||||
|
|
||||||
|
<div className="space-y-6 mt-6">
|
||||||
|
{/* Global stats */}
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
|
<div className="p-3 rounded-lg bg-muted">
|
||||||
|
<p className="text-xs text-muted-foreground">Score</p>
|
||||||
|
<p className="text-2xl font-bold">
|
||||||
|
{ev.globalScore !== null && ev.globalScore !== undefined ? `${ev.globalScore}/10` : '-'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 rounded-lg bg-muted">
|
||||||
|
<p className="text-xs text-muted-foreground">Decision</p>
|
||||||
|
<div className="mt-1">
|
||||||
|
{ev.binaryDecision !== null && ev.binaryDecision !== undefined ? (
|
||||||
|
ev.binaryDecision ? (
|
||||||
|
<div className="flex items-center gap-1.5 text-emerald-600">
|
||||||
|
<ThumbsUp className="h-5 w-5" />
|
||||||
|
<span className="font-semibold">Yes</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center gap-1.5 text-red-600">
|
||||||
|
<ThumbsDown className="h-5 w-5" />
|
||||||
|
<span className="font-semibold">No</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<span className="text-2xl font-bold">-</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Criterion Scores */}
|
||||||
|
{hasScores && (
|
||||||
|
<CriterionScoresSection criterionScores={criterionScores} roundId={roundId} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Feedback Text — editable */}
|
||||||
|
<FeedbackSection
|
||||||
|
evaluationId={ev.id}
|
||||||
|
feedbackText={ev.feedbackText}
|
||||||
|
isEditing={isEditing}
|
||||||
|
editedFeedback={editedFeedback}
|
||||||
|
onStartEdit={() => {
|
||||||
|
setEditedFeedback(ev.feedbackText || '')
|
||||||
|
setIsEditing(true)
|
||||||
|
}}
|
||||||
|
onCancelEdit={() => setIsEditing(false)}
|
||||||
|
onSave={() => {
|
||||||
|
editMutation.mutate({
|
||||||
|
evaluationId: ev.id,
|
||||||
|
feedbackText: editedFeedback,
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
onChangeFeedback={setEditedFeedback}
|
||||||
|
isSaving={editMutation.isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CriterionScoresSection({
|
||||||
|
criterionScores,
|
||||||
|
roundId,
|
||||||
|
}: {
|
||||||
|
criterionScores: Record<string, number | boolean | string>
|
||||||
|
roundId?: string
|
||||||
|
}) {
|
||||||
|
const { data: activeForm } = trpc.evaluation.getStageForm.useQuery(
|
||||||
|
{ roundId: roundId ?? '' },
|
||||||
|
{ enabled: !!roundId }
|
||||||
|
)
|
||||||
|
|
||||||
|
const criteriaMap = new Map<string, { label: string; type: string; trueLabel?: string; falseLabel?: string }>()
|
||||||
|
if (activeForm?.criteriaJson) {
|
||||||
|
for (const c of activeForm.criteriaJson as Array<{ id: string; label: string; type?: string; trueLabel?: string; falseLabel?: string }>) {
|
||||||
|
criteriaMap.set(c.id, {
|
||||||
|
label: c.label,
|
||||||
|
type: c.type || 'numeric',
|
||||||
|
trueLabel: c.trueLabel,
|
||||||
|
falseLabel: c.falseLabel,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h4 className="text-sm font-medium mb-3 flex items-center gap-2">
|
||||||
|
<BarChart3 className="h-4 w-4" />
|
||||||
|
Criterion Scores
|
||||||
|
</h4>
|
||||||
|
<div className="space-y-2.5">
|
||||||
|
{Object.entries(criterionScores).map(([key, value]) => {
|
||||||
|
const meta = criteriaMap.get(key)
|
||||||
|
const label = meta?.label || key
|
||||||
|
const type = meta?.type || (typeof value === 'boolean' ? 'boolean' : typeof value === 'string' ? 'text' : 'numeric')
|
||||||
|
|
||||||
|
if (type === 'section_header') return null
|
||||||
|
|
||||||
|
if (type === 'boolean' || type === 'advance') {
|
||||||
|
return (
|
||||||
|
<div key={key} className="flex items-center justify-between p-2.5 rounded-lg border">
|
||||||
|
<span className="text-sm">{label}</span>
|
||||||
|
{value === true ? (
|
||||||
|
<Badge className="bg-emerald-100 text-emerald-700 border-emerald-200" variant="outline">
|
||||||
|
<ThumbsUp className="mr-1 h-3 w-3" />
|
||||||
|
{meta?.trueLabel || 'Yes'}
|
||||||
|
</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge className="bg-red-100 text-red-700 border-red-200" variant="outline">
|
||||||
|
<ThumbsDown className="mr-1 h-3 w-3" />
|
||||||
|
{meta?.falseLabel || 'No'}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'text') {
|
||||||
|
return (
|
||||||
|
<div key={key} className="space-y-1">
|
||||||
|
<span className="text-sm font-medium">{label}</span>
|
||||||
|
<div className="text-sm text-muted-foreground p-2.5 rounded-lg border bg-muted/50 whitespace-pre-wrap">
|
||||||
|
{typeof value === 'string' ? value : String(value)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Numeric
|
||||||
|
return (
|
||||||
|
<div key={key} className="flex items-center gap-3 p-2.5 rounded-lg border">
|
||||||
|
<span className="text-sm flex-1 truncate">{label}</span>
|
||||||
|
<div className="flex items-center gap-2 shrink-0">
|
||||||
|
<div className="w-20 h-2 rounded-full bg-muted overflow-hidden">
|
||||||
|
<div
|
||||||
|
className="h-full rounded-full bg-primary"
|
||||||
|
style={{ width: `${(Number(value) / 10) * 100}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-bold tabular-nums w-8 text-right">
|
||||||
|
{typeof value === 'number' ? value : '-'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FeedbackSection({
|
||||||
|
evaluationId,
|
||||||
|
feedbackText,
|
||||||
|
isEditing,
|
||||||
|
editedFeedback,
|
||||||
|
onStartEdit,
|
||||||
|
onCancelEdit,
|
||||||
|
onSave,
|
||||||
|
onChangeFeedback,
|
||||||
|
isSaving,
|
||||||
|
}: {
|
||||||
|
evaluationId: string
|
||||||
|
feedbackText: string | null
|
||||||
|
isEditing: boolean
|
||||||
|
editedFeedback: string
|
||||||
|
onStartEdit: () => void
|
||||||
|
onCancelEdit: () => void
|
||||||
|
onSave: () => void
|
||||||
|
onChangeFeedback: (v: string) => void
|
||||||
|
isSaving: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<h4 className="text-sm font-medium flex items-center gap-2">
|
||||||
|
<MessageSquare className="h-4 w-4" />
|
||||||
|
Feedback
|
||||||
|
</h4>
|
||||||
|
{!isEditing && evaluationId && (
|
||||||
|
<Button variant="ghost" size="sm" onClick={onStartEdit}>
|
||||||
|
<Pencil className="h-3 w-3 mr-1" />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{isEditing ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Textarea
|
||||||
|
value={editedFeedback}
|
||||||
|
onChange={(e) => onChangeFeedback(e.target.value)}
|
||||||
|
rows={8}
|
||||||
|
className="text-sm"
|
||||||
|
/>
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
<Button variant="outline" size="sm" onClick={onCancelEdit} disabled={isSaving}>
|
||||||
|
<X className="h-3 w-3 mr-1" />
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" onClick={onSave} disabled={isSaving}>
|
||||||
|
{isSaving ? (
|
||||||
|
<Loader2 className="h-3 w-3 mr-1 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Check className="h-3 w-3 mr-1" />
|
||||||
|
)}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : feedbackText ? (
|
||||||
|
<div className="text-sm text-muted-foreground p-3 rounded-lg border bg-muted/30 whitespace-pre-wrap leading-relaxed">
|
||||||
|
{feedbackText}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-muted-foreground italic">No feedback provided</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -66,11 +66,18 @@ type ProjectInfo = {
|
|||||||
country: string | null
|
country: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JurorScore = {
|
||||||
|
jurorName: string
|
||||||
|
globalScore: number | null
|
||||||
|
decision: boolean | null
|
||||||
|
}
|
||||||
|
|
||||||
type SortableProjectRowProps = {
|
type SortableProjectRowProps = {
|
||||||
projectId: string
|
projectId: string
|
||||||
currentRank: number
|
currentRank: number
|
||||||
entry: RankedProjectEntry | undefined
|
entry: RankedProjectEntry | undefined
|
||||||
projectInfo: ProjectInfo | undefined
|
projectInfo: ProjectInfo | undefined
|
||||||
|
jurorScores: JurorScore[] | undefined
|
||||||
onSelect: () => void
|
onSelect: () => void
|
||||||
isSelected: boolean
|
isSelected: boolean
|
||||||
}
|
}
|
||||||
@@ -82,6 +89,7 @@ function SortableProjectRow({
|
|||||||
currentRank,
|
currentRank,
|
||||||
entry,
|
entry,
|
||||||
projectInfo,
|
projectInfo,
|
||||||
|
jurorScores,
|
||||||
onSelect,
|
onSelect,
|
||||||
isSelected,
|
isSelected,
|
||||||
}: SortableProjectRowProps) {
|
}: SortableProjectRowProps) {
|
||||||
@@ -102,6 +110,10 @@ function SortableProjectRow({
|
|||||||
// isOverridden: current position differs from AI-assigned rank
|
// isOverridden: current position differs from AI-assigned rank
|
||||||
const isOverridden = entry !== undefined && currentRank !== entry.rank
|
const isOverridden = entry !== undefined && currentRank !== entry.rank
|
||||||
|
|
||||||
|
// Compute yes count from juror scores
|
||||||
|
const yesCount = jurorScores?.filter((j) => j.decision === true).length ?? 0
|
||||||
|
const totalJurors = jurorScores?.length ?? entry?.evaluatorCount ?? 0
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={setNodeRef}
|
ref={setNodeRef}
|
||||||
@@ -150,26 +162,57 @@ function SortableProjectRow({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Stats */}
|
{/* Juror scores + advance decision */}
|
||||||
{entry && (
|
<div className="flex items-center gap-3 flex-shrink-0">
|
||||||
<div className="flex items-center gap-4 flex-shrink-0 text-xs text-muted-foreground">
|
{/* Individual juror score pills */}
|
||||||
<span title="Composite score">
|
{jurorScores && jurorScores.length > 0 ? (
|
||||||
<BarChart3 className="inline h-3 w-3 mr-0.5" />
|
<div className="flex items-center gap-1" title={jurorScores.map((j) => `${j.jurorName}: ${j.globalScore ?? '—'}/10`).join('\n')}>
|
||||||
{Math.round(entry.compositeScore * 100)}%
|
{jurorScores.map((j, i) => (
|
||||||
|
<span
|
||||||
|
key={i}
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center justify-center rounded-md px-1.5 py-0.5 text-xs font-medium border',
|
||||||
|
j.globalScore != null && j.globalScore >= 8
|
||||||
|
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||||
|
: j.globalScore != null && j.globalScore >= 6
|
||||||
|
? 'bg-blue-50 text-blue-700 border-blue-200'
|
||||||
|
: j.globalScore != null && j.globalScore >= 4
|
||||||
|
? 'bg-amber-50 text-amber-700 border-amber-200'
|
||||||
|
: 'bg-red-50 text-red-700 border-red-200',
|
||||||
|
)}
|
||||||
|
title={`${j.jurorName}: ${j.globalScore ?? '—'}/10`}
|
||||||
|
>
|
||||||
|
{j.globalScore ?? '—'}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : entry?.avgGlobalScore !== null && entry?.avgGlobalScore !== undefined ? (
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
Avg {entry.avgGlobalScore.toFixed(1)}
|
||||||
</span>
|
</span>
|
||||||
{entry.avgGlobalScore !== null && (
|
) : null}
|
||||||
<span title="Average global score">
|
|
||||||
Avg {entry.avgGlobalScore.toFixed(1)}
|
{/* Average score */}
|
||||||
</span>
|
{entry?.avgGlobalScore !== null && entry?.avgGlobalScore !== undefined && jurorScores && jurorScores.length > 1 && (
|
||||||
|
<span className="text-xs font-medium text-muted-foreground" title="Average score">
|
||||||
|
= {entry.avgGlobalScore.toFixed(1)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Advance decision indicator */}
|
||||||
|
<div className={cn(
|
||||||
|
'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium',
|
||||||
|
yesCount > 0
|
||||||
|
? 'bg-emerald-100 text-emerald-700'
|
||||||
|
: 'bg-gray-100 text-gray-500',
|
||||||
|
)}>
|
||||||
|
{yesCount > 0 ? (
|
||||||
|
<>{yesCount}/{totalJurors} Yes</>
|
||||||
|
) : (
|
||||||
|
<>{totalJurors} juror{totalJurors !== 1 ? 's' : ''}</>
|
||||||
)}
|
)}
|
||||||
<span title="Yes/No vote rate">
|
|
||||||
Yes {Math.round(entry.passRate * 100)}%
|
|
||||||
</span>
|
|
||||||
<span title="Evaluator count">
|
|
||||||
{entry.evaluatorCount} juror{entry.evaluatorCount !== 1 ? 's' : ''}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -226,6 +269,10 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
|||||||
|
|
||||||
const { data: roundData } = trpc.round.getById.useQuery({ id: roundId })
|
const { data: roundData } = trpc.round.getById.useQuery({ id: roundId })
|
||||||
|
|
||||||
|
const { data: evalScores } = trpc.ranking.roundEvaluationScores.useQuery(
|
||||||
|
{ roundId },
|
||||||
|
)
|
||||||
|
|
||||||
// ─── tRPC mutations ───────────────────────────────────────────────────────
|
// ─── tRPC mutations ───────────────────────────────────────────────────────
|
||||||
const utils = trpc.useUtils()
|
const utils = trpc.useUtils()
|
||||||
|
|
||||||
@@ -236,13 +283,21 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
|||||||
// Do NOT invalidate getSnapshot — would reset localOrder
|
// Do NOT invalidate getSnapshot — would reset localOrder
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [rankingInProgress, setRankingInProgress] = useState(false)
|
||||||
|
|
||||||
const triggerRankMutation = trpc.ranking.triggerAutoRank.useMutation({
|
const triggerRankMutation = trpc.ranking.triggerAutoRank.useMutation({
|
||||||
|
onMutate: () => setRankingInProgress(true),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success('Ranking complete. Reload to see results.')
|
toast.success('Ranking complete!')
|
||||||
initialized.current = false // allow re-init on next snapshot load
|
initialized.current = false // allow re-init on next snapshot load
|
||||||
void utils.ranking.listSnapshots.invalidate({ roundId })
|
void utils.ranking.listSnapshots.invalidate({ roundId })
|
||||||
|
void utils.ranking.getSnapshot.invalidate()
|
||||||
|
setRankingInProgress(false)
|
||||||
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
toast.error(err.message)
|
||||||
|
setRankingInProgress(false)
|
||||||
},
|
},
|
||||||
onError: (err) => toast.error(err.message),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const advanceMutation = trpc.round.advanceProjects.useMutation({
|
const advanceMutation = trpc.round.advanceProjects.useMutation({
|
||||||
@@ -379,28 +434,43 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
|||||||
// ─── Empty state ──────────────────────────────────────────────────────────
|
// ─── Empty state ──────────────────────────────────────────────────────────
|
||||||
if (!latestSnapshotId) {
|
if (!latestSnapshotId) {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<div className="space-y-4">
|
||||||
<CardContent className="flex flex-col items-center justify-center gap-4 py-12 text-center">
|
<Card>
|
||||||
<BarChart3 className="h-10 w-10 text-muted-foreground" />
|
<CardContent className="flex flex-col items-center justify-center gap-4 py-12 text-center">
|
||||||
<div>
|
{rankingInProgress ? (
|
||||||
<p className="font-medium">No ranking available yet</p>
|
<>
|
||||||
<p className="mt-1 text-sm text-muted-foreground">
|
<Loader2 className="h-10 w-10 text-blue-500 animate-spin" />
|
||||||
Run ranking from the Config tab to generate results, or trigger it now.
|
<div>
|
||||||
</p>
|
<p className="font-medium">AI ranking in progress…</p>
|
||||||
</div>
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
<Button
|
This may take a minute. You can continue working — results will appear automatically.
|
||||||
onClick={() => triggerRankMutation.mutate({ roundId })}
|
</p>
|
||||||
disabled={triggerRankMutation.isPending}
|
</div>
|
||||||
>
|
<div className="h-2 w-48 rounded-full bg-blue-100 dark:bg-blue-900 overflow-hidden">
|
||||||
{triggerRankMutation.isPending ? (
|
<div className="h-full w-full rounded-full bg-blue-500 animate-pulse" />
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
</div>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<RefreshCw className="mr-2 h-4 w-4" />
|
<>
|
||||||
|
<BarChart3 className="h-10 w-10 text-muted-foreground" />
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">No ranking available yet</p>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
Run ranking from the Config tab to generate results, or trigger it now.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => triggerRankMutation.mutate({ roundId })}
|
||||||
|
disabled={triggerRankMutation.isPending}
|
||||||
|
>
|
||||||
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
|
Run Ranking Now
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
Run Ranking Now
|
</CardContent>
|
||||||
</Button>
|
</Card>
|
||||||
</CardContent>
|
</div>
|
||||||
</Card>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,14 +514,19 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
|||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => triggerRankMutation.mutate({ roundId })}
|
onClick={() => triggerRankMutation.mutate({ roundId })}
|
||||||
disabled={triggerRankMutation.isPending}
|
disabled={rankingInProgress}
|
||||||
>
|
>
|
||||||
{triggerRankMutation.isPending ? (
|
{rankingInProgress ? (
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
<>
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
Ranking…
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<RefreshCw className="mr-2 h-4 w-4" />
|
<>
|
||||||
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
|
Run Ranking
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
Run Ranking
|
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -469,6 +544,26 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{/* Ranking in-progress banner */}
|
||||||
|
{rankingInProgress && (
|
||||||
|
<Card className="border-blue-200 bg-blue-50 dark:border-blue-800 dark:bg-blue-950/30">
|
||||||
|
<CardContent className="flex items-center gap-3 py-4">
|
||||||
|
<Loader2 className="h-5 w-5 animate-spin text-blue-600 dark:text-blue-400 flex-shrink-0" />
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<p className="text-sm font-medium text-blue-900 dark:text-blue-200">
|
||||||
|
AI ranking in progress…
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-blue-700 dark:text-blue-400">
|
||||||
|
This may take a minute. You can continue working — results will appear automatically.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="h-1.5 w-32 rounded-full bg-blue-200 dark:bg-blue-800 overflow-hidden flex-shrink-0">
|
||||||
|
<div className="h-full w-full rounded-full bg-blue-500 animate-pulse" />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Per-category sections */}
|
{/* Per-category sections */}
|
||||||
{(['STARTUP', 'BUSINESS_CONCEPT'] as const).map((category) => (
|
{(['STARTUP', 'BUSINESS_CONCEPT'] as const).map((category) => (
|
||||||
<Card key={category}>
|
<Card key={category}>
|
||||||
@@ -520,6 +615,7 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
|||||||
currentRank={index + 1}
|
currentRank={index + 1}
|
||||||
entry={rankingMap.get(projectId)}
|
entry={rankingMap.get(projectId)}
|
||||||
projectInfo={projectInfoMap.get(projectId)}
|
projectInfo={projectInfoMap.get(projectId)}
|
||||||
|
jurorScores={evalScores?.[projectId]}
|
||||||
onSelect={() => setSelectedProjectId(projectId)}
|
onSelect={() => setSelectedProjectId(projectId)}
|
||||||
isSelected={selectedProjectId === projectId}
|
isSelected={selectedProjectId === projectId}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1780,4 +1780,87 @@ export const evaluationRouter = router({
|
|||||||
submissions,
|
submissions,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin: edit the feedbackText on a submitted evaluation.
|
||||||
|
*/
|
||||||
|
adminEditEvaluation: adminProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
evaluationId: z.string(),
|
||||||
|
feedbackText: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const evaluation = await ctx.prisma.evaluation.findUnique({
|
||||||
|
where: { id: input.evaluationId },
|
||||||
|
select: { id: true, feedbackText: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!evaluation) {
|
||||||
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'Evaluation not found' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await ctx.prisma.evaluation.update({
|
||||||
|
where: { id: input.evaluationId },
|
||||||
|
data: { feedbackText: input.feedbackText },
|
||||||
|
})
|
||||||
|
|
||||||
|
await logAudit({
|
||||||
|
prisma: ctx.prisma,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
action: 'ADMIN_EDIT_EVALUATION_FEEDBACK',
|
||||||
|
entityType: 'Evaluation',
|
||||||
|
entityId: input.evaluationId,
|
||||||
|
detailsJson: {
|
||||||
|
adminUserId: ctx.user.id,
|
||||||
|
before: (evaluation.feedbackText ?? '').slice(0, 200),
|
||||||
|
after: input.feedbackText.slice(0, 200),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return updated
|
||||||
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin: get all evaluations submitted by a specific juror.
|
||||||
|
*/
|
||||||
|
getJurorEvaluations: adminProcedure
|
||||||
|
.input(z.object({ userId: z.string() }))
|
||||||
|
.query(async ({ ctx, input }) => {
|
||||||
|
const assignments = await ctx.prisma.assignment.findMany({
|
||||||
|
where: { userId: input.userId },
|
||||||
|
include: {
|
||||||
|
project: { select: { id: true, title: true } },
|
||||||
|
round: { select: { id: true, name: true, roundType: true, sortOrder: true } },
|
||||||
|
evaluation: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
globalScore: true,
|
||||||
|
binaryDecision: true,
|
||||||
|
feedbackText: true,
|
||||||
|
status: true,
|
||||||
|
submittedAt: true,
|
||||||
|
criterionScoresJson: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orderBy: [
|
||||||
|
{ round: { sortOrder: 'asc' } },
|
||||||
|
{ project: { title: 'asc' } },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
return assignments
|
||||||
|
.filter((a) => a.evaluation !== null)
|
||||||
|
.map((a) => ({
|
||||||
|
assignmentId: a.id,
|
||||||
|
roundId: a.roundId,
|
||||||
|
roundName: a.round.name,
|
||||||
|
roundType: a.round.roundType,
|
||||||
|
projectId: a.project.id,
|
||||||
|
projectTitle: a.project.title,
|
||||||
|
evaluation: a.evaluation!,
|
||||||
|
}))
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -721,18 +721,20 @@ export const projectRouter = router({
|
|||||||
? (country === null ? null : normalizeCountryToCode(country))
|
? (country === null ? null : normalizeCountryToCode(country))
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
// Validate status transition if status is being changed
|
// Validate status transition if status is actually changing
|
||||||
if (status) {
|
if (status) {
|
||||||
const currentProject = await ctx.prisma.project.findUniqueOrThrow({
|
const currentProject = await ctx.prisma.project.findUniqueOrThrow({
|
||||||
where: { id },
|
where: { id },
|
||||||
select: { status: true },
|
select: { status: true },
|
||||||
})
|
})
|
||||||
const allowedTransitions = VALID_PROJECT_TRANSITIONS[currentProject.status] || []
|
if (status !== currentProject.status) {
|
||||||
if (!allowedTransitions.includes(status)) {
|
const allowedTransitions = VALID_PROJECT_TRANSITIONS[currentProject.status] || []
|
||||||
throw new TRPCError({
|
if (!allowedTransitions.includes(status)) {
|
||||||
code: 'BAD_REQUEST',
|
throw new TRPCError({
|
||||||
message: `Invalid status transition: cannot change from ${currentProject.status} to ${status}. Allowed: ${allowedTransitions.join(', ') || 'none'}`,
|
code: 'BAD_REQUEST',
|
||||||
})
|
message: `Invalid status transition: cannot change from ${currentProject.status} to ${status}. Allowed: ${allowedTransitions.join(', ') || 'none'}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -387,4 +387,79 @@ export const rankingRouter = router({
|
|||||||
triggered: results.filter((r) => r.triggered).length,
|
triggered: results.filter((r) => r.triggered).length,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get per-project evaluation scores for a round.
|
||||||
|
* Returns a map of projectId → array of { jurorName, globalScore, binaryDecision }.
|
||||||
|
* Used by the ranking dashboard to show individual juror scores inline.
|
||||||
|
*/
|
||||||
|
roundEvaluationScores: adminProcedure
|
||||||
|
.input(z.object({ roundId: z.string() }))
|
||||||
|
.query(async ({ ctx, input }) => {
|
||||||
|
// Fetch the round config to find the boolean criterion ID (legacy fallback)
|
||||||
|
const round = await ctx.prisma.round.findUniqueOrThrow({
|
||||||
|
where: { id: input.roundId },
|
||||||
|
select: { configJson: true },
|
||||||
|
})
|
||||||
|
const roundConfig = round.configJson as Record<string, unknown> | null
|
||||||
|
const criteria = (roundConfig?.criteria ?? roundConfig?.evaluationCriteria ?? []) as Array<{
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
type?: string
|
||||||
|
}>
|
||||||
|
const boolCriterionId = criteria.find(
|
||||||
|
(c) => c.type === 'boolean' && c.label?.toLowerCase().includes('move to the next stage'),
|
||||||
|
)?.id ?? null
|
||||||
|
|
||||||
|
const assignments = await ctx.prisma.assignment.findMany({
|
||||||
|
where: {
|
||||||
|
roundId: input.roundId,
|
||||||
|
isRequired: true,
|
||||||
|
evaluation: { status: 'SUBMITTED' },
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
projectId: true,
|
||||||
|
user: { select: { name: true, email: true } },
|
||||||
|
evaluation: {
|
||||||
|
select: {
|
||||||
|
globalScore: true,
|
||||||
|
binaryDecision: true,
|
||||||
|
criterionScoresJson: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const byProject: Record<string, Array<{
|
||||||
|
jurorName: string
|
||||||
|
globalScore: number | null
|
||||||
|
decision: boolean | null
|
||||||
|
}>> = {}
|
||||||
|
|
||||||
|
for (const a of assignments) {
|
||||||
|
if (!a.evaluation) continue
|
||||||
|
const list = byProject[a.projectId] ?? []
|
||||||
|
|
||||||
|
// Resolve binary decision: column first, then criterion fallback
|
||||||
|
let decision = a.evaluation.binaryDecision
|
||||||
|
if (decision == null && boolCriterionId) {
|
||||||
|
const scores = a.evaluation.criterionScoresJson as Record<string, unknown> | null
|
||||||
|
if (scores) {
|
||||||
|
const val = scores[boolCriterionId]
|
||||||
|
if (typeof val === 'boolean') decision = val
|
||||||
|
else if (val === 'true') decision = true
|
||||||
|
else if (val === 'false') decision = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list.push({
|
||||||
|
jurorName: a.user.name ?? a.user.email ?? 'Unknown',
|
||||||
|
globalScore: a.evaluation.globalScore,
|
||||||
|
decision,
|
||||||
|
})
|
||||||
|
byProject[a.projectId] = list
|
||||||
|
}
|
||||||
|
|
||||||
|
return byProject
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -160,13 +160,49 @@ function anonymizeProjectsForRanking(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute pass rate from Evaluation records.
|
* Find the boolean criterion ID for "Move to the Next Stage?" from round config.
|
||||||
* Handles both legacy binaryDecision boolean and future dedicated field.
|
* Returns null if no such criterion exists.
|
||||||
* Falls back to binaryDecision if no future field exists.
|
|
||||||
*/
|
*/
|
||||||
function computePassRate(evaluations: Array<{ binaryDecision: boolean | null }>): number {
|
function findBooleanCriterionId(roundConfig: Record<string, unknown> | null): string | null {
|
||||||
|
if (!roundConfig) return null
|
||||||
|
const criteria = (roundConfig.criteria ?? roundConfig.evaluationCriteria ?? []) as Array<{
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
type?: string
|
||||||
|
}>
|
||||||
|
const boolCriterion = criteria.find(
|
||||||
|
(c) => c.type === 'boolean' && c.label?.toLowerCase().includes('move to the next stage'),
|
||||||
|
)
|
||||||
|
return boolCriterion?.id ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the binary advance decision for an evaluation.
|
||||||
|
* 1. Use binaryDecision column if set
|
||||||
|
* 2. Fall back to the boolean criterion in criterionScoresJson
|
||||||
|
*/
|
||||||
|
function resolveBinaryDecision(
|
||||||
|
binaryDecision: boolean | null,
|
||||||
|
criterionScoresJson: Record<string, unknown> | null,
|
||||||
|
boolCriterionId: string | null,
|
||||||
|
): boolean | null {
|
||||||
|
if (binaryDecision != null) return binaryDecision
|
||||||
|
if (!boolCriterionId || !criterionScoresJson) return null
|
||||||
|
const value = criterionScoresJson[boolCriterionId]
|
||||||
|
if (typeof value === 'boolean') return value
|
||||||
|
if (value === 'true') return true
|
||||||
|
if (value === 'false') return false
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute pass rate from Evaluation records.
|
||||||
|
* Counts evaluations where the advance decision resolved to true.
|
||||||
|
* Evaluations with null decision are treated as "no" (not counted as pass).
|
||||||
|
*/
|
||||||
|
function computePassRate(evaluations: Array<{ resolvedDecision: boolean | null }>): number {
|
||||||
if (evaluations.length === 0) return 0
|
if (evaluations.length === 0) return 0
|
||||||
const passCount = evaluations.filter((e) => e.binaryDecision === true).length
|
const passCount = evaluations.filter((e) => e.resolvedDecision === true).length
|
||||||
return passCount / evaluations.length
|
return passCount / evaluations.length
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,6 +413,13 @@ export async function fetchAndRankCategory(
|
|||||||
prisma: PrismaClient,
|
prisma: PrismaClient,
|
||||||
userId?: string,
|
userId?: string,
|
||||||
): Promise<RankingResult> {
|
): Promise<RankingResult> {
|
||||||
|
// Fetch the round config to find the boolean criterion ID (legacy fallback)
|
||||||
|
const round = await prisma.round.findUniqueOrThrow({
|
||||||
|
where: { id: roundId },
|
||||||
|
select: { configJson: true },
|
||||||
|
})
|
||||||
|
const boolCriterionId = findBooleanCriterionId(round.configJson as Record<string, unknown> | null)
|
||||||
|
|
||||||
// Query submitted evaluations grouped by projectId for this category
|
// Query submitted evaluations grouped by projectId for this category
|
||||||
const assignments = await prisma.assignment.findMany({
|
const assignments = await prisma.assignment.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -395,7 +438,7 @@ export async function fetchAndRankCategory(
|
|||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
evaluation: {
|
evaluation: {
|
||||||
select: { globalScore: true, binaryDecision: true },
|
select: { globalScore: true, binaryDecision: true, criterionScoresJson: true },
|
||||||
},
|
},
|
||||||
project: {
|
project: {
|
||||||
select: { id: true, competitionCategory: true },
|
select: { id: true, competitionCategory: true },
|
||||||
@@ -403,12 +446,17 @@ export async function fetchAndRankCategory(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Group by projectId
|
// Group by projectId, resolving binaryDecision from column or criterionScoresJson fallback
|
||||||
const byProject = new Map<string, Array<{ globalScore: number | null; binaryDecision: boolean | null }>>()
|
const byProject = new Map<string, Array<{ globalScore: number | null; resolvedDecision: boolean | null }>>()
|
||||||
for (const a of assignments) {
|
for (const a of assignments) {
|
||||||
if (!a.evaluation) continue
|
if (!a.evaluation) continue
|
||||||
|
const resolved = resolveBinaryDecision(
|
||||||
|
a.evaluation.binaryDecision,
|
||||||
|
a.evaluation.criterionScoresJson as Record<string, unknown> | null,
|
||||||
|
boolCriterionId,
|
||||||
|
)
|
||||||
const list = byProject.get(a.project.id) ?? []
|
const list = byProject.get(a.project.id) ?? []
|
||||||
list.push({ globalScore: a.evaluation.globalScore, binaryDecision: a.evaluation.binaryDecision })
|
list.push({ globalScore: a.evaluation.globalScore, resolvedDecision: resolved })
|
||||||
byProject.set(a.project.id, list)
|
byProject.set(a.project.id, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user