Refactor physics exam review scoring to count true/false sub-questions individually and improve accuracy of correct answer calculations
This commit is contained in:
+19
-14
@@ -522,27 +522,32 @@ def exam_review_question_summary(request, pk: int, q_index: int):
|
||||
correct_count = None
|
||||
correct_pct = None
|
||||
try:
|
||||
# per-question max for physics is 5 (see generic.get_max_score mapping)
|
||||
per_question_max = 5
|
||||
# For physics, count true/false sub-questions individually rather than
|
||||
# requiring a full-match across all parts.
|
||||
if total_responses:
|
||||
cnt = 0
|
||||
correct_subitems = 0
|
||||
total_subitems = 0
|
||||
for ua in ua_qs:
|
||||
try:
|
||||
score = ua.get_answer_score()
|
||||
except Exception:
|
||||
continue
|
||||
if isinstance(score, (list, tuple)):
|
||||
try:
|
||||
ssum = sum([s for s in score if isinstance(s, (int, float))])
|
||||
except Exception:
|
||||
continue
|
||||
if ssum == per_question_max:
|
||||
cnt += 1
|
||||
if isinstance(score, (list, tuple)) and score:
|
||||
for s in score:
|
||||
if isinstance(s, (int, float)) and s > 0:
|
||||
correct_subitems += 1
|
||||
total_subitems += len(score)
|
||||
else:
|
||||
if isinstance(score, (int, float)) and score == per_question_max:
|
||||
cnt += 1
|
||||
correct_count = cnt
|
||||
correct_pct = round(100.0 * correct_count / total_responses, 1) if total_responses else 0.0
|
||||
if isinstance(score, (int, float)):
|
||||
if score > 0:
|
||||
correct_subitems += 1
|
||||
total_subitems += 1
|
||||
|
||||
correct_count = correct_subitems
|
||||
if total_subitems:
|
||||
correct_pct = round(100.0 * correct_subitems / total_subitems, 1)
|
||||
else:
|
||||
correct_pct = 0.0
|
||||
else:
|
||||
correct_count = 0
|
||||
correct_pct = 0.0
|
||||
|
||||
Reference in New Issue
Block a user