Skip to content

Commit

Permalink
chore: rename subsession to childsession
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiin Kim authored and Jiin Kim committed Feb 6, 2025
1 parent 83ead09 commit 59c094e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
70 changes: 57 additions & 13 deletions app/agents/scrapers/simon_fraser_university.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytz

from .base import BaseScraper
from app.models.course import ProgramModel, CourseModel, SessionModel, CourseListingModel, Day
from app.models.course import ProgramModel, CourseModel, SessionModel, CourseListingModel, Day, ChildSessionModel

class SimonFraserUniversityScraper(BaseScraper):
def __init__(self, task_name: str, logger: logging.Logger):
Expand Down Expand Up @@ -91,21 +91,63 @@ def _resolve_schedule_block(self, block: Dict) -> SessionModel:
raise Exception(f"Failed to parse schedule block: {str(e)}") from e

def _organize_sessions(self, sessions: List[SessionModel]) -> List[SessionModel]:
main_sessions = []
subsessions = []
lecture_sessions = []
child_sessions = []

for session in sessions:
sname = session.get("sessionName", "")
if sname.upper().startswith("LEC"):
main_sessions.append(session)
elif sname.upper().startswith("TUT") or sname.upper().startswith("LAB"):
subsessions.append(session)
session["sessionType"] = "Lecture"
session["childSession"] = [] # Initialize empty child session list
lecture_sessions.append(session)
elif sname.upper().startswith("TUT"):
child_session: ChildSessionModel = {
"childSessionName": session.get("sessionName"),
"childSessionType": "Tutorial",
"campus": session.get("campus"),
"location": session.get("location"),
"schedules": session.get("schedules", [])
}
child_sessions.append(child_session)
elif sname.upper().startswith("LAB"):
child_session: ChildSessionModel = {
"childSessionName": session.get("sessionName"),
"childSessionType": "Laboratory",
"campus": session.get("campus"),
"location": session.get("location"),
"schedules": session.get("schedules", [])
}
child_sessions.append(child_session)
else:
main_sessions.append(session)
if main_sessions and subsessions:
for main in main_sessions:
main["subsessions"] = subsessions
return main_sessions
return sessions
# For other types of sessions (seminars, etc)
session["sessionType"] = "Other"
session["childSession"] = []
lecture_sessions.append(session)

# If we have both lectures and child sessions, attach child sessions to lectures
if lecture_sessions and child_sessions:
for lecture in lecture_sessions:
lecture["childSession"] = child_sessions
return lecture_sessions

# If we only have lectures or other sessions without children
if lecture_sessions:
return lecture_sessions

# If we somehow only have child sessions, convert them to regular sessions
converted_sessions = []
for child in child_sessions:
session: SessionModel = {
"sessionName": child["childSessionName"],
"sessionType": child["childSessionType"],
"professorName": None,
"campus": child["campus"],
"location": child["location"],
"schedules": child["schedules"],
"childSession": []
}
converted_sessions.append(session)
return converted_sessions

async def fetch_courses(self) -> CourseListingModel:
year = datetime.now().year
Expand Down Expand Up @@ -151,10 +193,12 @@ async def fetch_courses(self) -> CourseListingModel:
continue
current_session: SessionModel = {
"sessionName": f"{section.get('sectionCode', '')} {section.get('text', '')}".strip(),
"sessionType": None, # Will be set in _organize_sessions
"professorName": None,
"campus": None,
"location": None,
"schedules": []
"schedules": [],
"childSession": [] # Initialize empty child session list
}
schedule_blocks = detail.get('courseSchedule', [])
instructors = detail.get('instructor', [])
Expand Down
4 changes: 2 additions & 2 deletions app/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ChildSessionModel(TypedDict):
schedules: List[ScheduleModel]

class SessionModel(TypedDict):
sessionName: Optional[str]
professorName: Optional[str] # e.g. "John Doe"
sessionName: Optional[str] # e.g. LEC, TUT, SEM, etc
sessionType: Optional[str]
campus: Optional[str]
location: Optional[str]
Expand All @@ -33,7 +34,6 @@ class SessionModel(TypedDict):
class CourseModel(TypedDict):
courseName: Optional[str] # e.g. "Operating Systems"
courseCode: Optional[str] # e.g. "CMPT 300 D100"
professorName: Optional[str] # e.g. "John Doe"
credit: Optional[float] # Changed from Optional[int] to Optional[float]
sessions: List[SessionModel]

Expand Down

0 comments on commit 59c094e

Please sign in to comment.