-
Notifications
You must be signed in to change notification settings - Fork 2
Fix/judge redistribution #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fe249d7
ff8dfd8
e4307c6
be0cd95
713ea5e
b961928
0d1e82b
d96eda6
177a558
d13b25d
aa1cf17
6652219
000482a
c79a9a4
02d3e2d
8839f35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import JudgeToTeam from '@typeDefs/judgeToTeam'; | ||
| import { getDatabase } from '@utils/mongodb/mongoClient.mjs'; | ||
| import { HttpError } from '@utils/response/Errors'; | ||
| import Submission from '@typeDefs/submission'; | ||
| import { ObjectId, Db } from 'mongodb'; | ||
|
|
||
| type MongoSubmission = Omit<Submission, 'judge_id' | 'team_id'> & { | ||
| judge_id: ObjectId; | ||
| team_id: ObjectId; | ||
| }; | ||
|
|
||
| export const GetJudgeToTeamPairings = async () => { | ||
| try { | ||
| const db = (await getDatabase()) as Db; | ||
| const submissions = await db | ||
| .collection<MongoSubmission>('submissions') | ||
| .find() | ||
| .toArray(); | ||
| const pairings = submissions.map((submission) => ({ | ||
| judge_id: String(submission.judge_id), | ||
| team_id: String(submission.team_id), | ||
| })); | ||
| return { ok: true, body: pairings as JudgeToTeam[], error: null }; | ||
| } catch (e) { | ||
| const error = e as HttpError; | ||
| return { ok: false, body: null, error: error.message }; | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { optedHDTracks, nonHDTracks } from '@data/tracks'; | |
|
|
||
| import { GetManyUsers } from '@datalib/users/getUser'; | ||
| import { GetManyTeams } from '@datalib/teams/getTeam'; | ||
| import { GetJudgeToTeamPairings } from '@datalib/judgeToTeam/getJudgeToTeamPairings'; | ||
|
|
||
| interface Judge { | ||
| user: User; | ||
|
|
@@ -66,7 +67,7 @@ export default async function matchAllTeams(options?: { alpha?: number }) { | |
| const teamMatchQualities: { [teamId: string]: number[] } = {}; | ||
| const teamJudgeDomainTypes: { [teamId: string]: string[] } = {}; | ||
|
|
||
| const rounds = 3; | ||
| const rounds = 2; | ||
| const ALPHA = options?.alpha ?? 4; | ||
| // Fetch all checked in judges. | ||
| const judgesResponse = await GetManyUsers({ | ||
|
|
@@ -157,6 +158,18 @@ export default async function matchAllTeams(options?: { alpha?: number }) { | |
| .filter((team) => team.tracks.length < rounds) | ||
| .map((team) => [team._id ?? '', rounds - team.tracks.length]) | ||
| ); | ||
|
|
||
| // Get previous pairings and push it to the judgeToTeam array (so that !duplicateExists is true) | ||
| const previousPairings = await GetJudgeToTeamPairings(); | ||
| if (!previousPairings.ok || !previousPairings.body) { | ||
| throw new Error( | ||
| `Failed to load existing judge-to-team pairings: ${ | ||
| previousPairings.error ?? 'Unknown error' | ||
| }` | ||
| ); | ||
| } | ||
| judgeToTeam.push(...previousPairings.body); | ||
|
|
||
| // Main loop: process each team for each round. | ||
| for (let domainIndex = 0; domainIndex < rounds; domainIndex++) { | ||
| for (const team of modifiedTeams) { | ||
|
|
@@ -170,8 +183,8 @@ export default async function matchAllTeams(options?: { alpha?: number }) { | |
| for (const judge of judgesQueue) { | ||
| const duplicateExists = judgeToTeam.some( | ||
| (entry) => | ||
| entry.judge_id === judge.user._id?.toString() && | ||
| entry.team_id === team._id?.toString() | ||
| String(entry.judge_id) === judge.user._id?.toString() && | ||
| String(entry.team_id) === team._id?.toString() | ||
| ); | ||
|
Comment on lines
+186
to
188
|
||
| if (!duplicateExists) { | ||
| selectedJudge = judge; | ||
|
|
@@ -212,6 +225,11 @@ export default async function matchAllTeams(options?: { alpha?: number }) { | |
| shuffleArray(modifiedTeams); | ||
| } | ||
|
|
||
| // Remove the previous pairings | ||
| if (previousPairings.ok && previousPairings.body) { | ||
| judgeToTeam.splice(0, previousPairings.body.length); | ||
| } | ||
|
|
||
| console.log('No. of judgeToTeam:', judgeToTeam.length); | ||
|
|
||
| const judgeAssignments = judgesQueue.map((judge) => judge.teamsAssigned); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.