Commit 7f0d3def by Jonathan Piacenti

Add 'get_results' method to all assessment block types

parent 00b3d93f
...@@ -179,6 +179,14 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock): ...@@ -179,6 +179,14 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
""" Normal view of this XBlock, identical to mentoring_view """ """ Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context) return self.mentoring_view(context)
def get_results(self):
return {
'student_input': self.student_input,
'status': self.status,
'weight': self.weight,
'score': 1 if self.status == 'correct' else 0,
}
def submit(self, submission): def submit(self, submission):
""" """
The parent block is handling a student submission, including a new answer for this The parent block is handling a student submission, including a new answer for this
...@@ -187,12 +195,7 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock): ...@@ -187,12 +195,7 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
self.student_input = submission[0]['value'].strip() self.student_input = submission[0]['value'].strip()
self.save() self.save()
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input)) log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
return { return self.get_results()
'student_input': self.student_input,
'status': self.status,
'weight': self.weight,
'score': 1 if self.status == 'correct' else 0,
}
@property @property
def status(self): def status(self):
......
...@@ -74,9 +74,7 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock): ...@@ -74,9 +74,7 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
return self._(u"Wrong") return self._(u"Wrong")
return self._(u"Not Acceptable") return self._(u"Not Acceptable")
def submit(self, submission): def calculate_results(self, submission):
log.debug(u'Received MCQ submission: "%s"', submission)
correct = submission in self.correct_choices correct = submission in self.correct_choices
tips_html = [] tips_html = []
for tip in self.get_tips(): for tip in self.get_tips():
...@@ -86,7 +84,7 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock): ...@@ -86,7 +84,7 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
if tips_html: if tips_html:
formatted_tips = loader.render_template('templates/html/tip_choice_group.html', { formatted_tips = loader.render_template('templates/html/tip_choice_group.html', {
'tips_html': tips_html, 'tips_html': tips_html,
}) })
self.student_choice = submission self.student_choice = submission
...@@ -94,13 +92,21 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock): ...@@ -94,13 +92,21 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
# Also send to the submissions API: # Also send to the submissions API:
sub_api.create_submission(self.student_item_key, submission) sub_api.create_submission(self.student_item_key, submission)
result = { return {
'submission': submission, 'submission': submission,
'status': 'correct' if correct else 'incorrect', 'status': 'correct' if correct else 'incorrect',
'tips': formatted_tips if tips_html else None, 'tips': formatted_tips if tips_html else None,
'weight': self.weight, 'weight': self.weight,
'score': 1 if correct else 0, 'score': 1 if correct else 0,
} }
def get_results(self):
return self.calculate_results(self.student_choice)
def submit(self, submission):
log.debug(u'Received MCQ submission: "%s"', submission)
result = self.calculate_results(submission)
self.student_choice = submission
log.debug(u'MCQ submission result: %s', result) log.debug(u'MCQ submission result: %s', result)
return result return result
......
...@@ -81,9 +81,7 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -81,9 +81,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
return self._(u"Ignored") return self._(u"Ignored")
return self._(u"Not Acceptable") return self._(u"Not Acceptable")
def submit(self, submissions): def calculate_results(self, submissions):
log.debug(u'Received MRQ submissions: "%s"', submissions)
score = 0 score = 0
results = [] results = []
...@@ -106,22 +104,20 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -106,22 +104,20 @@ class MRQBlock(QuestionnaireAbstractBlock):
choice_result = { choice_result = {
'value': choice.value, 'value': choice.value,
'selected': choice_selected, 'selected': choice_selected,
} }
# Only include tips/results in returned response if we want to display them # Only include tips/results in returned response if we want to display them
if not self.hide_results: if not self.hide_results:
loader = ResourceLoader(__name__) loader = ResourceLoader(__name__)
choice_result['completed'] = choice_completed choice_result['completed'] = choice_completed
choice_result['tips'] = loader.render_template('templates/html/tip_choice_group.html', { choice_result['tips'] = loader.render_template('templates/html/tip_choice_group.html', {
'tips_html': choice_tips_html, 'tips_html': choice_tips_html,
}) })
results.append(choice_result) results.append(choice_result)
self.student_choices = submissions
status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial' status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial'
result = { return {
'submissions': submissions, 'submissions': submissions,
'status': status, 'status': status,
'choices': results, 'choices': results,
...@@ -130,6 +126,15 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -130,6 +126,15 @@ class MRQBlock(QuestionnaireAbstractBlock):
'score': (float(score) / len(results)) if results else 0, 'score': (float(score) / len(results)) if results else 0,
} }
def get_results(self):
return self.calculate_results(self.student_choices)
def submit(self, submissions):
log.debug(u'Received MRQ submissions: "%s"', submissions)
result = self.calculate_results(submissions)
self.student_choices = submissions
log.debug(u'MRQ submissions result: %s', result) log.debug(u'MRQ submissions result: %s', result)
return result return result
......
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