Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #1710, adds getInteractionObject() function #108

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions js/adapt-contrib-matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,67 @@ define([
this.$('select').eq(i).val(value).trigger('change');
},

/**
* Used by tracking extensions to return an object containing the component's specific interactions.
*/
getInteractionObject: function() {
var interactions = {
correctResponsesPattern: null,
source: null,
target: null
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to define the properties as null if you're setting them directly below?


// This contains an array with a single string value, matching the source 'id' with the correct
// matching target 'id' value. An example is as follows:
// [ "1[.]1_2[,]2[.]2_3" ]
interactions.correctResponsesPattern = [
this.model.get('_items').map(function(item, questionIndex) {
// Offset the item index and use it as a group identifier.
questionIndex = questionIndex + 1;

return [
questionIndex,
item._options.filter(function(item) {
// Get the correct item(s).
return item._isCorrect;
}).map(function(item) {
// Prefix the option's index and offset by 1.
return questionIndex + '_' + (item._index + 1).toString()
})
].join('[.]');

}).join('[,]')
];

// The 'source' property contains an array of all the stems/questions, e.g.
// [{id: "1", description: "First question"}, {id: "2", description: "Second question"}]
interactions.source = _.flatten(this.model.get('_items').map(function(item) {
return {
// Offset by 1.
id: (item._index + 1).toString(),
description: item.text
}
}));

// The 'target' property contains an array of all the option responses, with the 'id'
// prefixed to indicate the grouping, e.g.
// [ {id: "1_1": description: "First option, group 1"},
// {id: "1_2": description: "Second option, group 1"}
// {id: "2_1": description: "First option, group 2"} ]
interactions.target = _.flatten(this.model.get('_items').map(function(item, index) {
// Offset by 1, as these values are not zero-indexed.
index = index + 1;
return item._options.map(function(option) {
return {
id: index + '_' + (option._index + 1),
description: option.text
}
});
}));

return interactions;
},

/**
* Used by adapt-contrib-spoor to get the user's answers in the format required by the cmi.interactions.n.student_response data field
* Returns the user's answers as a string in the format "1.1#2.3#3.2" assuming user selected option 1 in drop-down 1, option 3 in drop-down 2
Expand Down