Skip to content

Commit

Permalink
Assign submission graded (#45)
Browse files Browse the repository at this point in the history
* fix scoring for submission graded

* amend assignment graded
  • Loading branch information
milt authored Oct 25, 2024
1 parent 689f4b3 commit 0e99b97
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 38 deletions.
54 changes: 36 additions & 18 deletions src/transformer/events/mod_assign/assignment_graded.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function assignment_graded(array $config, \stdClass $event) {
$assignment = $repo->read_record_by_id('assign', $grade->assignment);
$lang = utils\get_course_lang($course);

$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$module = $repo->read_record_by_id('modules', $coursemodule->module);
$instance = $repo->read_record_by_id($module->name, $coursemodule->instance);
$instancename = property_exists($instance, 'name') ? $instance->name : $module->name;

$gradecomment = null;
try {
$gradecomment = $repo->read_record('assignfeedback_comments', [
Expand All @@ -62,6 +67,8 @@ function assignment_graded(array $config, \stdClass $event) {
$scoreraw = (float) ($grade->grade ?: 0);
$scoremin = (float) ($gradeitems->grademin ?: 0);
$scoremax = (float) ($gradeitems->grademax ?: 0);
$validscore = ($scoremin <= $scoreraw && $scoreraw <= $scoremax) ? true : false;

$scorepass = (float) ($gradeitems->gradepass ?: null);

$success = false;
Expand All @@ -72,13 +79,26 @@ function assignment_graded(array $config, \stdClass $event) {

$statement = [
'actor' => utils\get_user($config, $user),
'verb' => utils\get_verb('scored', $config, $lang),
'object' => utils\get_activity\course_assignment($config, $event->contextinstanceid, $assignment->name, $lang),
'result' => [
'score' => [
'raw' => $scoreraw
'verb' => [
'id' => 'https://w3id.org/xapi/tla/verbs/scored',
'display' => [
$lang => 'Scored',
],
'completion' => true,
],
'object' => [
'id' => $config['app_url']
. '/mod/assign/view.php?id='
. $event->contextinstanceid
. '#submission',
'objectType' => 'Activity',
'definition' => [
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/submission',
'name' => [
$lang => $instancename . ' Submission'
]
]
],
'result' => [
'success' => $success
],
'context' => [
Expand All @@ -88,7 +108,8 @@ function assignment_graded(array $config, \stdClass $event) {
'contextActivities' => [
'parent' => utils\context_activities\get_parent(
$config,
$event->contextinstanceid
$event->contextinstanceid,
true
),
'category' => [
utils\get_activity\site($config),
Expand All @@ -101,17 +122,14 @@ function assignment_graded(array $config, \stdClass $event) {
$statement['result']['response'] = $gradecomment;
}

// 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;
// only write a score if valid
if ($validscore) {
$statement['result']['score'] = [
'raw' => $scoreraw,
'min' => $scoremin,
'max' => $scoremax,
'scaled' => utils\get_scaled_score($scoreraw, $scoremin, $scoremax),
];
}

return [$statement];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@
"grademax": 2,
"gradepass": 1
}
],
"modules": [
{
"id": 1,
"name": "assign"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
}
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/scored",
"id": "https://w3id.org/xapi/tla/verbs/scored",
"display": {
"en": "attained grade for"
"en": "Scored"
}
},
"object": {
"id": "http://www.example.org/mod/assign/view.php?id=1",
"id": "http://www.example.org/mod/assign/view.php?id=1#submission",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/assessment",
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/submission",
"name": {
"en": "test_name"
"en": "test_name Submission"
}
}
},
"result": {
"score": {
"raw": 1,
"min": 0,
"max": 2,
"scaled": 0.5
"raw": 1.0,
"min": 0.0,
"max": 2.0,
"scaled": 0.0
},
"completion": true,
"success": true,
"response": "test_comment_text"
},
Expand All @@ -52,6 +52,15 @@
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/mod/assign/view.php?id=1",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/assignment",
"name": {
"en": "test_name"
}
}
},
{
"id": "http://www.example.org/course/section.php?id=1",
"objectType": "Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@
"grademax": 2,
"gradepass": 1
}
],
"modules": [
{
"id": 1,
"name": "assign"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
}
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/scored",
"id": "https://w3id.org/xapi/tla/verbs/scored",
"display": {
"en": "attained grade for"
"en": "Scored"
}
},
"object": {
"id": "http://www.example.org/mod/assign/view.php?id=1",
"id": "http://www.example.org/mod/assign/view.php?id=1#submission",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/assessment",
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/submission",
"name": {
"en": "test_name"
"en": "test_name Submission"
}
}
},
"result": {
"score": {
"raw": 1,
"min": 0,
"max": 2,
"scaled": 0.5
"raw": 1.0,
"min": 0.0,
"max": 2.0,
"scaled": 0.0
},
"completion": true,
"success": true
},
"context": {
Expand All @@ -51,6 +51,15 @@
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/mod/assign/view.php?id=1",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/assignment",
"name": {
"en": "test_name"
}
}
},
{
"id": "http://www.example.org/course/section.php?id=1",
"objectType": "Activity",
Expand Down

0 comments on commit 0e99b97

Please sign in to comment.