Simplify wrong answer percentage display

This commit is contained in:
hz
2026-07-11 01:46:37 -05:00
parent 8a86734a0b
commit bdd32c9dac
3 changed files with 19 additions and 7 deletions
@@ -84,7 +84,9 @@ public class QuestionsController : ControllerBase
return Ok(new FirstQuestionAttemptResponse
{
QuestionExternalId = question.ExternalId,
ChoiceSelectionPercentages = await _attempts.GetPercentagesForQuestionAsync(question.ExternalId)
ChoiceSelectionPercentages = QuestionResponse.BuildChoiceSelectionPercentages(
question,
await _attempts.GetPercentagesForQuestionAsync(question.ExternalId))
});
}
+11 -3
View File
@@ -28,9 +28,7 @@ public class QuestionResponse
CorrectChoiceId = question.CorrectChoiceId,
Explanation = question.Explanation,
ChoiceExplanations = question.ChoiceExplanations,
ChoiceSelectionPercentages = liveChoiceSelectionPercentages is { Count: > 0 }
? liveChoiceSelectionPercentages
: question.ChoiceSelectionPercentages,
ChoiceSelectionPercentages = BuildChoiceSelectionPercentages(question, liveChoiceSelectionPercentages),
Discipline = question.Discipline,
System = question.System,
Difficulty = question.Difficulty,
@@ -38,6 +36,16 @@ public class QuestionResponse
Media = question.Media,
Tags = question.Tags
};
public static Dictionary<string, int> BuildChoiceSelectionPercentages(Question question, Dictionary<string, int>? liveChoiceSelectionPercentages)
{
if (liveChoiceSelectionPercentages is not { Count: > 0 })
return question.ChoiceSelectionPercentages;
return question.Choices.ToDictionary(
choice => choice.Id,
choice => liveChoiceSelectionPercentages.GetValueOrDefault(choice.Id, 0));
}
}
public class FirstQuestionAttemptResponse
+5 -3
View File
@@ -601,10 +601,10 @@ func _set_choice_button_text(index: int, choice: Dictionary) -> void:
var choice_id := str(choice.get("id", ""))
var choice_text := str(choice.get("text", ""))
if locked_wrong_choice_ids.has(choice_id):
var text := "%s. [wrong] %s" % [choice_id, _strike_text(choice_text)]
var text := "%s. %s" % [choice_id, _strike_text(choice_text)]
var percentage := _get_choice_selection_percentage(choice_id)
if percentage >= 0:
text += "\n %d%% chose this on first attempt" % percentage
text += "\n %d%%" % percentage
choice_buttons[index].text = text
elif eliminated.has(choice_id):
choice_buttons[index].text = "%s. [eliminated] %s" % [choice_id, _strike_text(choice_text)]
@@ -615,8 +615,10 @@ func _set_choice_button_text(index: int, choice: Dictionary) -> void:
func _get_choice_selection_percentage(choice_id: String) -> int:
var question := BlockSessionService.get_current_question()
var percentages: Dictionary = question.get("choice_selection_percentages", {})
if not percentages.has(choice_id):
if percentages.is_empty():
return -1
if not percentages.has(choice_id):
return 0
return clamp(int(percentages.get(choice_id, -1)), 0, 100)