-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_determine_condition.html
487 lines (400 loc) · 20.5 KB
/
4_determine_condition.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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>4 Determine Conditions</title>
<script src = "./extra_functions/jquery-3.4.1.js" type="text/javascript"></script>
<script src="./extra_functions/helper_functions.js"> </script>
<script src='./extra_functions/lodash.js'></script>
<script src="jatos.js"></script>
</head>
<body></body>
<script>
jatos.onLoad(function() {
// How many phases to have? 2 or 3?
jatos.studySessionData.max_phases = 2;
// Counter for advancing through sessions
jatos.studySessionData.session_counter = {
phase_1: 1,
phase_2: 1,
phase_3: 1,
}
jatos.studySessionData.phase_counter = 1;
jatos.studySessionData.global_trial_counter = 1; // a global variable to keep track of overall how many trials have run. Use when recording trial info in the outputData.phase_results array.
jatos.studySessionData.session_trial_counter = 1;
jatos.studySessionData.progress_state = 'starting' // a string that will say whether to advance a session, phase, fail the participant, or whatnot.
// Which scripts have which component IDs?
jatos.studySessionData.script_comp_pos = {
instructions: 5,
practice_trials: 6,
post_practice_instructions: 7,
phase_pa: 8,
intermediate_feedback: 9,
qc_checks: 10,
data_submission: 11,
transition: 12,
}
// Bunch of flags:
// - debugging or not. If debugging, fewer trials will be done.
// - The pilot flag is for when asking labmates to test the paradigm, it just reduces the number of trials they'll have to do per sesiosn.
// - Auto respond: script will make random responses by itself.
jatos.studySessionData.debug = false;
jatos.studySessionData.debug_n_trials = 10;
jatos.studySessionData.auto_respond = false;
jatos.studySessionData.auto_respons_probability = 9.5; // how often to select the right answer? Ex: 9 is 90%
jatos.studySessionData.show_correct = false;
jatos.studySessionData.use_batch_data = true;
jatos.studySessionData.pilot = false;
jatos.studySessionData.pilot_n_trials = 10;
jatos.studySessionData.simulate_data = false; // Simulate data to intentionally fail the QC?
jatos.studySessionData.simulate_condition = 'rt' // what QC condition should we intentionally fail
jatos.studySessionData.perf_check_over_n_trials = 14; // Over how many previous trials is the performance calculated?
jatos.studySessionData.random_target_loc = false;
// Duration of trials, breaks, ITI, etc
if (jatos.studySessionData.debug || jatos.studySessionData.pilot) {
jatos.studySessionData.short_break_duration = 2; // seconds
jatos.studySessionData.long_break_duration = 2; // seconds
jatos.studySessionData.timer_after_response = 100; // milliseconds
jatos.studySessionData.timer_allow_space_key = 500; // milliseconds. After a response is made, or missed, how long to wait until allowing a space key?
jatos.studySessionData.timer_response_window = 10000; // milliseconds
jatos.studySessionData.post_trial_gap = 10; // milliseconds
jatos.studySessionData.n_practice_trials = 2;
// Minimum % correct on each item
jatos.studySessionData.training_criterion = 85; // percentage accuracy required for each toy
} else {
jatos.studySessionData.short_break_duration = 15; // seconds
jatos.studySessionData.long_break_duration = 30; // seconds
jatos.studySessionData.timer_after_response = 4000; // milliseconds
jatos.studySessionData.timer_allow_space_key = 500;
jatos.studySessionData.timer_response_window = 10000; // milliseconds
jatos.studySessionData.post_trial_gap = 500; // milliseconds
jatos.studySessionData.n_practice_trials = 6;
jatos.studySessionData.training_criterion = 85; // percentage accuracy required for each toy
};
// Add all the QC checking conditions
if (jatos.studySessionData.pilot || jatos.studySessionData.debug){
jatos.studySessionData.qc_criteria = {
rt_min_speed: 10,
rt_min_perc: 100,
uniform_resp_perc: 95,
min_perf_check_perc: 50,
min_perf_check_ses: 3,
perc_max_missed: 100,
max_training_sess: 4,
min_training_sess: 2, // force people to do at least this many sessions for each phase.
min_time_instruct: 1,
}
} else {
jatos.studySessionData.qc_criteria = {
rt_min_speed: 500, // If more than "rt_min_perc" trials have RT < "rt_min_speed", then disqualify.
rt_min_perc: 80, // If more than this percentage of trials have an RT less than "rt_min_speed", disqualify.
uniform_resp_perc: 95, // Percentage of trials that are allowed to have the same response
min_perf_check_perc: 50, // Minimum accuracy to reach by a certain session, else gets discontinued
min_perf_check_ses: 3, // After this many sessions, will check for minimum accuracy. Else discontinued.
perc_max_missed: 15, // max percentage of trials allowed to be missed.
max_training_sess: 4, // if after these many sessions, performance is not good, discontinue.
min_training_sess: 2, // force people to do at least this many sessions for each phase.
min_time_instruct: 500, // minimum time spent on each instruction page.
}
}
// Create an object with pass-fail info for each criteria
jatos.studySessionData.qc_status = {
global_pass: true,
rt_pass: true,
uniform_resp_perc_pass: true,
min_perf_pass: true,
practice_pass: true,
perc_max_misses_pass: true,
max_training_sess_pass: true,
min_time_instruct_pass: true,
}
// If we're auto-responding, edit the rt_check criteria, and the ITI, and break durations
if (jatos.studySessionData.auto_respond){
jatos.studySessionData.qc_criteria.rt_min_speed = 10;
jatos.studySessionData.qc_criteria.rt_min_perc = 5;
jatos.studySessionData.qc_criteria.min_time_instruct = 5;
jatos.studySessionData.short_break_duration = 2; // seconds
jatos.studySessionData.long_break_duration = 2; // seconds
jatos.studySessionData.timer_after_response = 10; // milliseconds
jatos.studySessionData.timer_allow_space_key = 5;
jatos.studySessionData.timer_response_window = 7000; // milliseconds
jatos.studySessionData.post_trial_gap = 10; // milliseconds
}
// ////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////
// Now, allocate coordinates for all empty location
const targetCoordsNames = {
pointNamesEmpty: ['E1','E2','E3','E4','E5','E6','E7','E8','E9','E10','E11','E12','E13','E14','E15','E16'],
pointNamesTarget: ['T1','T2','T3','T4','T5','T6'],
imgNamesEmpty: Array(16).fill('Empty'),
imgNamesTarget: {
phase_1: ['Tree','Santa','Bell','Sledge','Gingerman','Bear'],
phase_2: ['Tree','Santa','Bell','Sledge','Gingerman','Bear'],
phase_3: ['Tree','Santa','Bell','Sledge','Gingerman','Bear'],
},
pointXCoord: [],
pointYCoord: [],
}
for (iX = 0; iX < 4; iX++){
for (iY = 0; iY < 4; iY++){
targetCoordsNames.pointXCoord.push(iX * 50 + 100);
targetCoordsNames.pointYCoord.push(iY * 50 + 100);
}
}
// How many targets
let nTargets = 3
// Randomly choose the target indices. i.e. which pictures to use as targets?
// let chosenTarget_idxs = _.sampleSize(targetCoordsNames.pointNamesTarget.length, basic_parameters.nTargets)
let chosenTarget_idxs = {
phase_1: [3,4,5],
phase_2: [3,4,5],
phase_3: [3,4,5],
}
// Get BATCH DATA or not? ////////////////////////////////
if (jatos.studySessionData.use_batch_data){
// Get batchData
let batchData = jatos.batchSession.getAll();
// Get the number of participants needed for each condition
let n_ptp_needed = batchData.map(item => item.n_ptp_needed)
// Find the one with the most number of ptp
let maxCond = n_ptp_needed.indexOf(Math.max(...n_ptp_needed));
// Increment its runnning participant count
batchData[maxCond].n_ptp_pass_or_ongoing ++;
batchData[maxCond].n_ptp_needed --;
// Update the batch data
jatos.batchSession.setAll(batchData);
// Set congruency
var congruency = batchData[maxCond].congruency
var phase_1_concept = batchData[maxCond].phase_1_concept
var phase_2_concept = batchData[maxCond].phase_2_concept
// Set arrangements
var phase_1_arrangement = batchData[maxCond].phase_1_arrangement
var phase_2_arrangement = batchData[maxCond].phase_2_arrangement
} else {
// So not reading the batch. Set manually
var congruency = false
var phase_2_concept = 'neck_legs_space'
var phase_1_concept = 'beak_tail_space'
var phase_1_arrangement = [1,8,15]
var phase_2_arrangement = [14,9,4]
} // get batch data or not
// Define arrangements to use
let all_available_arrangements = {
arr1: [1,8,15], // These are base 1, so corresponding to the 16 points in the 4x4 space
arr2: [14,9,4],
}
let arrangementsUsed = {
phase_1: phase_1_arrangement,
phase_2: phase_2_arrangement,
phase_3: phase_1_arrangement,
}
// The two variables below are needed for randomly generating target locations in the concept space
let totalPointsInSpace = targetCoordsNames.pointNamesEmpty.length
let allPointsInSpace = [...Array(totalPointsInSpace).keys()].map(item => item + 1) // creates an array from 1 to max number
if (jatos.studySessionData.random_target_loc){
// Randomly sample
arrangementsUsed.phase_1 =_.sampleSize(allPointsInSpace, nTargets)
}
arrangementsUsed.phase_3 = arrangementsUsed.phase_1 // phase 3 is exactly the same, whether its congruency or not
if (congruency){
arrangementsUsed.phase_2 = arrangementsUsed.phase_1
} else {
if (jatos.studySessionData.random_target_loc){
// Choose it randomly
arrangementsUsed.phase_2 = _.sampleSize(allPointsInSpace, nTargets)
}
};
const basic_parameters = {
// Display
sort_area_width: 750,
sort_area_height: 700,
prompt_target_width: 70,
prompt_target_height: 70,
get prompt_img_x_coords() {
return this.sort_area_width/2 - this.prompt_target_width/2;
},
prompt_img_y_coords: 80,
pa_box_height: 350, // height for the area that displays an example PA, during debriefing pages, when asking if the ptp realized congruent mappings.
pa_box_width: 350,
// Feedback items
fb_correct_img: './img/feedback/correct.png',
fb_incorrect_img: './img/feedback/incorrect.png',
audio_stimulus: './img/feedback/success.wav',
// Peformance box
score_box_target_width: 30,
score_box_target_height: 30,
score_box_score_font_size: 13, // Size of the score text, "100%"
score_box_description_font_size: 15, // "Your scores"
///////////////////////////////////////// Targets ////////////////////////////////////
nTargets: nTargets,
targetPoints: {
phase_1: arrangementsUsed.phase_1,
phase_2: arrangementsUsed.phase_2,
phase_3: arrangementsUsed.phase_3,
},
// Point names, i.e. T1 T2 T6 etc
targetPointNames: {
phase_1: index_into_array(targetCoordsNames.pointNamesTarget,chosenTarget_idxs.phase_1),
phase_2: index_into_array(targetCoordsNames.pointNamesTarget,chosenTarget_idxs.phase_2),
phase_3: index_into_array(targetCoordsNames.pointNamesTarget,chosenTarget_idxs.phase_3),
},
// Which target images are used for each phase?
targetNamesUsed: {
phase_1: index_into_array(targetCoordsNames.imgNamesTarget.phase_1,chosenTarget_idxs.phase_1),
phase_2: index_into_array(targetCoordsNames.imgNamesTarget.phase_2,chosenTarget_idxs.phase_2),
phase_3: index_into_array(targetCoordsNames.imgNamesTarget.phase_2,chosenTarget_idxs.phase_3),
},
// Paths to the target images
targetPathsUsed: {
phase_1: [],
phase_2: [],
phase_3: [],
},
// For all 16 points, what are the corresponding point names? For now, all E points
pointNamesUsed: {
phase_1: ['E1','E2','E3','E4','E5','E6','E7','E8','E9','E10','E11','E12','E13','E14','E15','E16'],
phase_2: ['E1','E2','E3','E4','E5','E6','E7','E8','E9','E10','E11','E12','E13','E14','E15','E16'],
phase_3: ['E1','E2','E3','E4','E5','E6','E7','E8','E9','E10','E11','E12','E13','E14','E15','E16'],
},
// For all 16 points, what are the names for corresponding image? For now, all "Empty" items
imgNamesUsed: {
phase_1: Array(16).fill('Empty'),
phase_2: Array(16).fill('Empty'),
phase_3: Array(16).fill('Empty'),
},
}
// For each phase, specify which points are used as targets, paths to those targets, and the names of all 16 points.
for (iPhase=0; iPhase<Object.keys(basic_parameters.targetPathsUsed).length; iPhase++){
let phase_string = 'phase_'+(iPhase+1)
for (iT=0; iT<basic_parameters.nTargets; iT++){
// Which of the 16 locations are we changeing?
let iLocation = basic_parameters.targetPoints[phase_string][iT]-1
// Whats the name of the target point? (T1, T5, etc)
let iPointName = targetCoordsNames.pointNamesTarget[chosenTarget_idxs[phase_string][iT]]
// Whats the name of the target? (Bell, Tree, etc)a
let iImageName = targetCoordsNames.imgNamesTarget[phase_string][chosenTarget_idxs[phase_string][iT]]
// Change the E1 E2 E3 etc. Intersperce it with Target point names
basic_parameters.pointNamesUsed[phase_string][iLocation] = iPointName
basic_parameters.imgNamesUsed[phase_string][iLocation] = iImageName
// For the score box, create names of the target itesm
basic_parameters.targetPathsUsed[phase_string][iT] = './img/targets/' + iImageName + '.jpg'
}
}
// Create an array of objects to hold which point goes as 1st and 2nd stimuli on the screen
let baseTrialArray = {
phase_1: genBaseTrialArray(cleanEmptyCombos(getCombos(basic_parameters.pointNamesUsed['phase_1']))),
phase_2: genBaseTrialArray(cleanEmptyCombos(getCombos(basic_parameters.pointNamesUsed['phase_2']))),
phase_3: genBaseTrialArray(cleanEmptyCombos(getCombos(basic_parameters.pointNamesUsed['phase_3']))),
}
// If debug, then shorten these arrays
if (jatos.studySessionData.debug){
baseTrialArray.phase_1 = deepCopy(shuffle(baseTrialArray.phase_1).slice(0,jatos.studySessionData.debug_n_trials))
baseTrialArray.phase_2 = deepCopy(shuffle(baseTrialArray.phase_2).slice(0,jatos.studySessionData.debug_n_trials))
baseTrialArray.phase_3 = deepCopy(shuffle(baseTrialArray.phase_3).slice(0,jatos.studySessionData.debug_n_trials))
}
// Define the neck_legs_space
let neck_legs_space = new ConceptCreator('neck_legs_space','bird',
'neck','legs',
200, // if displaying individual ones, whats the width
undefined,350,60,
[170,525],[350,400], // onscreen idx coords
[90,560],[350,400], // fb_imgs coords
'row')
// Define the beak_tail_space
let beak_tail_space = new ConceptCreator('beak_tail_space','bird',
'beak','tail',
600, // if displaying individual ones, whats the width
undefined,650,100, // height, width, margin on top
[250,310],[240,460], // onscreen idx coords6
[350,410],[210,424], // fb_imgs coords
'column')
let all_available_concepts = {
neck_legs_space: neck_legs_space,
beak_tail_space: beak_tail_space,
}
let conceptsUsed = {
phase_1: all_available_concepts[phase_1_concept],
phase_2: all_available_concepts[phase_2_concept],
phase_3: all_available_concepts[phase_1_concept],
}
// Create an array that will hold paths to images to prelod. Will be filled in prior to each session
let imgs_to_preload = {
base_images: [],
exemplar_images: [],
}
imgs_to_preload.base_images = [basic_parameters.fb_correct_img, basic_parameters.fb_incorrect_img]
// Record all these variables in JATOS
jatos.studySessionData.inputData = {
targetCoordsNames: targetCoordsNames,
basic_parameters: basic_parameters,
baseTrialArray: baseTrialArray,
concepts: conceptsUsed,
imgs_to_preload: imgs_to_preload,
choices: ['1','2'],
nTrials: baseTrialArray.phase_1.length,
congruency: congruency
}
// ////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////
// Create save the sessions in jatos studySessionData.
// Make JATOS remember that this session was run
jatos.studySessionData.latestFinishedComponentId = jatos.componentId;
jatos.studySessionData.latestFinishedComponentPos = jatos.componentPos;
jatos.studySessionData.latestFinishedComponentTitle = jatos.componentProperties.title;
jatos.submitResultData("[conditions_start---" +
JSON.stringify(jatos.studySessionData) + "---conditions_end]", jatos.startNextComponent);
});
////////////////////////////////////////////////////////////////////////////////////////////
// All the subfunctions
////////////////////////////////////////////////////////////////////////////////////////////
// Create a constructor function for creating an object with info for each space
let ConceptCreator = function(concept_space,concept_object,dim1_name,dim2_name,
single_ex_img_width, ex_pairs_img_height,ex_pairs_img_width,
ex_pairs_img_margin_top,
onscreen_idx_x_coords,onscreen_idx_y_coords,
fb_imgs_x_coords,fb_imgs_y_coords,debrief_flex_dir){
this.concept_space = concept_space,
this.concept_object = concept_object,
this.dim1_name = dim1_name,
this.dim2_name = dim2_name,
this.single_ex_img_width = single_ex_img_width,
this.ex_pairs_img_height = ex_pairs_img_height,
this.ex_pairs_img_width = ex_pairs_img_width,
this.ex_pairs_img_margin_top = ex_pairs_img_margin_top,
this.onscreen_idx_x_coords = onscreen_idx_x_coords,
this.onscreen_idx_y_coords = onscreen_idx_y_coords,
this.fb_imgs_x_coords = fb_imgs_x_coords,
this.fb_imgs_y_coords = fb_imgs_y_coords,
this.debrief_flex_dir = debrief_flex_dir
}
let getCombos = function(array){
// A function to get an array with combinations of 2 items.
// Basically, n choose k amount of elements.
var result = array.flatMap(
(v, i) => array.slice(i+1).map( w => [v,w] )
);
return result
};
let cleanEmptyCombos = function(array){
// Function to delete the array items that contain both empty points
let cleanedArray = []
for (i=0; i<array.length; i++){
if (array[i][0].includes('T') || array[i][1].includes('T')){
cleanedArray.push(array[i])
}
}
return cleanedArray
};
let genBaseTrialArray = function(combos){
// Function to create the baseTrialArray object, containing item1 and item2 keys
// specifying which of the points are 1st and 2nd items on the screen
let baseTrialArray = []
for (i=0; i<combos.length; i++){
baseTrialArray[i] = {
item1: combos[i][0],
item2: combos[i][1],
}
}
return baseTrialArray;
};
</script>