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):
""" Normal view of this XBlock, identical to mentoring_view """
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):
"""
The parent block is handling a student submission, including a new answer for this
......@@ -187,12 +195,7 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
self.student_input = submission[0]['value'].strip()
self.save()
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
return {
'student_input': self.student_input,
'status': self.status,
'weight': self.weight,
'score': 1 if self.status == 'correct' else 0,
}
return self.get_results()
@property
def status(self):
......
......@@ -74,9 +74,7 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
return self._(u"Wrong")
return self._(u"Not Acceptable")
def submit(self, submission):
log.debug(u'Received MCQ submission: "%s"', submission)
def calculate_results(self, submission):
correct = submission in self.correct_choices
tips_html = []
for tip in self.get_tips():
......@@ -94,13 +92,21 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
# Also send to the submissions API:
sub_api.create_submission(self.student_item_key, submission)
result = {
return {
'submission': submission,
'status': 'correct' if correct else 'incorrect',
'tips': formatted_tips if tips_html else None,
'weight': self.weight,
'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)
return result
......
......@@ -81,9 +81,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
return self._(u"Ignored")
return self._(u"Not Acceptable")
def submit(self, submissions):
log.debug(u'Received MRQ submissions: "%s"', submissions)
def calculate_results(self, submissions):
score = 0
results = []
......@@ -117,11 +115,9 @@ class MRQBlock(QuestionnaireAbstractBlock):
results.append(choice_result)
self.student_choices = submissions
status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial'
result = {
return {
'submissions': submissions,
'status': status,
'choices': results,
......@@ -130,6 +126,15 @@ class MRQBlock(QuestionnaireAbstractBlock):
'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)
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