From f9ea9adb1ba634b074304cbe2830b478c2507f45 Mon Sep 17 00:00:00 2001 From: Andrew Downes Date: Tue, 20 Oct 2015 11:13:08 +0100 Subject: [PATCH 1/4] Add support for result.success & completion --- js/h5p-x-api-event.js | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/js/h5p-x-api-event.js b/js/h5p-x-api-event.js index 98b287a..1653b0c 100644 --- a/js/h5p-x-api-event.js +++ b/js/h5p-x-api-event.js @@ -18,18 +18,40 @@ H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent; * * @param {number} score * @param {number} maxScore + * @param {object} instance + * @param {boolean} completion + * @param {boolean} success */ -H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance) { - this.data.statement.result = { - 'score': { - 'min': 0, - 'max': maxScore, - 'raw': score +H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, completion, success) { + this.data.statement.result = {}; + + if (typeof score !== 'undefined') { + if (typeof maxScore === 'undefined') { + this.data.statement.result.score = {'raw': score}; + } + else { + this.data.statement.result.score = { + 'min': 0, + 'max': maxScore, + 'raw': score + }; + if (maxScore > 0) { + this.data.statement.result.score.scaled = Math.round(score / maxScore * 10000) / 10000; + } } - }; - if (maxScore > 0) { - this.data.statement.result.score.scaled = Math.round(score / maxScore * 10000) / 10000; } + + if (typeof completion === 'undefined') { + this.data.statement.result.completion = true; + } + else { + this.data.statement.result.completion = completion; + } + + if (typeof success !== 'undefined') { + this.data.statement.result.success = success; + } + if (instance && instance.activityStartTime) { var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100; // xAPI spec allows a precision of 0.01 seconds From 76a02867aa9a26acd0a0cb83086d6da4a32b4de3 Mon Sep 17 00:00:00 2001 From: Andrew Downes Date: Tue, 20 Oct 2015 11:29:01 +0100 Subject: [PATCH 2/4] Update triggerXAPICompleted and triggerXAPIScored Added support for completion and success. --- js/h5p-x-api.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/h5p-x-api.js b/js/h5p-x-api.js index e287c1a..aeec7b6 100644 --- a/js/h5p-x-api.js +++ b/js/h5p-x-api.js @@ -65,9 +65,16 @@ H5P.EventDispatcher.prototype.createXAPIEventTemplate = function (verb, extra) { * Will be set as the 'raw' value of the score object * @param {number} maxScore * will be set as the "max" value of the score object + * @param {boolean} success + * will be set as the "success" value of the result object */ -H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore) { - this.triggerXAPIScored(score, maxScore, 'completed'); +H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore, success) { + var verb = 'completed'; + if (typeof success !== 'undefined') { + if (success) {verb = "passed";} + else {verb = "failed";} + } + this.triggerXAPIScored(score, maxScore, verb, true, success); }; /** @@ -80,9 +87,9 @@ H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore) * @param {string} verb * Short form of adl verb */ -H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb) { +H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb, completion, success) { var event = this.createXAPIEventTemplate(verb); - event.setScoredResult(score, maxScore, this); + event.setScoredResult(score, maxScore, this, completion, success); this.trigger(event); }; From cc6521c4a1d11f10d7c63b9cae2b50ecb8e1ac31 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 1 Nov 2015 00:19:56 +0100 Subject: [PATCH 3/4] completed default value depends on verb --- js/h5p-x-api-event.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/h5p-x-api-event.js b/js/h5p-x-api-event.js index 1653b0c..c5ce2e3 100644 --- a/js/h5p-x-api-event.js +++ b/js/h5p-x-api-event.js @@ -42,7 +42,7 @@ H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, c } if (typeof completion === 'undefined') { - this.data.statement.result.completion = true; + this.data.statement.result.completion = (this.getVerb() === 'completed' || this.getVerb() === 'answered'); } else { this.data.statement.result.completion = completion; From 844883a1cff662558daf2eb7c1544319a0b1c6e4 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 1 Nov 2015 00:23:10 +0100 Subject: [PATCH 4/4] triggerXAPICompleted is deprecated so we don't change it. Also fixes doc --- js/h5p-x-api.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/js/h5p-x-api.js b/js/h5p-x-api.js index aeec7b6..735161c 100644 --- a/js/h5p-x-api.js +++ b/js/h5p-x-api.js @@ -69,12 +69,7 @@ H5P.EventDispatcher.prototype.createXAPIEventTemplate = function (verb, extra) { * will be set as the "success" value of the result object */ H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore, success) { - var verb = 'completed'; - if (typeof success !== 'undefined') { - if (success) {verb = "passed";} - else {verb = "failed";} - } - this.triggerXAPIScored(score, maxScore, verb, true, success); + this.triggerXAPIScored(score, maxScore, 'completed', true, success); }; /** @@ -86,6 +81,10 @@ H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore, * Will be set as the "max" value of the score object * @param {string} verb * Short form of adl verb + * @param {boolean} completion + * Is this a statement from a completed activity? + * @param {boolean} success + * Is this a statement from an activity that was done successfully? */ H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb, completion, success) { var event = this.createXAPIEventTemplate(verb);