From 8010a33a6cf22dbfb6764001e33df0e625d94bae Mon Sep 17 00:00:00 2001 From: Tom Reijnders Date: Mon, 1 Apr 2024 22:31:43 +0200 Subject: [PATCH] Extend and fix adaptiveContent page - Add extra graph (radar graph of group members - Filter on LTI enrolled students --- .../models_html5/adaptiveContent.html | 1237 +++++++++-------- .../Nottingham/wizards/en-GB/data.xwd | 24 +- modules/xerte/xAPI/xttracking_xapi.js | 16 +- .../wizards/en-GB/adaptiveContent.xwd | 21 +- src/Nottingham/wizards/en-GB/template.xwd | 24 +- 5 files changed, 716 insertions(+), 606 deletions(-) diff --git a/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html b/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html index fec65f843..62695a95f 100644 --- a/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html +++ b/modules/xerte/parent_templates/Nottingham/models_html5/adaptiveContent.html @@ -36,7 +36,9 @@ var classtitles = []; var numUserSubmits = 0; var xertelo = interaction.getAttribute('xertelo'); + var radarData = interaction.getAttribute('opinionRadarData'); var textSize = Math.round(interaction.getAttribute("labelFontSize")); + var groupedData = []; if (textSize == null || textSize == 0) textSize = 12; @@ -46,421 +48,465 @@ return; } - if (showall_only === "true") - { + if (showall_only === "true") { showall_only = true; } - if (showall_only === "false") - { + if (showall_only === "false") { showall_only = false; } - importData.forEach(function(obj) - { - if (objlabel == null) { - objlabel = obj.graph.label; - } + if (radarData === 'personal'|| radarData === null) { + importData.forEach(function (obj) { + if (objlabel == null) { + objlabel = obj.graph.label; + } - for (var i = 0; i < obj.graph.classvalues.length; i++) { - if (mean_all[i] == null) { - mean_all[i] = obj.graph.classvalues[i]; + for (var i = 0; i < obj.graph.classvalues.length; i++) { + if (mean_all[i] == null) { + mean_all[i] = obj.graph.classvalues[i]; + } else { + mean_all[i] += obj.graph.classvalues[i]; + } + + if (classnames[i] == null) { + classnames[i] = x_GetTrackingTextFromHTML(obj.graph.classnames[i], obj.graph.classnames[i]); + } + if (classtitles[i] == null) { + if ( + typeof obj.graph.classtitles != "undefined" && + typeof obj.graph.classtitles[i] != "undefined" && + obj.graph.classtitles[i] != "" + ) { + classtitles[i] = x_GetTrackingTextFromHTML(obj.graph.classtitles[i], obj.graph.classtitles[i]); + } else { + classtitles[i] = classnames[i]; + } + } } - else - { - mean_all[i] += obj.graph.classvalues[i]; + + if (matchActor(obj, xertelo)) { + if (obj.timestamp > latest_ts) { + latest_ts = obj.timestamp; + latest = obj; + } + + for (var i = 0; i < obj.graph.classvalues.length; i++) { + if (mean[i] == null) { + mean[i] = obj.graph.classvalues[i]; + } else { + mean[i] += obj.graph.classvalues[i]; + } + } + + numUserSubmits++; } + }); - if (classnames[i] == null) { - classnames[i] = x_GetTrackingTextFromHTML(obj.graph.classnames[i], obj.graph.classnames[i]); + for (var x = 0; x < mean_all.length; x++) { + if (mean_all[x] != null) { + mean_all[x] = Math.round((mean_all[x] * 10) / numSubmits) / 10; + } + if (mean[x] != null) { + mean[x] = Math.round((mean[x] * 10) / numUserSubmits) / 10; + } + } } - if (classtitles[i] == null) { - if ( - typeof obj.graph.classtitles != "undefined" && - typeof obj.graph.classtitles[i] != "undefined" && - obj.graph.classtitles[i] != "" - ) { - classtitles[i] = x_GetTrackingTextFromHTML(obj.graph.classtitles[i], obj.graph.classtitles[i]); - } else { - classtitles[i] = classnames[i]; - } + else { + // Prepare grouped datasets + importData.forEach(function (obj) { + for (var i = 0; i < obj.graph.classvalues.length; i++) { + if (classnames[i] == null) { + classnames[i] = x_GetTrackingTextFromHTML(obj.graph.classnames[i], obj.graph.classnames[i]); + } + if (classtitles[i] == null) { + if ( + typeof obj.graph.classtitles != "undefined" && + typeof obj.graph.classtitles[i] != "undefined" && + obj.graph.classtitles[i] != "" + ) { + classtitles[i] = x_GetTrackingTextFromHTML(obj.graph.classtitles[i], obj.graph.classtitles[i]); + } else { + classtitles[i] = classnames[i]; + } + } + } + const actor = getActor(obj, xertelo); + if (groupedData[actor.key] == undefined) { + groupedData[actor.key] = { + 'actor': actor, + 'attempts': [], + }; + } + groupedData[actor.key].actor = mergeActor(groupedData[actor.key].actor, actor); + groupedData[actor.key].attempts.push(obj); + }); + Object.keys(groupedData).forEach(function(key) + { + const user = groupedData[key]; + const obj = user.attempts[0]; + for (var i = 0; i < obj.graph.classvalues.length; i++) { + if (mean_all[i] == null) { + mean_all[i] = obj.graph.classvalues[i]; + } else { + mean_all[i] += obj.graph.classvalues[i]; + } + } + }); + const numUsers = Object.keys(groupedData).length; + for (var x = 0; x < mean_all.length; x++) { + if (mean_all[x] != null) { + mean_all[x] = Math.round((mean_all[x] * 10) / numUsers) / 10; + } + } } - } - // Check what method is used for identification. - var matchactor = false; - switch (studentidmode) { - case 0: - case 2: - if (obj.actor.mbox == userEMail) { - matchactor = true; - } - break; - case 1: - if (obj.actor.mbox_sha1sum == mboxsha1) { - matchactor = true; - } - break; - case 3: - if (obj.actor.account != undefined && - obj.actor.account.name == groupname) { - matchactor = true; - } - break; - } - if (!matchactor && - xertelo == x_TemplateId && - obj.context != undefined && - obj.context.extensions != undefined && - obj.context.extensions["http://xerte.org.uk/sessionId"] != undefined && - obj.context.extensions["http://xerte.org.uk/sessionId"] == - state.sessionId) { - matchactor = true; - } + function hexToRgb(hex, opa) { + var bigint = parseInt(hex, 16); + var r = (bigint >> 16) & 255; + var g = (bigint >> 8) & 255; + var b = bigint & 255; - if (matchactor) { - if (obj.timestamp > latest_ts) { - latest_ts = obj.timestamp; - latest = obj; + return "rgba(" + r + ", " + g + ", " + b + ", " + opa + ")"; } - for (var i = 0; i < obj.graph.classvalues.length; i++) { - if (mean[i] == null) { - mean[i] = obj.graph.classvalues[i]; - } else { - mean[i] += obj.graph.classvalues[i]; - } + var ctx = $('#' + identifier + ' .graph-container canvas'); + var bgColourIn = "0xff0000"; + if (interaction.getAttribute("colour") != null) { + bgColourIn = interaction.getAttribute("colour"); } + var bgColour = hexToRgb(bgColourIn.substring(bgColourIn.length - 6), 0.5); + var lnColour = hexToRgb(bgColourIn.substring(bgColourIn.length - 6), 1); - numUserSubmits++; - } - }); - - for (var x = 0; x < mean_all.length; x++) { - if (mean_all[x] != null) { - mean_all[x] = Math.round((mean_all[x] * 10) / numSubmits) / 10; - } - if (mean[x] != null) { - mean[x] = Math.round((mean[x] * 10) / numUserSubmits) / 10; - } - } - - function hexToRgb(hex, opa) { - var bigint = parseInt(hex, 16); - var r = (bigint >> 16) & 255; - var g = (bigint >> 8) & 255; - var b = bigint & 255; - - return "rgba(" + r + ", " + g + ", " + b + ", " + opa + ")"; - } + var pavgbgColourIn = "0x0000ff"; + if (interaction.getAttribute("colourPersonalAvg") != null) { + pavgbgColourIn = interaction.getAttribute("colourPersonalAvg"); + } + var pavgbgColour = hexToRgb( + pavgbgColourIn.substring(pavgbgColourIn.length - 6), + 0.5 + ); + var pavglnColour = hexToRgb( + pavgbgColourIn.substring(pavgbgColourIn.length - 6), + 1 + ); - var ctx = $('#' + identifier + ' .graph-container canvas'); - var bgColourIn = "0xff0000"; - if (interaction.getAttribute("colour") != null) { - bgColourIn = interaction.getAttribute("colour"); - } - var bgColour = hexToRgb(bgColourIn.substr(bgColourIn.length - 6), 0.5); - var lnColour = hexToRgb(bgColourIn.substr(bgColourIn.length - 6), 1); + var avgbgColourIn = "0x00ff00"; + if (interaction.getAttribute("colourAvg") != null) { + avgbgColourIn = interaction.getAttribute("colourAvg"); + } + var avgbgColour = hexToRgb( + avgbgColourIn.substring(avgbgColourIn.length - 6), + 0.5 + ); + var avglnColour = hexToRgb( + avgbgColourIn.substring(avgbgColourIn.length - 6), + 1 + ); - var pavgbgColourIn = "0x0000ff"; - if (interaction.getAttribute("colourPersonalAvg") != null) { - pavgbgColourIn = interaction.getAttribute("colourPersonalAvg"); - } - var pavgbgColour = hexToRgb( - pavgbgColourIn.substr(pavgbgColourIn.length - 6), - 0.5 - ); - var pavglnColour = hexToRgb( - pavgbgColourIn.substr(pavgbgColourIn.length - 6), - 1 - ); - - var avgbgColourIn = "0x00ff00"; - if (interaction.getAttribute("colourAvg") != null) { - avgbgColourIn = interaction.getAttribute("colourAvg"); - } - var avgbgColour = hexToRgb( - avgbgColourIn.substr(avgbgColourIn.length - 6), - 0.5 - ); - var avglnColour = hexToRgb( - avgbgColourIn.substr(avgbgColourIn.length - 6), - 1 - ); - - var avgAllLabelText = interaction.getAttribute("avgAllLabelText"); - if (avgAllLabelText == undefined) { - avgAllLabelText = "Avg. of all attempts"; - } + var avgAllLabelText = interaction.getAttribute("avgAllLabelText"); + if (avgAllLabelText == undefined) { + avgAllLabelText = "Avg. of all attempts"; + } - var personalLabelText = interaction.getAttribute("personalLabelText"); - if (personalLabelText == undefined) { - personalLabelText = "Your last attempt"; - } + var personalLabelText = interaction.getAttribute("personalLabelText"); + if (personalLabelText == undefined) { + personalLabelText = "Your last attempt"; + } - var personalAvgLabelText = interaction.getAttribute("personalAvgLabelText"); - if (personalAvgLabelText == undefined) { - personalAvgLabelText = "Avg. of your attempts"; - } + var personalAvgLabelText = interaction.getAttribute("personalAvgLabelText"); + if (personalAvgLabelText == undefined) { + personalAvgLabelText = "Avg. of your attempts"; + } - var groupAverageLabelText = interaction.getAttribute("groupAverageLabelText"); - if (groupAverageLabelText == undefined) { - groupAverageLabelText = "Group Average"; - } + var groupAverageLabelText = interaction.getAttribute("groupAverageLabelText"); + if (groupAverageLabelText == undefined) { + groupAverageLabelText = "Group Average"; + } - var datasets = []; - if (showall_only || latest == null) { - // Only show mean_all - datasets = [ - { - label: avgAllLabelText, - data: mean_all, - backgroundColor: avgbgColour, - borderColor: avglnColour, - }, - ]; - } else { - datasets = [ - { - label: personalLabelText, - data: latest.graph.classvalues, - backgroundColor: bgColour, - borderColor: lnColour, - }, - ]; - if (numUserSubmits > 1) { - datasets.push({ - label: personalAvgLabelText, - data: mean, - backgroundColor: pavgbgColour, - borderColor: pavglnColour, - }); - } - datasets.push({ - label: avgAllLabelText, - data: mean_all, - backgroundColor: avgbgColour, - borderColor: avglnColour, - }); - } + var datasets = []; + if (showall_only || (latest == null && radarData !== 'group')) { + // Only show mean_all + datasets = [ + { + label: avgAllLabelText, + data: mean_all, + backgroundColor: avgbgColour, + borderColor: avglnColour, + }, + ]; + } else { + if (radarData === 'personal'|| radarData === null) { + datasets = [ + { + label: personalLabelText, + data: latest.graph.classvalues, + backgroundColor: bgColour, + borderColor: lnColour, + }, + ]; + if (numUserSubmits > 1) { + datasets.push({ + label: personalAvgLabelText, + data: mean, + backgroundColor: pavgbgColour, + borderColor: pavglnColour, + }); + } + datasets.push({ + label: avgAllLabelText, + data: mean_all, + backgroundColor: avgbgColour, + borderColor: avglnColour, + }); + } + else { + let colors = [ + "#FF6384", + "#4BC0C0", + "#FFCD56", + "#C9CBCF", + "#36A2EB", + "#B284BE", + ]; + if (interaction.getAttribute('graphColorScale') != null && interaction.getAttribute('graphColorScale') != "") { + colors = interaction.getAttribute('graphColorScale').split(","); + } + let colorIndex=0; + for (var user in groupedData) { + let bgColour = hexToRgb(colors[colorIndex].substring(colors[colorIndex].length - 6), 0.5); + let lnColour = hexToRgb(colors[colorIndex].substring(colors[colorIndex].length - 6), 1); + datasets.push({ + label: (groupedData[user].actor.name != undefined ? groupedData[user].actor.name : substring(groupedData[user].actor.mbox, 7)), + data: groupedData[user].attempts[0].graph.classvalues, + backgroundColor: bgColour, + borderColor: lnColour, + }); + colorIndex++; + if (colorIndex >= colors.length) { + colorIndex = 0; + } + } + datasets.push({ + label: groupAverageLabelText, + data: mean_all, + backgroundColor: avgbgColour, + borderColor: avglnColour, + }); + } + } - if (interaction.getAttribute('opinionGraphType') == 'radar' || interaction.getAttribute('opinionGraphType') == null) { - // Show mean_all and latest - var myRadarChart = new Chart(ctx, { - type: "radar", - data: { - labels: classtitles, - datasets: datasets, - }, - options: { - scales: { - r: { - beginAtZero: true, - max: 100, - pointLabels: { - font: { - size: textSize - }, - }, - ticks: { - font: { - size: textSize - 4 - }, - } - }, - }, - legend: { - labels: { - font: { - size: textSize - }, - }, - }, - responsive: true, - maintainAspectRatio: false, - }, - }); - } else if (interaction.getAttribute('opinionGraphType') == 'hor_bar_comb_marks_avg') { - let passingGrade = x_params.trackingPassed; - if (passingGrade == null) { - passingGrade = "55"; - } else { - if (passingGrade.indexOf("%") >= 0) { - passingGrade = parseInt(passingGrade) + ""; - } else if ( - parsefloat(passingGrade) >= 0 && - parsefloat(passingGrade) <= 1 - ) { - passingGrade = parseFloat(passingGrade) * 100.0 + ""; + if (interaction.getAttribute('opinionGraphType') == 'radar' || interaction.getAttribute('opinionGraphType') == null) { + // Show mean_all and latest + var myRadarChart = new Chart(ctx, { + type: "radar", + data: { + labels: classtitles, + datasets: datasets, + }, + options: { + scales: { + r: { + beginAtZero: true, + max: 100, + pointLabels: { + font: { + size: textSize + }, + }, + ticks: { + font: { + size: textSize - 4 + }, + } + }, + }, + legend: { + labels: { + font: { + size: textSize + }, + }, + }, + responsive: true, + maintainAspectRatio: false, + }, + }); + } else if (interaction.getAttribute('opinionGraphType') == 'hor_bar_comb_marks_avg') { + let passingGrade = x_params.trackingPassed; + if (passingGrade == null) { + passingGrade = "55"; + } else { + if (passingGrade.indexOf("%") >= 0) { + passingGrade = parseInt(passingGrade) + ""; + } else if ( + parsefloat(passingGrade) >= 0 && + parsefloat(passingGrade) <= 1 + ) { + passingGrade = parseFloat(passingGrade) * 100.0 + ""; + } + } + let ctx = "#" + identifier + "-graph"; + + let labelCounter = 0; + let data = []; + if (datasets.length < 2) { + var insufficientDataText = interaction.getAttribute("insufficientDataText"); + if (insufficientDataText == undefined) { + insufficientDataText = "There is insufficient data for this graph"; + } + $(ctx).parent().append('

' + insufficientDataText + '

'); + } else { + const avgDataSet = datasets.length - 1; + + datasets[0].data.forEach((val, key) => { + data.push({ + x: classtitles[key], + y: Math.round(val, 2), + goals: [ + { + name: groupAverageLabelText, + value: datasets[avgDataSet].data[key], + strokeWidth: 5, + strokeColor: "#775DD0", + }, + ], + }); + labelCounter += 1; + }); + let colors = [ + "#FF6384", + "#4BC0C0", + "#FFCD56", + "#C9CBCF", + "#36A2EB", + "#B284BE", + ]; + if (interaction.getAttribute('graphColorScale') != null && interaction.getAttribute('graphColorScale') != "") { + colors = interaction.getAttribute('graphColorScale').split(","); + } + var options = { + series: [ + { + data, + }, + ], + chart: { + toolbar: { + show: false, + }, + height: 350, + type: "bar", + }, + plotOptions: { + bar: { + horizontal: true, + distributed: true, + }, + }, + colors: colors, + dataLabels: { + formatter: function (val, opt) { + const goals = + opt.w.config.series[opt.seriesIndex].data[opt.dataPointIndex] + .goals; + + if (goals && goals.length) { + return `${val}%`; + } + return val; + }, + style: { + fontSize: textSize + 'px', + } + }, + legend: { + show: true, + showForSingleSeries: true, + customLegendItems: [groupAverageLabelText], + markers: { + fillColors: ["#775DD0"], + }, + style: { + fontSize: textSize + 'px', + } + }, + xaxis: { + position: 'bottom', + labels: { + offsetY: 1, + style: { + fontSize: textSize + 'px', + }, + }, + }, + yaxis: { + labels: { + style: { + fontSize: textSize + 'px', + }, + }, + }, + }; + var chart = new ApexCharts( + document.querySelector(`${ctx}`), + options + ); + chart.render(); + $(ctx + ' svg text').css('font-size', textSize + 'px'); + } } - } - let ctx = "#" + identifier + "-graph"; - - let labelCounter = 0; - let data = []; - if (datasets.length < 2) - { - var insufficientDataText = interaction.getAttribute("insufficientDataText"); - if (insufficientDataText == undefined) { - insufficientDataText = "There is insufficient data for this graph"; - } - $(ctx).parent().append('

' + insufficientDataText + '

'); - } - else { - const avgDataSet = datasets.length - 1; - - datasets[0].data.forEach((val, key) => { - data.push({ - x: classtitles[key], - y: Math.round(val, 2), - goals: [ - { - name: groupAverageLabelText, - value: datasets[avgDataSet].data[key], - strokeWidth: 5, - strokeColor: "#775DD0", - }, - ], - }); - labelCounter += 1; - }); - let colors = [ - "#FF6384", - "#4BC0C0", - "#FFCD56", - "#C9CBCF", - "#36A2EB", - "#B284BE", - ]; - if (interaction.getAttribute('graphColorScale') != null && interaction.getAttribute('graphColorScale') != "") { - colors = interaction.getAttribute('graphColorScale').split(","); - } - var options = { - series: [ - { - data, - }, - ], - chart: { - toolbar: { - show: false, - }, - height: 350, - type: "bar", - }, - plotOptions: { - bar: { - horizontal: true, - distributed: true, - }, - }, - colors: colors, - dataLabels: { - formatter: function (val, opt) { - const goals = - opt.w.config.series[opt.seriesIndex].data[opt.dataPointIndex] - .goals; - - if (goals && goals.length) { - return `${val}%`; - } - return val; - }, - style: { - fontSize: textSize + 'px', - } - }, - legend: { - show: true, - showForSingleSeries: true, - customLegendItems: [groupAverageLabelText], - markers: { - fillColors: ["#775DD0"], - }, - style: { - fontSize: textSize + 'px', - } - }, - xaxis: { - position: 'bottom', - labels: { - offsetY: 1, - style: { - fontSize: textSize + 'px', - }, - }, - }, - yaxis: { - labels: { - style: { - fontSize: textSize + 'px', - }, - }, - }, - }; - var chart = new ApexCharts( - document.querySelector(`${ctx}`), - options - ); - chart.render(); - $(ctx + ' svg text').css('font-size', textSize + 'px'); - } - } - }; + }; - function hasToRetrieveAll(interaction) { - var dashboardMode = x_currentPageXML.getAttribute("dashboardMode"); - if (dashboardMode == undefined) { - dashboardMode = "false"; - } - if (dashboardMode == "true") { - return true; - } else { - if ( - (interaction.getAttribute("interactionType") !== "open" && - (interaction.getAttribute("interactionType") !== "opinion" - || interaction.getAttribute("opinionClass") == undefined)) - ) { - if (interaction.getAttribute("graph") === "true") { - return ( - interaction.getAttribute("graphType") === "bar_answers" || - interaction.getAttribute("graphType") === "bar_marks" || - interaction.getAttribute("graphType") === "line_average_marks" || - interaction.getAttribute("graphType") === "bar_marks_score" - ); + function hasToRetrieveAll(interaction) { + var dashboardMode = x_currentPageXML.getAttribute("dashboardMode"); + if (dashboardMode == undefined) { + dashboardMode = "false"; + } + if (dashboardMode == "true") { + return true; } else { - return false; + if ( + (interaction.getAttribute("interactionType") !== "open" && + (interaction.getAttribute("interactionType") !== "opinion" + || interaction.getAttribute("opinionClass") !== null)) + ) { + if (interaction.getAttribute("graph") === "true") { + return ( + interaction.getAttribute("graphType") === "bar_answers" || + interaction.getAttribute("graphType") === "bar_marks" || + interaction.getAttribute("graphType") === "line_average_marks" || + interaction.getAttribute("graphType") === "bar_marks_score" + ); + } else { + return false; + } + } else { + return true; + } } - } else { - return true; - } } - } - function escapeUrl(url, type, interactionIndex) { - return ( - url.replace(/[^A-Za-z0-9]/g, "_") + "_" + type + "_" + interactionIndex - ); - } + function escapeUrl(url, type, interactionIndex) { + return ( + url.replace(/[^A-Za-z0-9]/g, "_") + "_" + type + "_" + interactionIndex + ); + } function matchActor(statement, xertelo) { - switch (studentidmode) { - case 0: - case 2: - if (statement.actor.mbox == 'mailto:' + username) { - return true; - } - break; - case 1: - if (statement.actor.mbox_sha1sum == mboxsha1) { - return true; - } - break; - case 3: - if (statement.actor.account != undefined - && statement.actor.account.name == groupname) { - return true; - } - break; + if (statement.actor != undefined) { + if (statement.actor.mbox != undefined + && statement.actor.mbox == 'mailto:' + username) { + return true; + } + if (statement.actor.mbox_sha1sum != undefined + && statement.actor.mbox_sha1sum == mboxsha1) { + return true; + } + if (statement.actor.account != undefined + && statement.actor.account.name != undefined + && statement.actor.account.name == groupname) { + return true; + } } if (xertelo != undefined && xertelo == x_TemplateId && statement.context != undefined @@ -473,208 +519,260 @@ return false; } - function filterOwnStatements(data, xertelo) { - var statements = []; - for (var i = 0; i < data.length; i++) { - if (matchActor(data[i], xertelo)) { - statements.push(data[i]); - } + function getActor(statement, xertelo) { + if (statement.actor != undefined) { + let actor = {}; + if (statement.actor.name != undefined) { + actor.name = statement.actor.name; + } + if (statement.actor.mbox != undefined) { + actor.mbox = statement.actor.mbox; + actor.mbox_sha1sum = toSHA1(statement.actor.mbox); + actor.key = actor.mbox_sha1sum; + } + if (statement.actor.mbox_sha1sum != undefined) { + actor.mbox_sha1sum = statement.actor.mbox_sha1sum; + actor.key = actor.mbox_sha1sum; + } + if (statement.actor.account != undefined + && statement.actor.account.name != undefined) { + actor.groupname = statement.actor.account.name; + if (actor.key == undefined) { + actor.key = actor.groupname; + } + } + return actor; + } + return false; } - return statements; - } - function queryStatements(endpoint, mode, query, interactionIndex, handler) { - search = mode + "=" + JSON.stringify(query); + function mergeActor(actor1, actor2) + { + if (actor2.name != undefined) { + actor1.name = actor2.name; + } + if (actor2.mbox != undefined) { + actor1.mbox = actor2.mbox; + actor1.mbox_sha1sum = toSHA1(actor2.mbox); + actor1.key = actor1.mbox_sha1sum; + } + if (actor2.mbox_sha1sum != undefined) { + actor1.mbox_sha1sum = actor2.mbox_sha1sum; + actor1.key = actor1.mbox_sha1sum; + } + if (actor2.groupname != undefined) { + actor1.groupname = actor2.groupname; + if (actor1.key == undefined) { + actor1.key = actor1.groupname; + } + } + return actor1; + } - var statements = []; - url = endpoint + "?first=1000&" + search; - requestJSON(url, function (data) { - statements = data.edges.map(function (s) { - return s.node.statement; - }); - requestMoreStatement(url, data, statements, interactionIndex, handler); - }); - } + function filterOwnStatements(data, xertelo) { + var statements = []; + for (var i = 0; i < data.length; i++) { + if (matchActor(data[i], xertelo)) { + statements.push(data[i]); + } + } + return statements; + } + + function queryStatements(endpoint, mode, query, interactionIndex, handler) { + search = mode + "=" + JSON.stringify(query); + + var statements = []; + url = endpoint + "?first=1000&" + search; + requestJSON(url, function (data) { + statements = data.edges.map(function (s) { + return s.node.statement; + }); + requestMoreStatement(url, data, statements, interactionIndex, handler); + }); + } - function requestMoreStatement( + function requestMoreStatement( endpoint, data, statements, interactionIndex, doneHandler ) { - if (data.pageInfo.hasNextPage) { - requestJSON( - endpoint + "&first=1000&after=" + data.pageInfo.endCursor, - function (res) { - statements = statements.concat( - res.edges.map(function (s) { - return s.node.statement; - }) - ); - requestMoreStatement( - endpoint, - res, - statements, - interactionIndex, - doneHandler - ); + if (data.pageInfo.hasNextPage) { + requestJSON( + endpoint + "&first=1000&after=" + data.pageInfo.endCursor, + function (res) { + statements = statements.concat( + res.edges.map(function (s) { + return s.node.statement; + }) + ); + requestMoreStatement( + endpoint, + res, + statements, + interactionIndex, + doneHandler + ); + } + ); + } else { + doneHandler(statements, interactionIndex); } - ); - } else { - doneHandler(statements, interactionIndex); } - } - function requestJSON(url, handler) { - $.ajax({ - type: "GET", - url: url, - success: handler, - beforeSend: function (xhr) { - xhr.setRequestHeader( - "Authorization", - "Basic " + toBase64(lrsUsername + ":" + lrsPassword) - ); - }, - }); - } + function requestJSON(url, handler) { + $.ajax({ + type: "GET", + url: url, + success: handler, + beforeSend: function (xhr) { + xhr.setRequestHeader( + "Authorization", + "Basic " + toBase64(lrsUsername + ":" + lrsPassword) + ); + }, + }); + } - function verifyInteraction(interaction) { - errors = []; - if (interaction.getAttribute("interactionType") == "score") { - for (var ci = 0; ci < interaction.children.length; ci++) { - c = interaction.children[ci]; - if (!c.hasAttribute("conScoreBetween")) { - errors.push("No score between given."); - } else { - values = c.getAttribute("conScoreBetween").split(","); - if (values.length != 2) { - errors.push("Invalid pattern for score between."); - } + function verifyInteraction(interaction) { + errors = []; + if (interaction.getAttribute("interactionType") == "score") { + for (var ci = 0; ci < interaction.children.length; ci++) { + c = interaction.children[ci]; + if (!c.hasAttribute("conScoreBetween")) { + errors.push("No score between given."); + } else { + values = c.getAttribute("conScoreBetween").split(","); + if (values.length != 2) { + errors.push("Invalid pattern for score between."); + } + } + } } - } - } - if (interaction.getAttribute("interactionType") == "answer") { - for (var ci = 0; ci < interaction.children.length; ci++) { - c = interaction.children[ci]; - if (!c.hasAttribute("conScoreAnswer")) { - errors.push("No answer given."); + if (interaction.getAttribute("interactionType") == "answer") { + for (var ci = 0; ci < interaction.children.length; ci++) { + c = interaction.children[ci]; + if (!c.hasAttribute("conScoreAnswer")) { + errors.push("No answer given."); + } + } } - } + return errors; } - return errors; - } - function getUrl(xerteurl, xertelo, xertelabel, opinionClass) { - var url = xerteurl + xertelo; - if (xertelabel != undefined && xertelabel != "") { - url += "/" + xertelabel.replace(/ /g, "_"); - } - if (opinionClass != undefined && opinionClass != "") { - url += "/" + opinionClass.replace(/ /g, "_"); + function getUrl(xerteurl, xertelo, xertelabel, opinionClass) { + var url = xerteurl + xertelo; + if (xertelabel != undefined && xertelabel != "") { + url += "/" + xertelabel.replace(/ /g, "_"); + } + if (opinionClass != undefined && opinionClass != "") { + url += "/" + opinionClass.replace(/ /g, "_"); + } + return url; } - return url; - } - function getGroupingLabel(statement) { - // statements DO have context.contextActivities.grouping[0].id defined (see above) - // Check context.contextActivities.grouping[0].definition.name['en-US'] - if ( - statement.context.contextActivities.grouping[0].definition != undefined && - statement.context.contextActivities.grouping[0].definition.name != - undefined && - statement.context.contextActivities.grouping[0].definition.name[ - "en-US" - ] != undefined - ) { - return statement.context.contextActivities.grouping[0].definition.name[ - "en-US" - ]; - } else { - let id = statement.context.contextActivities.grouping[0].id; - let pos = id.lastIndexOf("/"); - let group = id.substr(pos + 1); - return group.replace(/_/g, " "); + function getGroupingLabel(statement) { + // statements DO have context.contextActivities.grouping[0].id defined (see above) + // Check context.contextActivities.grouping[0].definition.name['en-US'] + if ( + statement.context.contextActivities.grouping[0].definition != undefined && + statement.context.contextActivities.grouping[0].definition.name != + undefined && + statement.context.contextActivities.grouping[0].definition.name[ + "en-US" + ] != undefined + ) { + return statement.context.contextActivities.grouping[0].definition.name[ + "en-US" + ]; + } else { + let id = statement.context.contextActivities.grouping[0].id; + let pos = id.lastIndexOf("/"); + let group = id.substr(pos + 1); + return group.replace(/_/g, " "); + } } - } - function filterRelevantStatements(statements, type) { - if (type == "all") {return statements} - var groupedData = {}; - statements.forEach(function(statement, i) { - var participant = { - 'attemptkeys' : [], - 'attempts': [], - }; + 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]['attemptkeys'].includes(attemptkey)) { - groupedData[key]['attempts'].push(statement) - groupedData[key]['attemptkeys'].push(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 - } + 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]['attemptkeys'].includes(attemptkey)) { + groupedData[key]['attempts'].push(statement) + groupedData[key]['attemptkeys'].push(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, @@ -710,21 +808,6 @@ } if (!retrieveAll) { - /* - switch(studentidmode) { - case 0: - case 2: - q['statement.actor.mbox'] = 'mailto:' + username; - break; - case 1: - q['statement.actor.mbox_sha1summbox'] = mboxsha1; - break; - case 3: - q['statement.actor.objectType'] = 'Group'; - q['statement.actor.account.name'] = groupname; - break; - } - */ if (typeof actor != "undefined") { //actor.account.homePage = xerteurl + xertelo; q["agent"] = JSON.stringify(actor); diff --git a/modules/xerte/parent_templates/Nottingham/wizards/en-GB/data.xwd b/modules/xerte/parent_templates/Nottingham/wizards/en-GB/data.xwd index 33a3b7a59..ce89cf550 100644 --- a/modules/xerte/parent_templates/Nottingham/wizards/en-GB/data.xwd +++ b/modules/xerte/parent_templates/Nottingham/wizards/en-GB/data.xwd @@ -852,23 +852,32 @@