Skip to content

Commit 4068d31

Browse files
committed
LTI 1.1 configure number of digits to round score.
This adds a configuration option `$LTI{v1p1}{round_score_digits}` which sets the number of digits to round the score to before sending it to the LMS. If this is set to a number less than 2 (nearest whole percent), then rounding of the score is disabled. The default is `2` which is current behavior. This option was added to the list of possible configurable items in the LTI course configuration tab. This was requested in #2785.
1 parent f3abb2f commit 4068d31

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

conf/authen_LTI.conf.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ $LTIMassUpdateInterval = 86400;
240240
#'LTISendGradesEarlyThreshold',
241241
#'LTIMassUpdateInterval',
242242
#'LMSManageUserData',
243+
#'LTI{v1p1}{round_score_digits}',
243244
#'LTI{v1p1}{BasicConsumerSecret}',
244245
#'LTI{v1p3}{PlatformID}',
245246
#'LTI{v1p3}{ClientID}',

conf/authen_LTI_1_1.conf.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ $LTI{v1p1}{LMS_name} = 'the LMS';
1919
$LTI{v1p1}{LMS_url} = '';
2020
#$LTI{v1p1}{LMS_url} = 'https://myschool.edu/lms/';
2121

22+
# This sets the number of decimal digits to round the score (a value between 0 and 1) sent to the LMS.
23+
# A setting of 2 means the score is rounded to 2 digits or the nearest whole percent. Setting this to
24+
# a number less than 2 will disable rounding. Note that there maybe some rounding since floats are
25+
# used to compute and save scores in the database and LMS may round the score received.
26+
$LTI{v1p1}{round_score_digits} = 2;
27+
#$LTI{v1p1}{round_score_digits} = 0; # Disable rounding.
28+
2229
################################################################################################
2330
# LTI 1.1 preferred and fallback source of WW user_id
2431
################################################################################################

lib/WeBWorK/Authen/LTIAdvanced/SubmitGrade.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,13 @@ async sub submit_set_grade ($self, $userID, $setID, $submittedSet = undef) {
168168

169169
# Submits a score of $score to the lms with $sourcedid as the identifier.
170170
async sub submit_grade ($self, $sourcedid, $score) {
171-
my $c = $self->{c};
172-
my $ce = $c->{ce};
173-
my $db = $c->{db};
171+
my $c = $self->{c};
172+
my $ce = $c->{ce};
173+
my $db = $c->{db};
174+
my $digits = $ce->{LTI}{v1p1}{round_score_digits} // 2;
174175

175-
$score = wwRound(2, $score);
176+
# Disable rounding unless rounding to two or more digits, which is the nearest whole percent.
177+
$score = wwRound($digits, $score) if $digits > 1;
176178

177179
my $request_url = $db->getSettingValue('lis_outcome_service_url');
178180
if (!$request_url) {

lib/WeBWorK/ConfigValues.pm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,21 @@ sub getConfigValues ($ce) {
10871087
),
10881088
type => 'boolean'
10891089
},
1090+
'LTI{v1p1}{round_score_digits}' => {
1091+
var => 'LTI{v1p1}{round_score_digits}',
1092+
doc => x(
1093+
'Number of digits to round the score (between 0 and 1) sent to the LMS using LTI 1.1. '
1094+
. '(0 => disable rounding)'
1095+
),
1096+
doc2 => x(
1097+
'This sets the number of decimal digits to round the set score (a value between 0 and 1) sent to the '
1098+
. 'LMS using LTI 1.1. A setting of 2 means the score is rounded to 2 digits or the nearest whole '
1099+
. 'percent. Setting this to a number less than 2 will disable rounding. Note that there maybe '
1100+
. 'some rounding since floats are used to compute and save scores in the database and the LMS may '
1101+
. 'round the score it recives.'
1102+
),
1103+
type => 'number'
1104+
},
10901105
'LTI{v1p1}{BasicConsumerSecret}' => {
10911106
var => 'LTI{v1p1}{BasicConsumerSecret}',
10921107
doc => x('LMS shared secret for LTI 1.1 authentication'),

0 commit comments

Comments
 (0)