-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscheduling.py
51 lines (45 loc) · 1.51 KB
/
scheduling.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
import datetime
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
def convertTimeStringToDictionary(timeString):
times = timeString.split(";")[:-1]
schedule = {}
for date in times:
date = date.strip()
for i in range(0,7):
if date[i] != '.':
if days[i] in schedule:
schedule[days[i]].append( timeRangeToMilitary(date[8:]) )
else:
schedule[days[i]] = [timeRangeToMilitary(date[8:])]
return schedule
def noConflict(currSchedule, newCourse):
''' Tests two times, and returns True if they do not conflict '''
for currCourseID in currSchedule:
currCourse = currSchedule[currCourseID]
for day in days:
if day in currCourse:
for courseTime in currCourse[day]:
startTime = courseTime[0]
endTime = courseTime[1]
if day in newCourse:
for time in newCourse[day]:
if (time[0] >= startTime and time[0] <= endTime) or (startTime >= time[0] and startTime <= time[1]):
return False
return True
def timeRangeToMilitary(timeString):
timeArray = timeString.split('-')
outTime = []
for time in timeArray:
print 'TIME IS ' + time
hour = time.split(":")[0]
minute = time.split(":")[1][0:2]
m = time[-2:]
if m == 'AM':
hour = str(int(hour) % 12)
else:
hour = str(int(hour) % 12 + 12)
if len(hour) < 2:
hour = '0' + hour
outTime.append(int(hour)+(float(minute) / 60))
#outTime.append(int(hour)+(float('0.' + minute)))
return outTime