~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-marks

  • Committer: Matt Giuca
  • Date: 2009-04-24 13:18:50 UTC
  • mto: This revision was merged to the branch mainline in revision 1196.
  • Revision ID: matt.giuca@gmail.com-20090424131850-z6tz53fwitt0exi7
ivle-marks: Fixed up header and actual body calculation (now uses the database
    objects). This should now print the correct results, except for Unicode
    problems.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
50
51
userdata_header = ["Student ID", "Login", "Full name", "Last login"]
51
 
 
52
 
def get_marks_header(worksheets):
53
 
    """
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.
56
 
    """
57
 
    return worksheets + ["Total %", "Mark"]
58
 
 
59
 
def get_marks_user(subject, worksheet_names, user):
60
 
    """
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):
 
53
    """
 
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
 
56
    output.
 
57
    """
 
58
    return (userdata_header + [ws.name for ws in worksheets]
 
59
            + ["Total %", "Mark"])
 
60
 
 
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.
65
68
    """
66
 
    # NOTE: This code is copy/edited from
67
 
    # www/apps/tutorial/__init__.py:handle_subject_menu
68
 
    # Should be factored out of there.
69
 
 
70
69
    worksheet_pcts = []
71
70
    # As we go, calculate the total score for this subject
72
71
    # (Assessable worksheets only, mandatory problems only)
73
72
    problems_done = 0
74
73
    problems_total = 0
75
74
 
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]
92
89
 
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)
97
94
 
98
95
def main(argv=None):
175
172
    for ws in worksheets:
176
173
        print "    %r" % ws
177
174
 
178
 
    # TEMP (since the code below is going to fail)
179
 
    return
180
 
 
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))
184
178
 
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)
188
182
 
189
183
if __name__ == "__main__":
190
184
    sys.exit(main(sys.argv))