-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab_allotment.py
321 lines (286 loc) · 12.9 KB
/
Lab_allotment.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
import pandas as pd
import numpy as np
import xlsxwriter
global max_seats_dict, registered_seats_dict
#Create dicts of option:capacity and option:registered (registered is 0 now)
max_seats_df = pd.read_excel('combination.xlsx', sheet_name='Seats')
max_seats_dict = {} #eg. 'CS4': 42
registered_seats_dict = {} #eg. 'CS4': 0
for i in range(len(max_seats_df['option'])):
max_seats_dict[max_seats_df['option'][i].strip()]=max_seats_df['seats'][i]
registered_seats_dict[max_seats_df['option'][i].strip()] = 0
#Create DF of ID No | PR No. DF sorted on PR NO.
pr_df_2019 = pd.read_excel('GOA PR.xlsx', sheet_name='2019')
pr_df_2019 = pr_df_2019[['CAMPUS_ID', 'PR NO.']]
pr_df_2019 = pr_df_2019.sort_values(by=['PR NO.'])
pr_df_2019 = pr_df_2019.reset_index(drop = True)
#CS Responses:
global cs_lab_dict #id_no: preference list
#eg. 2019A7PS0036G:['CS2', 'CS3', 'CS5', 'CS4', 'CS1']
#create such list for each response
cs_lab_dict = {}
responses_df = pd.read_excel('./Responses/CS Form (Responses).xlsx')
no_of_options = 5
no_of_cols_to_skip = 3
for i in range(len(responses_df['ID Number'])):
current_id = responses_df['ID Number'][i].strip().upper()
current_pref_list = ['','','','','']
current_row = responses_df.iloc[i]
for i in range(no_of_options):
pref_no = current_row[i+no_of_cols_to_skip][0]
list_index = int(pref_no) - 1
current_option = 'CS' + str(i+1)
current_pref_list[list_index] = current_option
cs_lab_dict[current_id] = current_pref_list
global cs_lab_allot
cs_lab_allot = {}
#eg. 2019A7PS0036G:'CS2'
def allotCS(current_id):
global registered_seats_dict, max_seats_dict,cs_lab_allot,cs_lab_dict
if current_id not in cs_lab_dict: #don't allot if ID not in reponses
return
current_pref_list = cs_lab_dict[current_id]
for i in range(len(current_pref_list)):
current_option = current_pref_list[i]
#check for seats availability for current (i+1)th preference
if registered_seats_dict[current_option] < max_seats_dict[current_option]:
cs_lab_allot[current_id] = current_option
registered_seats_dict[current_option] += 1
return
#ECE Responses:
global ece_lab_dict #id_no: preference list
#eg. 2019AAPS0036G:['ECE2','ECE1','ECE3']
#create such list for each response
ece_lab_dict = {}
responses_df = pd.read_excel('./Responses/ECE Form (Responses).xlsx')
no_of_options = 3
no_of_cols_to_skip = 3
for i in range(len(responses_df['ID Number'])):
current_id = responses_df['ID Number'][i].strip().upper()
current_pref_list = ['','','']
current_row = responses_df.iloc[i]
for i in range(no_of_options):
pref_no = current_row[i+no_of_cols_to_skip][0]
list_index = int(pref_no) - 1
current_option = 'ECE' + str(i+1)
current_pref_list[list_index] = current_option
ece_lab_dict[current_id] = current_pref_list
global ece_lab_allot
ece_lab_allot = {}
#eg. 2019AAPS0036G:'ECE2'
def allotECE_lab(current_id):
global registered_seats_dict, max_seats_dict,ece_lab_allot,ece_lab_dict
if current_id not in ece_lab_dict: #don't allot if ID not in reponses
return
current_pref_list = ece_lab_dict[current_id]
for i in range(len(current_pref_list)):
current_option = current_pref_list[i]
#check for seats availability for current (i+1)th preference
if registered_seats_dict[current_option] < max_seats_dict[current_option]:
ece_lab_allot[current_id] = current_option
registered_seats_dict[current_option] += 1
return
#EEE Responses:
global eee_lab_dict #id_no: preference list
#eg. 2019AAPS0036G:['EEE2','ECE1',...]
#create such list for each response
eee_lab_dict = {}
responses_df = pd.read_excel('./Responses/EEE Form (Responses).xlsx')
no_of_options = 6
no_of_cols_to_skip = 3
for i in range(len(responses_df['ID Number'])):
current_id = responses_df['ID Number'][i].strip().upper()
current_pref_list = ['','','','','','']
current_row = responses_df.iloc[i]
for i in range(no_of_options):
pref_no = current_row[i+no_of_cols_to_skip][0]
list_index = int(pref_no) - 1
current_option = 'EEE' + str(i+1)
current_pref_list[list_index] = current_option
eee_lab_dict[current_id] = current_pref_list
global eee_lab_allot
eee_lab_allot = {}
#eg. 2019AAPS0036G:'EEE2'
def allotEEE_lab(current_id):
global registered_seats_dict, max_seats_dict,eee_lab_allot,eee_lab_dict
if current_id not in eee_lab_dict: #don't allot if ID not in reponses
return
current_pref_list = eee_lab_dict[current_id]
for i in range(len(current_pref_list)):
current_option = current_pref_list[i]
#check for seats availability for current (i+1)th preference
if registered_seats_dict[current_option] < max_seats_dict[current_option]:
eee_lab_allot[current_id] = current_option
registered_seats_dict[current_option] += 1
return
#ENI Responses:
global eni_lab_dict #id_no: preference list
#eg. 2019AAPS0036G:['ENI2','ENI1',...]
#create such list for each response
eni_lab_dict = {}
responses_df = pd.read_excel('./Responses/ENI Form (Responses).xlsx')
no_of_options = 6
no_of_cols_to_skip = 3
for i in range(len(responses_df['ID Number'])):
current_id = responses_df['ID Number'][i].strip().upper()
current_pref_list = ['','','','','','']
current_row = responses_df.iloc[i]
for i in range(no_of_options):
pref_no = current_row[i+no_of_cols_to_skip][0]
list_index = int(pref_no) - 1
current_option = 'ENI' + str(i+1)
current_pref_list[list_index] = current_option
eni_lab_dict[current_id] = current_pref_list
global eni_lab_allot
eni_lab_allot = {}
#eg. 2019AAPS0036G:'ENI2'
def allotENI_lab(current_id):
global registered_seats_dict, max_seats_dict,eni_lab_allot,eni_lab_dict
if current_id not in eni_lab_dict: #don't allot if ID not in reponses
return
current_pref_list = eni_lab_dict[current_id]
for i in range(len(current_pref_list)):
current_option = current_pref_list[i]
#check for seats availability for current (i+1)th preference
if registered_seats_dict[current_option] < max_seats_dict[current_option]:
eni_lab_allot[current_id] = current_option
registered_seats_dict[current_option] += 1
return
#iterate through sorted PR NO. list and allot
for i in range(len(pr_df_2019['PR NO.'])):
current_id = pr_df_2019['CAMPUS_ID'][i].strip().upper()
current_branch = current_id[4:6]
if current_branch=='A7':
allotCS(current_id)
elif current_branch=='AA':
allotECE_lab(current_id)
elif current_branch=='A8':
allotENI_lab(current_id)
elif current_branch=='A3':
allotEEE_lab(current_id)
# print(len(cs_lab_dict))
# print(len(cs_lab_allot))
#generate output excel files
combined_output_df = pd.DataFrame(columns=['ID Number', 'Allotted Option'])
cs_output_df = pd.DataFrame(columns=['ID Number', 'Allotted Option'])
for id_no, allotted_option in cs_lab_allot.items():
combined_output_df = combined_output_df.append(pd.Series([id_no, allotted_option], index = combined_output_df.columns), ignore_index=True)
cs_output_df = cs_output_df.append(pd.Series([id_no, allotted_option], index = cs_output_df.columns), ignore_index=True)
cs_output_df.to_excel('Temporary CS allotments.xlsx', index=False)
ece_output_df = pd.DataFrame(columns=['ID Number', 'Allotted Option'])
for id_no, allotted_option in ece_lab_allot.items():
combined_output_df = combined_output_df.append(pd.Series([id_no, allotted_option], index = combined_output_df.columns), ignore_index=True)
ece_output_df = ece_output_df.append(pd.Series([id_no, allotted_option], index = ece_output_df.columns), ignore_index=True)
ece_output_df.to_excel('Temporary ECE allotments.xlsx', index=False)
eee_output_df = pd.DataFrame(columns=['ID Number', 'Allotted Option'])
for id_no, allotted_option in eee_lab_allot.items():
combined_output_df = combined_output_df.append(pd.Series([id_no, allotted_option], index = combined_output_df.columns), ignore_index=True)
eee_output_df = eee_output_df.append(pd.Series([id_no, allotted_option], index = eee_output_df.columns), ignore_index=True)
eee_output_df.to_excel('Temporary EEE allotments.xlsx', index=False)
eni_output_df = pd.DataFrame(columns=['ID Number', 'Allotted Option'])
for id_no, allotted_option in eni_lab_allot.items():
combined_output_df = combined_output_df.append(pd.Series([id_no, allotted_option], index = combined_output_df.columns), ignore_index=True)
eni_output_df = eni_output_df.append(pd.Series([id_no, allotted_option], index = eni_output_df.columns), ignore_index=True)
eni_output_df.to_excel('Temporary ENI allotments.xlsx', index=False)
combined_output_df.to_excel('Temporary Combined Lab allotments.xlsx', index=False)
#generating final output files:
class_map = pd.read_excel('classs.xlsx', sheet_name='ClassNumb')
course_map = pd.read_excel('classs.xlsx', sheet_name='ClassCode')
time_map = pd.read_excel('classs.xlsx', sheet_name='ClassTime')
course_dict={}
class_dict={}
time_dict={}
for i in range(course_map.shape[0]):
course_dict[course_map['Course'][i]]=[course_map['o1'][i],course_map['o2'][i],course_map['o3'][i]]
for i in range(class_map.shape[0]):
class_dict[class_map['Course'][i]]=[class_map['o1'][i],class_map['o2'][i],class_map['o3'][i]]
for i in range(time_map.shape[0]):
time_dict[time_map['Course'][i]]=[time_map['o1'][i],time_map['o2'][i],time_map['o3'][i]]
id_to_name={}
pr_df_2019 = pd.read_excel('GOA PR.xlsx', sheet_name='2019')
for i in range(pr_df_2019.shape[0]):
current_id = pr_df_2019['CAMPUS_ID'][i].strip().upper()
current_name=pr_df_2019['NAME'][i].strip()
id_to_name[current_id]=current_name
def solve_CS(curr_id ,labs, lab_allot):
for i in range(3):
try:
p=course_dict[lab_allot[curr_id]]
l=[curr_id,p[i],class_dict[lab_allot[curr_id]][i],time_dict[lab_allot[curr_id]][i]]
labs.append(l)
print(l)
except:
print(curr_id)
def solve_REST(curr_id ,labs, lab_allot):
for i in range(2):
try:
p=course_dict[lab_allot[curr_id]]
l=[curr_id,p[i],class_dict[lab_allot[curr_id]][i],time_dict[lab_allot[curr_id]][i]]
labs.append(l)
print(l)
except:
print(curr_id)
#labs.append(l)
CS_labs=[]
ECE_labs=[]
EEE_labs=[]
ENI_labs=[]
for i in range(len(pr_df_2019['PR NO.'])):
current_id = pr_df_2019['CAMPUS_ID'][i].strip().upper()
current_branch = current_id[4:6]
if current_branch=='A7' or current_branch=='a7':
solve_CS(current_id,CS_labs,cs_lab_allot)
elif current_branch=='A3' or current_branch=='a3':
solve_REST(current_id,EEE_labs,eee_lab_allot)
elif current_branch=='A8' or current_branch=='a8':
solve_REST(current_id,ENI_labs,eni_lab_allot)
elif current_branch=='AA' or current_branch=='aa':
solve_REST(current_id,ECE_labs,ece_lab_allot)
def make_file_cs(course,CS_labs):
workbook = xlsxwriter.Workbook('output_cs.xlsx')
workbook.add_worksheet(course)
cell_format = workbook.add_format({'bold': True, 'align': 'center'})
cell_format3 =workbook.add_format ({'align': 'center'})
worksheet=workbook.get_worksheet_by_name(course)
worksheet.set_column(0,200, 50)
worksheet.write(0,0,'StudentID',cell_format)
worksheet.write(0,1,'StudentName',cell_format)
worksheet.write(0,2,'Section',cell_format)
worksheet.write(0,3,'ClassNbr',cell_format)
worksheet.write(0,4,'Time',cell_format)
j=1
for i in CS_labs:
worksheet.write(j,0,i[0],cell_format3)
worksheet.write(j,1,id_to_name[i[0]],cell_format3)
worksheet.write(j,2,i[1],cell_format3)
worksheet.write(j,3,i[2],cell_format3)
worksheet.write(j,4,i[3],cell_format3)
j=j+1
#print(i)
workbook.close()
def make_file_rest(course,rest_labs):
workbook = xlsxwriter.Workbook('output_'+course+'.xlsx')
workbook.add_worksheet(course)
cell_format = workbook.add_format({'bold': True, 'align': 'center'})
cell_format3 =workbook.add_format ({'align': 'center'})
worksheet=workbook.get_worksheet_by_name(course)
worksheet.set_column(0,200, 50)
worksheet.write(0,0,'StudentID',cell_format)
worksheet.write(0,1,'StudentName',cell_format)
worksheet.write(0,2,'Section',cell_format)
worksheet.write(0,3,'ClassNbr',cell_format)
worksheet.write(0,4,'Time',cell_format)
j=1
for i in rest_labs:
worksheet.write(j,0,i[0],cell_format3)
worksheet.write(j,1,id_to_name[i[0]],cell_format3)
worksheet.write(j,2,i[1],cell_format3)
worksheet.write(j,3,i[2],cell_format3)
worksheet.write(j,4,i[3],cell_format3)
j=j+1
#print(i)
workbook.close()
make_file_cs('CS',CS_labs)
make_file_rest('EEE',EEE_labs)
make_file_rest('ECE',ECE_labs)
make_file_rest('ENI',ENI_labs)