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

« back to all changes in this revision

Viewing changes to ivle/worksheet/utils.py

  • Committer: Matt Giuca
  • Date: 2010-02-24 13:13:21 UTC
  • mfrom: (1689.1.19 worksheet-marks)
  • Revision ID: matt.giuca@gmail.com-20100224131321-eno7xbrqsyukz869
Added worksheet marks reporting UI for lecturers. This includes the ability to view worksheet marks table in the web application and download as a CSV, as well as some basic statistics on exercise completion. Removed the ivle-marks script, as now lecturers can get the same data themselves. Fixes Launchpad bug #520179.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
import ivle.database
32
32
from ivle.database import ExerciseAttempt, ExerciseSave, Worksheet, \
33
 
                          WorksheetExercise, Exercise
 
33
                          WorksheetExercise, Exercise, User
34
34
import ivle.webapp.tutorial.test
35
35
 
36
36
__all__ = ['ExerciseNotFound', 'get_exercise_status',
 
37
           'get_exercise_statistics',
37
38
           'get_exercise_stored_text', 'get_exercise_attempts',
38
39
           'get_exercise_attempt', 'test_exercise_submission',
39
40
          ]
82
83
 
83
84
    return first_success is not None, num_attempts
84
85
 
 
86
def get_exercise_statistics(store, worksheet_exercise):
 
87
    """Return statistics about an exercise (with respect to a given
 
88
    worksheet).
 
89
    (number of students completed, number of students attempted)."""
 
90
    # Count the set of Users whose ID matches an attempt in this worksheet
 
91
    num_completed = store.find(User, User.id == ExerciseAttempt.user_id,
 
92
        ExerciseAttempt.ws_ex_id == worksheet_exercise.id,
 
93
        ExerciseAttempt.complete == True).config(distinct=True).count()
 
94
    num_attempted = store.find(User, User.id == ExerciseAttempt.user_id,
 
95
        ExerciseAttempt.ws_ex_id == worksheet_exercise.id,
 
96
        ).config(distinct=True).count()
 
97
    return num_completed, num_attempted
 
98
 
85
99
def get_exercise_stored_text(store, user, worksheet_exercise):
86
100
    """Given a storm.store, User and WorksheetExercise, returns an
87
101
    ivle.database.ExerciseSave object for the last saved/submitted attempt for