Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EECS renumbering #31

Merged
merged 10 commits into from
Apr 30, 2022
8 changes: 8 additions & 0 deletions catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class CourseFields:
enrollment_number = "enrollment_number"
enrollment_number = "enrollment_number"
either_prereq_or_coreq = "either_prereq_or_coreq"
old_id = "old_id"
new_id = "new_id"
public = "public"
creator = "creator"
custom_color = "custom_color"
Expand Down Expand Up @@ -177,6 +179,8 @@ def list_converter(value):
CourseAttribute.averageOutOfClassHours: (CourseFields.out_of_class_hours, float_converter),
CourseAttribute.enrollment: (CourseFields.enrollment_number, float_converter),
CourseAttribute.eitherPrereqOrCoreq: (CourseFields.either_prereq_or_coreq, bool_converter),
CourseAttribute.oldID: (CourseFields.old_id, string_converter),
CourseAttribute.newID: (CourseFields.new_id, string_converter),
CourseAttribute.sourceSemester: (CourseFields.source_semester, string_converter),
CourseAttribute.isHistorical: (CourseFields.is_historical, bool_converter),
CourseAttribute.parent: (CourseFields.parent, string_converter),
Expand Down Expand Up @@ -283,6 +287,10 @@ def get_meets_with_subjects(self):
corequisites = models.TextField(null=True)
either_prereq_or_coreq = models.BooleanField(default=False)

# EECS subject renumbering
old_id = models.TextField(null=True)
new_id = models.TextField(null=True)

gir_attribute = models.CharField(max_length=20, null=True)
communication_requirement = models.CharField(max_length=30, null=True)
hass_attribute = models.CharField(max_length=20, null=True)
Expand Down
39 changes: 39 additions & 0 deletions catalog_parse/catalog_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import sys
import os
import json

from .utils import *

Expand Down Expand Up @@ -52,6 +53,10 @@

ALPHABET = "abcdefghijklmnopqrstuvwxyz"

RENUMBERING_URL = "https://eecsis.mit.edu/numbering.html"

RENUMBERING_DATA = None

# Stores the HTML of the last page retrieved
LAST_PAGE_HTML = None

Expand Down Expand Up @@ -179,6 +184,29 @@ def extract_course_properties(elements):

return info_items

def load_renumbering_data():
"""
Downloads the EECS subject renumbering data, converts it to a Python
object, and stores it in RENUMBERING_DATA unless this has already been
done.
"""
global RENUMBERING_DATA

if RENUMBERING_DATA is not None:
return

page = requests.get(RENUMBERING_URL)
assert page.status_code == 200

content = page.content
_, content = content.split("generatePage([")
content, _ = content.split("])")
content = "[" + content + "]"

RENUMBERING_DATA = json.loads(content)
assert RENUMBERING_DATA is not None
return

### Information Item Processing

def subject_title_regex(subject_id):
Expand Down Expand Up @@ -455,6 +483,17 @@ def courses_from_dept_code(dept_code, **options):
if len(autofill_ids) > 0:
autofill_ids = []

# Add old and new IDs for EECS renumbering
if dept_code[:-1] == "6":
load_renumbering_data()
for course in courses:
id = course[CourseAttribute.subjectID]
for item in RENUMBERING_DATA:
if item["newnum"] == id or item["oldnum"] == id:
course[CourseAttribute.oldID] = item["oldnum"]
course[CourseAttribute.newID] = item["newnum"]
break

return courses

### Writing courses
Expand Down
8 changes: 8 additions & 0 deletions catalog_parse/utils/catalog_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class CourseAttribute:
subjectLevel = "Subject Level"
eitherPrereqOrCoreq = "Prereq or Coreq"

# Renumbering fields
oldID = "Old Subject Id"
newID = "New Subject Id"

# Evaluation fields
averageRating = "Rating"
averageInClassHours = "In-Class Hours"
Expand Down Expand Up @@ -159,6 +163,8 @@ class CourseAttribute:
CourseAttribute.oldPrerequisites,
CourseAttribute.oldCorequisites,
CourseAttribute.eitherPrereqOrCoreq,
CourseAttribute.oldID,
CourseAttribute.newID,
CourseAttribute.description,
CourseAttribute.jointSubjects,
CourseAttribute.meetsWithSubjects,
Expand Down Expand Up @@ -192,6 +198,8 @@ class CourseAttribute:
CourseAttribute.oldPrerequisites,
CourseAttribute.oldCorequisites,
CourseAttribute.eitherPrereqOrCoreq,
CourseAttribute.oldID,
CourseAttribute.newID,
CourseAttribute.jointSubjects,
CourseAttribute.equivalentSubjects,
CourseAttribute.meetsWithSubjects,
Expand Down