From 3125e7ae171a98d574be2bc1e5f4584f08bc2040 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Thu, 6 Jun 2024 00:40:59 -0700 Subject: [PATCH 1/2] In LTI Advantage, pass actual scores back (with total possible) --- .../Authen/LTIAdvantage/SubmitGrade.pm | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm b/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm index 4ebf703374..526c52db79 100644 --- a/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm +++ b/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm @@ -192,7 +192,7 @@ async sub get_access_token ($self) { } # Computes and submits the course grade for userID to the LMS. -# The course grade is the average of all sets assigned to the user. +# The course grade is the sum of all (weighted) problems assigned to the user. async sub submit_course_grade ($self, $userID) { my $c = $self->{c}; my $ce = $c->{ce}; @@ -207,7 +207,7 @@ async sub submit_course_grade ($self, $userID) { $self->warning('LMS user id is not available for this user.') unless $user->lis_source_did; $self->warning('LMS lineitem is not available for the course.') unless $lineitem; - return await $self->submit_grade($user->lis_source_did, $lineitem, scalar(grade_all_sets($db, $userID))); + return await $self->submit_grade($user->lis_source_did, $lineitem, grade_all_sets($db, $userID)); } # Computes and submits the set grade for $userID and $setID to the LMS. For gateways the best score is used. @@ -225,19 +225,14 @@ async sub submit_set_grade ($self, $userID, $setID) { $self->warning('LMS user id is not available for this user.') unless $user->lis_source_did; $self->warning('LMS lineitem is not available for this set.') unless $userSet->lis_source_did; - return await $self->submit_grade( - $user->lis_source_did, - $userSet->lis_source_did, - scalar( - $userSet->assignment_type =~ /gateway/ - ? grade_gateway($db, $userSet, $userSet->set_id, $userID) - : grade_set($db, $userSet, $userID, 0) - ) - ); + return await $self->submit_grade($user->lis_source_did, $userSet->lis_source_did, + $userSet->assignment_type =~ /gateway/ + ? grade_gateway($db, $userSet, $userSet->set_id, $userID) + : (grade_set($db, $userSet, $userID, 0))[ 0, 1 ]); } -# Submits a score of $score to the lms with $sourcedid as the identifier. -async sub submit_grade ($self, $LMSuserID, $lineitem, $score) { +# Submits scoreGiven and scoreMaximum to the lms with $sourcedid as the identifier. +async sub submit_grade ($self, $LMSuserID, $lineitem, $scoreiGiven, $scoreMaximum) { my $c = $self->{c}; my $ce = $c->{ce}; @@ -249,8 +244,6 @@ async sub submit_grade ($self, $LMSuserID, $lineitem, $score) { # So change $c to be the app instead to get access to the url_for helper. $c = $c->{app} if $self->{post_processing_mode}; - $score = wwRound(2, $score); - my $ua = Mojo::UserAgent->new; if ($ce->{LTICheckPrior}) { @@ -281,6 +274,7 @@ async sub submit_grade ($self, $LMSuserID, $lineitem, $score) { my $priorScore = @$priorData && $priorData->[0]{resultMaximum} ? $priorData->[0]{resultScore} / $priorData->[0]{resultMaximum} : 0; + my $score = $scoreGiven / $scoreMaximum; if (abs($score - $priorScore) < 0.001) { $self->warning( "LMS grade will NOT be updated as the grade is unchanged. Old score: $priorScore, New score: $score."); @@ -302,8 +296,8 @@ async sub submit_grade ($self, $LMSuserID, $lineitem, $score) { json => { # This must be in ISO 8601 format with sub-second precision. That is why the Time::HiRes::time is used. timestamp => Mojo::Date->new(Time::HiRes::time())->to_datetime, - scoreGiven => $score, - scoreMaximum => 1, + scoreGiven => $scoreGiven, + scoreMaximum => $scoreMaximum, activityProgress => 'Submitted', gradingProgress => 'FullyGraded', userId => $LMSuserID From b922682835bab3abe922cd707b21147e001d4413 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Sat, 8 Jun 2024 16:09:01 -0700 Subject: [PATCH 2/2] fix a typo --- lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm b/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm index 526c52db79..c7c9418767 100644 --- a/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm +++ b/lib/WeBWorK/Authen/LTIAdvantage/SubmitGrade.pm @@ -232,7 +232,7 @@ async sub submit_set_grade ($self, $userID, $setID) { } # Submits scoreGiven and scoreMaximum to the lms with $sourcedid as the identifier. -async sub submit_grade ($self, $LMSuserID, $lineitem, $scoreiGiven, $scoreMaximum) { +async sub submit_grade ($self, $LMSuserID, $lineitem, $scoreGiven, $scoreMaximum) { my $c = $self->{c}; my $ce = $c->{ce};