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

« back to all changes in this revision

Viewing changes to ivle/worksheet/utils.py

  • Committer: Matt Giuca
  • Date: 2009-04-24 13:44:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1196.
  • Revision ID: matt.giuca@gmail.com-20090424134439-pwgr5gjluocs7l84
ivle.worksheet.utils: Added calculate_mark, which is from the duplicated code
    in both bin/ivle-marks and ivle.webapp.tutorial.OfferingView.populate.
    This calculates a user's final mark for a subject.
ivle-marks, ivle.webapp.tutorial: Call ivle.worksheet.utils.calculate_mark
    instead of manually calculating (avoid code duplication).

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
 
195
195
    return mand_done, mand_total, opt_done, opt_total
196
196
 
 
197
def calculate_mark(mand_done, mand_total):
 
198
    """Calculate a subject mark, given the result of all worksheets.
 
199
    @param mand_done: The total number of mandatory exercises completed by
 
200
        some student, across all worksheets.
 
201
    @param mand_total: The total number of mandatory exercises across all
 
202
        worksheets in the offering.
 
203
    @return: (percent, mark, mark_total)
 
204
        percent: The percentage of exercises the student has completed, as an
 
205
            integer between 0 and 100 inclusive.
 
206
        mark: The mark the student has received, based on the percentage.
 
207
        mark_total: The total number of marks available (currently hard-coded
 
208
            as 5).
 
209
    """
 
210
    # We want to display a students mark out of 5. However, they are
 
211
    # allowed to skip 1 in 5 questions and still get 'full marks'.
 
212
    # Hence we divide by 16, essentially making 16 percent worth
 
213
    # 1 star, and 80 or above worth 5.
 
214
    percent_int = (100 * mand_done) / mand_total
 
215
    # percent / 16, rounded down, with a maximum mark of 5
 
216
    max_mark = 5
 
217
    mark = min(percent_int // 16, max_mark)
 
218
    return (percent_int, mark, max_mark)
 
219
 
197
220
def update_exerciselist(worksheet):
198
221
    """Runs through the worksheetstream, generating the appropriate
199
222
    WorksheetExercises, and de-activating the old ones."""