Commit 859aaff4 by dragonfi

Use str instead of mixed types for completion status

parent beb43c10
......@@ -121,18 +121,18 @@ class AnswerBlock(LightChild, StepMixin):
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
return {
'student_input': self.student_input,
'completed': self.completed,
'status': self.status,
'weight': self.weight,
'score': 1 if self.completed else 0,
'score': 1 if self.status == 'correct' else 0,
}
@property
def completed(self):
def status(self):
answer_length_ok = self.student_input
if self.min_characters > 0:
answer_length_ok = len(self.student_input.strip()) >= self.min_characters
return bool(self.read_only or answer_length_ok)
return 'correct' if (self.read_only or answer_length_ok) else 'incorrect'
def save(self):
"""
......
......@@ -52,31 +52,31 @@ class MCQBlock(QuestionnaireAbstractBlock):
def submit(self, submission):
log.debug(u'Received MCQ submission: "%s"', submission)
completed = True
correct = True
tips_fragments = []
for tip in self.get_tips():
completed = completed and self.is_tip_completed(tip, submission)
correct = correct and self.is_tip_correct(tip, submission)
if submission in tip.display_with_defaults:
tips_fragments.append(tip.render())
formatted_tips = render_template('templates/html/tip_choice_group.html', {
'self': self,
'tips_fragments': tips_fragments,
'completed': completed,
'completed': correct,
})
self.student_choice = submission
result = {
'submission': submission,
'completed': completed,
'status': 'correct' if correct else 'incorrect',
'tips': formatted_tips,
'weight': self.weight,
'score': 1 if completed else 0,
'score': 1 if correct else 0,
}
log.debug(u'MCQ submission result: %s', result)
return result
def is_tip_completed(self, tip, submission):
def is_tip_correct(self, tip, submission):
if not submission:
return False
......
......@@ -113,9 +113,9 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
if total_child_weight == 0:
return (0, 0, 0, 0)
score = sum(r[1]['score'] * r[1]['weight'] for r in self.student_results) / total_child_weight
correct = sum(1 for r in self.student_results if r[1]['completed'] is True)
incorrect = sum(1 for r in self.student_results if r[1]['completed'] is False)
partially_correct = sum(1 for r in self.student_results if r[1]['completed'] is 'partial')
correct = sum(1 for r in self.student_results if r[1]['status'] == 'correct')
incorrect = sum(1 for r in self.student_results if r[1]['status'] == 'incorrect')
partially_correct = sum(1 for r in self.student_results if r[1]['status'] == 'partial')
return (score, int(round(score * 100)), correct, incorrect, partially_correct)
......@@ -217,7 +217,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
child_result = child.submit(submission)
submit_results.append([child.name, child_result])
child.save()
completed = completed and (child_result['completed'] is True)
completed = completed and (child_result['status'] == 'correct')
if self.max_attempts_reached:
message = self.get_message_html('max_attempts_reached')
......@@ -303,7 +303,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
del child_result['tips']
self.student_results.append([child.name, child_result])
child.save()
completed = child_result['completed']
completed = child_result['status'] == 'correct'
event_data = {}
......
......@@ -83,11 +83,11 @@ class MRQBlock(QuestionnaireAbstractBlock):
self.student_choices = submissions
completed = False if score <= 0 else True if score >= len(results) else 'partial'
status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial'
result = {
'submissions': submissions,
'completed': completed,
'status': status,
'choices': results,
'message': self.message,
'weight': self.weight,
......
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