Skip to content

Commit

Permalink
fix: fixing excluding conflicting courses function
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonNotJson committed Nov 26, 2023
1 parent 35b9194 commit d7744fb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lambda/post-chat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CourseRecommender:
def __init__(self, s3_client, bucket, school_code_map, syllabus_file_template="syllabus/{}.json"):
self.s3_client = s3_client
self.bucket = bucket
self.simplified_timetable = []
self.school_code_map = school_code_map
self.syllabus_file_template = syllabus_file_template
self.day_map = {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 7: 'Sunday'}
Expand Down Expand Up @@ -143,7 +144,17 @@ def filter_courses_by_min_year(self, filtered_courses, most_common_min_year):
return [course for course in filtered_courses if course.get('j') == most_common_min_year]

def exclude_conflicting_courses(self, filtered_courses):
timetable_schedule = {(occurrence.get('d'), occurrence.get('p')) for course in self.timetable_data['courses'] for occurrence in course.get('i', [])}
# Create a set of tuples for each (day, period) in the actual timetable
timetable_schedule = set()
for course_id in self.get_timetable_course_ids():
course = next((c for c in self.courses if c['a'] == course_id), None)
if course:
for occurrence in course.get('i', []):
day = occurrence.get('d')
period = occurrence.get('p')
timetable_schedule.add((day, period))

# Exclude courses that have conflicting days and periods
return [course for course in filtered_courses if not any((occurrence.get('d'), occurrence.get('p')) in timetable_schedule for occurrence in course.get('i', []))]

def create_timetable_with_titles(self):
Expand Down

0 comments on commit d7744fb

Please sign in to comment.