Skip to content

Commit

Permalink
Add logging for lessons with duplicate dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYiJiang committed Jul 15, 2019
1 parent 6c61c5f commit 401def4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scrapers/nus-v2/src/tasks/GetSemesterTimetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ const getLessonKey = (lesson: TimetableLesson) =>
* the range of date and the intervals between lessons
*/
export function mapLessonWeeks(dates: string[], semester: number, logger: Logger): Weeks {
// Sanity check for lessons occurring on duplicate days
if (dates.length !== new Set(dates).size) {
logger.error('Lesson has duplicate dates');
}

const semesterName = SEMESTER_NAMES[semester];
const lessonDates = dates.map((date) => parseISO(date)).sort(compareAsc);
const weekInfo = lessonDates.map(NUSModerator.academicCalendar.getAcadWeekInfo);
Expand Down Expand Up @@ -203,7 +208,11 @@ export default class GetSemesterTimetable extends BaseTask implements Task<Input
// 5. Remove the lesson key inserted in (2) and remap the weeks to their correct shape
values(timetableObject).map((lesson) => ({
...lesson,
weeks: mapLessonWeeks(lesson.weeks, this.semester, this.logger.child({ moduleCode })),
weeks: mapLessonWeeks(
lesson.weeks,
this.semester,
this.logger.child({ moduleCode, lesson }),
),
})),
);
};
Expand Down

0 comments on commit 401def4

Please sign in to comment.