From 46bc5169e3c3a1c5fd35bd2b8bc99d0cb5d393cf Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Mon, 18 Nov 2024 20:21:42 -0800 Subject: [PATCH] handling "0/0" scores for the LMS --- lib/WeBWorK/Utils/Sets.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/WeBWorK/Utils/Sets.pm b/lib/WeBWorK/Utils/Sets.pm index 5f1c812007..acc582a477 100644 --- a/lib/WeBWorK/Utils/Sets.pm +++ b/lib/WeBWorK/Utils/Sets.pm @@ -245,25 +245,37 @@ sub get_LTISendScoresAfterDate ($set, $ce) { # Checks if the set is past the LTISendScoresAfterDate or has met the LTISendGradesEarlyThreshold. # Returns a reference to hash with keys totalRight, total, score, criticalDate if the set has met # either condition and undef if not. +# If the set is a test, the score "0/0" is treated as 0. +# If the set is not a test, the score "0/0" is treated as 0 if we have not yet reached the +# LTISendScoresAfterDate and have not attempted the set. Otherwise, "0/0" is treated as 1. sub can_submit_LMS_score ($db, $ce, $userID, $userSet) { my $totalRight; my $total; - if ($userSet->assignment_type() =~ /gateway/) { + if ($userSet->assignment_type =~ /gateway/) { ($totalRight, $total) = grade_gateway($db, $userSet->set_id, $userID); } else { ($totalRight, $total) = (grade_set($db, $userSet, $userID))[ 0, 1 ]; } + my $score = $total ? $totalRight / $total : 0; my $return = { totalRight => $totalRight, total => $total, score => $score }; if ($ce->{LTISendScoresAfterDate} ne 'never') { my $critical_date; - if ($userSet->assignment_type() =~ /gateway/) { + if ($userSet->assignment_type =~ /gateway/) { $critical_date = earliest_gateway_date($db, $ce, $userSet); } else { $critical_date = get_LTISendScoresAfterDate($userSet, $ce); } $return->{criticalDate} = $critical_date; + if ($total == 0) { + $score = ( + $userSet->assignment_type =~ /gateway/ + || ($ce->{LTISendScoresAfterDate} eq 'never' + || before($critical_date) && !set_attempted($db, $userID, $userSet)) + ) ? 0 : 1; + + } return $return if after($critical_date); }