Skip to content

Commit

Permalink
Optimize Path Sync and Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shiva-menta committed Nov 11, 2024
1 parent 4f62930 commit 772e6b8
Show file tree
Hide file tree
Showing 6 changed files with 1,854 additions and 1,663 deletions.
2 changes: 2 additions & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ python-dateutil = "*"
docutils = "*"
ics = "*"
drf-nested-routers = "*"
asyncio = "*"
aiohttp = "*"

[requires]
python_full_version = "3.11"
3,120 changes: 1,637 additions & 1,483 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

43 changes: 21 additions & 22 deletions backend/courses/management/commands/loadstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
)


def set_all_status(semester=None, add_status_update=False):
def set_all_status(semester=None, add_status_update=False, verbose=False):
if semester is None:
semester = get_current_semester()
print(semester)
statuses = registrar.get_all_course_status(semester)
if not statuses:
return
Expand All @@ -39,39 +38,36 @@ def set_all_status(semester=None, add_status_update=False):
if any(course_term.endswith(s) for s in ["10", "20", "30"]):
course_term = translate_semester_inv(course_term)

# Ignore sections not in db
try:
_, section = get_course_and_section(section_code, semester)
except (Section.DoesNotExist, Course.DoesNotExist):
continue

# Resync database (doesn't need to be atomic)
last_status_update = section.last_status_update
current_status = section.status

# 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 last_status_update.new_status != course_status:
if add_status_update and 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)
if verbose:
print(f"{len(statuses_out_of_sync)} statuses were out of sync.")
print(statuses_out_of_sync)

print(f"{len(status_updates_out_of_sync)} status updates were out of sync.")
print(status_updates_out_of_sync)
print(f"{len(status_updates_out_of_sync)} status updates were out of sync.")
print(status_updates_out_of_sync)


class Command(BaseCommand):
Expand All @@ -82,11 +78,14 @@ def add_arguments(self, parser):
parser.add_argument(
"--create-status-updates", action="store_true", help="Create status updates if set"
)
parser.add_argument("--verbose", action="store_true")

def handle(self, *args, **kwargs):
root_logger = logging.getLogger("")
root_logger.setLevel(logging.DEBUG)

set_all_status(
semester=kwargs["semester"], add_status_update=kwargs["create_status_updates"]
semester=kwargs["semester"],
add_status_update=kwargs["create_status_updates"],
verbose=kwargs["verbose"],
)
157 changes: 0 additions & 157 deletions backend/courses/management/commands/pathopendata.py

This file was deleted.

Loading

0 comments on commit 772e6b8

Please sign in to comment.