Add duration and scaled to result
parent
769fd219bc
commit
5d1cd188d0
|
@ -19,7 +19,7 @@ H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent;
|
|||
* @param {number} score
|
||||
* @param {number} maxScore
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore) {
|
||||
H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance) {
|
||||
this.data.statement.result = {
|
||||
'score': {
|
||||
'min': 0,
|
||||
|
@ -27,6 +27,15 @@ H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore) {
|
|||
'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';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,10 +82,14 @@ H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore)
|
|||
*/
|
||||
H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb) {
|
||||
var event = this.createXAPIEventTemplate(verb);
|
||||
event.setScoredResult(score, maxScore);
|
||||
event.setScoredResult(score, maxScore, this);
|
||||
this.trigger(event);
|
||||
};
|
||||
|
||||
H5P.EventDispatcher.prototype.setActivityStarted = function() {
|
||||
this.activityStartTime = Date.now();
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal H5P function listening for xAPI completed events and stores scores
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue