Ejemplo n.º 1
0
def offline_grade_calculation(course_key):
    '''
    Compute grades for all students for a specified course, and save results to the DB.
    '''

    tstart = time.time()
    enrolled_students = User.objects.filter(
        courseenrollment__course_id=course_key,
        courseenrollment__is_active=1
    ).prefetch_related("groups").order_by('username')

    enc = MyEncoder()

    print "{} enrolled students".format(len(enrolled_students))
    course = get_course_by_id(course_key)

    for student in enrolled_students:
        request = DummyRequest()
        request.user = student
        request.session = {}

        gradeset = grades.grade(student, request, course, keep_raw_scores=True)
        gs = enc.encode(gradeset)
        ocg, _created = models.OfflineComputedGrade.objects.get_or_create(user=student, course_id=course_key)
        ocg.gradeset = gs
        ocg.save()
        print "%s done" % student  	# print statement used because this is run by a management command

    tend = time.time()
    dt = tend - tstart

    ocgl = models.OfflineComputedGradeLog(course_id=course_key, seconds=dt, nstudents=len(enrolled_students))
    ocgl.save()
    print ocgl
    print "All Done!"
Ejemplo n.º 2
0
def offline_grade_calculation(course_id):
    '''
    Compute grades for all students for a specified course, and save results to the DB.
    '''

    tstart = time.time()
    enrolled_students = User.objects.filter(
        courseenrollment__course_id=course_id).prefetch_related(
            "groups").order_by('username')

    enc = MyEncoder()

    class DummyRequest(object):
        META = {}

        def __init__(self):
            return

        def get_host(self):
            return 'edx.mit.edu'

        def is_secure(self):
            return False

    request = DummyRequest()

    print "%d enrolled students" % len(enrolled_students)
    course = get_course_by_id(course_id)

    for student in enrolled_students:
        gradeset = grades.grade(student, request, course, keep_raw_scores=True)
        gs = enc.encode(gradeset)
        ocg, created = models.OfflineComputedGrade.objects.get_or_create(
            user=student, course_id=course_id)
        ocg.gradeset = gs
        ocg.save()
        print "%s done" % student  # print statement used because this is run by a management command

    tend = time.time()
    dt = tend - tstart

    ocgl = models.OfflineComputedGradeLog(course_id=course_id,
                                          seconds=dt,
                                          nstudents=len(enrolled_students))
    ocgl.save()
    print ocgl
    print "All Done!"
Ejemplo n.º 3
0
def offline_grade_calculation(course):
    '''
    Compute grades for all students for a specified course, and save results to the DB.
    '''

    tstart = time.time()
    enrolled_students = User.objects.filter(
        courseenrollment__course_id=course.id,
        courseenrollment__is_active=1).prefetch_related("groups").order_by(
            'username')

    enc = MyEncoder()
    all_studnets = len(enrolled_students)
    print "{} enrolled students in {}".format(all_studnets, course.id)
    counter = 0
    for student in enrolled_students:
        counter += 1
        if counter % 1000 == 0:
            print "{}/{} done: Course {}".format(counter, all_studnets,
                                                 course.id)
        request = DummyRequest()
        request.user = student
        request.session = {}

        gradeset = grades.grade(student, request, course, keep_raw_scores=True)
        ocg, _created = models.OfflineComputedGrade.objects.get_or_create(
            user=student, course_id=course.id)
        ocg.gradeset = gradeset['grade']
        ocg.save()

    tend = time.time()
    dt = tend - tstart

    ocgl = models.OfflineComputedGradeLog(course_id=course.id,
                                          seconds=dt,
                                          nstudents=len(enrolled_students))
    ocgl.save()
    print ocgl
    print "All Done!"