Round system redesign: Phases 1-7 complete
Full pipeline/track/stage architecture replacing the legacy round system. Schema: 11 new models (Pipeline, Track, Stage, StageTransition, ProjectStageState, RoutingRule, Cohort, CohortProject, LiveProgressCursor, OverrideAction, AudienceVoter) + 8 new enums. Backend: 9 new routers (pipeline, stage, routing, stageFiltering, stageAssignment, cohort, live, decision, award) + 6 new services (stage-engine, routing-engine, stage-filtering, stage-assignment, stage-notifications, live-control). Frontend: Pipeline wizard (17 components), jury stage pages (7), applicant pipeline pages (3), public stage pages (2), admin pipeline pages (5), shared stage components (3), SSE route, live hook. Phase 6 refit: 23 routers/services migrated from roundId to stageId, all frontend components refitted. Deleted round.ts (985 lines), roundTemplate.ts, round-helpers.ts, round-settings.ts, round-type-settings.tsx, 10 legacy admin pages, 7 legacy jury pages, 3 legacy dialogs. Phase 7 validation: 36 tests (10 unit + 8 integration files) all passing, TypeScript 0 errors, Next.js build succeeds, 13 integrity checks, legacy symbol sweep clean, auto-seed on first Docker startup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -273,17 +273,22 @@ export function calculateAvailabilityPenalty(
|
||||
* Get smart assignment suggestions for a round
|
||||
*/
|
||||
export async function getSmartSuggestions(options: {
|
||||
roundId: string
|
||||
stageId: string
|
||||
type: 'jury' | 'mentor'
|
||||
limit?: number
|
||||
aiMaxPerJudge?: number
|
||||
}): Promise<AssignmentScore[]> {
|
||||
const { roundId, type, limit = 50, aiMaxPerJudge = 20 } = options
|
||||
const { stageId, type, limit = 50, aiMaxPerJudge = 20 } = options
|
||||
|
||||
const projectStageStates = await prisma.projectStageState.findMany({
|
||||
where: { stageId },
|
||||
select: { projectId: true },
|
||||
})
|
||||
const projectIds = projectStageStates.map((pss) => pss.projectId)
|
||||
|
||||
// Get projects in round with their tags and description
|
||||
const projects = await prisma.project.findMany({
|
||||
where: {
|
||||
roundId,
|
||||
id: { in: projectIds },
|
||||
status: { not: 'REJECTED' },
|
||||
},
|
||||
select: {
|
||||
@@ -303,7 +308,6 @@ export async function getSmartSuggestions(options: {
|
||||
return []
|
||||
}
|
||||
|
||||
// Get users of the appropriate role with bio for matching
|
||||
const role = type === 'jury' ? 'JURY_MEMBER' : 'MENTOR'
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
@@ -323,7 +327,7 @@ export async function getSmartSuggestions(options: {
|
||||
_count: {
|
||||
select: {
|
||||
assignments: {
|
||||
where: { roundId },
|
||||
where: { stageId },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -334,26 +338,21 @@ export async function getSmartSuggestions(options: {
|
||||
return []
|
||||
}
|
||||
|
||||
// Get round voting window for availability checking
|
||||
const roundForAvailability = await prisma.round.findUnique({
|
||||
where: { id: roundId },
|
||||
select: { votingStartAt: true, votingEndAt: true },
|
||||
const stageForAvailability = await prisma.stage.findUnique({
|
||||
where: { id: stageId },
|
||||
select: { windowOpenAt: true, windowCloseAt: true },
|
||||
})
|
||||
|
||||
// Get existing assignments to avoid duplicates
|
||||
const existingAssignments = await prisma.assignment.findMany({
|
||||
where: { roundId },
|
||||
where: { stageId },
|
||||
select: { userId: true, projectId: true },
|
||||
})
|
||||
const assignedPairs = new Set(
|
||||
existingAssignments.map((a) => `${a.userId}:${a.projectId}`)
|
||||
)
|
||||
|
||||
// ── Batch-query data for new scoring factors ──────────────────────────────
|
||||
|
||||
// 1. Geographic diversity: per-juror country distribution for existing assignments
|
||||
const assignmentsWithCountry = await prisma.assignment.findMany({
|
||||
where: { roundId },
|
||||
where: { stageId },
|
||||
select: {
|
||||
userId: true,
|
||||
project: { select: { country: true } },
|
||||
@@ -373,32 +372,38 @@ export async function getSmartSuggestions(options: {
|
||||
countryMap.set(country, (countryMap.get(country) || 0) + 1)
|
||||
}
|
||||
|
||||
// 2. Previous round familiarity: find assignments in earlier rounds of the same program
|
||||
const currentRound = await prisma.round.findUnique({
|
||||
where: { id: roundId },
|
||||
select: { programId: true, sortOrder: true },
|
||||
const currentStage = await prisma.stage.findUnique({
|
||||
where: { id: stageId },
|
||||
select: { trackId: true, sortOrder: true },
|
||||
})
|
||||
|
||||
const previousRoundAssignmentPairs = new Set<string>()
|
||||
if (currentRound) {
|
||||
const previousAssignments = await prisma.assignment.findMany({
|
||||
const previousStageAssignmentPairs = new Set<string>()
|
||||
if (currentStage) {
|
||||
const earlierStages = await prisma.stage.findMany({
|
||||
where: {
|
||||
round: {
|
||||
programId: currentRound.programId,
|
||||
sortOrder: { lt: currentRound.sortOrder },
|
||||
},
|
||||
trackId: currentStage.trackId,
|
||||
sortOrder: { lt: currentStage.sortOrder },
|
||||
},
|
||||
select: { userId: true, projectId: true },
|
||||
select: { id: true },
|
||||
})
|
||||
for (const pa of previousAssignments) {
|
||||
previousRoundAssignmentPairs.add(`${pa.userId}:${pa.projectId}`)
|
||||
const earlierStageIds = earlierStages.map((s) => s.id)
|
||||
|
||||
if (earlierStageIds.length > 0) {
|
||||
const previousAssignments = await prisma.assignment.findMany({
|
||||
where: {
|
||||
stageId: { in: earlierStageIds },
|
||||
},
|
||||
select: { userId: true, projectId: true },
|
||||
})
|
||||
for (const pa of previousAssignments) {
|
||||
previousStageAssignmentPairs.add(`${pa.userId}:${pa.projectId}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. COI declarations: all active conflicts for this round
|
||||
const coiRecords = await prisma.conflictOfInterest.findMany({
|
||||
where: {
|
||||
roundId,
|
||||
assignment: { stageId },
|
||||
hasConflict: true,
|
||||
},
|
||||
select: { userId: true, projectId: true },
|
||||
@@ -464,11 +469,10 @@ export async function getSmartSuggestions(options: {
|
||||
? calculateCountryMatchScore(user.country, project.country)
|
||||
: 0
|
||||
|
||||
// Availability check against the round's voting window
|
||||
const availabilityPenalty = calculateAvailabilityPenalty(
|
||||
user.availabilityJson,
|
||||
roundForAvailability?.votingStartAt,
|
||||
roundForAvailability?.votingEndAt
|
||||
stageForAvailability?.windowOpenAt,
|
||||
stageForAvailability?.windowCloseAt
|
||||
)
|
||||
|
||||
// ── New scoring factors ─────────────────────────────────────────────
|
||||
@@ -486,9 +490,8 @@ export async function getSmartSuggestions(options: {
|
||||
}
|
||||
}
|
||||
|
||||
// Previous round familiarity bonus
|
||||
let previousRoundFamiliarity = 0
|
||||
if (previousRoundAssignmentPairs.has(pairKey)) {
|
||||
if (previousStageAssignmentPairs.has(pairKey)) {
|
||||
previousRoundFamiliarity = PREVIOUS_ROUND_FAMILIARITY_BONUS
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user