-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpairing_processor.py
More file actions
284 lines (267 loc) · 9.63 KB
/
Copy pathpairing_processor.py
File metadata and controls
284 lines (267 loc) · 9.63 KB
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
import data_reader
from counts_processor import Month
from matplotlib import pyplot as plt
__minor_keys = [
'Minor 1 Description',
'Minor 2 Description',
'Minor 3 Description'
]
def ReverseLocate(o):
if o['do_reverse_Locate'] == '' and o['do_reverse_locate'] == '':
return
if o['do_reverse_Locate']:
data = __CollectAnyMajor(o)
if not o['quiet']:
print('{:<28s} {:<28s}'.format('Major', 'Major'), end='')
print('{:<10}'.format('ID'), end='')
print()
for row in data:
print('{:<28s} {:<28s}'.format(row[0][0], row[0][1]), end='')
print('{:<10}'.format(row[2][0]), end='')
print('{0} {1}'.format(row[2][1], row[2][2]), end='')
print('{0} {1} {2}'.format(row[1][0], row[1][1], row[1][2]), end='')
print()
def __CollectAnyMajor(o) -> list:
data = []
major = o['do_reverse_Locate']
month = int(o['end_month'][-6:-4])
term = data_reader.DetermineTerm(month)
year = int(int(o['end_month'][-11: -7]))
d = o['student_data'][year][term][month]
for row in d:
M1 = row['Major 1 Description'].strip()
M2 = row['Major 2 Description'].strip()
if M1 != major and M2 != major:
continue
M = (M2, M1) if M2 == major else (M1, M2)
m = (
row['Minor 1 Description'],
row['Minor 2 Description'],
row['Minor 3 Description'] if 'Minor 3 Description' in row.keys() else ''
)
email = row['Carthage E-mail'].strip() if 'Carthage E-mail' in row.keys() else 'N/A'
if '\ufeffStudent ID Number' in row.keys():
id_number = row['\ufeffStudent ID Number']
else:
id_number = row['Student ID Number']
E = (id_number, row['Last Name'], row['First Name'], email)
data.append((M, m, E))
return data
def LocateMajors(o):
if o['do_Locate'] == '' and o['do_locate'] == '':
return
if o['do_Locate'] != '':
pairings = __CollectMajorEmails(o)
m = 'Major 2'
M = 'Major 1'
else:
pairings = __CollectMinorEmails(o)
m = 'Minor'
M = 'Major'
if not o['graph']:
if not o['quiet']:
month = Month(int(o['end_month'][-6:-4]))
year = int(int(o['end_month'][-11: -7]))
print(month, year)
print('{:<28} {:<28} {:<28}'.format(M, m, 'Email'))
pairings.sort()
for p in pairings:
if o['csv']:
print('{:},'.format(p[0]), end='')
print('{:},'.format(p[1]), end='')
print('{:},'.format(p[3]), end='')
print('{:}'.format(p[2]))
else:
print(p)
print('{:<28} '.format(p[0]), end='')
print('{:<28} '.format(p[1]), end='')
print('{:<4}'.format(p[3]), end='')
print('{:<24}'.format(p[2]))
def MajorPairings(o):
if not o['do_Pairings']:
return
pairings = __CollectMajors(o)
if not o['graph']:
if not o['quiet']:
print('{:<28} {:<28} {:<6}'.format('Major 1', 'Major 2', 'Count'))
l = list(pairings.keys())
l.sort()
for key in l:
if o['csv']:
print('{:},'.format(key[0]), end='')
print('{:}, '.format(key[1]), end='')
print('{:}'.format(pairings[key]))
else:
print('{:<28} '.format(key[0]), end='')
print('{:<28} '.format(key[1]), end='')
print('{:<6}'.format(pairings[key]))
else:
__MakeMajorChart(o,
pairings,
'double_majors.png',
'No Double Major',
'Double Majors'
)
def MinorPairings(o):
if not o['do_pairings']:
return
pairings, counts = __CollectMinors(o)
if not o['graph']:
if not o['quiet']:
print('{:<28} {:<28} {:<6}'.format('Major', 'Minor', 'Count'))
l = list(pairings.keys())
l.sort()
for key in l:
if o['csv']:
print('{:},'.format(key[0]), end='')
print('{:},'.format(key[1]), end='')
print('{:}'.format(pairings[key]))
else:
print('{:<28} '.format(key[0]), end='')
print('{:<28} '.format(key[1]), end='')
print('{:<6}'.format(pairings[key]))
if not o['quiet']:
print()
print('{:<24s}{:5}'.format('Majors with no minors', counts[0]))
print('{:<24s}{:5}'.format('Majors with one minors', counts[1]))
print('{:<24s}{:5}'.format('Majors with two minors', counts[2]))
print('{:<24s}{:5}'.format('Majors with three minors', counts[3]))
else:
__MakeMajorChart(o,
pairings,
'minors.png',
'No Minor',
'Minors'
)
def __CollectMajors(o) -> dict:
pairings = {}
major = o['major'] if o['do_reverse_Locate'] == '' \
else o['do_reverse_Locate']
month = int(o['end_month'][-6:-4])
term = data_reader.DetermineTerm(month)
year = int(int(o['end_month'][-11: -7]))
d = o['student_data'][year][term][month]
for row in d:
M1 = row['Major 1 Description'].strip()
M2 = row['Major 2 Description'].strip()
if M1 != major and M2 != major:
continue
M = (M2, M1) if M2 == major else (M1, M2)
if M not in pairings.keys():
pairings[M] = 0
pairings[M] += 1
return pairings
def __CollectMajorEmails(o) -> list:
pairings = []
major1 = o['major']
major2 = o['do_Locate']
month = int(o['end_month'][-6:-4])
term = data_reader.DetermineTerm(month)
year = int(int(o['end_month'][-11: -7]))
d = o['student_data'][year][term][month]
for row in d:
M1 = row['Major 1 Description'].strip()
M2 = row['Major 2 Description'].strip()
if M1 != major1 and M2 != major1:
continue
M = (M2, M1) if M2 == major1 else (M1, M2)
if M[1] != major2:
continue
email = row['Carthage E-mail'].strip() if 'Carthage E-mail' in row.keys() else 'N/A'
if email != 'N/A':
email = row['First Name'].strip() + ' ' + \
row['Last Name'].strip() + ' <' + \
email + '>'
pairings.append((M[0], M[1], email, row['Classification Code']))
return pairings
def __CollectMinorEmails(o) -> list:
pairings = []
major = o['major']
minor = o['do_locate']
month = int(o['end_month'][-6:-4])
term = data_reader.DetermineTerm(month)
year = int(int(o['end_month'][-11: -7]))
d = o['student_data'][year][term][month]
for row in d:
M1 = row['Major 1 Description'].strip()
M2 = row['Major 2 Description'].strip()
if M1 != major and M2 != major:
continue
M = M2 if M2 == major else M1
m = ''
for mk in __minor_keys:
if mk in row.keys() and row[mk] == minor:
m = row[mk]
break
if m == '':
continue
email = row['Carthage E-mail'].strip() if 'Carthage E-mail' in row.keys() else 'N/A'
if email != 'N/A':
email = row['First Name'].strip() + ' ' + \
row['Last Name'].strip() + ' <' + \
email + '>'
pairings.append((M, m, email, row['Classification Code']))
return pairings
def __CollectMinors(o) -> dict:
pairings = {}
counts = [ 0, 0, 0, 0]
major = o['major']
month = int(o['end_month'][-6:-4])
term = data_reader.DetermineTerm(month)
year = int(int(o['end_month'][-11: -7]))
pairings[(major,'')] = 0
d = o['student_data'][year][term][month]
for row in d:
M1 = row['Major 1 Description'].strip()
M2 = row['Major 2 Description'].strip()
if M1 != major and M2 != major:
# this person is not a major
continue
M1 = M1 if M1 == major else M2
flag = False
minors = [
row['Minor 1 Description'].strip(),
row['Minor 2 Description'].strip(),
row['Minor 3 Description'].strip()
]
count = 0
for m in minors:
if m == '':
# if the minor is empty, skip it to avoid double counting
continue
M = (M1, m)
if M not in pairings.keys():
pairings[M] = 0
pairings[M] += 1
flag = True
count += 1
if not flag:
pairings[(major,'')] += 1
counts[count] += 1
return pairings, counts
def __MakeMajorChart(o, pairings, file_name, no_text, t):
labels = []
minors = []
values = []
month = int(o['end_month'][-6:-4])
year = int(int(o['end_month'][-11: -7]))
l = list(pairings.keys())
l.sort()
total = 0
for key in l:
minors.append(key[1] if key[1] != '' else no_text)
values.append(pairings[key])
total += pairings[key]
percentage = [ pairings[key] * 100.0 / total for key in l]
labels = ['{0} - {1:2.1f}%'.format(s, p) for s, p in zip(minors, percentage) ]
fig1, ax1 = plt.subplots()
p = ax1.pie(values, startangle=90)
ax1.axis('equal')
plt.legend(p[0], labels, bbox_to_anchor=(1, 0.5), loc="right",
bbox_transform=plt.gcf().transFigure)
plt.subplots_adjust(left=0.0, bottom=0.1, right=0.575)
plt.suptitle(o['major'] + ' - ' + t + '\n' +
str(month) + '/' + str(year) +
' Total ' + str(total), ha='right')
plt.savefig(file_name, bbox_inches='tight')
print(t, 'image saved with file name:', file_name)