compute_grades.py 1.53 KB
Newer Older
1 2 3 4 5
#!/usr/bin/python
#
# django management command: dump grades to csv files
# for use by batch processes

6
from instructor.offline_gradecalc import offline_grade_calculation
7 8 9 10 11
from courseware.courses import get_course_by_id
from xmodule.modulestore.django import modulestore

from django.core.management.base import BaseCommand

Calen Pennington committed
12

13 14 15 16
class Command(BaseCommand):
    help = "Compute grades for all students in a course, and store result in DB.\n"
    help += "Usage: compute_grades course_id_or_dir \n"
    help += "   course_id_or_dir: either course_id or course_dir\n"
17
    help += 'Example course_id: MITx/8.01rq_MW/Classical_Mechanics_Reading_Questions_Fall_2012_MW_Section'
18 19 20 21 22

    def handle(self, *args, **options):

        print "args = ", args

Calen Pennington committed
23
        if len(args) > 0:
24
            course_id = args[0]
25 26 27
        else:
            print self.help
            return
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

        try:
            course = get_course_by_id(course_id)
        except Exception as err:
            if course_id in modulestore().courses:
                course = modulestore().courses[course_id]
            else:
                print "-----------------------------------------------------------------------------"
                print "Sorry, cannot find course %s" % course_id
                print "Please provide a course ID or course data directory name, eg content-mit-801rq"
                return

        print "-----------------------------------------------------------------------------"
        print "Computing grades for %s" % (course.id)

        offline_grade_calculation(course.id)