Skip to content

Commit

Permalink
feat: add cut-off score to test score slide
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Aug 1, 2024
1 parent bc60284 commit cfb83df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions multi_problem_xblock/multi_problem_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import logging
import math
from copy import copy

from lxml import etree
Expand Down Expand Up @@ -273,20 +274,26 @@ def get_test_scores(self, _data, _suffix):
if completed_problems != total_problems and total_problems > 0:
return Response(_('All problems need to be completed before checking test results!'), status=400)
question_answers, student_score, total_possible_score = self._prepare_user_score(include_question_answers=True)
passed = False

if self.score_display_format == SCORE_DISPLAY_FORMAT.X_OUT_OF_Y:
score_display = f'{student_score}/{total_possible_score}'
cut_off_score = f'{math.ceil(self.cut_off_score * total_possible_score)}/{total_possible_score}'
else:
score_display = f'{(student_score / total_possible_score):.0%}'
cut_off_score = f'{self.cut_off_score:.0%}'

if (student_score / total_possible_score) >= self.cut_off_score:
self.publish_completion(1)
passed = True

template = loader.render_django_template(
'/templates/html/multi_problem_xblock_test_scores.html',
{
'cut_off_score': cut_off_score if self.cut_off_score else '',
'question_answers': question_answers,
'score': score_display,
'passed': passed,
},
)
return Response(template, content_type='text/html')
Expand Down
4 changes: 4 additions & 0 deletions multi_problem_xblock/public/css/multi_problem_xblock.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
margin-right: 10px;
}

.multi-problem-test-results .text-red {
color: #b4131b;
}

.multi-problem-test-results .accordion.correct:after {
content: var(--correct-svg);
margin-left: auto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ <h2 class="hd hd-2 text-center">{% trans 'Test score' %}</h2>
{% endfor %}
<div class="test-score-row p-3 pl-5 hd-5">
<b>{% trans 'Test Score' %}</b>
<b class="test-score">{{ score }}</b>
{% if cut_off_score != '' %}<sup>1</sup>{% endif %}
<b class="test-score{% if not passed %} text-red{% endif %}">{{ score }}</b>
</div>
</div>
{% if cut_off_score != '' %}
<small class="pl-3">
<sup>1</sup>
{% trans 'Minimum score required for this to be marked as complete: ' %}
{{ cut_off_score }}
</small>
{% endif %}
</div>

0 comments on commit cfb83df

Please sign in to comment.