Conversation
tyu012
left a comment
There was a problem hiding this comment.
I am leaving some comments that might want to be addressed.
backend/src/utils/Scheduler.ts
Outdated
| console.warn("This event does not have end time, eventId: " + event.id); | ||
| continue; | ||
| } | ||
| total_events_duration_for_a_deadline += UserPreferenceUtils.dateToMinuteNumber(event.end_time) - UserPreferenceUtils.dateToMinuteNumber(event.start_time); |
There was a problem hiding this comment.
We can just perform this operation with the Date objects: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#calculating_elapsed_time
This would resolve the edge case of whether an event spans across midnight.
There was a problem hiding this comment.
Also, remember to use camel case in TypeScript
backend/src/utils/Scheduler.ts
Outdated
| const dayEnd = userPreferences.endTime; | ||
| const minIncrement = 5; | ||
|
|
||
| while (UserPreferenceUtils.dateToMinuteNumber(checkTime) <= dayEnd) { |
backend/src/utils/Scheduler.ts
Outdated
| currentMinutes >= userPreferences.startTime && | ||
| currentMinutes + userPreferences.workDuration <= userPreferences.endTime | ||
| ); | ||
| currentMinutes + userPreferences.workDuration <= userPreferences.endTime; |
There was a problem hiding this comment.
I am not sure if we need to add workDuration. Maybe a minimum work duration of 5 minutes instead as a workaround?
There was a problem hiding this comment.
then we are not considering the work duration at all. i guess we can do + min(workDuration, projected_duration)
There was a problem hiding this comment.
Changed to the following:
const isWithinWorkHours =
currentMinutes >= userPreferences.startTime &&
currentMinutes <= userPreferences.endTime;
backend/src/utils/Scheduler.ts
Outdated
| event && | ||
| (event.start_time == undefined || | ||
| event.end_time == undefined || | ||
| (event.start_time <= time && event.end_time > time)) |
There was a problem hiding this comment.
If start time or end time is undefined, I think that we should exclude the event from the events at a given time.
There was a problem hiding this comment.
I might have written this wrong when I initially wrote this.
| ); | ||
| } | ||
|
|
||
| return dayEnd - currentMinutes; |
There was a problem hiding this comment.
In general about this function, this is not filtering by events that occur within the current day first.
backend/src/utils/Scheduler.ts
Outdated
| * @param deadlineId A deadline_id to match to event | ||
| * @private | ||
| */ | ||
| private static getEventByDeadlineId(events: UserEvent[], deadlineId: string) { |
There was a problem hiding this comment.
Can specify return type now
There was a problem hiding this comment.
Also, functions can be renamed getEventsByDeadlineId with events being plural since we are returning multiple events.
backend/src/utils/Scheduler.ts
Outdated
| const freeBlock = this.nextFreeTimeBlock([...events, ...scheduledEvents], userPreferences, currentTime); | ||
|
|
||
| // No available block left today | ||
| if (!freeBlock) break; |
There was a problem hiding this comment.
We should probably try again at the next day (if the deadline is not due by then).
There was a problem hiding this comment.
We didn't ask which work day users prefer, so should we default to M-F or 7 days a week (the latter is more useful for college students in my opinion)
| userPreferences: UserPreferences | ||
| ): SchedulerOutput { | ||
| const scheduledEvents: UserEvent[] = []; | ||
| const deadlineRemainders = this.calculateDeadlineRemainders(events, deadlines); |
There was a problem hiding this comment.
Sorting by priority may be useful
There was a problem hiding this comment.
oh true i forgot to consider that field completely
There was a problem hiding this comment.
I will leave this as a to-do since priority is a string
tyu012
left a comment
There was a problem hiding this comment.
I have implemented most of the commented changes; I will approve the PR.
| userPreferences: UserPreferences | ||
| ): SchedulerOutput { | ||
| const scheduledEvents: UserEvent[] = []; | ||
| const deadlineRemainders = this.calculateDeadlineRemainders(events, deadlines); |
There was a problem hiding this comment.
I will leave this as a to-do since priority is a string
backend/src/utils/Scheduler.ts
Outdated
| currentMinutes >= userPreferences.startTime && | ||
| currentMinutes + userPreferences.workDuration <= userPreferences.endTime | ||
| ); | ||
| currentMinutes + userPreferences.workDuration <= userPreferences.endTime; |
There was a problem hiding this comment.
Changed to the following:
const isWithinWorkHours =
currentMinutes >= userPreferences.startTime &&
currentMinutes <= userPreferences.endTime;|
I have implemented most of the commented changes; I will approve the PR. |
Non-breaking changes, can be merged into dev then keep working on scheduling logic.