Skip to content

Commit 857f1b9

Browse files
authored
Merge pull request #1 from ande8936/FoodChoiceTask-08.24.20
Food choice task 08.24.20
2 parents a1562e4 + dbaf1bc commit 857f1b9

121 files changed

Lines changed: 11831 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 0 deletions

Rewrite.v1.1_08.13.2020.html

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<!--
2+
v1.1
3+
8/13/2020
4+
-->
5+
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title></title>
10+
<script src="jspsych-6.1.0/jspsych.js"></script>
11+
<script src="jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js"></script>
12+
<script src="jspsych-6.1.0/plugins/jspsych-image-keyboard-response.js"></script>
13+
<link href="jspsych-6.1.0/css/jspsych.css" rel="stylesheet" type="text/css"></link>
14+
<style>img {width:300px;}</style>
15+
<meta charset="UTF-8">
16+
</head>
17+
<body></body>
18+
<script>
19+
//Declaring timeline variable containing all the stimulus items from the /img folder for use in all Trials.
20+
var test_stimuli = [
21+
{ stimulus: 'img/LF_pic_01.png', data: {test_part: 'test', correct_response: '3'}},
22+
{ stimulus: 'img/HF_pic_01.png', data: {test_part: 'test', correct_response: '3'}},
23+
{ stimulus: 'img/LF_pic_02.png', data: {test_part: 'test', correct_response: '3'}},
24+
{ stimulus: 'img/HF_pic_02.png', data: {test_part: 'test', correct_response: '3'}},
25+
{ stimulus: 'img/LF_pic_03.png', data: {test_part: 'test', correct_response: '3'}},
26+
{ stimulus: 'img/HF_pic_03.png', data: {test_part: 'test', correct_response: '3'}},
27+
{ stimulus: 'img/LF_pic_04.png', data: {test_part: 'test', correct_response: '3'}},
28+
{ stimulus: 'img/HF_pic_04.png', data: {test_part: 'test', correct_response: '3'}},
29+
{ stimulus: 'img/LF_pic_05.png', data: {test_part: 'test', correct_response: '3'}},
30+
{ stimulus: 'img/HF_pic_05.png', data: {test_part: 'test', correct_response: '3'}},
31+
{ stimulus: 'img/LF_pic_06.png', data: {test_part: 'test', correct_response: '3'}},
32+
{ stimulus: 'img/HF_pic_06.png', data: {test_part: 'test', correct_response: '3'}},
33+
{ stimulus: 'img/LF_pic_07.png', data: {test_part: 'test', correct_response: '3'}},
34+
{ stimulus: 'img/HF_pic_07.png', data: {test_part: 'test', correct_response: '3'}},
35+
{ stimulus: 'img/LF_pic_08.png', data: {test_part: 'test', correct_response: '3'}},
36+
{ stimulus: 'img/HF_pic_08.png', data: {test_part: 'test', correct_response: '3'}},
37+
{ stimulus: 'img/LF_pic_09.png', data: {test_part: 'test', correct_response: '3'}},
38+
{ stimulus: 'img/HF_pic_09.png', data: {test_part: 'test', correct_response: '3'}},
39+
{ stimulus: 'img/LF_pic_10.png', data: {test_part: 'test', correct_response: '3'}},
40+
{ stimulus: 'img/HF_pic_10.png', data: {test_part: 'test', correct_response: '3'}},
41+
{ stimulus: 'img/LF_pic_11.png', data: {test_part: 'test', correct_response: '3'}},
42+
{ stimulus: 'img/HF_pic_11.png', data: {test_part: 'test', correct_response: '3'}},
43+
{ stimulus: 'img/LF_pic_12.png', data: {test_part: 'test', correct_response: '3'}},
44+
{ stimulus: 'img/HF_pic_12.png', data: {test_part: 'test', correct_response: '3'}},
45+
{ stimulus: 'img/LF_pic_13.png', data: {test_part: 'test', correct_response: '3'}},
46+
{ stimulus: 'img/HF_pic_13.png', data: {test_part: 'test', correct_response: '3'}},
47+
{ stimulus: 'img/LF_pic_14.png', data: {test_part: 'test', correct_response: '3'}},
48+
{ stimulus: 'img/HF_pic_14.png', data: {test_part: 'test', correct_response: '3'}},
49+
{ stimulus: 'img/LF_pic_15.png', data: {test_part: 'test', correct_response: '3'}},
50+
{ stimulus: 'img/HF_pic_15.png', data: {test_part: 'test', correct_response: '3'}},
51+
{ stimulus: 'img/LF_pic_16.png', data: {test_part: 'test', correct_response: '3'}},
52+
{ stimulus: 'img/HF_pic_16.png', data: {test_part: 'test', correct_response: '3'}},
53+
{ stimulus: 'img/LF_pic_17.png', data: {test_part: 'test', correct_response: '3'}},
54+
{ stimulus: 'img/HF_pic_17.png', data: {test_part: 'test', correct_response: '3'}},
55+
{ stimulus: 'img/LF_pic_18.png', data: {test_part: 'test', correct_response: '3'}},
56+
{ stimulus: 'img/HF_pic_18.png', data: {test_part: 'test', correct_response: '3'}},
57+
{ stimulus: 'img/LF_pic_19.png', data: {test_part: 'test', correct_response: '3'}},
58+
{ stimulus: 'img/HF_pic_19.png', data: {test_part: 'test', correct_response: '3'}},
59+
{ stimulus: 'img/LF_pic_20.png', data: {test_part: 'test', correct_response: '3'}},
60+
{ stimulus: 'img/HF_pic_20.png', data: {test_part: 'test', correct_response: '3'}},
61+
{ stimulus: 'img/LF_pic_21.png', data: {test_part: 'test', correct_response: '3'}},
62+
{ stimulus: 'img/HF_pic_21.png', data: {test_part: 'test', correct_response: '3'}},
63+
{ stimulus: 'img/LF_pic_22.png', data: {test_part: 'test', correct_response: '3'}},
64+
{ stimulus: 'img/HF_pic_22.png', data: {test_part: 'test', correct_response: '3'}},
65+
{ stimulus: 'img/LF_pic_23.png', data: {test_part: 'test', correct_response: '3'}},
66+
{ stimulus: 'img/HF_pic_23.png', data: {test_part: 'test', correct_response: '3'}},
67+
{ stimulus: 'img/LF_pic_24.png', data: {test_part: 'test', correct_response: '3'}},
68+
{ stimulus: 'img/HF_pic_24.png', data: {test_part: 'test', correct_response: '3'}},
69+
{ stimulus: 'img/LF_pic_25.png', data: {test_part: 'test', correct_response: '3'}},
70+
{ stimulus: 'img/HF_pic_25.png', data: {test_part: 'test', correct_response: '3'}}
71+
];
72+
73+
//Declaring function to find the name of the reference file for use in Trial 3.
74+
function findReference() {
75+
var trueImages = jsPsych.data.get().filter({correct: true}).select('stimulus').values;
76+
trueImages.sort();
77+
for (i = 0; i < trueImages.length - 1; i++) {
78+
if (trueImages[i] === trueImages[i + 1]) {
79+
return trueImages[i];
80+
}
81+
}
82+
}
83+
84+
//Create Timeline
85+
var timeline = [];
86+
87+
//Generate Random Subject ID with 15 Characters
88+
var subject_id = jsPsych.randomization.randomID(15);
89+
jsPsych.data.addProperties({ subject: subject_id });
90+
91+
//Welcome Screen
92+
var welcome = {
93+
type: "html-keyboard-response",
94+
stimulus: "Welcome to today's experiment. Press any key to begin."
95+
};
96+
timeline.push(welcome);
97+
98+
//Instructions: 3 timeline variables for each set of instructions corresponding to Trials 1-3.
99+
var instructions1 = {
100+
type: "html-keyboard-response",
101+
stimulus: "<h1>Module 1 Instructions</h1>" +
102+
"<p>Rate the following foods on how tasty they are, with 1 being BAD - Not Tasty and 5 being GOOD - Tasty.</p>" +
103+
"<p><strong>Press any button when ready to begin...</strong></p>",
104+
};
105+
timeline.push(instructions1);
106+
107+
var test1 = {
108+
type: "image-keyboard-response",
109+
stimulus: jsPsych.timelineVariable('stimulus'),
110+
prompt: "<p>How HEALTHY is this food?</p>" +
111+
"<p>[Unhealthy] 1 -------- 2 ------- 3 ------- 4 ------- 5 [Healthy]</p>",
112+
choices: ['1', '2', '3', '4', '5'],
113+
labels: ['1 (BAD)', '3 (NEUTRAL)','5 (GOOD)'],
114+
data: jsPsych.timelineVariable('data'),
115+
on_finish: function(data) {
116+
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
117+
},
118+
}
119+
timeline.push({
120+
timeline: [test1],
121+
timeline_variables: test_stimuli,
122+
randomize_order: true,
123+
repetitions: 1,
124+
})
125+
126+
var instructions2 = {
127+
type: "html-keyboard-response",
128+
stimulus: "<h1>Module 2 Instructions</h1>" +
129+
"<p>Rate the following foods on how HEALTHY they are, with 1 being the UNHEALTHY and 5 being HEALTHY.</p>" +
130+
"<p><strong>Press any key to begin.</strong></p>",
131+
};
132+
timeline.push(instructions2);
133+
134+
var test2 = {
135+
type: "image-keyboard-response",
136+
stimulus: jsPsych.timelineVariable('stimulus'),
137+
prompt: "<p>How TASTY is this food?</p>" +
138+
"<p>[Not Tasty] 1 -------- 2 ------- 3 ------- 4 ------- 5 [Tasty]</p>",
139+
choices: ['1', '2', '3', '4', '5'],
140+
labels: ['1 (BAD)', '3 (NEUTRAL)','5 (GOOD)'],
141+
data: jsPsych.timelineVariable('data'),
142+
on_finish: function(data) {
143+
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
144+
},
145+
}
146+
timeline.push({
147+
timeline: [test2],
148+
timeline_variables: test_stimuli,
149+
randomize_order: true,
150+
repetitions: 1,
151+
})
152+
153+
var instructions3 = {
154+
type: "html-keyboard-response",
155+
stimulus: "<h1>Module 3 Instructions</h1>" +
156+
"<p>You will be presented with an image of a REFERENCE food item and an OTHER food item. Please indicate if you would PREFER to eat the OTHER food item instead of the REFERENCE food item, with 1 being NO, 3 being NEUTRAL and 5 being YES.</p>" +
157+
"<p><strong>Press any button when ready to begin...</strong></p>",
158+
};
159+
timeline.push(instructions3);
160+
161+
var test3 = {
162+
type: "html-keyboard-response",
163+
stimulus: function() {
164+
return "<div style='float: left;'>" +
165+
"<img src=" +
166+
jsPsych.timelineVariable('stimulus',true) +
167+
"></img>" +
168+
"<p style='small'><strong>OTHER</strong></p></div>" +
169+
"<div class='float: right;'>" +
170+
"<img src=" +
171+
findReference() +
172+
"></img>" +
173+
"<p style='small'><strong>REFERENCE</strong></p></div>"
174+
},
175+
prompt:
176+
"<p><center>Would you rather have the OTHER food item instead of the REFERENCE food item?</center></p>" +
177+
"<p><center>[NO] 1 -------- 2 ------- 3 ------- 4 ------- 5 [YES]</center></p>",
178+
choices: ['1', '2', '3', '4', '5'],
179+
labels: ["1 (NO)", "3 (NEUTRAL)", "5 (YES)"],
180+
data: jsPsych.timelineVariable('data'),
181+
}
182+
timeline.push({
183+
timeline: [test3],
184+
timeline_variables: test_stimuli,
185+
randomize_order: true,
186+
repetitions: 1,
187+
})
188+
189+
//Initializes Timeline with all blocks therein as defined by test_procedure
190+
jsPsych.init ({
191+
timeline: timeline,
192+
on_finish: function() {
193+
var content = "data:text/csv;charset:utf-8," + jsPsych.data.get().json();
194+
outputfile = "food_choice_trial" + generateFileName('.json')
195+
var link = document.createElement("a");
196+
link.setAttribute("href",encodeURI(content));
197+
link.setAttribute("download",outputfile);
198+
document.body.appendChild(link);
199+
link.click();
200+
}
201+
});
202+
203+
//Same function as in original code, dictating details of output file name
204+
function generateFileName(suffix) {
205+
var k = 0;
206+
var today = new Date();
207+
datenow = today.getFullYear().toString() +
208+
'_' + (today.getMonth()+1).toString() +
209+
'_' + today.getDate().toString() +
210+
'_' + today.getHours().toString() +
211+
'_' + today.getMinutes().toString() +
212+
'_' + today.getSeconds().toString();
213+
return datenow + suffix;
214+
}
215+
</script>
216+
</html>

img/HF_pic_01.png

90.8 KB

img/HF_pic_02.png

107 KB

img/HF_pic_03.png

139 KB

img/HF_pic_04.png

140 KB

img/HF_pic_05.png

106 KB

img/HF_pic_06.png

1.03 MB

img/HF_pic_07.png

81.5 KB

img/HF_pic_08.png

128 KB

0 commit comments

Comments
 (0)