-
Notifications
You must be signed in to change notification settings - Fork 5
/
grades_notenspiegel_plotter.py
executable file
·76 lines (63 loc) · 1.97 KB
/
grades_notenspiegel_plotter.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
#!/usr/bin/env python3
'''
Plot the "Notenspiegel" of all courses.
'''
import numpy as np
import matplotlib.pyplot as plt
import os
import re
import helper
OUTPUT_DIR = 'output'
grades = helper.get_grades()
available_grades = helper.get_available_grades()
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
def autolabel_bars(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2., 1.02 * height,
'%d' % int(height),
ha='center', va='bottom')
def get_notenspiegel_index(grade):
for (index, grade_) in enumerate(available_grades):
if grade == grade_:
return index
return -1
def plot_notenspiegel(title, notenspiegel):
plt.cla()
plt.clf()
plt.style.use('seaborn-whitegrid')
sanitized_title = helper.sanitize_filename(title)
ind = np.arange(len(notenspiegel))
ind = np.array(available_grades)
width = 0.20
bars = plt.bar(ind, notenspiegel, width)
autolabel_bars(bars)
plt.xticks(0.1 + ind, ind)
# Nice naming, eh?
# Color the bar with your grade in green
notenspiegel_index = get_notenspiegel_index(grade['grade'])
if notenspiegel_index != -1:
bars[notenspiegel_index].set_color('g')
plt.xlabel("grades")
plt.ylabel("# students")
plt.tick_params(
axis='both',
which='both',
top='off',
left='off',
labelleft='off',
right='off'
)
plt.grid(False)
plt.title(title, loc='left')
plt.savefig('{}/{}.png'.format(OUTPUT_DIR, sanitized_title))
for grade in grades:
plot_notenspiegel(grade['title'], grade['notenspiegel'])
notenspiegel = [0] * len(available_grades)
for grade in grades:
grade_ = grade['grade']
notenspiegel_index = get_notenspiegel_index(grade['grade'])
if notenspiegel_index != -1:
notenspiegel[notenspiegel_index] = notenspiegel[notenspiegel_index] + 1
plot_notenspiegel('_NOTENSPIEGEL', notenspiegel)