Skip to content

Commit

Permalink
fix: Fixes assignment_graded. (#362 - Thanks @garemoko)
Browse files Browse the repository at this point in the history
  • Loading branch information
garemoko authored and ryasmi committed Dec 19, 2018
1 parent 61f8d61 commit bd8c361
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/transformer/events/mod_assign/assignment_graded.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,13 @@ function assignment_graded(array $config, \stdClass $event) {
$scoremax = (float) ($gradeitems->grademax ?: 0);
$scorepass = (float) ($gradeitems->gradepass ?: null);

$completion = 'unknown';
$success = false;

if ($scoreraw >= $scorepass) {
$completion = true;
$success = true;
}

// Calculate scaled score as the distance from zero towards the max (or min for negative scores).
if ($scoreraw >= 0) {
$scorescaled = $scoreraw / $scoremax;
} else {
$scorescaled = $scoreraw / $scoremin;
}

return [[
$statement = [
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://adlnet.gov/expapi/verbs/scored',
Expand All @@ -67,12 +60,10 @@ function assignment_graded(array $config, \stdClass $event) {
'object' => utils\get_activity\course_assignment($config, $event->contextinstanceid, $assignment->name, $lang),
'result' => [
'score' => [
'raw' => $scoreraw,
'min' => $scoremin,
'max' => $scoremax,
'scaled' => $scorescaled
'raw' => $scoreraw
],
'completion' => $completion,
'completion' => true,
'success' => $success,
'response' => $gradecomment
],
'timestamp' => utils\get_event_timestamp($event),
Expand All @@ -93,5 +84,20 @@ function assignment_graded(array $config, \stdClass $event) {
],
],
]
]];
];

// Only include min score if raw score is valid for that min.
if ($scoreraw >= $scoremin) {
$statement['result']['score']['min'] = $scoremin;
}
// Only include max score if raw score is valid for that max.
if ($scoreraw <= $scoremax) {
$statement['result']['score']['max'] = $scoremax;
}
// Calculate scaled score as the distance from zero towards the max (or min for negative scores).
if ($scoreraw >= 0) {
$statement['result']['score']['scaled'] = $scoreraw / $scoremax;
}

return [$statement];
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"scaled": 0.5
},
"completion": true,
"success": true,
"response": "test_comment_text"
},
"timestamp": "2015-06-10T15:31:41+01:00",
Expand Down

0 comments on commit bd8c361

Please sign in to comment.