-
Notifications
You must be signed in to change notification settings - Fork 0
/
period-overview-csv.py
executable file
·73 lines (61 loc) · 3.05 KB
/
period-overview-csv.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
#!/usr/bin/env python
import sys
from getpass import getpass
from os import linesep
from devilryrestfullib import RestfulFactory
from devilrycliscriptslib.argparsewrapper import ArgumentParser
from devilrycliscriptslib.login import login_using_args
from devilrycliscriptslib.commonargs import add_common_args
from devilrycliscriptslib.queries import find_period_id_by_shortnames
from devilrycliscriptslib.queries import aggregate_points_for_each_student
from devilrycliscriptslib.utils import split_path
argparser = ArgumentParser(description=('Show a table with CSV results for each '
'student on the entire period '
'aggregated. Meaning of the numbers in '
'the table: 0: No deliveries, 1: Not approved, 2: Approved'))
add_common_args(argparser)
argparser.add_argument('--period', required=True,
help='Path to the period. E.g: "duck1010.spring2010"')
args = argparser.parse_args()
logincookie = login_using_args(args, getpass())
restful_factory = RestfulFactory(args.url)
PeriodApi = restful_factory.make('/administrator/restfulsimplifiedperiod/')
AssignmentApi = restful_factory.make('/administrator/restfulsimplifiedassignment/')
AssignmentGroupApi = restful_factory.make('/administrator/restfulsimplifiedassignmentgroup/')
def csv_approvedstats(students, all_assignments):
"""
Create a csv table of students. For each assignment, a number is added:
0: No deliveries
1: Not approved
2: Approved
"""
# Print header ({0:<20} format string makes positional arg 0 occupy 20 chars left aligned)
sys.stdout.write('USER') # Ending comma prevent newline
for assignment_shortname in all_assignments:
sys.stdout.write(',{0}'.format(assignment_shortname))
sys.stdout.write(linesep)
# Print the documented number for each user on each assignment
for student, student_assignments in students.iteritems():
sys.stdout.write(student)
for assignment_shortname in all_assignments:
number = 0
if assignment_shortname in student_assignments:
group = student_assignments[assignment_shortname]
deliveries = group['number_of_deliveries']
if deliveries > 0:
if group['feedback__is_passing_grade']:
number = 2
else:
number = 1
else:
pass # Student no registered on assignment - keep number at 0
sys.stdout.write(',{0}'.format(number))
sys.stdout.write(linesep)
subject, period = split_path(args.period, '--period', 2)
try:
period_id = find_period_id_by_shortnames(PeriodApi, logincookie, subject, period)
except LookupError, e:
raise SystemExit('ERROR: Could not find requested period: {0}'.format(args.period))
else:
students, all_assignments = aggregate_points_for_each_student(AssignmentApi, AssignmentGroupApi, logincookie, period_id)
csv_approvedstats(students, all_assignments)