forked from maxjdobrei/cuHacking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuScheduling.py
355 lines (292 loc) · 9.27 KB
/
cuScheduling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
from Schedule import *
from Restrictions import *
validSchedules = []
def createSchedules(lecturesFound):
try:
if lecturesFound == "":
return []
except:
if len(lecturesFound) == 0:
return []
tempSchedule = [0,0,0,0,0,0]
for lec in lecturesFound[0]:
tempSchedule.pop(0)
tempSchedule.insert(0, lec)
try:
for lect in lecturesFound[1]:
tempSchedule.pop(1)
tempSchedule.insert(1, lect)
try:
for lectu in lecturesFound[2]:
tempSchedule.pop(2)
tempSchedule.insert(2, lectu)
try:
for lectur in lecturesFound[3]:
tempSchedule.pop(3)
tempSchedule.insert(3, lectur)
try:
for lecture in lecturesFound[4]:
tempSchedule.pop(4)
tempSchedule.insert(4, lecture)
try:
for lectureFinal in lecturesFound[5]:
tempSchedule.pop(5)
tempSchedule.insert(5, lectureFinal)
if scheduleValidator(tempSchedule):
temp = tempSchedule
tutorialVersions = addTutorials(temp)
if len(tutorialVersions) != 0:
for version in tutorialVersions:
temp = Schedule(version)
validSchedules.append(temp)
except:
tempSchedule = removeNull(tempSchedule)
if scheduleValidator(tempSchedule):
temp = tempSchedule
tutorialVersions = addTutorials(temp)
if len(tutorialVersions) != 0:
for version in tutorialVersions:
temp = Schedule(version)
validSchedules.append(temp)
continue
except:
tempSchedule = removeNull(tempSchedule)
if scheduleValidator(tempSchedule):
temp = tempSchedule
tutorialVersions = addTutorials(temp)
if len(tutorialVersions) != 0:
for version in tutorialVersions:
temp = Schedule(version)
validSchedules.append(temp)
continue
except:
tempSchedule = removeNull(tempSchedule)
if scheduleValidator(tempSchedule):
temp = tempSchedule
tutorialVersions = addTutorials(temp)
if len(tutorialVersions) != 0:
for version in tutorialVersions:
temp = Schedule(version)
validSchedules.append(temp)
continue
except:
tempSchedule = removeNull(tempSchedule)
if scheduleValidator(tempSchedule):
tutorialVersions = addTutorials(tempSchedule)
if len(tutorialVersions) != 0:
for version in tutorialVersions:
temp = Schedule(version)
validSchedules.append(temp)
continue
except:
tempSchedule = removeNull(tempSchedule)
if scheduleValidator(tempSchedule):
temp = tempSchedule
tutorialVersions = addTutorials(temp)
if len(tutorialVersions) != 0:
for version in tutorialVersions:
temp = Schedule(version)
validSchedules.append(temp)
continue
return validSchedules
def removeNull(potentialSchedule):
indexesToRemove = []
for i in range(len(potentialSchedule)):
if potentialSchedule[i] == 0:
indexesToRemove.append(i)
for index in indexesToRemove:
potentialSchedule.remove(0)
return potentialSchedule
def scheduleValidator(potentialSchedule):
return overlapCheckerTwo(potentialSchedule)
def overlapChecker(potentialSchedule, lecture):
temp = lecture.getTimes()
times = []
tempSched = Schedule(potentialSchedule)
for i in range(5):
dayClasses = tempSched.getClassesOnDay(i)
for lect in dayClasses:
times.append(lect.getTimes())
for time in times:
if temp[0][0] == time[1][0]:
if temp[0][1] <= time[1][1]:
return False
elif temp[1][0] == time[0][0]:
if temp[1][1] <= time[0][1]:
return False
elif temp[0][0] > time[0][0] and temp[0][0] < time[1][0]:
return False
return True
def overlapCheckerTwo(potentialSchedule):
timez = []
tempSched = Schedule(potentialSchedule)
for i in range(5):
dayClasses = tempSched.getClassesOnDay(i)
timez.clear()
for lect in dayClasses:
timez.append(lect.getTimes())
for i in range(len(timez)):
for j in range(i, len(timez)):
time = timez[i]
timeTwo = timez[j]
if time!=timeTwo:
if time[0][0] == timeTwo[1][0]:
if time[0][1] <= timeTwo[1][1]:
return False
elif time[1][0] == timeTwo[0][0]:
if time[1][1] <= timeTwo[0][1]:
return False
elif time[0][0] > timeTwo[0][0] and time[0][0] < timeTwo[1][0]:
return False
return True
def addTutorials(potentialSchedule):
tutLengths = []
for lecture in potentialSchedule:
if len(lecture.getTutorials()) == 0:
tutLengths.append(-1)
else:
tutLengths.append(len(lecture.getTutorials()))
lecturesWithTutorials = []
for i in range(len(tutLengths)):
if tutLengths[i] != -1:
lecturesWithTutorials.append(potentialSchedule[i])
return addTutorialsHelper(potentialSchedule, lecturesWithTutorials)
def addTutorialsHelper(potentialSchedule, lectures):
result = []
indexCounter = []
for i in range(len(lectures)):
indexCounter.append(0)
foundSomething = False
tutorialsToCheck = True
listOfSchedules = []
holder = 0
counter = 0;
while tutorialsToCheck:
foundSomething = False
listOfSchedules.clear()
listOfSchedules.append(potentialSchedule)
holder = indexCounter[0]
counter = 0
for i in range(len(lectures)):
for j in range(indexCounter[i], len(lectures[i].getTutorials())):
if overlapChecker(listOfSchedules[counter], lectures[i].getTutorials()[j]):
foundSomething = True
temp = listOfSchedules[counter][:] ###################################################################################################
temp.append(lectures[i].getTutorials()[j])
for resultSched in result:
if temp == resultSched:
foundSomething = False
indexCounter[i] = len(lectures[i].getTutorials())
else:
if j == (len(lectures[i].getTutorials()) - 1):
indexCounter[i] = 0
else:
indexCounter[i] = j + 1
if len(temp) == (len(potentialSchedule) + len(lectures)):
result.append(temp)
else:
listOfSchedules.append(temp)
counter += 1
break
else:
foundSomething = False
break
if foundSomething == False:
tutorialsToCheck = False
if foundSomething == False:
tutorialsToCheck = False
return result
def scheduleRanker(schedule, restrictions):
firstRank=0.45
secondRank=0.20
thirdRank=0.35
classRange=tuple()
breakTime=tuple()
if (restrictions.getTimeofDay()=="Morning"):
classRange=(8,12)
elif (restrictions.getTimeofDay()=="Afternoon"):
classRange=(13,17)
elif (restrictions.getTimeofDay()=="Evening"):
classRange=(18,21)
breakTime=restrictions.getbreakTime()
classMetPref = 0
classNotMetPref = 0
for j in range(5):
currentClassesOnDay=schedule.getClassesOnDay(j)
for course in currentClassesOnDay:
try:
course.getTutorials()
except:
currentClassesOnDay.remove(course)
for classes in currentClassesOnDay:
temp=classes.getTimes()
if restrictions.getTimeofDay()=="":
break
elif temp[0][0] <classRange[0] or temp[1][0]>classRange[1]:
classNotMetPref += 1
classMetPref = len(currentClassesOnDay) - classNotMetPref
if classNotMetPref == 0:
classNotMetPref = 1
if classMetPref == 0:
difference = 0.09
else:
difference = 0.09 / (classMetPref / classNotMetPref)
firstRank -= difference
for i in range(5):
currentClassesOnDay=schedule.getClassesOnDay(i)
if not (len(currentClassesOnDay) == 0):
differenceIntensity=(0.07/len(currentClassesOnDay))*2
oldIntensity=restrictions.getIntensity().index(currentClassesOnDay[0].getCoursecode())
else:
differenceIntensity = 0
oldIntensity=0
for currentClass in currentClassesOnDay:
temp=currentClass.getTimes()
if breakTime=="":
pass
elif temp[0][0]> int(breakTime[0][0]) and temp[1][0]< int(breakTime[1][0]):
secondRank=secondRank-0.04
try:
throwAway=currentClass.getTutorials()
if oldIntensity==restrictions.getIntensity().index(currentClass.getCoursecode())-1 or oldIntensity==restrictions.getIntensity().index(currentClass.getCoursecode())+1:
thirdRank=thirdRank-differenceIntensity
oldIntensity=restrictions.getIntensity().index(currentClass)
except:
pass
if (firstRank+secondRank+thirdRank>1.0):
schedule.setRating(1)
else:
schedule.setRating(firstRank+secondRank+thirdRank)
def dayTo(day):
if day == 0:
return "Monday"
elif day == 1:
return "Tuesday"
elif day == 2:
return "Wednesday"
elif day == 3:
return "Thursday"
elif day == 4:
return "Friday"
def lectureParser(lecture,i):
listOfDays = lecture.days
newListOfDays = []
for day in listOfDays:
newListOfDays.append(dayTo(day))
returnedDict = {"name":lecture.courseCode,"location":lecture.location,"days":newListOfDays, "startTime":lecture.startTime,"endTime":lecture.endTime,"color":i}
return returnedDict
def scheduleParser(schedule):
lecturesList = []
i=0
if schedule is not None:
for lecture in schedule.lectures:
if len(lecture.courseCode) == 9:
i +=1
lecturesList.append(lectureParser(lecture,i))
newLecturesList = lecturesList[:]
for tutorial in schedule.lectures:
if len(tutorial.courseCode) == 10:
for lecture in newLecturesList:
if lecture['name'] in tutorial.courseCode:
lecturesList.append(lectureParser(tutorial,lecture['color']))
return lecturesList