Refactor DICOM image div indentation for improved readability in exam review template

This commit is contained in:
Ross
2025-11-10 11:00:54 +00:00
parent fee123741d
commit 486a897e64
2 changed files with 21 additions and 6 deletions
+18 -3
View File
@@ -347,7 +347,15 @@ def exam_review_question_summary(request, pk: int, q_index: int):
pass
# simpler: compute via values and normalise unmarked -> 'empty'
score_counts = {str(row["score"]) if row["score"] is not None else "empty": row["count"] for row in ua_qs.values("score").annotate(count=Count("id"))}
def _norm_score_key(v):
# Treat None or empty-string scores as the 'empty' bucket
if v is None:
return "empty"
if isinstance(v, str) and v.strip() == "":
return "empty"
return str(v)
score_counts = {_norm_score_key(row["score"]): row["count"] for row in ua_qs.values("score").annotate(count=Count("id"))}
# top submitted answers (by answer_compare) with dominant score per answer
# First, get counts grouped by answer_compare and score
@@ -357,7 +365,7 @@ def exam_review_question_summary(request, pk: int, q_index: int):
answer_map = {}
for row in grouped:
ans = row["answer_compare"]
sc = str(row["score"]) if row["score"] is not None else "empty"
sc = _norm_score_key(row["score"])
cnt = row["count"]
if ans not in answer_map:
answer_map[ans] = {"total": 0, "score_counts": {}}
@@ -372,7 +380,14 @@ def exam_review_question_summary(request, pk: int, q_index: int):
# sort by (count desc, score desc) where 'empty' maps to -1
def score_key(item):
s, c = item
s_val = -1 if s == "empty" else int(s)
# Map 'empty' (or any non-numeric key) to a low value so numeric scores win ties
if s == "empty":
s_val = -1
else:
try:
s_val = int(s)
except Exception:
s_val = -1
return (c, s_val)
dominant = max(score_counts.items(), key=score_key)[0]