From 4f6293071c96b51a887e6109d537262fa8949f9d Mon Sep 17 00:00:00 2001 From: Shiva Menta Date: Thu, 12 Sep 2024 16:30:49 -0400 Subject: [PATCH] changes --- .../courses/management/commands/loadstatus.py | 25 ++++---- .../management/commands/pathopendata.py | 57 ++++++++++++++----- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/backend/courses/management/commands/loadstatus.py b/backend/courses/management/commands/loadstatus.py index 8880ddd4..4a77061d 100644 --- a/backend/courses/management/commands/loadstatus.py +++ b/backend/courses/management/commands/loadstatus.py @@ -17,6 +17,7 @@ def set_all_status(semester=None, add_status_update=False): if semester is None: semester = get_current_semester() + print(semester) statuses = registrar.get_all_course_status(semester) if not statuses: return @@ -51,20 +52,20 @@ def set_all_status(semester=None, add_status_update=False): # Change status attribute of section model (might want to use bulk update) if current_status != course_status: statuses_out_of_sync.append(section_code) - section.status = course_status - section.save() + # section.status = course_status + # section.save() # Add corresponding status update object - if add_status_update and last_status_update.new_status != course_status: + if last_status_update.new_status != course_status: status_updates_out_of_sync.append(section_code) - record_update( - section, - course_term, - last_status_update.new_status, - course_status, - False, - json.dumps(status), - ) + # record_update( + # section, + # course_term, + # last_status_update.new_status, + # course_status, + # False, + # json.dumps(status), + # ) print(f"{len(statuses_out_of_sync)} statuses were out of sync.") print(statuses_out_of_sync) @@ -86,8 +87,6 @@ def handle(self, *args, **kwargs): root_logger = logging.getLogger("") root_logger.setLevel(logging.DEBUG) - print(f"Create status updates is {kwargs['create_status_updates']}") - set_all_status( semester=kwargs["semester"], add_status_update=kwargs["create_status_updates"] ) diff --git a/backend/courses/management/commands/pathopendata.py b/backend/courses/management/commands/pathopendata.py index 4d34121e..493c02ae 100644 --- a/backend/courses/management/commands/pathopendata.py +++ b/backend/courses/management/commands/pathopendata.py @@ -18,9 +18,6 @@ def status_on_path_at_penn(course_code, path_at_penn_semester="202430"): - # Note: this api is actually unauthenticated as far as I can tell - # so no cookies needed! - headers = { "accept": "application/json, text/javascript, */*; q=0.01", "accept-language": "en-US,en;q=0.9", @@ -60,13 +57,15 @@ def status_on_path_at_penn(course_code, path_at_penn_semester="202430"): def map_opendata_to_path(course_status): return "A" if course_status == "O" else "F" +def map_path_to_opendata(course_status): + return "O" if course_status == "A" else "C" def get_path_code(section_code): parts = section_code.split("-") return f"{parts[0]} {parts[1]}" -def find_diff(semester=None, add_status_update=False): +def resolve_path_differences(semester=None, add_status_update=False): if semester is None: semester = get_current_semester() statuses = registrar.get_all_course_status(semester) @@ -91,9 +90,10 @@ def find_diff(semester=None, add_status_update=False): if course_term != "2024C": continue - course_map[section_code] = map_opendata_to_path(course_status) + course_map[section_code] = course_status out_of_sync = [] + status_updates_out_of_sync = [] visited = set() for section_code in tqdm(course_map): if section_code in visited: @@ -102,20 +102,47 @@ def find_diff(semester=None, add_status_update=False): results = status_on_path_at_penn(path_code) for result in results: + if result in visited: + continue visited.add(result) - path_status = results[result] - if path_status != "A" and path_status != "F": + + try: + _, section = get_course_and_section(result, semester) + except (Section.DoesNotExist, Course.DoesNotExist): continue - section_status = course_map[result] - if path_status != section_status: - out_of_sync.append((result, section_status, path_status)) + # Resync database (doesn't need to be atomic) + last_status_update = section.last_status_update + current_status = section.status - for code, status1, status2 in out_of_sync: - print( - f"{code} is out of sync. OpenData has status {status1} and Path has status {status2}." - ) + path_status = map_path_to_opendata(results[result]) + section_status = course_map[result] + if path_status not in "OC" or section_status not in "OC": + continue + if path_status != current_status: + out_of_sync.append((result, section_status, path_status, last_status_update.new_status, current_status)) + # section.status = path_status + # section.save() + + if last_status_update.new_status != path_status: + status_updates_out_of_sync.append((result, section_status, path_status, last_status_update.new_status, current_status)) + # record_update( + # section, + # "2024C", + # last_status_update.new_status, + # path_status, + # False, + # json.dumps(path_status), + # ) + + print(f"{len(out_of_sync)} statuses were out of sync.") + for line in out_of_sync: + print(line) + + print(f"{len(status_updates_out_of_sync)} status updates were out of sync.") + for line in status_updates_out_of_sync: + print(line) class Command(BaseCommand): help = "Report the difference between OpenData and Path registrations." @@ -127,4 +154,4 @@ def handle(self, *args, **kwargs): root_logger = logging.getLogger("") root_logger.setLevel(logging.DEBUG) - find_diff(semester=kwargs["semester"]) + resolve_path_differences(semester=kwargs["semester"])