-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeTable.py
105 lines (85 loc) · 3.36 KB
/
TimeTable.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
def createTimeTable():
import timing
periods = timing.makePeriods()
import room
allRooms = room.readAllRooms().Name
days = list()
for i in timing.daysOfWeek():
for j in range(0, len(allRooms)):
days.append(i)
rooms = list()
for i in range(0,len(timing.daysOfWeek())):
rooms.extend(allRooms)
import pandas as pd
dataF = pd.DataFrame(index = [days,rooms],columns = ['P%s'%(i) for i in range(1,len(periods)+1)])
dataF = dataF.rename_axis(['Days','Rooms'], axis = 'index')
initializeCells(dataF)
dataF.to_csv('TimeTable.csv')
def readTimeTable(fileName='TimeTable.csv'):
import pandas as pd
data = pd.read_csv(fileName)
data = data.set_index(['Days','Rooms'])
return data
def theDefaultEmptyChar():
return '#'
def initializeCells(timeTableFrame):
'timeTableFrame whose cells are to be initialized'
import timing
import room
for p in list(timeTableFrame.columns):
for d in timing.daysOfWeek():
for r in room.readAllRooms().Name:
timeTableFrame.loc[(d,r),p] = theDefaultEmptyChar()
def generateTimeTable(className,duration):
'class whose timetable is to be generated'
import pandas as pd
timeTable = readTimeTable()
import semester
courseTable = semester.readClass(className)
subjects = list()
print(courseTable)
for i in courseTable.index:
tempSubject = courseTable.loc[i,'Subjects']
creditMin = courseTable.loc[i,'CM']
while(creditMin != 0):
if(creditMin == duration):
subjects.append([tempSubject,duration])
creditMin -= duration
elif(creditMin > duration):
if((creditMin-duration) >= duration):
subjects.append([tempSubject,duration])
creditMin -= duration
else:
subjects.append([tempSubject,creditMin])
creditMin -= creditMin
else:
subjects.append([tempSubject : creditMin])
creditMin -= creditMin
print(subjects)
input('wait..')
timeList = list()
with open('timeHeader.txt') as f:
data = f.read()
timeList = eval(data)
timeList.insert(0,'')
import random
random.shuffle(subjects)
import timing
import room
for r in room.readAllRooms().Name:
for p in timeTable.columns:
for d in timing.daysOfWeek():
if((len(subjects)!=0)):
if((timeTable.loc[(d,r),p] == theDefaultEmptyChar())):
temp = subjects.pop()
if(temp[1] == duration)
timeTable.loc[(d,r),p] = [
className,temp[0],'Teacher',timeList[int(p[-1])]]
elif(temp[1] < duration):
s = timeList[p[-1]]
timeTable.loc[(d,r),p] = [
className,temp[0],'Teacher',timeList[int(p[-1])]]
if(len(subjects)!=0):
print('Not enough rooms...')
timeTable.to_csv('TimeTable.csv')
timeTable.to_html('TimeTable.html')