Simplify wrong answer percentage display
This commit is contained in:
@@ -84,7 +84,9 @@ public class QuestionsController : ControllerBase
|
|||||||
return Ok(new FirstQuestionAttemptResponse
|
return Ok(new FirstQuestionAttemptResponse
|
||||||
{
|
{
|
||||||
QuestionExternalId = question.ExternalId,
|
QuestionExternalId = question.ExternalId,
|
||||||
ChoiceSelectionPercentages = await _attempts.GetPercentagesForQuestionAsync(question.ExternalId)
|
ChoiceSelectionPercentages = QuestionResponse.BuildChoiceSelectionPercentages(
|
||||||
|
question,
|
||||||
|
await _attempts.GetPercentagesForQuestionAsync(question.ExternalId))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ public class QuestionResponse
|
|||||||
CorrectChoiceId = question.CorrectChoiceId,
|
CorrectChoiceId = question.CorrectChoiceId,
|
||||||
Explanation = question.Explanation,
|
Explanation = question.Explanation,
|
||||||
ChoiceExplanations = question.ChoiceExplanations,
|
ChoiceExplanations = question.ChoiceExplanations,
|
||||||
ChoiceSelectionPercentages = liveChoiceSelectionPercentages is { Count: > 0 }
|
ChoiceSelectionPercentages = BuildChoiceSelectionPercentages(question, liveChoiceSelectionPercentages),
|
||||||
? liveChoiceSelectionPercentages
|
|
||||||
: question.ChoiceSelectionPercentages,
|
|
||||||
Discipline = question.Discipline,
|
Discipline = question.Discipline,
|
||||||
System = question.System,
|
System = question.System,
|
||||||
Difficulty = question.Difficulty,
|
Difficulty = question.Difficulty,
|
||||||
@@ -38,6 +36,16 @@ public class QuestionResponse
|
|||||||
Media = question.Media,
|
Media = question.Media,
|
||||||
Tags = question.Tags
|
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
|
public class FirstQuestionAttemptResponse
|
||||||
|
|||||||
@@ -601,10 +601,10 @@ func _set_choice_button_text(index: int, choice: Dictionary) -> void:
|
|||||||
var choice_id := str(choice.get("id", ""))
|
var choice_id := str(choice.get("id", ""))
|
||||||
var choice_text := str(choice.get("text", ""))
|
var choice_text := str(choice.get("text", ""))
|
||||||
if locked_wrong_choice_ids.has(choice_id):
|
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)
|
var percentage := _get_choice_selection_percentage(choice_id)
|
||||||
if percentage >= 0:
|
if percentage >= 0:
|
||||||
text += "\n %d%% chose this on first attempt" % percentage
|
text += "\n %d%%" % percentage
|
||||||
choice_buttons[index].text = text
|
choice_buttons[index].text = text
|
||||||
elif eliminated.has(choice_id):
|
elif eliminated.has(choice_id):
|
||||||
choice_buttons[index].text = "%s. [eliminated] %s" % [choice_id, _strike_text(choice_text)]
|
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:
|
func _get_choice_selection_percentage(choice_id: String) -> int:
|
||||||
var question := BlockSessionService.get_current_question()
|
var question := BlockSessionService.get_current_question()
|
||||||
var percentages: Dictionary = question.get("choice_selection_percentages", {})
|
var percentages: Dictionary = question.get("choice_selection_percentages", {})
|
||||||
if not percentages.has(choice_id):
|
if percentages.is_empty():
|
||||||
return -1
|
return -1
|
||||||
|
if not percentages.has(choice_id):
|
||||||
|
return 0
|
||||||
return clamp(int(percentages.get(choice_id, -1)), 0, 100)
|
return clamp(int(percentages.get(choice_id, -1)), 0, 100)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user