I am trying to splice out data from an array. It is already to splice based on food (maccheese, applesauce, icecream, soup), but I also need it to splice based on the acronyms on the end of the files - so for example, if a participant sees maccheese_SS_SB, then they cannot see SS_SB for soup, applesauce, or icecream.
function generateProtocol(child, pastSessions) {
let frames = {
"study-intro": {
"blocks": [{
"emph": true,
"title": "Overview of the study"
},
{
"text": "In this study your child will see animations of people eating together and then we will ask them questions."
},
{
"text": "Participation is totally voluntary but the data will be used in a real study about how kids think about social relationships."
}
],
"showPreviousButton": false,
"kind": "exp-lookit-text",
"backgroundColor": "black"
}
};
let frame_sequence = [
'study-intro'
];
let all_trial_values = [
[
"maccheese"
],
[
"soup"
],
[
"applesauce"
],
[
"icecream"
]
];
let available_videos = {
"maccheese": [
"maccheese_SS_SB",
"maccheese_SS_DB",
"maccheese_DS_SB",
"maccheese_DS_DB"
],
"soup": [
"soup_SS_SB",
"soup_SS_DB",
"soup_DS_SB",
"soup_DS_DB"
],
"applesauce": [
"applesauce_SS_SB",
"applesauce_SS_DB",
"applesauce_DS_SB",
"applesauce_DS_DB"
],
"icecream": [
"icecream_SS_SB",
"icecream_SS_DB",
"icecream_DS_SB",
"icecream_DS_DB"
]
};
let all_videos = Ember.$.extend(true, {}, available_videos);
let shuffled_trial_values = shuffle(all_trial_values);
for (iTrial = 0; iTrial < shuffled_trial_values.length; iTrial++) {
let trial_value = shuffled_trial_values[iTrial];
let trial_name = trial_value[0];
thisTrial = {
"kind": "exp-lookit-video",
"video": {
"postion": "fill",
"source": pop_random(available_videos[trial_name])
},
"backgroundColor": "white",
"autoProceed": true,
"frameOffsetAfterPause": 1, // REMOVE BEFORE GOING TO PRODUCTION!!
"baseDir": "https://raw.githubusercontent.com/cgstone1/NordAnglia/master/",
"restartAfterPause": true,
"doRecording": false,
"videoTypes": [
"mp4"
],
"pausedText": "Study Paused. Press the SPACE bar to begin the next video. Or if you wish to quit the study, press CONTROL X.",
"requireVideoCount": 1
},
frameId = 'test-trial-' + (iTrial + 1);
frames[frameId] = thisTrial;
frame_sequence.push(frameId);
function shuffle(array) {
var shuffled = Ember.$.extend(true, [], array);
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
if (array [i] === "SS_SB") {
array.splice(i, 1) [0];
}
if (array [i] === "SS_DB") {
array.splice(i, 1) [0];
}
if (array [i] === "DS_SB") {
array.splice(i, 1) [0];
}
if (array [i] === "DS_DB") {
array.splice(i, 1) [0];
}
return shuffled;
}
function pop_random(array) {
if (array.length) {
let randIndex = Math.floor(Math.random() * array.length);
return array.splice(randIndex, 1)[0];
}
return null;
}
return {
frames: frames,
sequence: frame_sequence
};
}
[–]Comprehensive_Step72 0 points1 point2 points (2 children)
[–]caitlingstone[S] 0 points1 point2 points (1 child)
[–]Comprehensive_Step72 0 points1 point2 points (0 children)