Skip to content

Commit

Permalink
improved extraction of information from course catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
Highfire1 committed Jun 28, 2024
1 parent 30269ff commit e120491
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,49 @@ def _generateCourseIndexes(self) -> None:
This takes quite a bit of effort to build...
"""

r = None
course_summary_possibly_old = None
statement = select(CourseSummaryDB).where(
CourseSummaryDB.subject == subject,
CourseSummaryDB.course_code == course_code
).order_by(col(CourseSummaryDB.year).desc(), col(CourseSummaryDB.term).desc()).limit(1)
).order_by(col(CourseSummaryDB.year).desc(), col(CourseSummaryDB.term).desc()).limit(5)
results = session.exec(statement)
r = session.exec(statement).first()
r_all = session.exec(statement).all()
if len(r_all) > 0:
r = r_all[0]
if r:
gragh = r.description
r2 = None
# we want to get information from the second most recent
# catalogue, because the most recent one
# will only say "discontinued" and have no info otherwise
i = 1
while gragh and "discontinued" in gragh.lower():
if len(r_all) > i:
r2 = r_all[i]
gragh = r2.description
else:
break
i += 1


c.credits = r.credits
c.title = r.title
c.description = r.description
c.hours_lecture = r.hours_lecture
c.hours_seminar = r.hours_seminar
c.hours_lab = r.hours_lab

course_summary_possibly_old = r

if r.description != None and r.desc_last_updated != None:
c.description = r.description + "\n\n" + r.desc_last_updated

if r2 and r2.description != None:
c.description = c.description + "\n\n" + r2.description

c.desc_replacement_course = r.desc_replacement_course
c.desc_prerequisite = r.desc_requisites


# CoursePage
# We replace the attributes from CourseSummary because
# CourseSummary has information for some discontinued courses
Expand Down Expand Up @@ -416,12 +442,6 @@ def _generateCourseIndexes(self) -> None:
c.preparatory_course = r.preparatory_course
else:
c.active = False
if course_summary_possibly_old != None:
r = course_summary_possibly_old
if r.description != None and r.desc_last_updated != None:
c.description = r.description + "\n\n" + r.desc_last_updated
c.desc_replacement_course = r.desc_replacement_course
c.desc_prerequisite = r.desc_requisites


statement = select(CourseAttributeDB).where(
Expand Down

0 comments on commit e120491

Please sign in to comment.