Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a rounding error with SingleProblemGrader point values. #2613

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions templates/HTML/SingleProblemGrader/grader.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
<div class="problem-grader">
<hr>
<div class="problem-grader-table">
% my $currentScore = 0;
% my $currentScore = 0;
% my $rawCurrentScore = 0;
%
% # Subscores for each answer in the problem.
% if (@{ $grader->{pg}{flags}{ANSWER_ENTRY_ORDER} } > 1) {
% # Determine the scores and weights for each part of the problem.
% my $total = 0;
% my (@scores, @weights);
% for my $ans_id (@{ $grader->{pg}{flags}{ANSWER_ENTRY_ORDER} }) {
% push(@scores, wwRound(0, $grader->{pg}{answers}{$ans_id}{score} * 100));
% push(@scores, $grader->{pg}{answers}{$ans_id}{score} * 100);
% push(@weights, $grader->{pg}{answers}{$ans_id}{weight} // 1);
% $total += $weights[-1];
% }
Expand All @@ -27,7 +28,8 @@
% @weights = map { $_ / $total } @weights;
%
% for my $part (0 .. $#scores) {
% $currentScore += $scores[$part] * $weights[$part];
% $rawCurrentScore += $scores[$part] * $weights[$part];
% $scores[$part] = wwRound(0, $scores[$part]);
<div class="row align-items-center mb-2">
<%= label_for "score_problem$grader->{problem_id}_$grader->{pg}{flags}{ANSWER_ENTRY_ORDER}[$part]",
class => 'col-fixed col-form-label',
Expand Down Expand Up @@ -69,10 +71,10 @@
</div>
</div>
% }
% $currentScore = wwRound(0, $currentScore);
% $currentScore = wwRound(0, $rawCurrentScore);
% } elsif (@{ $grader->{pg}{flags}{ANSWER_ENTRY_ORDER} }) {
% $currentScore =
% wwRound(0, $grader->{pg}{answers}{ $grader->{pg}{flags}{ANSWER_ENTRY_ORDER}[0] }{score} * 100);
% $rawCurrentScore = $grader->{pg}{answers}{ $grader->{pg}{flags}{ANSWER_ENTRY_ORDER}[0] }{score} * 100;
% $currentScore = wwRound(0, $rawCurrentScore);
<%= hidden_field 'answer-part-score' => $currentScore, class => 'answer-part-score',
data => { problem_id => $grader->{problem_id}, weight => 1 } =%>
% }
Expand Down Expand Up @@ -100,7 +102,7 @@
% my $recordedPoints =
% wwRound(2, wwRound(0, $grader->{recorded_score} * $grader->{problem_value} / $stepSize) * $stepSize);
% my $currentPoints =
% wwRound(2, wwRound(0, $currentScore / 100 * $grader->{problem_value} / $stepSize) * $stepSize);
% wwRound(2, wwRound(0, $rawCurrentScore / 100 * $grader->{problem_value} / $stepSize) * $stepSize);
% param('grader-problem-points', $recordedPoints);
<div class="row align-items-center mb-2">
<%= label_for "score_problem$grader->{problem_id}_points",
Expand Down