Commit 504f2279 authored by Jack Otto's avatar Jack Otto
Browse files

11/18/21 random changes I have leftover

parent 2e9041f2
...@@ -7,6 +7,7 @@ from googleapiclient import errors ...@@ -7,6 +7,7 @@ from googleapiclient import errors
from .schedule_objects import Course, Room, Professor from .schedule_objects import Course, Room, Professor
class Schedule: class Schedule:
def __init__(self, courses, rooms, profs, days, hours): def __init__(self, courses, rooms, profs, days, hours):
self.model = cp_model.CpModel() self.model = cp_model.CpModel()
...@@ -20,12 +21,13 @@ class Schedule: ...@@ -20,12 +21,13 @@ class Schedule:
for n in self.courses: for n in self.courses:
for day in self.days: for day in self.days:
for hour in ['10', '11', '12', '14', '15', '09', '08', '16', '13']: ## This is the ideal arrangement of hours for hour in ['10', '11', '12', '14', '15', '09', '08', '16',
'13']: ## This is the ideal arrangement of hours
for c in self.rooms: for c in self.rooms:
for p in self.profs: for p in self.profs:
self.scheduled_classes[(n, c, p, day, hour)] = self.model.NewBoolVar( self.scheduled_classes[(n, c, p, day, hour)] = self.model.NewBoolVar(
f'{n}_{c}_{p}_{day}_{hour}') f'{n}_{c}_{p}_{day}_{hour}')
self.initialize_constraints() self.initialize_constraints()
def initialize_constraints(self): def initialize_constraints(self):
...@@ -227,20 +229,19 @@ class Schedule: ...@@ -227,20 +229,19 @@ class Schedule:
for p in self.profs: for p in self.profs:
if self.solver.Value(self.scheduled_classes[(n, c, p, d, h)]) == 1: if self.solver.Value(self.scheduled_classes[(n, c, p, d, h)]) == 1:
print(f'{n} is taught with {p} in {c} on {d} at {h}') print(f'{n} is taught with {p} in {c} on {d} at {h}')
self.create_event(n,c,p,d,h) # Create GCAL events
self.create_event(n, c, p, d, h) # Create GCAL events
## TODO Manually add these events ## TODO Manually add these events
#final_schedule.append(ScheduleObject(Course("MECH 402C 10", 20, "", 2, ["Th"], 4), Room("DANA115", 20, "", []), Professor("Senior Design Profs", 0, []), "Th", "13")) # final_schedule.append(ScheduleObject(Course("MECH 402C 10", 20, "", 2, ["Th"], 4), Room("DANA115", 20, "", []), Professor("Senior Design Profs", 0, []), "Th", "13"))
#final_schedule.append(ScheduleObject(Course("MECH 402C 11", 20, "", 2, ["Th"], 4), Room("DANA137", 20, "", []), Professor("Senior Design Profs", 0, []), "Th", "13")) # final_schedule.append(ScheduleObject(Course("MECH 402C 11", 20, "", 2, ["Th"], 4), Room("DANA137", 20, "", []), Professor("Senior Design Profs", 0, []), "Th", "13"))
def create_event(self, n, c, p, d, h): def create_event(self, n, c, p, d, h):
# creates an event that lasts the length of the class # creates an event that lasts the length of the class
service = get_calendar_service() service = get_calendar_service()
dt_now = datetime.now().date() dt_now = datetime.now().date()
dayOffset=0 dayOffset = 0
if d == "Mo": if d == "Mo":
dayOffset = 0 dayOffset = 0
elif d == "Tu": elif d == "Tu":
...@@ -253,7 +254,7 @@ class Schedule: ...@@ -253,7 +254,7 @@ class Schedule:
dayOffset = 4 dayOffset = 4
# using 11/1/21 as the date to start the calendar on because 11/1/21 is a monday and thus can use the days the class is taught on to determine the day offset # using 11/1/21 as the date to start the calendar on because 11/1/21 is a monday and thus can use the days the class is taught on to determine the day offset
setTime = datetime(dt_now.year, 11, 1+dayOffset, int(h)) setTime = datetime(dt_now.year, 11, 1 + dayOffset, int(h))
start = setTime.isoformat() start = setTime.isoformat()
end = (setTime + timedelta(hours=n.length)).isoformat() end = (setTime + timedelta(hours=n.length)).isoformat()
...@@ -267,7 +268,7 @@ class Schedule: ...@@ -267,7 +268,7 @@ class Schedule:
} }
).execute() ).execute()
#write the id to a file to save it # write the id to a file to save it
with open("./backend/scheduler/eventID.txt", 'a') as file: with open("./backend/scheduler/eventID.txt", 'a') as file:
file.write(event_result['id']) file.write(event_result['id'])
file.write("\n") file.write("\n")
...@@ -300,11 +301,11 @@ class Schedule: ...@@ -300,11 +301,11 @@ class Schedule:
for n in self.courses: for n in self.courses:
if n.name == name: if n.name == name:
return n return n
for c in self.rooms: for c in self.rooms:
if c.name == name: if c.name == name:
return c return c
for p in self.profs: for p in self.profs:
if p.name == name: if p.name == name:
return p return p
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment