Skip to content

Commit

Permalink
Changed way statements are collected for drawScore. now based on vari…
Browse files Browse the repository at this point in the history
…able from xerte: graphAnswerType. Choices for First, last, best and all.
  • Loading branch information
TimoBoer authored and torinfo committed Apr 1, 2024
1 parent b5c3c25 commit f6aee62
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 15 deletions.
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions modules/xerte/xAPI/xttracking_xapi.js
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -2018,7 +2018,7 @@ function getStatements(q, one, callback)
}
);
}
debugger;

}
}

Expand Down Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions src/Nottingham/wizards/en-GB/adaptiveContent.xwd
Expand Up @@ -79,6 +79,7 @@
<graphShowAvgBar label="Display the avg and score with a bar" type="checkbox" defaultValue="false" optional="true" condition="graphType=='bar_marks'" tooltip="Adds a line in the graph for the avg and user score" />
<graphFitInfoInBar label="Show info in bar" type="checkbox" defaultValue="false" optional="true" condition="graphType=='bar_marks'" tooltip="Scales the user score and avg and displays them in the bars" />
<graphColorScale label="Color scale" type="textInput" wysiwyg="false" defaultValue="#FF6384,#4BC0C0,#FFCD56,#C9CBCF,#36A2EB,#B284BE" optional="true" condition="graphType=='polar_area_per_category'||opinionGraphType=='hor_bar_comb_marks_avg'" tooltip="The color scale for the bars in a bargraph, or the color scale for the points in a polar graph" />
<graphAnswerType label="Answer used" type="combobox" data="first,last,best,all" options="First,Last,Best,All" default="last" optional="true"/>
</graphgroup>
<showScore label="Show score/answer" type="CheckBox" condition="interactionType=='score'||interactionType=='answer'||(interactionType=='opinion' &amp;&amp; opinionClass!=null)||interactionType=='grouping'||interactionType=='groupings'||interactionType=='opinionclasses'" optional="true" defaultValue="false" tooltip="Show your score or answer on which the interactionBlocks based" />
<scoreText label="Score text" type="TextInput" wysiwyg="true" language="true" />
Expand Down

0 comments on commit f6aee62

Please sign in to comment.