Skip to content
Snippets Groups Projects
Commit e2a05ac1 authored by Millian Poquet's avatar Millian Poquet
Browse files

code: add course types & improve debuggability

parent a343591f
Branches
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ import re ...@@ -11,7 +11,7 @@ import re
from . import fetch from . import fetch
ROOM_RE = re.compile(r'^(?:FSI|F2SMH) / (.*)$') ROOM_RE = re.compile(r'^(?:FSI|F2SMH) / (.*)$')
COURSE_TYPE_RE = re.compile(r'COURS|COURS/TD|TD|TP|CONTROLE CONTINU|CONTROLE PARTIEL') COURSE_TYPE_RE = re.compile(r'COURS|COURS/TD|TD|TP|CONTROLE CONTINU|CONTROLE PARTIEL|EXAMEN|Controle de Substitution|CONSULTATION DE COPIES')
STUDENT_GROUP_RE = re.compile(r'K?IN[A-Z0-9]+') STUDENT_GROUP_RE = re.compile(r'K?IN[A-Z0-9]+')
class CelcatEvents: class CelcatEvents:
...@@ -98,47 +98,52 @@ def parse_description(row): ...@@ -98,47 +98,52 @@ def parse_description(row):
groups = [] groups = []
course_type = 'unset' course_type = 'unset'
if len(fields) == 0: try:
raise ValueError(f'There should be at least 1 field, but fields are {fields}') if len(fields) == 0:
elif len(fields) == 1: raise ValueError(f'There should be at least 1 field, but fields are {fields}')
# probably not a course. examples: "CONGES\r\n" or "FERIE\r\n" elif len(fields) == 1:
course_type = fields[0] # probably not a course. examples: "CONGES\r\n" or "FERIE\r\n"
else: course_type = fields[0]
# first fields should be the room, but this is not always set else:
while (m := ROOM_RE.match(fields[0])) is not None: # first fields should be the room, but this is not always set
rooms.append(m[1]) while (m := ROOM_RE.match(fields[0])) is not None:
rooms.append(m[1])
fields = fields[1:]
# assume that the next field is the course name, and skip it
fields = fields[1:] fields = fields[1:]
# assume that the next field is the course name, and skip it # skip notes at the end of the fields until they look like a course type
fields = fields[1:] while COURSE_TYPE_RE.match(fields[-1]) is None:
fields = fields[:-1]
if len(fields) <= 0:
break
# skip notes at the end of the fields until they look like a course type # last field is a course type
while COURSE_TYPE_RE.match(fields[-1]) is None: course_type = fields[-1]
fields = fields[:-1] fields = fields[:-1]
if len(fields) <= 0:
break
# last field is a course type # the last field may be a teacher, but this is optional
course_type = fields[-1] if STUDENT_GROUP_RE.match(fields[-1]) is None:
fields = fields[:-1] teacher = fields[-1]
fields = fields[:-1]
# the last field may be a teacher, but this is optional # all remaining fields should be student groups
if STUDENT_GROUP_RE.match(fields[-1]) is None: groups = []
teacher = fields[-1] while len(fields) > 0 and (m := STUDENT_GROUP_RE.match(fields[0])) is not None:
fields = fields[:-1] groups.append(m[0])
fields = fields[1:]
# all remaining fields should be student groups if len(rooms) == 0:
groups = [] rooms = ['unset']
while len(fields) > 0 and (m := STUDENT_GROUP_RE.match(fields[0])) is not None: if len(groups) == 0:
groups.append(m[0]) groups = ['unset']
fields = fields[1:]
if len(rooms) == 0: return pd.Series([rooms, teacher, course_type, groups], index=['rooms_parsed', 'teacher_parsed', 'course_type_parsed', 'groups_parsed'])
rooms = ['unset'] except Exception as e:
if len(groups) == 0: print(f"Could not parse an event description. fields={preparse_fields}")
groups = ['unset'] raise e
return pd.Series([rooms, teacher, course_type, groups], index=['rooms_parsed', 'teacher_parsed', 'course_type_parsed', 'groups_parsed'])
def request_slots_by_mod_code(flat_slot_df, session): def request_slots_by_mod_code(flat_slot_df, session):
subject_codes = list(flat_slot_df['mod_code'].dropna().unique()) subject_codes = list(flat_slot_df['mod_code'].dropna().unique())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment