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

« back to all changes in this revision

Viewing changes to bin/ivle-marks

  • Committer: me at id
  • Date: 2009-01-15 01:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1147
ivle.makeuser: Don't create a local.auth. It wasn't used anywhere, and seems
    to have only been there for historical reasons.
setup.configure: Remove svn_auth_local from the config.py boilerplate; it was
    used solely by ivle.makeuser.

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
30
31
from xml.dom import minidom
31
32
 
32
 
import ivle.database
33
 
import ivle.worksheet.utils
 
33
import ivle.db
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
 
                    user.last_login.strftime("%d/%m/%y"))
 
66
                    time.strftime("%d/%m/%y", user.last_login))
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, worksheet_names, user):
 
113
def get_marks_user(subject, worksheets, 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_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.utils.calculate_score(store, user, worksheet))
136
 
        worksheet_pcts.append(float(mand_done) / mand_total)
137
 
        problems_done += mand_done
138
 
        problems_total += mand_total
 
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
139
142
    problems_pct = float(problems_done) / problems_total
140
143
    problems_pct_int = (100 * problems_done) / problems_total
141
144
    # XXX Marks calculation (should be abstracted out of here!)
150
153
    csvfile.writerow(userdata + marksdata)
151
154
 
152
155
try:
153
 
    # Get the list of assessable worksheets from the subject.xml file.
 
156
    # Get the list of assessable worksheets from the subject.xml file,
 
157
    # and the list of all users from the DB.
154
158
    worksheets = get_assessable_worksheets(subject)
155
 
    store = ivle.database.get_store()
 
159
    db = ivle.db.DB()
 
160
    list = db.get_users()
156
161
except Exception, message:
157
162
    print >>sys.stderr, "Error: " + str(message)
158
163
    sys.exit(1)
161
166
csvfile = csv.writer(sys.stdout)
162
167
csvfile.writerow(userdata_header + get_marks_header(worksheets))
163
168
 
164
 
for user in store.find(ivle.database.User).order_by(ivle.database.User.login):
 
169
list.sort(key=lambda user: user.login)
 
170
for user in list:
165
171
    writeuser(subject, worksheets, user, csvfile)
166
172