Skip to content

Commit

Permalink
Provides the xapi changes to all xapi files
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhofman committed Mar 2, 2023
1 parent 7c153f7 commit 77cab1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions modules/site/parent_templates/site/common/js/xttracking_noop.js
Expand Up @@ -71,6 +71,7 @@ function NoopTrackingState()
this.initialise = initialise;
this.pageCompleted = pageCompleted;
this.getCompletionStatus = getCompletionStatus;
this.getCompletionPercentage = getCompletionPercentage;
this.getSuccessStatus = getSuccessStatus;
this.getdScaledScore = getdScaledScore;
this.getdRawScore = getdRawScore;
Expand Down Expand Up @@ -130,6 +131,20 @@ function NoopTrackingState()
}
}

function getCompletionPercentage() {
var completed = true;
var completedpages = 0;
if (this.completedPages.length == 0) {
return 0;
}
for (var i = 0; i < this.completedPages.length; i++) {
if (this.completedPages[i] == true) {
completedpages++;
}
}
return (completedpages / this.completedPages.length) * 100.0;
}

function getSuccessStatus()
{
if (this.lo_type != "pages only")
Expand Down Expand Up @@ -321,7 +336,7 @@ function NoopTrackingState()
function setPageScore(page_nr, score)
{
var sit = state.findPage(page_nr);
if (sit != null && (state.scoremode != 'first' || sit.count < 1))
if (sit != null && (state.scoremode != 'first' || sit.count <= 1))
{
sit.score = score;
sit.count++;
Expand Down Expand Up @@ -1026,6 +1041,9 @@ function XTSetOption(option, value)
break;
case "toComplete":
state.toCompletePages = value;
for (i = 0; i < state.toCompletePages.length; i++) {
state.completedPages[i] = false;
}
break;
case "tracking-mode":
switch(value)
Expand Down Expand Up @@ -1221,7 +1239,7 @@ function XTTerminate()
method: "POST",
url: url,
data: {
grade: state.getdScaledScore()
grade: state.getdScaledScore() * state.getCompletionPercentage() / 100.0,
}
})
.done(function (msg) {
Expand Down
2 changes: 1 addition & 1 deletion modules/site/xAPI/xttracking_xapi.js
Expand Up @@ -458,7 +458,7 @@ function XApiTrackingState() {

function setPageScore(page_nr, score) {
var sit = this.findPage(page_nr);
if (sit != null && (this.scoremode != 'first' || sit.count < 1)) {
if (sit != null && (this.scoremode != 'first' || sit.count <= 1)) {
sit.score = score;
}
}
Expand Down
Expand Up @@ -336,7 +336,7 @@ function NoopTrackingState()
function setPageScore(page_nr, score)
{
var sit = state.findPage(page_nr);
if (sit != null && (state.scoremode != 'first' || sit.count < 1))
if (sit != null && (state.scoremode != 'first' || sit.count <= 1))
{
sit.score = score;
sit.count++;
Expand Down

0 comments on commit 77cab1e

Please sign in to comment.