]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6186 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 25 Sep 2023 15:44:04 +0000 (17:44 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 25 Sep 2023 15:44:04 +0000 (17:44 +0200)
js/quiz.score.js
js/quiz.scorm.js

index dec9675797caff2bc3ef44c2eb883de392731030..7025a197c11f33a17faf32ee454fc35f6be40dcd 100644 (file)
@@ -103,13 +103,12 @@ QuizScore.prototype = {
         }
 
         this.questionStatus[questionIndex] = {
-            ok: ok, answers: answersStatus, // dbg_min_score: min_score,
-            // dbg_this_score: this_score
+            ok: ok, answers: answersStatus,
         };
 
         if (count) {
             this.maxScore++;
-            if (ok == 'ok') {
+            if (ok === 'ok') {
                 this.score++;
                 log.score = 1;
             } else {
@@ -121,6 +120,19 @@ QuizScore.prototype = {
         this.logQuestions[questionIndex] = log;
     },
 
+    getNormalizedScore: function (pct) {
+        var s = this.score / this.getQuestionsCount();
+        if (pct === undefined || pct === false) {
+            return s;
+        }
+        return Math.round(100 * s);
+    },
+
+    isPassed: function () {
+        let threshold = parseInt(this.quiz.data.threshold);
+        return isNaN(threshold) || this.getNormalizedScore(true) > threshold;
+    },
+
     getMinScore: function (question) {
         // Le score minimal est le score que l'utilisateur doit atteindre sur une question pour que sa réponse soit considérée
         let min_score = parseInt(question.min_score);
@@ -146,6 +158,13 @@ QuizScore.prototype = {
         }
 
         this.quiz.scorm.saveState(this.getCurrentState());
+        if (this.lastAnsweredQuestion === this.getQuestionsCount()) {
+            this.quiz.scorm.completed()
+        }
+    },
+
+    getQuestionsCount: function () {
+        return this.quiz.data.questions.length - 1
     },
 
     getCurrentState: function () {
index df3f6a5fe2fa6c4bf2bf3d9fd6a7d6bb5ca3f258..bad02ad43045865d0d00d927fc0335bfdfb449c2 100644 (file)
@@ -36,7 +36,7 @@ QuizScorm.prototype = {
 
     completed: function (passed) {
         cubeSCORM.scormMarkAsComplete();
-        cubeSCORM.setScormValue('success_status', this.quiz.score.passed ? 'passed' : 'failed');
+        cubeSCORM.setScormValue('success_status', this.quiz.score.isPassed() ? 'passed' : 'failed');
         cubeSCORM.setSCORMScore(this.quiz.score.getNormalizedScore(true), 100, 0, this.quiz.score.getNormalizedScore());
         this.saveState(this.defaultState)
     },