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

« back to all changes in this revision

Viewing changes to bin/ivle-marks

Require that plugins providing media subclass MediaPlugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import os
28
28
import re
29
29
import csv
30
 
import time
31
30
from xml.dom import minidom
32
31
 
33
 
import ivle.db
 
32
import ivle.database
 
33
import ivle.worksheet
34
34
import ivle.conf
35
35
 
36
36
if os.getuid() != 0:
63
63
    (This is not marks, it's other user data).
64
64
    """
65
65
    last_login = (None if user.last_login is None else
66
 
                    time.strftime("%d/%m/%y", user.last_login))
 
66
                    user.last_login.strftime("%d/%m/%y"))
67
67
    return [user.studentid, user.login, user.fullname, last_login]
68
68
userdata_header = ["Student ID", "Login", "Full name", "Last login"]
69
69
 
110
110
    """
111
111
    return worksheets + ["Total %", "Mark"]
112
112
 
113
 
def get_marks_user(subject, worksheets, user):
 
113
def get_marks_user(subject, worksheet_names, user):
114
114
    """
115
115
    Given a subject, a list of strings (the assessable worksheets), and a user
116
116
    object, returns the user's percentage for each worksheet, overall, and
127
127
    problems_done = 0
128
128
    problems_total = 0
129
129
 
130
 
    for worksheet in worksheets:
131
 
        try:
132
 
            # We simply ignore optional exercises here
133
 
            mand_done, mand_total, _, _ = (
134
 
                db.calculate_score_worksheet(user.login, subject,
135
 
                    worksheet))
136
 
            worksheet_pcts.append(float(mand_done) / mand_total)
137
 
            problems_done += mand_done
138
 
            problems_total += mand_total
139
 
        except ivle.db.DBException:
140
 
            # Worksheet is probably not in database yet
141
 
            pass
 
130
    for worksheet_name in worksheet_names:
 
131
        worksheet = ivle.database.Worksheet.get_by_name(store,
 
132
            subject, worksheet_name)
 
133
        # We simply ignore optional exercises here
 
134
        mand_done, mand_total, _, _ = (
 
135
            ivle.worksheet.calculate_score(store, user, worksheet))
 
136
        worksheet_pcts.append(float(mand_done) / mand_total)
 
137
        problems_done += mand_done
 
138
        problems_total += mand_total
142
139
    problems_pct = float(problems_done) / problems_total
143
140
    problems_pct_int = (100 * problems_done) / problems_total
144
141
    # XXX Marks calculation (should be abstracted out of here!)
153
150
    csvfile.writerow(userdata + marksdata)
154
151
 
155
152
try:
156
 
    # Get the list of assessable worksheets from the subject.xml file,
157
 
    # and the list of all users from the DB.
 
153
    # Get the list of assessable worksheets from the subject.xml file.
158
154
    worksheets = get_assessable_worksheets(subject)
159
 
    db = ivle.db.DB()
160
 
    list = db.get_users()
 
155
    store = ivle.database.get_store()
161
156
except Exception, message:
162
157
    print >>sys.stderr, "Error: " + str(message)
163
158
    sys.exit(1)
166
161
csvfile = csv.writer(sys.stdout)
167
162
csvfile.writerow(userdata_header + get_marks_header(worksheets))
168
163
 
169
 
list.sort(key=lambda user: user.login)
170
 
for user in list:
 
164
for user in store.find(ivle.database.User).order_by(ivle.database.User.login):
171
165
    writeuser(subject, worksheets, user, csvfile)
172
166