-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add dynamic mlh timing #434
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
Changes from all commits
0a0b05e
586bb2a
f74bf7c
c327f67
7c20795
c148df0
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -892,6 +892,15 @@ export const timeSlotRouter = router({ | |||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // MLH slot duration in minutes - must divide evenly into slotDurationMinutes | ||||||||||||||||||||||||||||||||||||
| const MLH_SLOT_MINUTES = 2.5; | ||||||||||||||||||||||||||||||||||||
| if (input.slotDurationMinutes % MLH_SLOT_MINUTES !== 0) { | ||||||||||||||||||||||||||||||||||||
| throw new TRPCError({ | ||||||||||||||||||||||||||||||||||||
| code: "BAD_REQUEST", | ||||||||||||||||||||||||||||||||||||
| message: `slotDurationMinutes (${input.slotDurationMinutes}) must be divisible by MLH slot duration (${MLH_SLOT_MINUTES})`, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+897
to
+902
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modulo operation with a floating point number ( A more robust approach would be to use integer arithmetic:
Suggested change
Alternatively, you could multiply both values by 2 to work with integers: Prompt To Fix With AIThis is a comment left during a code review.
Path: src/server/router/judging.ts
Line: 897:902
Comment:
The modulo operation with a floating point number (`2.5`) can have precision issues in JavaScript due to how floating point arithmetic works. While `10 % 2.5` should equal `0`, floating point precision errors could cause unexpected failures.
A more robust approach would be to use integer arithmetic:
```suggestion
// MLH slot duration in minutes - must divide evenly into slotDurationMinutes
const MLH_SLOT_MINUTES = 2.5;
// Check divisibility using integer arithmetic to avoid floating point precision issues
const slotMillis = input.slotDurationMinutes * 60 * 1000;
const mlhSlotMillis = MLH_SLOT_MINUTES * 60 * 1000;
if (slotMillis % mlhSlotMillis !== 0) {
throw new TRPCError({
code: "BAD_REQUEST",
message: `slotDurationMinutes (${input.slotDurationMinutes}) must be divisible by MLH slot duration (${MLH_SLOT_MINUTES})`,
});
}
```
Alternatively, you could multiply both values by 2 to work with integers: `(input.slotDurationMinutes * 2) % (MLH_SLOT_MINUTES * 2) !== 0`
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Separate MLH and non-MLH tracks | ||||||||||||||||||||||||||||||||||||
| const mlhProjectTracks = allProjectTracks.filter( | ||||||||||||||||||||||||||||||||||||
| (pt) => pt.track.name === "MLH", | ||||||||||||||||||||||||||||||||||||
|
|
@@ -973,7 +982,9 @@ export const timeSlotRouter = router({ | |||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Schedule MLH judging slots | ||||||||||||||||||||||||||||||||||||
| const mlhSlotsToSchedule = Math.floor(input.slotDurationMinutes / 5); | ||||||||||||||||||||||||||||||||||||
| const mlhSlotsToSchedule = Math.floor( | ||||||||||||||||||||||||||||||||||||
| input.slotDurationMinutes / MLH_SLOT_MINUTES, | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| let mlhStartTime = currentTimeChunk; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| for ( | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1002,9 +1013,7 @@ export const timeSlotRouter = router({ | |||||||||||||||||||||||||||||||||||
| projectId: chosenProject.projectId, | ||||||||||||||||||||||||||||||||||||
| startTime: mlhStartTime, | ||||||||||||||||||||||||||||||||||||
| endTime: new Date( | ||||||||||||||||||||||||||||||||||||
| new Date(mlhStartTime).setMinutes( | ||||||||||||||||||||||||||||||||||||
| mlhStartTime.getMinutes() + 5, | ||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||
| mlhStartTime.getTime() + MLH_SLOT_MINUTES * 60 * 1000, | ||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||
| dhYear: dhYearConfig.value, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1036,7 +1045,7 @@ export const timeSlotRouter = router({ | |||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| mlhStartTime = new Date( | ||||||||||||||||||||||||||||||||||||
| new Date(mlhStartTime).setMinutes(mlhStartTime.getMinutes() + 5), | ||||||||||||||||||||||||||||||||||||
| mlhStartTime.getTime() + MLH_SLOT_MINUTES * 60 * 1000, | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| currentTimeChunk = new Date( | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1053,18 +1062,14 @@ export const timeSlotRouter = router({ | |||||||||||||||||||||||||||||||||||
| projectId: mlhProject.projectId, | ||||||||||||||||||||||||||||||||||||
| startTime: currentTimeChunk, | ||||||||||||||||||||||||||||||||||||
| endTime: new Date( | ||||||||||||||||||||||||||||||||||||
| new Date(currentTimeChunk).setMinutes( | ||||||||||||||||||||||||||||||||||||
| currentTimeChunk.getMinutes() + 5, // 5 minute slots for MLH | ||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||
| currentTimeChunk.getTime() + MLH_SLOT_MINUTES * 60 * 1000, | ||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||
| dhYear: dhYearConfig.value, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| currentTimeChunk = new Date( | ||||||||||||||||||||||||||||||||||||
| new Date(currentTimeChunk).setMinutes( | ||||||||||||||||||||||||||||||||||||
| currentTimeChunk.getMinutes() + 5, | ||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||
| currentTimeChunk.getTime() + MLH_SLOT_MINUTES * 60 * 1000, | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the MLH slot duration from 5 minutes to 2.5 minutes, which is a breaking behavior change, not just a refactoring. This means:
slotDurationMinutesof 10, this changes from scheduling 2 MLH projects per time chunk to 4 MLH projects per time chunkThis is a significant logic change that affects the actual judging schedule and should be:
If this change is intentional, it should be clearly communicated in the PR description.
Prompt To Fix With AI