diff --git a/lib/WeBWorK/ContentGenerator/Grades.pm b/lib/WeBWorK/ContentGenerator/Grades.pm index 6845193158..bc6881fa36 100644 --- a/lib/WeBWorK/ContentGenerator/Grades.pm +++ b/lib/WeBWorK/ContentGenerator/Grades.pm @@ -26,6 +26,7 @@ use WeBWorK::Utils qw(wwRound); use WeBWorK::Utils::DateTime qw(after); use WeBWorK::Utils::JITAR qw(jitar_id_to_seq); use WeBWorK::Utils::Sets qw(grade_set format_set_name_display); +use WeBWorK::Utils::ProblemProcessing qw(compute_unreduced_score); use WeBWorK::Localize; sub initialize ($c) { @@ -319,7 +320,7 @@ sub displayStudentStats ($c, $studentID) { next; } - my ($totalRight, $total, $problem_scores, $problem_incorrect_attempts) = + my ($totalRight, $total, $problem_scores, $problem_incorrect_attempts, $problem_records) = grade_set($db, $set, $studentID, $setIsVersioned, 1); $totalRight = wwRound(2, $totalRight); @@ -334,8 +335,9 @@ sub displayStudentStats ($c, $studentID) { $show_problem_scores = 0; } - for (my $i = 0; $i < $max_problems; ++$i) { - my $score = defined $problem_scores->[$i] && $show_problem_scores ? $problem_scores->[$i] : ''; + for my $i (0 .. $max_problems - 1) { + my $score = defined $problem_scores->[$i] && $show_problem_scores ? $problem_scores->[$i] : ''; + my $is_correct = $score =~ /^\d+$/ && compute_unreduced_score($ce, $problem_records->[$i], $set) == 1; push( @html_prob_scores, $c->tag( @@ -344,7 +346,7 @@ sub displayStudentStats ($c, $studentID) { $c->c( $c->tag( 'span', - class => $score eq '100' ? 'correct' : $score eq ' . ' ? 'unattempted' : '', + class => $is_correct ? 'correct' : $score eq ' . ' ? 'unattempted' : '', $c->b($score) ), $c->tag('br'), diff --git a/lib/WeBWorK/Utils/Sets.pm b/lib/WeBWorK/Utils/Sets.pm index 5c2d69c868..9d13fe4165 100644 --- a/lib/WeBWorK/Utils/Sets.pm +++ b/lib/WeBWorK/Utils/Sets.pm @@ -114,7 +114,7 @@ sub grade_set ($db, $set, $studentName, $setIsVersioned = 0, $wantProblemDetails } if (wantarray) { - return ($totalRight, $total, $problem_scores, $problem_incorrect_attempts); + return ($totalRight, $total, $problem_scores, $problem_incorrect_attempts, \@problemRecords); } else { return $total ? $totalRight / $total : 0; } @@ -309,7 +309,8 @@ In list context this returns a list containing the total number of correct problems, and the total number of problems in the set. If C<$wantProblemDetails> is true, then a reference to an array of the scores for each problem, and a reference to the array of the number of incorrect attempts -for each problem are also included in the returned list. +for each problem are also included in the returned list. An array reference +to the array of problem records is last in the returned list. In scalar context this returns the percentage correct.