From f6aee622b71c337cde66eee650273b3310de9ebe Mon Sep 17 00:00:00 2001 From: Timo Boer Date: Sun, 28 Jan 2024 16:55:24 +0100 Subject: [PATCH] Changed way statements are collected for drawScore. now based on variable from xerte: graphAnswerType. Choices for First, last, best and all. --- .../models_html5/adaptiveContent.html | 104 ++++++++++++++++-- modules/xerte/xAPI/xttracking_xapi.js | 10 +- .../wizards/en-GB/adaptiveContent.xwd | 1 + 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html b/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html index fef0c3df3..0250321d3 100644 --- a/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html +++ b/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html @@ -599,6 +599,87 @@ } } + function filterRelevantStatements(statements, type) { + if (type == "all") {return statements} + var groupedData = {}; + statements.forEach(function(statement, i) { + var participant = { + 'attemptkeys' : [], + 'attempts': [], + }; + + if (statement.actor.mbox != undefined) { + var key = statement.actor.mbox.substr(7).trim(); + if (groupedData[key] == undefined) { + participant['key'] = key; + groupedData[key] = participant; + } + } else if (statement.actor.mbox_sha1sum != undefined) { + var key = statement.actor.mbox_sha1sum; + if (groupedData[key] == undefined) { + participant['key'] = key; + groupedData[key] = participant; + } + } else { + // Key is group, session_id (if group is available), otherwise just session + var group = (statement.actor.group != undefined ? statement.actor.group.name : 'global'); + if (statement.context != undefined && + statement.context.extensions != undefined && + statement.context.extensions['http://xerte.org.uk/sessionId'] != undefined) { + var key = statement.context.extensions['http://xerte.org.uk/sessionId']; + if (key == undefined) { + key = statement.context.extensions[site_url + "sessionId"]; + } + if (key != undefined) { + key = group + ' ' + key; + if (groupedData[key] == undefined) { + participant['key'] = key; + groupedData[key] = participant; + } + } + } + } + if (key != undefined) { + if (statement.context != undefined && + statement.context.extensions != undefined && + statement.context.extensions['http://xerte.org.uk/sessionId'] != undefined) { + var attemptkey = statement.context.extensions['http://xerte.org.uk/sessionId']; + if (groupedData[key]['attempts'][attemptkey] == undefined) { + groupedData[key]['attempts'].push(statement) + groupedData[key]['attemptkeys'].push( + { + key: attemptkey, + } + ); + } + } + } + }); + var statements = []; + for (var user in groupedData) { + if (type == "first") { + statements.push(groupedData[user].attempts[0]) + } else if (type == "last") { + statements.push(groupedData[user].attempts[groupedData[user].attempts.length - 1]) + } else if (type == 'best'){ + //todo check if correct + var bestAttempt = null; + for (var attempt in groupedData[user].attempts){ + if (bestAttempt != null) { + if (bestAttempt.result.score.raw < groupedData[user].attempts[attempt].result.score.raw) { + bestAttempt = groupedData[user].attempts[attempt] + } + } else { + bestAttempt = groupedData[user].attempts[attempt] + } + } + statements.push(bestAttempt) + } + } + debugger + return statements + } + function getStatements( xerteurl, xertelo, @@ -677,7 +758,6 @@ var date = moment(endDate).add(1, "days").toISOString(); q["until"] = date; } - //todo not like this add indicator to q if only current users. let current_users = interaction.getAttribute("contextUsersFilter") if (current_users == 'true') { q["filter_current_users"] = current_users; @@ -1477,7 +1557,12 @@ } var xertelo = interaction.getAttribute("xertelo"); var ownstatements = filterOwnStatements(data, xertelo); - var statements = data; + + var graphAnswerType = interaction.getAttribute("graphAnswerType"); + if (graphAnswerType == undefined) { + graphAnswerType = "all"; + } + var statements = filterRelevantStatements(data, graphAnswerType); xerteurl = interaction.getAttribute("xerteurl"); xertelabel = interaction.getAttribute("label"); name = interaction.getAttribute("name"); @@ -1496,13 +1581,13 @@ graphFitInfoInBar = false; } var graphShowAvg = interaction.getAttribute("graphShowAvg"); - if (graphShowAvg == undefined) { - graphShowAvg = false; - } - var graphShowAvgLine = interaction.getAttribute("graphShowAvgBar"); - if (graphShowAvgLine == undefined) { - graphShowAvgLine = false; - } + if (graphShowAvg == undefined) { + graphShowAvg = false; + } + var graphShowAvgLine = interaction.getAttribute("graphShowAvgBar"); + if (graphShowAvgLine == undefined) { + graphShowAvgLine = false; + } var barName = []; var barNameValue = []; @@ -1990,7 +2075,6 @@ let barScoreColor = new Array(barRange.length); let barOwnScore = barSizeData.slice(); - if (followBlock == "true") { for (let i = 0; i < statements.length; i++) { //check what bar contains 100 (might not be the last) diff --git a/modules/xerte/xAPI/xttracking_xapi.js b/modules/xerte/xAPI/xttracking_xapi.js index 5b630316f..e8ffe8c74 100644 --- a/modules/xerte/xAPI/xttracking_xapi.js +++ b/modules/xerte/xAPI/xttracking_xapi.js @@ -1954,7 +1954,7 @@ function getStatements(q, one, callback) continue; } //todo add check if statemettns are from current users if userlist > 0 - debugger + if (filter_current_users){ if (!lti_user_list.includes(tmp.statements[x].actor.mbox.split(':')[1])) { continue; @@ -1964,7 +1964,7 @@ function getStatements(q, one, callback) } return statements; } else { - debugger; + ADL.XAPIWrapper.getStatements(search, null, function getmorestatements(err, res, body) { var lastSubmit = null; @@ -1989,7 +1989,7 @@ function getStatements(q, one, callback) || body.statements[x].context.extensions["http://xerte.org.uk/lti_context_id"] != context_id)) { continue; } - debugger; + if (filter_current_users == 'true'){ //done also check for field mbox_sha1sum (has of mailto:mail@mail.nl) if (body.statements[x].actor.mbox !== undefined) { @@ -2018,7 +2018,7 @@ function getStatements(q, one, callback) } ); } - debugger; + } } @@ -2090,7 +2090,7 @@ function XTInitialise(category) { if (typeof studentidmode != "undefined" && typeof studentidmode == 'string') { studentidmode = parseInt(studentidmode); } - debugger + if (typeof studentidmode == "undefined" || (studentidmode <= 0 && studentidmode > 3)) { // set actor to global group actor = { diff --git a/src/Nottingham/wizards/en-GB/adaptiveContent.xwd b/src/Nottingham/wizards/en-GB/adaptiveContent.xwd index ebea29881..74d5d27ff 100644 --- a/src/Nottingham/wizards/en-GB/adaptiveContent.xwd +++ b/src/Nottingham/wizards/en-GB/adaptiveContent.xwd @@ -79,6 +79,7 @@ +