Skip to content

Commit

Permalink
Get event id from the data instead of heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-maltsev committed Aug 3, 2024
1 parent 04c7349 commit aed90c2
Showing 1 changed file with 6 additions and 52 deletions.
58 changes: 6 additions & 52 deletions courses_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ def get_course_schedule(year: int, semester: int, course_number: str):
)
staff = staff.rstrip("\n")

event_id = raw_schedule_item["Otjid"]
if not event_id.startswith("E "):
raise RuntimeError(f"Invalid event id: {event_id}")
event_id = int(event_id.removeprefix("E "))

date_and_time_list = raw_schedule_item["ScheduleSummary"]
if date_and_time_list != raw_schedule_item["ScheduleText"]:
raise RuntimeError(
Expand Down Expand Up @@ -301,63 +306,12 @@ def get_course_schedule(year: int, semester: int, course_number: str):
"בניין": building,
"חדר": room,
"מרצה/מתרגל": staff,
"מס.": event_id,
}

if result_item not in result:
result.append(result_item)

has_lecture_mix = (
len(
set(x["קבוצה"] for x in result if x["סוג"] == "הרצאה")
& set(x["קבוצה"] for x in result if x["סוג"] != "הרצאה")
)
> 0
)

lectures_by_id = {}
for item in result:
if item["סוג"] != "הרצאה" or not has_lecture_mix:
item["מס."] = item["קבוצה"]
continue

item["מס."] = (item["קבוצה"] // 10) * 10
lectures_by_id.setdefault(item["מס."], []).append(item)

# Make sure each lecture of same id matches in all groups, and fill missing
# data.
for item in result:
if item["סוג"] != "הרצאה" or not has_lecture_mix:
continue

lectures_same_id = lectures_by_id[item["מס."]]
lectures_groups = set(x["קבוצה"] for x in lectures_same_id)
lectures_same_date_time = [
x
for x in lectures_same_id
if x["יום"] == item["יום"] and x["שעה"] == item["שעה"]
]

if len(lectures_groups) != len(lectures_same_date_time):
raise RuntimeError(
f"Invalid number of matched lectures: {len(lectures_groups)} !="
f" {len(lectures_same_date_time)}"
)

for lecture in lectures_same_date_time:
if item.keys() != lecture.keys():
raise RuntimeError(f"Invalid keys: {item.keys()} != {lecture.keys()}")

for key in item.keys() - {"מס.", "קבוצה", "סוג", "יום", "שעה"}:
if item[key] == lecture[key] or not lecture[key]:
continue

if not item[key]:
# Copy missing value.
item[key] = lecture[key]
continue

raise RuntimeError(f"Invalid value: {item[key]} != {lecture[key]}")

return result


Expand Down

0 comments on commit aed90c2

Please sign in to comment.