Skip to content

Commit

Permalink
Fix a rounding error with SingleProblemGrader point values.
Browse files Browse the repository at this point in the history
When computing the point value in the SingleProblemGrader, the
database saves 6 decimal digits in the status field, while the
single problem grader only saved 2. This difference in rounding can
cause the computation of the point value with a stepSize of 0.25
to get get different values between the computed score and the
score saved in the database, causing the "Use points from last check"
button to show up and present a different rounded value.

This fixes the issue by saving the current score in a `$rawCurrnetScore`
variable that isn't rounded and using that for the point computation.
Note, `$rawCurrentScore` can have more than the 6 decimal digits in the
saved database score, but rounding this to match the database won't
improve the accuracy of the point value rounded to the nearest stepSize.
  • Loading branch information
somiaj committed Nov 1, 2024
1 parent dd844c7 commit cc9f673
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions templates/HTML/SingleProblemGrader/grader.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<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) {
Expand All @@ -27,7 +28,7 @@
% @weights = map { $_ / $total } @weights;
%
% for my $part (0 .. $#scores) {
% $currentScore += $scores[$part] * $weights[$part];
% $rawCurrentScore += $scores[$part] * $weights[$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 +70,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 +101,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

0 comments on commit cc9f673

Please sign in to comment.