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

« back to all changes in this revision

Viewing changes to ivle/worksheet.py

  • 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:
143
143
    """
144
144
    return _get_exercise_attempts(store, user, exercise, as_of,
145
145
        allow_inactive).first()
 
146
 
 
147
def calculate_score(store, user, worksheet):
 
148
    """
 
149
    Given a storm.store, User, Exercise and Worksheet, calculates a score for
 
150
    the user on the given worksheet.
 
151
    Returns a 4-tuple of ints, consisting of:
 
152
    (No. mandatory exercises completed,
 
153
     Total no. mandatory exercises,
 
154
     No. optional exercises completed,
 
155
     Total no. optional exercises)
 
156
    """
 
157
    mand_done = 0
 
158
    mand_total = 0
 
159
    opt_done = 0
 
160
    opt_total = 0
 
161
 
 
162
    # Get the student's pass/fail for each exercise in this worksheet
 
163
    for worksheet_exercise in worksheet.worksheet_exercises:
 
164
        exercise = worksheet_exercise.exercise
 
165
        optional = worksheet_exercise.optional
 
166
 
 
167
        done, _ = get_exercise_status(store, user, exercise)
 
168
        # done is a bool, whether this student has completed that problem
 
169
        if optional:
 
170
            opt_total += 1
 
171
            if done: opt_done += 1
 
172
        else:
 
173
            mand_total += 1
 
174
            if done: mand_done += 1
 
175
 
 
176
    return mand_done, mand_total, opt_done, opt_total