From 4cbe18ebfd7acf1aa4062412e0f66885a71cf397 Mon Sep 17 00:00:00 2001 From: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:00:01 +0000 Subject: [PATCH] fix(sessions): leave pending answers out of the quiz score The [Quiz Performance] score counts only graded answers and states how many are not graded yet, instead of counting a pending photo answer as wrong. Refresh the router index for the router changes in this series. Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> --- deeptutor/api/router_index.json | 2 +- deeptutor/api/routers/sessions.py | 9 ++++++--- tests/api/test_notebook_router.py | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/deeptutor/api/router_index.json b/deeptutor/api/router_index.json index 03f68c95f..622201e5d 100644 --- a/deeptutor/api/router_index.json +++ b/deeptutor/api/router_index.json @@ -1,5 +1,5 @@ { - "fingerprint": "fa4a06aa1f5f2711229588b6eaba8bb307d90fe90a0dc31f19876cc900f1f7de", + "fingerprint": "c0ca823892e8dce785b3b8518761ecf4f960cfaf38da2dda9b1112230ea06a1d", "routers": { "deeptutor.api.routers.auth:router": [ { diff --git a/deeptutor/api/routers/sessions.py b/deeptutor/api/routers/sessions.py index 533ce06bc..75768ef3f 100644 --- a/deeptutor/api/routers/sessions.py +++ b/deeptutor/api/routers/sessions.py @@ -147,8 +147,10 @@ class QuizResultsRequest(BaseModel): def _format_quiz_results_message(answers: list[QuizResultItem]) -> str: - total = len(answers) - correct = sum(1 for item in answers if item.is_correct) + # A pending (ungraded) answer is neither right nor wrong in the score. + ungraded = sum(1 for item in answers if item.result == "ungraded") + total = len(answers) - ungraded + correct = sum(1 for item in answers if item.is_correct and item.result != "ungraded") score_pct = round((correct / total) * 100) if total else 0 lines = ["[Quiz Performance]"] for idx, item in enumerate(answers, 1): @@ -163,7 +165,8 @@ def _format_quiz_results_message(answers: list[QuizResultItem]) -> str: suffix = f" ({status}, correct: {(item.correct_answer or '').strip()})" qid = f"[{item.question_id}] " if item.question_id else "" lines.append(f"{idx}. {qid}Q: {question} -> Answered: {user_answer}{suffix}") - lines.append(f"Score: {correct}/{total} ({score_pct}%)") + pending = f", {ungraded} not graded" if ungraded else "" + lines.append(f"Score: {correct}/{total} ({score_pct}%){pending}") return "\n".join(lines) diff --git a/tests/api/test_notebook_router.py b/tests/api/test_notebook_router.py index 4701aa112..99a20ed79 100644 --- a/tests/api/test_notebook_router.py +++ b/tests/api/test_notebook_router.py @@ -618,6 +618,8 @@ def test_quiz_results_keep_a_judged_result(store: SQLiteSessionStore) -> None: in resp.json()["content"] ) assert "(Partially correct" in resp.json()["content"] + # A pending photo answer is neither right nor wrong in the score. + assert resp.json()["content"].endswith("Score: 0/1 (0%), 1 not graded") items = client.get("/api/question-notebook/entries").json()["items"] by_id = {item["question_id"]: item for item in items}