Add support for result.success & completion

pull/4/head
Andrew Downes 2015-10-20 11:13:08 +01:00
parent ee02f08bdb
commit f9ea9adb1b
1 changed files with 31 additions and 9 deletions

View File

@ -18,18 +18,40 @@ H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent;
* *
* @param {number} score * @param {number} score
* @param {number} maxScore * @param {number} maxScore
* @param {object} instance
* @param {boolean} completion
* @param {boolean} success
*/ */
H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance) { H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, completion, success) {
this.data.statement.result = { this.data.statement.result = {};
'score': {
'min': 0, if (typeof score !== 'undefined') {
'max': maxScore, if (typeof maxScore === 'undefined') {
'raw': score 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) { if (instance && instance.activityStartTime) {
var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100; var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100;
// xAPI spec allows a precision of 0.01 seconds // xAPI spec allows a precision of 0.01 seconds