2020-10-26 01:28:07 +01:00
|
|
|
from enums.platforms import Platforms
|
2020-10-26 00:31:21 +01:00
|
|
|
from functions.timeFormatters import timeFromInt
|
|
|
|
|
|
|
|
|
2020-10-26 01:28:07 +01:00
|
|
|
# A container class for schedules
|
|
|
|
class Schedule:
|
|
|
|
pass
|
|
|
|
# TODO extra's & special classes
|
|
|
|
|
|
|
|
|
|
|
|
# A container class for courses
|
2020-10-26 00:31:21 +01:00
|
|
|
class Course:
|
|
|
|
# Initialize a course from the dict that the JSON contains
|
|
|
|
def __init__(self, courseInfo: dict):
|
2020-10-26 01:28:07 +01:00
|
|
|
self.courseInfo = courseInfo
|
2020-10-26 00:31:21 +01:00
|
|
|
self.name = courseInfo["course"]
|
|
|
|
|
2020-10-26 01:28:07 +01:00
|
|
|
self.slots = []
|
|
|
|
self.initSlots()
|
|
|
|
|
|
|
|
self.platforms = {}
|
|
|
|
self.initPlatforms()
|
|
|
|
|
|
|
|
def initSlots(self):
|
|
|
|
"""
|
|
|
|
Function that creates Slot instances & adds them to the list
|
|
|
|
"""
|
|
|
|
for slot in self.courseInfo["slots"]:
|
|
|
|
self.slots.append(Slot(self, slot))
|
|
|
|
|
|
|
|
def initPlatforms(self):
|
|
|
|
"""
|
|
|
|
Function that creates Platform instances & adds them into the dict
|
|
|
|
"""
|
|
|
|
for platform in Platforms:
|
|
|
|
if platform["rep"] in self.courseInfo:
|
|
|
|
self.platforms[platform["rep"]] = Platform(platform["name"], self.courseInfo[platform["rep"]])
|
|
|
|
|
|
|
|
def getSlotsOnDay(self, day: str, week: int):
|
|
|
|
"""
|
|
|
|
Function that returns a list of all slots of this course
|
|
|
|
on a given day of the week
|
|
|
|
|
|
|
|
This list then has duplicate days filtered out depending on
|
|
|
|
whether or not there is a special class on this day
|
|
|
|
"""
|
|
|
|
slots = []
|
|
|
|
specials = []
|
|
|
|
|
|
|
|
for slot in self.slots:
|
|
|
|
# Skip slots on other days
|
|
|
|
if slot.day != day:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# TODO check weeks & filter slots down
|
2020-10-26 00:31:21 +01:00
|
|
|
|
2020-10-26 01:28:07 +01:00
|
|
|
if slot.special:
|
|
|
|
specials.append(slot)
|
|
|
|
else:
|
|
|
|
slots.append(slot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO add an is_online field to the JSON to allow toggling
|
|
|
|
# temporary online classes easier
|
2020-10-26 00:31:21 +01:00
|
|
|
# A slot in a course
|
|
|
|
class Slot:
|
2020-10-26 01:28:07 +01:00
|
|
|
def __init__(self, course: Course, slot: dict):
|
|
|
|
self.course = course
|
2020-10-26 00:31:21 +01:00
|
|
|
self.day = slot["time"][0]
|
|
|
|
self.start = timeFromInt(slot["time"][1])
|
|
|
|
self.end = timeFromInt(slot["time"][2])
|
2020-10-26 01:28:07 +01:00
|
|
|
self.canceled = "canceled" in slot # Boolean indicating whether or not this class has been canceled
|
|
|
|
self.special = "weeks" in slot or self.canceled # Boolean indicating if this class is special or generic
|
|
|
|
|
|
|
|
# TODO check if on-campus, else None
|
|
|
|
self.locations = self.setLocations(slot)
|
|
|
|
self.platform = self.course.platforms[slot["online"]]
|
2020-10-26 00:31:21 +01:00
|
|
|
|
2020-10-26 01:28:07 +01:00
|
|
|
def setLocations(self, slot: dict):
|
|
|
|
"""
|
|
|
|
Function that creates a list of Location instances
|
|
|
|
"""
|
2020-10-26 00:31:21 +01:00
|
|
|
locations = []
|
|
|
|
|
|
|
|
# Slot has multiple locations
|
|
|
|
if "locations" in slot:
|
|
|
|
for location in slot["locations"]:
|
|
|
|
locations.append(Location(location))
|
|
|
|
else:
|
|
|
|
# Slot has only one location
|
|
|
|
locations.append(Location(slot))
|
|
|
|
|
|
|
|
return locations
|
|
|
|
|
2020-10-26 01:28:07 +01:00
|
|
|
def getLocations(self):
|
|
|
|
"""
|
|
|
|
Function that creates a string representation for this
|
|
|
|
slot's locations
|
|
|
|
"""
|
|
|
|
if self.locations is None:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def getOnline(self):
|
|
|
|
pass
|
|
|
|
|
2020-10-26 00:31:21 +01:00
|
|
|
|
|
|
|
# A location where a course might take place
|
|
|
|
class Location:
|
|
|
|
def __init__(self, slot: dict):
|
|
|
|
self.campus = slot["campus"]
|
|
|
|
self.building = slot["building"]
|
|
|
|
self.room = slot["room"]
|
|
|
|
|
2020-10-26 01:28:07 +01:00
|
|
|
def __str__(self):
|
|
|
|
return " ".join([self.campus, self.building, self.room])
|
|
|
|
|
2020-10-26 00:31:21 +01:00
|
|
|
|
|
|
|
# A streaming platform
|
|
|
|
class Platform:
|
2020-10-26 01:28:07 +01:00
|
|
|
def __init__(self, name, url):
|
|
|
|
self.name = name
|
|
|
|
self.url = url
|