Skip to content

Commit

Permalink
Fix course names in prereq graph by using catalog names when possible
Browse files Browse the repository at this point in the history
Hello Dr. Cutler!
  • Loading branch information
powe97 authored Mar 15, 2024
1 parent 4953ba4 commit 42142b4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions scrapers/prerequisites_graph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ class CoursePrereqs(TypedDict):
prereqs: List[str]


def sem_add_courses(sem_dir: str, adj_list: Dict[str, CoursePrereqs]):
def sem_add_courses(
sem_dir: str,
adj_list: Dict[str, CoursePrereqs],
most_recent_catalog: Dict[str, Dict],
):
"""
Using the semester in the `sem_dir` directory,
update the graph in `adj_list`.
"""

# Load the JSONs
try:
with open(f"{sem_dir}/catalog.json", "r") as f:
sem_catalog = json.load(f)
with open(f"{sem_dir}/courses.json", "r") as f:
sem_courses = json.load(f)
with open(f"{sem_dir}/prerequisites.json", "r") as f:
Expand All @@ -42,7 +48,10 @@ def sem_add_courses(sem_dir: str, adj_list: Dict[str, CoursePrereqs]):
)

adj_list[course_id] = {
"title": course["title"],
"title": most_recent_catalog.get(
course["id"],
sem_catalog.get(course["id"], {"name": course["title"]}),
)["name"],
"prereqs": prereqs,
}

Expand Down Expand Up @@ -91,8 +100,10 @@ def generate(semester_data_path: str):
)
)

with open(f"{sem_dirs[-1]}/catalog.json", "r") as f:
most_recent_catalog = json.load(f)
for sem_dir in sem_dirs:
sem_add_courses(sem_dir, adj_list)
sem_add_courses(sem_dir, adj_list, most_recent_catalog)

return adj_list

Expand Down

0 comments on commit 42142b4

Please sign in to comment.