Commit 234fb813 by Bridger Maxwell

Changed grades.grade to use new xmodule API. Now properly explores descriptor tree.

parent 28826b8a
...@@ -27,6 +27,30 @@ def yield_module_descendents(module): ...@@ -27,6 +27,30 @@ def yield_module_descendents(module):
stack.extend( next_module.get_display_items() ) stack.extend( next_module.get_display_items() )
yield next_module yield next_module
def yield_dynamic_descriptor_descendents(descriptor, module_creator):
"""
This returns all of the descendants of a descriptor. If the descriptor
has dynamic children, the module will be created using module_creator
and the children (as descriptors) of that module will be returned.
"""
def get_dynamic_descriptor_children(descriptor):
if descriptor.has_dynamic_children():
module = module_creator(descriptor)
children_locations = module.get_children_locations()
return [descriptor.system.load_item(child_location) for child_location in child_locations ]
else:
return descriptor.get_children()
stack = get_dynamic_descriptor_children(descriptor)
stack.reverse()
while len(stack) > 0:
next_descriptor = stack.pop()
stack.extend( get_dynamic_descriptor_children(next_descriptor) )
yield next_descriptor
def yield_problems(request, course, student): def yield_problems(request, course, student):
""" """
Return an iterator over capa_modules that this student has Return an iterator over capa_modules that this student has
...@@ -128,7 +152,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F ...@@ -128,7 +152,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
section_name = section_descriptor.metadata.get('display_name') section_name = section_descriptor.metadata.get('display_name')
should_grade_section = False should_grade_section = False
# If we haven't seen a single problem in the section, we don't have to grade it at all! We can assume 0% # If we haven't seen a single problem in the section, we don't have to grade it at all! We can assume 0%
for moduledescriptor in section['xmoduledescriptors']: for moduledescriptor in section['xmoduledescriptors']:
if student_module_cache.lookup( if student_module_cache.lookup(
course.id, moduledescriptor.category, moduledescriptor.location.url()): course.id, moduledescriptor.category, moduledescriptor.location.url()):
...@@ -137,23 +161,16 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F ...@@ -137,23 +161,16 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
if should_grade_section: if should_grade_section:
scores = [] scores = []
# TODO: We need the request to pass into here. If we could forgo that, our arguments
# would be simpler
section_module = get_module(student, request,
section_descriptor.location, student_module_cache,
course.id)
if section_module is None:
# student doesn't have access to this module, or something else
# went wrong.
continue
#TODO: This won't get all problems, will it? They could be hidden in a sub-child. What is a better def create_module(descriptor):
# way of getting all of the children as descriptors? # TODO: We need the request to pass into here. If we could forgo that, our arguments
module_locations = section_module.definition.get('children', []) # would be simpler
for module_location in module_locations: return get_module(student, request, descriptor.location,
module_descriptor = section_module.descriptor.system.load_item(module_location) student_module_cache, course.id)
(correct, total) = get_score(course.id, student, module_descriptor, section_module.system, student_module_cache) for module_descriptor in yield_dynamic_descriptor_descendents(section_descriptor, create_module):
(correct, total) = get_score(course.id, student, module_descriptor, create_module, student_module_cache)
if correct is None and total is None: if correct is None and total is None:
continue continue
...@@ -277,7 +294,8 @@ def progress_summary(student, request, course, grader, student_module_cache): ...@@ -277,7 +294,8 @@ def progress_summary(student, request, course, grader, student_module_cache):
module_descriptor = course.system.load_item(module_location) module_descriptor = course.system.load_item(module_location)
course_id = course.id course_id = course.id
(correct, total) = get_score(course_id, student, module_descriptor, section_module.system, student_module_cache) module_creator = lambda decriptor : section_module.system.get_module(descriptor.location)
(correct, total) = get_score(course_id, student, module_descriptor, module_creator, student_module_cache)
if correct is None and total is None: if correct is None and total is None:
continue continue
...@@ -306,7 +324,7 @@ def progress_summary(student, request, course, grader, student_module_cache): ...@@ -306,7 +324,7 @@ def progress_summary(student, request, course, grader, student_module_cache):
return chapters return chapters
def get_score(course_id, user, problem_descriptor, xmodule_system, student_module_cache): def get_score(course_id, user, problem_descriptor, module_creator, student_module_cache):
""" """
Return the score for a user on a problem, as a tuple (correct, total). Return the score for a user on a problem, as a tuple (correct, total).
...@@ -326,7 +344,7 @@ def get_score(course_id, user, problem_descriptor, xmodule_system, student_modul ...@@ -326,7 +344,7 @@ def get_score(course_id, user, problem_descriptor, xmodule_system, student_modul
if not instance_module: if not instance_module:
# If the problem was not in the cache, we need to instantiate the problem. # If the problem was not in the cache, we need to instantiate the problem.
# Otherwise, the max score (cached in instance_module) won't be available # Otherwise, the max score (cached in instance_module) won't be available
problem = xmodule_system.get_module(problem_descriptor.location) problem = module_creator(problem_descriptor)
instance_module = get_instance_module(course_id, user, problem, student_module_cache) instance_module = get_instance_module(course_id, user, problem, student_module_cache)
# If this problem is ungraded/ungradable, bail # If this problem is ungraded/ungradable, bail
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment