Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenuni committed Feb 18, 2022
2 parents 1b0248d + 556fc9d commit a859b28
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 43 deletions.
74 changes: 68 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
const KEY_CODE_SPACE = 32;

// this function will eventually run the jsPsych timeline
function kickOffExperiment() {
function kickOffExperiment(stimuli) {
const G_QUESTION_CHOICES = [FALSE_BUTTON_TEXT, TRUE_BUTTON_TEXT];

let stimuli = pickRandomList();
let subject_id = jsPsych.randomization.randomID(8);
let subject_id = uil.session.isActive() ?
uil.session.subjectId() : jsPsych.randomization.randomID(8);
let practice_items = getPracticeItems().table;
let test_items = stimuli.table;
let list_name = stimuli.list_name;
Expand Down Expand Up @@ -190,7 +190,7 @@
on_finish: function (data) {
let choice = G_QUESTION_CHOICES[data.button_pressed];
data.answer = choice;
data.correct = choice == data.expected_answer;
data.correct = choice === data.expected_answer;
data.integer_correct = data.correct ? 1 : 0;
data.rt = Math.round(data.rt);
}
Expand Down Expand Up @@ -256,12 +256,74 @@
let paragraph = document.createElement("p")
paragraph.innerHTML = "Please run this experiment on a pc or laptop";
document.body.appendChild(paragraph);
};
}
}

/**
* Get the list of practice items
*
* Returns an object with a list and a table, the list will always indicate
* "practice" since it are the practice items
*
* @returns {object} object with list_name and table fields
*/
function getPracticeItems() {
return {list_name : "practice", table : PRACTICE_ITEMS};
}

/**
* This function will pick a random list from the TEST_ITEMS array.
*
* Returns an object with a list and a table, the list will always indicate
* which list has been chosen for the participant.
*
* @returns {object} object with list_name and table fields
*/
function pickRandomList() {
let range = function (n) {
let empty_array = [];
let i;
for (i = 0; i < n; i++) {
empty_array.push(i);
}
return empty_array;
}
let num_lists = TEST_ITEMS.length;
var shuffled_range = jsPsych.randomization.repeat(range(num_lists), 1)
var retlist = TEST_ITEMS[shuffled_range[0]];
return retlist
}

function findList(name) {
let list = TEST_ITEMS.find((entry) => entry.list_name === name);
if (!list) {
let found = TEST_ITEMS.map((entry) => `"${entry.list_name}"`).join(', ');
console.error(
`List not found "${name}".\n` +
'This name was configured on the UiL datastore server.\n' +
`The following lists exist in stimuli.js: \n${found}`)
}
return list;
}

function main() {

// Option 1: client side randomization:
let stimuli = pickRandomList();
kickOffExperiment(stimuli);

// Option 2: server side balancing:
// Make sure you have matched your groups on the dataserver with the
// This experiment uses groups/lists list1, and list2 by default.
// uil.session.start(ACCESS_KEY, (group_name) => {
// let stimuli = findList(group_name);
// kickOffExperiment(stimuli);
// });
}

window.addEventListener (
'load',
kickOffExperiment
main
);
</script>
</html>
Expand Down
34 changes: 0 additions & 34 deletions stimuli.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,4 @@ const TEST_ITEMS = [
// {list_name: LISTS[1], table: LIST_GROUP3}
];

/**
* Get the list of practice items
*
* Returns an object with a list and a table, the list will always indicate
* "practice" since it are the practice items
*
* @returns {object} object with list_name and table fields
*/
function getPracticeItems() {
return {list_name : "practice", table : PRACTICE_ITEMS};
}

/**
* This function will pick a random list from the TEST_ITEMS array.
*
* Returns an object with a list and a table, the list will always indicate
* which list has been chosen for the participant.
*
* @returns {object} object with list_name and table fields
*/
function pickRandomList() {
let range = function (n) {
let empty_array = [];
let i;
for (i = 0; i < n; i++) {
empty_array.push(i);
}
return empty_array;
}
let num_lists = TEST_ITEMS.length;
var shuffled_range = jsPsych.randomization.repeat(range(num_lists), 1)
var retlist = TEST_ITEMS[shuffled_range[0]];
return retlist
}

6 changes: 3 additions & 3 deletions survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ let survey_review = {
stimulus: function(data){

let survey_1_data=
jsPsych.data.get().last(2).values()[0]; //former
JSON.parse(jsPsych.data.get().last(2).values()[0].responses);

let survey_2_data =
jsPsych.data.get().last(1).values()[0];
JSON.parse(jsPsych.data.get().last(1).values()[0].responses);

let b_year = survey_1_data.birth_year;
let b_month = survey_1_data.birth_month;
Expand All @@ -132,7 +132,7 @@ let survey_review = {
let hand_pref = survey_2_data.HandPreference;

return `
<h1>Your data</h1>
<h1>Your responses</h1>
<div><strong>Birth year</strong>: ${b_year} </div>
<div><strong>Birth month</strong>: ${b_month} </div>
Expand Down

0 comments on commit a859b28

Please sign in to comment.