Add duration and scaled to result

editor-padding
Svein-Tore Griff With 2015-07-20 13:05:41 +02:00
parent 769fd219bc
commit 5d1cd188d0
2 changed files with 15 additions and 2 deletions

View File

@ -19,7 +19,7 @@ H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent;
* @param {number} score * @param {number} score
* @param {number} maxScore * @param {number} maxScore
*/ */
H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore) { H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance) {
this.data.statement.result = { this.data.statement.result = {
'score': { 'score': {
'min': 0, 'min': 0,
@ -27,6 +27,15 @@ H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore) {
'raw': score 'raw': score
} }
}; };
if (maxScore > 0) {
this.data.statement.result.score.scaled = Math.round(score / maxScore * 10000) / 10000;
}
if (instance && instance.activityStartTime) {
var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100;
// xAPI spec allows a precision of 0.01 seconds
this.data.statement.result.duration = 'PT' + duration + 'S';
}
}; };
/** /**

View File

@ -82,10 +82,14 @@ H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore)
*/ */
H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb) { H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb) {
var event = this.createXAPIEventTemplate(verb); var event = this.createXAPIEventTemplate(verb);
event.setScoredResult(score, maxScore); event.setScoredResult(score, maxScore, this);
this.trigger(event); this.trigger(event);
}; };
H5P.EventDispatcher.prototype.setActivityStarted = function() {
this.activityStartTime = Date.now();
};
/** /**
* Internal H5P function listening for xAPI completed events and stores scores * Internal H5P function listening for xAPI completed events and stores scores
* *