Commit aba25c2d by Waheed Ahmed Committed by Adam Palay

In OpenEndedModule latest_score and all_score calculate sum of rubric scores…

In OpenEndedModule latest_score and all_score calculate sum of rubric scores every time for ML grading.
ORA-72
parent 7e4820af
...@@ -258,8 +258,23 @@ class CombinedOpenEndedV1Module(): ...@@ -258,8 +258,23 @@ class CombinedOpenEndedV1Module():
if not task_states: if not task_states:
return (0, 0, state_values[OpenEndedChild.INITIAL], idx) return (0, 0, state_values[OpenEndedChild.INITIAL], idx)
final_child_state = json.loads(task_states[-1]) final_task_xml = self.task_xml[-1]
scores = [attempt.get('score', 0) for attempt in final_child_state.get('child_history', [])] final_child_state_json = task_states[-1]
final_child_state = json.loads(final_child_state_json)
tag_name = self.get_tag_name(final_task_xml)
children = self.child_modules()
task_descriptor = children['descriptors'][tag_name](self.system)
task_parsed_xml = task_descriptor.definition_from_xml(etree.fromstring(final_task_xml), self.system)
task = children['modules'][tag_name](
self.system,
self.location,
task_parsed_xml,
task_descriptor,
self.static_data,
instance_state=final_child_state_json,
)
scores = task.all_scores()
if scores: if scores:
best_score = max(scores) best_score = max(scores)
else: else:
......
...@@ -679,7 +679,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild): ...@@ -679,7 +679,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
return { return {
'success': success, 'success': success,
'error': error_message, 'error': error_message,
'student_response': data['student_answer'].replace("\n","<br/>") 'student_response': data['student_answer'].replace("\n", "<br/>")
} }
def update_score(self, data, system): def update_score(self, data, system):
...@@ -738,6 +738,44 @@ class OpenEndedModule(openendedchild.OpenEndedChild): ...@@ -738,6 +738,44 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
html = system.render_template('{0}/open_ended.html'.format(self.TEMPLATE_DIR), context) html = system.render_template('{0}/open_ended.html'.format(self.TEMPLATE_DIR), context)
return html return html
def latest_score(self):
"""None if not available"""
if not self.child_history:
return None
return self.score_for_attempt(-1)
def all_scores(self):
"""None if not available"""
if not self.child_history:
return None
return [self.score_for_attempt(index) for index in xrange(0, len(self.child_history))]
def score_for_attempt(self, index):
"""
Return sum of rubric scores for ML grading otherwise return attempt["score"].
"""
attempt = self.child_history[index]
score = attempt.get('score')
post_assessment_data = self._parse_score_msg(attempt.get('post_assessment'), self.system)
grader_types = post_assessment_data.get('grader_types')
# According to _parse_score_msg in ML grading there should be only one grader type.
if len(grader_types) == 1 and grader_types[0] == 'ML':
rubric_scores = post_assessment_data.get("rubric_scores")
# Similarly there should be only one list of rubric scores.
if len(rubric_scores) == 1:
rubric_scores_sum = sum(rubric_scores[0])
log.debug("""Score normalized for location={loc}, old_score={old_score},
new_score={new_score}, rubric_score={rubric_score}""".format(
loc=self.location_string,
old_score=score,
new_score=rubric_scores_sum,
rubric_score=rubric_scores
))
return rubric_scores_sum
return score
class OpenEndedDescriptor(): class OpenEndedDescriptor():
""" """
......
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