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

« back to all changes in this revision

Viewing changes to bin/ivle-marks

  • Committer: Matt Giuca
  • Date: 2009-01-19 17:28:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119172859-htjq3rfpp0fhtpc9
ivle.worksheet: Added calculate_score. This is a nice clean Storm port of
    ivle.db.calculate_worksheet_score.
tutorial: Replaced use of ivle.db.calculate_worksheet_score with
    ivle.worksheet.calculate_score.
    Guess What!! Removed this module's dependency on ivle.db! Hooray!
    (Note: tutorialservice still depends on it).
bin/ivle-marks: Updated this script to use ivle.worksheet_calculate_score.
    Note that this DOES NOT execute properly -- it seems it didn't even
    before my changes (tries to call db.get_users). Not my fault; I'm
    committing and going to bed!
ivle.db: Removed calculate_worksheet_score.
    As this removes the dependency on get_problem_status, removed that too!
    Almost all the worksheet stuff is gone now!

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from xml.dom import minidom
32
32
 
33
33
import ivle.db
 
34
import ivle.database
 
35
import ivle.worksheet
34
36
import ivle.conf
35
37
 
36
38
if os.getuid() != 0:
110
112
    """
111
113
    return worksheets + ["Total %", "Mark"]
112
114
 
113
 
def get_marks_user(subject, worksheets, user):
 
115
def get_marks_user(subject, worksheet_names, user):
114
116
    """
115
117
    Given a subject, a list of strings (the assessable worksheets), and a user
116
118
    object, returns the user's percentage for each worksheet, overall, and
127
129
    problems_done = 0
128
130
    problems_total = 0
129
131
 
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
 
132
    for worksheet_name in worksheet_names:
 
133
        worksheet = ivle.database.Worksheet.get_by_name(store,
 
134
            subject, worksheet_name)
 
135
        # We simply ignore optional exercises here
 
136
        mand_done, mand_total, _, _ = (
 
137
            ivle.worksheet.calculate_score(store, user, worksheet))
 
138
        worksheet_pcts.append(float(mand_done) / mand_total)
 
139
        problems_done += mand_done
 
140
        problems_total += mand_total
142
141
    problems_pct = float(problems_done) / problems_total
143
142
    problems_pct_int = (100 * problems_done) / problems_total
144
143
    # XXX Marks calculation (should be abstracted out of here!)
157
156
    # and the list of all users from the DB.
158
157
    worksheets = get_assessable_worksheets(subject)
159
158
    db = ivle.db.DB()
 
159
    store = ivle.database.get_store()
160
160
    list = db.get_users()
161
161
except Exception, message:
162
162
    print >>sys.stderr, "Error: " + str(message)