Commit f448b63c by Bill Filler

optimize calls to calculate subsection grade

parent 61a38ec8
......@@ -297,7 +297,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
banner_text = _('This subsection is unlocked for learners when they meet the prerequisite requirements.')
else:
# check if prerequiste has been met
prereq_met, prereq_meta_info = self._is_prereq_met(True)
prereq_met, prereq_meta_info = self._compute_is_prereq_met(True)
fragment = Fragment()
params = {
......@@ -339,7 +339,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
return False
def _is_prereq_met(self, recalc_on_unmet):
def _compute_is_prereq_met(self, recalc_on_unmet):
"""
Evaluate if the user has completed the prerequiste
......@@ -352,7 +352,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
"""
gating_service = self.runtime.service(self, 'gating')
if gating_service:
return gating_service.is_prereq_met(self.location, self.runtime.user_id, recalc_on_unmet)
return gating_service.compute_is_prereq_met(self.location, self.runtime.user_id, recalc_on_unmet)
return False, {}
......
......@@ -306,9 +306,10 @@ def get_gated_content(course, user):
]
def is_prereq_met(content_id, user_id, recalc_on_unmet=False):
def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
"""
Returns true if the prequiste has been met for a given milestone
Returns true if the prequiste has been met for a given milestone.
Will recalculate the subsection grade if specified and prereq unmet
Arguments:
content_id (BlockUsageLocator): BlockUsageLocator for the content
......@@ -339,14 +340,13 @@ def is_prereq_met(content_id, user_id, recalc_on_unmet=False):
store = modulestore()
with store.bulk_operations(course_id):
course_structure = get_course_blocks(student, store.make_course_usage_key(course_id))
course = store.get_course(course_id, depth=0)
subsection_grade_factory = SubsectionGradeFactory(student, course, course_structure)
subsection_usage_key = UsageKey.from_string(_get_gating_block_id(milestone))
subsection_structure = get_course_blocks(student, subsection_usage_key)
subsection_grade_factory = SubsectionGradeFactory(student, None, subsection_structure)
if subsection_usage_key in course_structure:
if subsection_usage_key in subsection_structure:
# this will force a recalcuation of the subsection grade
subsection_grade = subsection_grade_factory.update(course_structure[subsection_usage_key])
subsection_grade = subsection_grade_factory.update(subsection_structure[subsection_usage_key])
prereq_met = update_milestone(milestone, subsection_grade, milestone, user_id)
prereq_meta_info = {
'url': reverse('jump_to', kwargs={'course_id': course_id, 'location': subsection_usage_key}),
......@@ -405,7 +405,7 @@ def _get_subsection_percentage(subsection_grade):
"""
Returns the percentage value of the given subsection_grade.
"""
return _calculate_ratio(subsection_grade.graded_total.earned, subsection_grade.graded_total.possible) * 100.0
return subsection_grade.percent_graded * 100.0
def _calculate_ratio(earned, possible):
......
......@@ -9,7 +9,7 @@ class GatingService(object):
An XBlock service to talk to the Gating api.
"""
def is_prereq_met(self, content_id, user_id, recalc_on_unmet=False):
def compute_is_prereq_met(self, content_id, user_id, recalc_on_unmet=False):
"""
Returns true if the prequiste has been met for a given milestone
......@@ -22,7 +22,7 @@ class GatingService(object):
tuple: True|False,
prereq_meta_info = { 'url': prereq_url|None, 'display_name': prereq_name|None}
"""
return gating_api.is_prereq_met(content_id, user_id, recalc_on_unmet)
return gating_api.compute_is_prereq_met(content_id, user_id, recalc_on_unmet)
def is_prereq_required(self, course_key, content_key, relationship):
"""
......
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