-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2_prolific.html
405 lines (381 loc) · 15.9 KB
/
index2_prolific.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<!DOCTYPE html>
<html>
<head>
<title>PsychExp</title>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/plugin-survey-html-form"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<link href="https://unpkg.com/[email protected]/css/jspsych.css" rel="stylesheet" type="text/css" />
<script src="factorial_noRandom.js"></script>
<script src="make_condition.js"></script>
<script src="jspsych-psychophysics.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.2/underscore-min.js" integrity="sha512-anTuWy6G+usqNI0z/BduDtGWMZLGieuJffU89wUU7zwY/JhmDzFrfIZFA3PY7CEX4qxmn3QXRoXysk6NBh5muQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://www.gstatic.com/firebasejs/8.1.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.1.2/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.1.2/firebase-database.js"></script>
</head>
<body></body>
<script type="text/javascript">
// Firebase set up
var firebaseConfig = {
apiKey: "AIzaSyBB0wgVCYlPXiVfL6_o8BLKIFZKQhzsclY",
authDomain: "scene-categorybias.firebaseapp.com",
projectId: "scene-categorybias",
storageBucket: "scene-categorybias.appspot.com",
messagingSenderId: "714487112899",
appId: "1:714487112899:web:e9ac2772850fe4c8766e76"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// login anonymous user
firebase.auth().signInAnonymously().catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
});
</script>
<script>
const jsPsych = initJsPsych();
/* condition */
var factors = {
dist: [11],
set_size: [3,4,6,8],
target_ox: [0,1], // 0=target absent, 1=target present
dimension: [-1,1],
direction: [-1,1]
}
var cond_list = factorial_noRandom(factors);
var target_coord = '0_0';
var jitter = [-1,0,1];
var n_block = 4;
var stim_dir = 'stimuli/bedroom5_ver4/'
var position_idx = _.range(0,_.max(factors.set_size));
var exp_cond = make_condition(cond_list, jitter, target_coord, n_block, stim_dir, position_idx);
// * Prolific information * //
var subject_id = jsPsych.data.getURLVariable('PROLIFIC_PID');
var study_id = jsPsych.data.getURLVariable('STUDY_ID');
var session_id = jsPsych.data.getURLVariable('SESSION_ID');
jsPsych.data.addProperties({
subject_id: subject_id,
study_id: study_id,
session_id: session_id
});
/* conset_page */
var consent_page = {
type: jsPsychHtmlButtonResponse,
stimulus: function(){
var html =
'<p area-selected="font-size:15px;"> Press Agree to participate in the experiment.</p>'+
'<embed src="stimuli/consent_online_pay.pdf" style="width:80vw; height:70vh;"></embed>'
return html;
},
choices: ['Agree'],
data: {disp_type: 'consent_page'}
}
/* instruction */
var instruction1 = {
type: jsPsychHtmlButtonResponse,
stimulus: html='<img src="stimuli/instruction/p1_welcome.png" style="height:600px">',
choices: ['Go to procedure'],
data: {disp_type: 'inst_welcome'}
}
var instruction2 = {
type: jsPsychHtmlButtonResponse,
stimulus: html='<img src="stimuli/instruction/p2_procedure.png" style="height:600px">',
choices: ['Preview target'],
data: {disp_type: 'inst_procedure'}
}
var target_preview = {
type: jsPsychImageKeyboardResponse,
stimulus: stim_dir+'000312.webp',
choices: ['b'],
data: {disp_type: 'target_preview'},
prompt: "<p>The above image is the target scene you will search for among foil scenes.<br>"+
"The foils can be very similar to the target.<br>"+
"So, carefully look at this scene and try to remember it precisely.<br><br>"+
"In the task, press 'Y' if the target is present, or press 'N' if the target is absent.<br>"+
"Once you are ready to start, press 'B'.</p>"
}
/* preloading */
var images = [];
for(var i=0; i<625; i++){
images.push(stim_dir+'/'+("000000"+i).slice(-6)+'.webp');
}
var n_loaded = 0;
jsPsych.pluginAPI.preloadImages(images, function(){ startExperiment(); }, function(file) { updateLoadedCount(file); });
function updateLoadedCount(file){
n_loaded++;
var percentcomplete = n_loaded / images.length * 100;
// could put something fancier here, like a progress bar
// or updating text in the DOM.
console.log('Loaded '+percentcomplete+'% of images');
}
/* search trial composition */
// img position function
function img_pos(array_size, radius, stim_size, cx, cy, jitter){
var angles = _.range(0, 360, 360/array_size);
var jittered_angles = _.map(angles, function(x){return x + jitter})
var start_XYs = [];
for (var i of jittered_angles){
var x = cx + (Math.cos(i/180*Math.PI)*radius);
var y = cy + (Math.sin(i/180*Math.PI)*radius);
start_XYs.push([x,y]);
}
return start_XYs
}
// draw function
function prepare_stim(set_size, stim_pos, target_ox, target_path, nt_path, stim_size){
// img position
var position = img_pos(8,200,84,500,400, Math.random(1)*45)
// merge target path and nt path
var stim_path = nt_path;
if(target_ox==1){
stim_path = nt_path.concat(target_path);
}
// make stim object
var stim=[];
for (var i=0; i<set_size; i++){
stim.push({
obj_type: 'image',
file: stim_path[i],
image_width: stim_size,
startX: position[stim_pos[i]][0],
startY: position[stim_pos[i]][1]
})
}
stim.push({
obj_type: 'rect',
startX: 500,
startY: 400,
width: 900,
height: 700,
fill_color: '#ffffff',
show_end_time: 1000
})
// add central fixation
stim.push({
obj_type: 'text',
font: "34px Arial",
content: '+'
})
return stim;
}
var trial = {
type: jsPsychPsychophysics,
stimuli: function(){
var stim_list = prepare_stim(
jsPsych.timelineVariable('set_size'), jsPsych.timelineVariable('stim_position'),
jsPsych.timelineVariable('target_ox'), jsPsych.timelineVariable('target_path'),
jsPsych.timelineVariable('nt_path'), 84);
return stim_list;
},
choices: ['y', 'n'],
canvas_width: 1000,
canvas_height: 800,
background_color: '#ffffff',
trial_duration: 10000,
data: {
target_present: jsPsych.timelineVariable('target_ox'),
config_type: jsPsych.timelineVariable('type'),
config_dir: jsPsych.timelineVariable('direction'),
config_dim: jsPsych.timelineVariable('dimension'),
set_size: jsPsych.timelineVariable('set_size'),
disp_type: 'search_array'
}
}
// var fix_cross = {
// obj_type: 'text',
// font: "34px Arial",
// content: '+'
// }
// var fixation = {
// type: jsPsychPsychophysics,
// stimuli: [fix_cross],
// choices: "NO_KEYS",
// trial_duration: 1000,
// canvas_width: 1000,
// canvas_height: 800,
// background_color: '#ffffff',
// data: {disp_type: 'iti1000'}
// }
var search_main1 = {
timeline: [trial],
timeline_variables: exp_cond[0]
}
var search_main2 = {
timeline: [trial],
timeline_variables: exp_cond[1]
}
var search_main3 = {
timeline: [trial],
timeline_variables: exp_cond[2]
}
var search_main4 = {
timeline: [trial],
timeline_variables: exp_cond[3]
}
var search_practice = {
timeline: [trial],
timeline_variables: exp_cond[_.sample([0,1,2,3])]
}
/* break */
var n_rounds=9;
for (var i=1; i<n_rounds; i++){
this['inter_break'+i] = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `<p style="font-size: 24px;">Round ${i} is just done! Now you have ${n_rounds-i} round(s) to go.</br>
Take a short break and press "B" to resume.<br>
You will see the target once again and then start searching.</p>`,
choices: ['b'],
data: {disp_type: 'break'}
}
}
// * save data * //
var save_data = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<p>You are done! Now we are saving your data. Do not leave this page yet.</p>',
choices: "NO_KEYS",
trial_duration: 3000,
data: { // random rotation angle saving
disp_type: 'saving_display'
},
on_finish: function(){
jsPsych.data.displayData()
// // get data values
// var data = {experiment:"sceneSquare_visualSearch_prolific",
// repo:"sceneSquare_visualSearch_prolific",
// data:jsPsych.data.get().values(),
// interaction_data:jsPsych.data.getInteractionData().values()
// }
// // send data to savejs
// var xhr = new XMLHttpRequest();
// xhr.open('POST','https://macklab-savejs.netlify.app/api/savejs');
// xhr.setRequestHeader('Content-Type','application/json');
// xhr.onload = function(){
// if(xhr.status==200){
// var response=JSON.parse(xhr.responseText);
// console.log(response.success);
// }
// };
// xhr.send(JSON.stringify(data));
// send data to firebase!
var tmp = new Uint32Array(1);
tmp = window.crypto.getRandomValues(tmp)
var dbpath = firebase.auth().currentUser.uid+'/'+tmp;
firebase.database().ref(dbpath).set({
data:jsPsych.data.get().values(),
interaction_data:jsPsych.data.getInteractionData().values(),
date: Date()
});
}
}
// * demographic page * //
var gender_options = ['Male', 'Female', 'Other'];
var handed_option = ['Right', 'Left', 'ambidextrous'];
var dem_info = {
type: jsPsychSurveyHtmlForm,
preamble: '<p><b>Before starting, we would like to collect the basic information below.</b></p>',
html: '<p style="font-size:12pt;"> Gender: '+
'<input name="gender" type="radio" value="male" required/><label for="male">Male</label>'+
'<input name="gender" type="radio" value="female" required/><label for="female">Female</label>'+
'<input name="gender" type="radio" value="other" required/><label for="other">Other</label></br>'+
// age
'Age: <input name="age" type="text"/></br>'+
// handedness
'Handedness: '+
'<input name="hand" type="radio" value="right" required/><label for="right">Right</label>'+
'<input name="hand" type="radio" value="left" required/><label for="left">Left</label>'+
'<input name="hand" type="radio" value="ambidextrous" required/><label for="ambidextrous">Ambidextrous</label></br></br>'+
'Please respond to the following quetions by checking "Yes" or "No": </br>'+
// lenses
'</br>Do you wear corrective lenses?: '+
'<input name="lense" type="radio" value="yes" required/><label for="yes">Yes</label>'+
'<input name="lense" type="radio" value="no" required/><label for="no">No</label>'+
'</br>If yes, specify glasses or contacts: <input name="lensetype" type="text" /></br>'+
// hearing aids
'</br>Do you use hearing aid?: '+
'<input name="hear" type="radio" value="yes" required/><label for="yes">Yes</label>'+
'<input name="hear" type="radio" value="no" required/><label for="no">No</label>'+
'</br>If yes, please specify what kinds: <input name="hearaidtype" type="text" /></br>'+
// brain malfunction
'</br>Do you have any known brain malfunctions?: '+
'<input name="brain" type="radio" value="yes" required/><label for="yes">Yes</label>'+
'<input name="brain" type="radio" value="no" required/><label for="no">No</label>'+
'</br>If yes, please specify type and location: <input name="brainmaltype" type="text" /></br>'+
// color blindness
'</br>Do you experience color blindness?: '+
'<input name="color" type="radio" value="yes" required/><label for="yes">Yes</label>'+
'<input name="color" type="radio" value="no" required/><label for="no">No</label></br>'+
// neurological conditions
'</br>Do you have (or have you had) any neurological conditions?: '+
'<input name="neuro" type="radio" value="yes" required/><label for="yes">Yes</label>'+
'<input name="neuro" type="radio" value="no" required/><label for="no">No</label>'+
'</br>If yes, please specify type and location: <input name="neurotype" type="text" /></br></p>',
data: {
disp_type: 'demographic_info'
}
}
// debriefing letter
var debrief_page = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function(){
var html =
'<p area-selected="font-size:15px;"> Thank you for participating!</p>'+
'<p><a href="https://app.prolific.co/submissions/complete?cc=1C85CD1B">Click here to return to Prolific and complete the study</a>.</p>'+
'<embed src="stimuli/debriefing_letter.pdf" style="width:80vw; height:70vh;"></embed>'
return html;
},
choices: "NO_KEYS",
data: {disp_type: 'debriefing_page'}
}
timeline =[];
timeline.push(consent_page);
timeline.push(dem_info);
timeline.push({
type: jsPsychFullscreen,
fullscreen_mode: true,
data: {disp_type: 'fullscreen-in'}
});
timeline.push(instruction1);
timeline.push(instruction2);
timeline.push(target_preview);
timeline.push(search_practice);
timeline.push(inter_break1);
timeline.push(target_preview);
timeline.push(search_main1);
timeline.push(inter_break2);
timeline.push(target_preview);
timeline.push(search_main2);
timeline.push(inter_break3);
timeline.push(target_preview);
timeline.push(search_main3);
timeline.push(inter_break4);
timeline.push(target_preview);
timeline.push(search_main4);
timeline.push(inter_break5);
timeline.push(target_preview);
timeline.push(search_main1);
timeline.push(inter_break6);
timeline.push(target_preview);
timeline.push(search_main2);
timeline.push(inter_break7);
timeline.push(target_preview);
timeline.push(search_main3);
timeline.push(inter_break8);
timeline.push(target_preview);
timeline.push(search_main4);
timeline.push(save_data);
timeline.push({
type: jsPsychFullscreen,
fullscreen_mode: false,
data: {disp_type: 'fullscreen-out'}
});
timeline.push(debrief_page);
function startExperiment(){
jsPsych.run(timeline);
}
</script>
</html>