47
47
last_login = (None if user.last_login is None else
48
48
user.last_login.strftime("%d/%m/%y"))
49
49
return [user.studentid, user.login, user.fullname, last_login]
50
51
userdata_header = ["Student ID", "Login", "Full name", "Last login"]
52
def get_marks_header(worksheets):
54
Given a list of strings - the assessable worksheets - returns a new list
55
of strings - the column headings for the marks section of the CSV output.
57
return worksheets + ["Total %", "Mark"]
59
def get_marks_user(subject, worksheet_names, user):
61
Given a subject, a list of strings (the assessable worksheets), and a user
62
object, returns the user's percentage for each worksheet, overall, and
52
def get_header(worksheets):
54
Given a list of Worksheet objects (the assessable worksheets), returns a
55
list of strings -- the column headings for the marks section of the CSV
58
return (userdata_header + [ws.name for ws in worksheets]
59
+ ["Total %", "Mark"])
61
def get_marks_user(worksheets, user):
62
"""Gets marks for a particular user for a particular set of worksheets.
63
@param worksheets: List of Worksheet objects to get marks for.
64
@param user: User to get marks for.
65
@returns: The user's percentage for each worksheet, overall, and
63
66
their final mark, as a list of strings, in a manner which corresponds to
64
67
the headings produced by get_marks_header.
66
# NOTE: This code is copy/edited from
67
# www/apps/tutorial/__init__.py:handle_subject_menu
68
# Should be factored out of there.
70
69
worksheet_pcts = []
71
70
# As we go, calculate the total score for this subject
72
71
# (Assessable worksheets only, mandatory problems only)
76
for worksheet_name in worksheet_names:
77
worksheet = ivle.database.Worksheet.get_by_name(store,
78
subject, worksheet_name)
75
for worksheet in worksheets:
79
76
# We simply ignore optional exercises here
80
77
mand_done, mand_total, _, _ = (
81
78
ivle.worksheet.utils.calculate_score(store, user, worksheet))
90
87
mark = min(problems_pct_int / 16, max_mark)
91
88
return worksheet_pcts + [problems_pct, mark]
93
def writeuser(subject, worksheets, user, csvfile):
90
def writeuser(worksheets, user, csvfile):
94
91
userdata = get_userdata(user)
95
marksdata = get_marks_user(subject, worksheets, user)
92
marksdata = get_marks_user(worksheets, user)
96
93
csvfile.writerow(userdata + marksdata)
98
95
def main(argv=None):
175
172
for ws in worksheets:
178
# TEMP (since the code below is going to fail)
181
175
# Start writing the CSV file - header
182
176
csvfile = csv.writer(sys.stdout)
183
csvfile.writerow(userdata_header + get_marks_header(worksheets))
177
csvfile.writerow(get_header(worksheets))
185
179
users = store.find(ivle.database.User).order_by(ivle.database.User.login)
186
180
for user in users:
187
writeuser(subject, worksheets, user, csvfile)
181
writeuser(worksheets, user, csvfile)
189
183
if __name__ == "__main__":
190
184
sys.exit(main(sys.argv))