-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiat8.js
1319 lines (1233 loc) · 52 KB
/
quiat8.js
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//YBYB:Created from iat8.js, for Qualtrics
define(['pipAPI','pipScorer','underscore'], function(APIConstructor, Scorer, _) {
/**
Created by: Yoav Bar-Anan ([email protected]). Modified by Elad
* @param {Object} options Options that replace the defaults...
* @return {Object} PIP script
**/
function iatExtension(options)
{
var API = new APIConstructor();
var scorer = new Scorer();
var piCurrent = API.getCurrent();
//Here we set the settings of our task.
//Read the comments to learn what each parameters means.
//You can also do that from the outside, with a dedicated jsp file.
var iatObj =
{
isTouch:true, //Set whether the task is on a touch device.
//Set the canvas of the task
canvas : {
maxWidth: 725,
proportions : 0.7,
background: '#ffffff',
borderWidth: 5,
canvasBackground: '#ffffff',
borderColor: 'lightblue'
},
//When scoring, we will consider the compatible condition the pairing condition that requires response with one key to [category1,attribute1] and the other key to [category2,attribute2]
category1 : {
name : 'Black people', //Will appear in the data and in the default feedback message.
title : {
media : {word : 'Black people'}, //Name of the category presented in the task.
css : {color:'#336600','font-size':'1.8em'}, //Style of the category title.
height : 4 //Used to position the "Or" in the combined block.
},
stimulusMedia : [ //Stimuli content as PIP's media objects
{word: 'Tyron'},
{word: 'Malik'},
{word: 'Terrell'},
{word: 'Jazmin'},
{word: 'Tiara'},
{word: 'Shanice'}
],
//Stimulus css (style)
stimulusCss : {color:'#336600','font-size':'2.3em'}
},
category2 : {
name : 'White people', //Will appear in the data and in the default feedback message.
title : {
media : {word : 'White people'}, //Name of the category presented in the task.
css : {color:'#336600','font-size':'1.8em'}, //Style of the category title.
height : 4 //Used to position the "Or" in the combined block.
},
stimulusMedia : [ //Stimuli content as PIP's media objects
{word: 'Jake'},
{word: 'Connor'},
{word: 'Bradley'},
{word: 'Allison'},
{word: 'Emma'},
{word: 'Emily'}
],
//Stimulus css
stimulusCss : {color:'#336600','font-size':'2.3em'}
},
attribute1 :
{
name : 'Bad words',
title : {
media : {word : 'Bad words'},
css : {color:'#0000FF','font-size':'1.8em'},
height : 4 //Used to position the "Or" in the combined block.
},
stimulusMedia : [ //Stimuli content as PIP's media objects
{word: 'awful'},
{word: 'failure'},
{word: 'agony'},
{word: 'hurt'},
{word: 'horrible'},
{word: 'terrible'},
{word: 'nasty'},
{word: 'evil'}
],
//Stimulus css
stimulusCss : {color:'#0000FF','font-size':'2.3em'}
},
attribute2 :
{
name : 'Good words',
title : {
media : {word : 'Good words'},
css : {color:'#0000FF','font-size':'1.8em'},
height : 4 //Used to position the "Or" in the combined block.
},
stimulusMedia : [ //Stimuli content as PIP's media objects
{word: 'laughter'},
{word: 'happy'},
{word: 'glorious'},
{word: 'joy'},
{word: 'wonderful'},
{word: 'peace'},
{word: 'pleasure'},
{word: 'love'}
],
//Stimulus css
stimulusCss : {color:'#0000FF','font-size':'2.3em'}
},
base_url : {//Where are your images at?
image : '/implicit/user/yba/pipexample/biat/images/'
},
//nBlocks : 7, This is not-supported anymore. If you want a 5-block IAT, change blockSecondCombined_nTrials to 0.
////In each block, we can include a number of mini-blocks, to reduce repetition of same group/response.
////If you set the number of trials in any block to 0, that block will be skipped.
blockAttributes_nTrials : 20,
blockAttributes_nMiniBlocks : 5,
blockCategories_nTrials : 20,
blockCategories_nMiniBlocks : 5,
blockFirstCombined_nTrials : 20,
blockFirstCombined_nMiniBlocks : 5,
blockSecondCombined_nTrials : 40, //Change to 0 if you want 5 blocks (you would probably want to increase blockFirstCombined_nTrials).
blockSecondCombined_nMiniBlocks : 10,
blockSwitch_nTrials : 28,
blockSwitch_nMiniBlocks : 7,
//Should we randomize which attribute is on the right, and which on the left?
randomAttSide : false, // Accepts 'true' and 'false'. If false, then attribute2 on the right.
//Should we randomize which category is on the right first?
randomBlockOrder : true, //Accepts 'true' and 'false'. If false, then category1 on the left first.
//Note: the player sends block3Cond at the end of the task (saved in the explicit table) to inform about the categories in that block.
//In the block3Cond variable: "att1/cat1,att2/cat2" means att1 and cat1 on the left, att2 and cat2 on the right.
//Show a reminder what to do on error, throughout the task
remindError : true,
remindErrorText : '<p align="center" style="font-size:"0.6em"; font-family:arial">' +
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. ' +
'Press the other key to continue.<p/>',
remindErrorTextTouch : '<p align="center" style="font-size:"1.4em"; font-family:arial">' +
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. ' +
'Touch the other side to continue.<p/>',
errorCorrection : true, //Should participants correct error responses?
errorFBDuration : 500, //Duration of error feedback display (relevant only when errorCorrection is false)
ITIDuration : 250, //Duration between trials.
fontColor : '#000000', //The default color used for printed messages.
//Text and style for key instructions displayed about the category labels.
leftKeyText : 'Press "E" for',
rightKeyText : 'Press "I" for',
keysCss : {'font-size':'0.8em', 'font-family':'courier', color:'#000000'},
//Text and style for the separator between the top and bottom category labels.
orText : 'or',
orCss : {'font-size':'1.8em', color:'#000000'},
instWidth : 99, //The width of the instructions stimulus
finalText : 'Press space to continue to the next task',
finalTouchText : 'Touch the bottom green area to continue to the next task',
touchMaxStimulusWidth : '50%',
touchMaxStimulusHeight : '50%',
bottomTouchCss: {}, //Add any CSS value you want for changing the css of the bottom touch area.
//Instructions text.
// You can use the following variables and they will be replaced by
// the name of the categories and the block's number variables:
// leftCategory, rightCategory, leftAttribute and rightAttribute, blockNum, nBlocks.
// Notice that this is HTML text.
instAttributePractice: '<div><p align="center" style="font-size:20px; font-family:arial">' +
'<font color="#000000"><u>Part blockNum of nBlocks </u><br/><br/></p>' +
'<p style="font-size:20px; text-align:left; vertical-align:bottom; margin-left:10px; font-family:arial">' +
'Put a left finger on the <b>E</b> key for items that belong to the category <font color="#0000ff">leftAttribute.</font>' +
'<br/>Put a right finger on the <b>I</b> key for items that belong to the category <font color="#0000ff">rightAttribute</font>.<br/><br/>' +
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. ' +
'Press the other key to continue.<br/>' +
'<u>Go as fast as you can</u> while being accurate.<br/><br/></p>'+
'<p align="center">Press the <b>space bar</b> when you are ready to start.</font></p></div>',
instAttributePracticeTouch: [
'<div>',
'<p align="center">',
'<u>Part blockNum of nBlocks</u>',
'</p>',
'<p align="left" style="margin-left:5px">',
'<br/>',
'Put a left finger over the the <b>left</b> green area for items that belong to the category <font color="#0000ff">leftAttribute</font>.<br/>',
'Put a right finger over the <b>right</b> green area for items that belong to the category <font color="#0000ff">rightAttribute</font>.<br/>',
'Items will appear one at a time.<br/>',
'<br/>',
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. Touch the other side. <u>Go as fast as you can</u> while being accurate.',
'</p>',
'<p align="center">Touch the <b>lower </b> green area to start.</p>',
'</div>'
].join('\n'),
instCategoriesPractice: '<div><p align="center" style="font-size:20px; font-family:arial">' +
'<font color="#000000"><u>Part blockNum of nBlocks </u><br/><br/></p>' +
'<p style="font-size:20px; text-align:left; vertical-align:bottom; margin-left:10px; font-family:arial">' +
'Put a left finger on the <b>E</b> key for items that belong to the category <font color="#336600">leftCategory</font>. ' +
'<br/>Put a right finger on the <b>I</b> key for items that belong to the category <font color="#336600">rightCategory</font>.<br/>' +
'Items will appear one at a time.<br/><br/>' +
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. ' +
'Press the other key to continue.<br/>' +
'<u>Go as fast as you can</u> while being accurate.<br/><br/></p>'+
'<p align="center">Press the <b>space bar</b> when you are ready to start.</font></p></div>',
instCategoriesPracticeTouch: [
'<div>',
'<p align="center">',
'<u>Part blockNum of nBlocks</u>',
'</p>',
'<p align="left" style="margin-left:5px">',
'<br/>',
'Put a left finger over the <b>left</b> green area for items that belong to the category <font color="#336600">leftCategory</font>.<br/>',
'Put a right finger over the <b>right</b> green area for items that belong to the category <font color="#336600">rightCategory</font>.<br/>',
'Items will appear one at a time.<br/>',
'<br/>',
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. Touch the other side. <u>Go as fast as you can</u> while being accurate.',
'</p>',
'<p align="center">Touch the <b>lower </b> green area to start.</p>',
'</div>'
].join('\n'),
instFirstCombined : '<div><p align="center" style="font-size:20px; font-family:arial">' +
'<font color="#000000"><u>Part blockNum of nBlocks </u><br/><br/></p>' +
'<p style="font-size:20px; text-align:left; vertical-align:bottom; margin-left:10px; font-family:arial">' +
'Use the <b>E</b> key for <font color="#336600">leftCategory</font> and for <font color="#0000ff">leftAttribute</font>.<br/>' +
'Use the <b>I</b> key for <font color="#336600">rightCategory</font> and for <font color="#0000ff">rightAttribute</font>.<br/>' +
'Each item belongs to only one category.<br/><br/>' +
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. ' +
'Press the other key to continue.<br/>' +
'<u>Go as fast as you can</u> while being accurate.<br/><br/></p>' +
'<p align="center">Press the <b>space bar</b> when you are ready to start.</font></p></div>',
instFirstCombinedTouch:[
'<div>',
'<p align="center">',
'<u>Part blockNum of nBlocks</u>',
'</p>',
'<br/>',
'<br/>',
'<p align="left" style="margin-left:5px">',
'Put a left finger over the <b>left</b> green area for <font color="#336600">leftCategory</font> items and for <font color="#0000ff">leftAttribute</font>.</br>',
'Put a right finger over the <b>right</b> green area for <font color="#336600">rightCategory</font> items and for <font color="#0000ff">rightAttribute</font>.</br>',
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. Touch the other side. <u>Go as fast as you can</u> while being accurate.</br>',
'</p>',
'<p align="center">Touch the <b>lower </b> green area to start.</p>',
'</div>'
].join('\n'),
instSecondCombined : '<div><p align="center" style="font-size:20px; font-family:arial">' +
'<font color="#000000"><u>Part blockNum of nBlocks </u><br/><br/></p>' +
'<p style="font-size:20px; text-align:left; vertical-align:bottom; margin-left:10px; font-family:arial">' +
'This is the same as the previous part.<br/>' +
'Use the <b>E</b> key for <font color="#336600">leftCategory</font> and for <font color="#0000ff">leftAttribute</font>.<br/>' +
'Use the <b>I</b> key for <font color="#336600">rightCategory</font> and for <font color="#0000ff">rightAttribute</font>.<br/>' +
'Each item belongs to only one category.<br/><br/>' +
'<u>Go as fast as you can</u> while being accurate.<br/><br/></p>' +
'<p align="center">Press the <b>space bar</b> when you are ready to start.</font></p></div>',
instSecondCombinedTouch:[
'<div>',
'<p align="center"><u>Part blockNum of nBlocks</u></p>',
'<br/>',
'<br/>',
'<p align="left" style="margin-left:5px">',
'Put a left finger over the <b>left</b> green area for <font color="#336600">leftCategory</font> items and for <font color="#0000ff">leftAttribute</font>.<br/>',
'Put a right finger over the <b>right</b> green area for <font color="#336600">rightCategory</font> items and for <font color="#0000ff">rightAttribute</font>.<br/>',
'<br/>',
'<u>Go as fast as you can</u> while being accurate.<br/>',
'</p>',
'<p align="center">Touch the <b>lower </b> green area to start.</p>',
'</div>'
].join('\n'),
instSwitchCategories : '<div><p align="center" style="font-size:20px; font-family:arial">' +
'<font color="#000000"><u>Part blockNum of nBlocks </u><br/><br/></p>' +
'<p style="font-size:20px; text-align:left; vertical-align:bottom; margin-left:10px; font-family:arial">' +
'<b>Watch out, the labels have changed position!</b><br/>' +
'Use the left finger on the <b>E</b> key for <font color="#336600">leftCategory</font>.<br/>' +
'Use the right finger on the <b>I</b> key for <font color="#336600">rightCategory</font>.<br/><br/>' +
'<u>Go as fast as you can</u> while being accurate.<br/><br/></p>' +
'<p align="center">Press the <b>space bar</b> when you are ready to start.</font></p></div>',
instSwitchCategoriesTouch: [
'<div>',
'<p align="center">',
'<u>Part blockNum of nBlocks</u>',
'</p>',
'<p align="left" style="margin-left:5px">',
'<br/>',
'Watch out, the labels have changed position!<br/>',
'Put a left finger over the <b>left</b> green area for <font color="#336600">leftCategory</font> items.<br/>',
'Put a right finger over the <b>right</b> green area for <font color="#336600">rightCategory</font> items.<br/>',
'Items will appear one at a time.',
'<br/>',
'If you make a mistake, a red <font color="#ff0000"><b>X</b></font> will appear. Touch the other side. <u>Go as fast as you can</u> while being accurate.<br/>',
'</p>',
'<p align="center">Touch the <b>lower </b> green area to start.</p>',
'</div>'
].join('\n'),
instThirdCombined : 'instFirstCombined', //this means that we're going to use the instFirstCombined property for the third combined block as well. You can change that.
instFourthCombined : 'instSecondCombined', //this means that we're going to use the instSecondCombined property for the fourth combined block as well. You can change that.
instThirdCombinedTouch : 'instFirstCombined', //this means that we're going to use the instFirstCombined property for the third combined block as well. You can change that.
instFourthCombinedTouch : 'instSecondCombined', //this means that we're going to use the instSecondCombined property for the fourth combined block as well. You can change that.
//The default feedback messages for each cutoff -
//attribute1, and attribute2 will be replaced with the name of attribute1 and attribute2.
//categoryA is the name of the category that is found to be associated with attribute1,
//and categoryB is the name of the category that is found to be associated with attribute2.
fb_strong_Att1WithCatA_Att2WithCatB : 'Your responses suggested a strong automatic preference for categoryB over categoryA.',
fb_moderate_Att1WithCatA_Att2WithCatB : 'Your responses suggested a moderate automatic preference for categoryB over categoryA.',
fb_slight_Att1WithCatA_Att2WithCatB : 'Your responses suggested a slight automatic preference for categoryB over categoryA.',
fb_equal_CatAvsCatB : 'Your responses suggested no automatic preference between categoryA and categoryB.',
//Error messages in the feedback
manyErrors: 'There were too many errors made to determine a result.',
tooFast: 'There were too many fast trials to determine a result.',
notEnough: 'There were not enough trials to determine a result.'
};
// extend the "current" object with the default
_.defaults(piCurrent, options, iatObj);
_.extend(API.script.settings, options.settings);
/**
**** For Qualtrics
*/
API.addSettings('onEnd', window.minnoJS.onEnd);
//For debugging the logger
//window.minnoJS.logger = console.log;
//window.minnoJS.onEnd = console.log;
API.addSettings('logger', {
// gather logs in array
onRow: function(logName, log, settings, ctx){
if (!ctx.logs) ctx.logs = [];
ctx.logs.push(log);
},
// onEnd trigger save (by returning a value)
onEnd: function(name, settings, ctx){
return ctx.logs;
},
// Transform logs into a string
// we save as CSV because qualtrics limits to 20K characters and this is more efficient.
serialize: function (name, logs) {
var headers = ['block', 'trial', 'cond', 'comp', 'type', 'cat', 'stim', 'resp', 'err', 'rt', 'd', 'fb', 'bOrd'];
//console.log(logs);
var myLogs = [];
var iLog;
for (iLog = 0; iLog < logs.length; iLog++)
{
if(!hasProperties(logs[iLog], ['trial_id', 'name', 'responseHandle', 'stimuli', 'media', 'latency'])){
//console.log('---MISSING PROPERTIY---');
//console.log(logs[iLog]);
//console.log('---MISSING PROPERTIY---');
}
else if(!hasProperties(logs[iLog].data, ['block', 'condition', 'score', 'cong']))
{
//console.log('---MISSING data PROPERTIY---');
//console.log(logs[iLog].data);
//console.log('---MISSING data PROPERTIY---');
}
else
{
myLogs.push(logs[iLog]);
}
}
var content = myLogs.map(function (log) {
return [
log.data.block, //'block'
log.trial_id, //'trial'
log.data.condition, //'cond'
log.data.cong, //'comp'
log.name, //'type'
log.stimuli[0], //'cat'
log.media[0], //'stim'
log.responseHandle, //'resp'
log.data.score, //'err'
log.latency, //'rt'
'', //'d'
'', //'fb'
'' //'bOrd'
]; });
//console.log('mapped');
//Add a line with the feedback, score and block-order condition
content.push([
9, //'block'
999, //'trial'
'end', //'cond'
'', //'comp'
'', //'type'
'', //'cat'
'', //'stim'
'', //'resp'
'', //'err'
'', //'rt'
piCurrent.d, //'d'
piCurrent.feedback, //'fb'
block3Cond //'bOrd'
]);
//console.log('added');
content.unshift(headers);
return toCsv(content);
function hasProperties(obj, props) {
var iProp;
for (iProp = 0; iProp < props.length; iProp++)
{
if (!obj.hasOwnProperty(props[iProp]))
{
//console.log('missing ' + props[iProp]);
return false;
}
}
return true;
}
function toCsv(matrice) { return matrice.map(buildRow).join('\n'); }
function buildRow(arr) { return arr.map(normalize).join(','); }
// wrap in double quotes and escape inner double quotes
function normalize(val) {
var quotableRgx = /(\n|,|")/;
if (quotableRgx.test(val)) return '"' + val.replace(/"/g, '""') + '"';
return val;
}
},
// Set logs into an input (i.e. put them wherever you want)
send: function(name, serialized){
window.minnoJS.logger(serialized);
}
});
// are we on the touch version
var isTouch = piCurrent.isTouch;
//We use these objects a lot, so let's read them here
var att1 = piCurrent.attribute1;
var att2 = piCurrent.attribute2;
var cat1 = piCurrent.category1;
var cat2 = piCurrent.category2;
if (isTouch)
{
var maxW = piCurrent.touchMaxStimulusWidth;
var maxH = piCurrent.touchMaxStimulusHeight;
att1.stimulusCss.maxWidth = maxW;
att2.stimulusCss.maxWidth = maxW;
cat1.stimulusCss.maxWidth = maxW;
cat2.stimulusCss.maxWidth = maxW;
att1.stimulusCss.maxHeight = maxH;
att2.stimulusCss.maxHeight = maxH;
cat1.stimulusCss.maxHeight = maxH;
cat2.stimulusCss.maxHeight = maxH;
}
//Set the attribute on the left.
var rightAttName = (piCurrent.randomAttSide) ? (Math.random() >= 0.5 ? att1.name : att2.name) : att2.name;
/**
* Create inputs
*/
var leftInput = !isTouch ? {handle:'left',on:'keypressed',key:'e'} : {handle:'left',on:'click', stimHandle:'left'};
var rightInput = !isTouch ? {handle:'right',on:'keypressed',key:'i'} : {handle:'right',on:'click', stimHandle:'right'};
var proceedInput = !isTouch ? {handle:'space',on:'space'} : {handle:'space',on:'bottomTouch', css:piCurrent.bottomTouchCss};
/**
*Set basic settings.
*/
API.addSettings('canvas',piCurrent.canvas);
API.addSettings('base_url',piCurrent.base_url);
API.addSettings('hooks',{
endTask: function(){
//console.log('compute score');
var DScoreObj = scorer.computeD();
piCurrent.feedback = DScoreObj.FBMsg;
piCurrent.d = DScoreObj.DScore; //YBYB: Added on 28March2017
//console.log('score computed, d='+piCurrent.d + " fb=" + piCurrent.feedback);
//YBYB: API.save will not work in qualtrics
//API.save({block3Cond:block3Cond, feedback:DScoreObj.FBMsg, d: DScoreObj.DScore});
//Perhaps we need to add this to support Qualtrics
window.minnoJS.onEnd();
}
});
/**
* Create default sorting trial
*/
API.addTrialSets('sort',{
// by default each trial is correct, this is modified in case of an error
data: {score:0, parcel:'none'}, //We're using only one parcel for computing the score, so we're always going to call it 'first'.
// set the interface for trials
input: [
{handle:'skip1',on:'keypressed', key:27}, //Esc + Enter will skip blocks
leftInput,
rightInput
],
// user interactions
interactions: [
// begin trial : display stimulus immediately
{
conditions: [{type:'begin'}],
actions: [{type:'showStim',handle:'targetStim'}]
},
// error response
{
conditions: [
{type:'inputEqualsTrial', property:'corResp',negate:true}, //Not the correct response.
{type:'inputEquals',value:['right','left']} // responded with one of the two responses
],
actions: [
{type:'setTrialAttr', setter:{score:1}}, // set the score to 1
{type:'showStim',handle:'error'}, // show error stimulus
{type:'trigger',handle:'onError'} // perhaps we need to end the trial (if no errorCorrection)
]
},
// error when there is no correction
{
conditions: [
{type:'currentEquals', property:'errorCorrection', value:false}, //no error correction.
{type:'inputEquals',value:'onError'} //Was error
],
actions: [
{type:'removeInput',handle:'All'}, //Cannot respond anymore
{type:'log'}, // log this trial
{type:'trigger',handle:'ITI', duration:piCurrent.errorFBDuration} // Continue to the ITI, after that error fb has been displayed
]
},
// correct
{
conditions: [{type:'inputEqualsTrial', property:'corResp'}], // check if the input handle is equal to correct response (in the trial's data object)
actions: [
{type:'removeInput',handle:'All'}, //Cannot respond anymore
{type:'hideStim', handle: 'All'}, // hide everything
{type:'log'}, // log this trial
{type:'trigger',handle:'ITI'} // End the trial after ITI
]
},
// Display nothing for ITI until the next trial
{
conditions: [{type:'inputEquals',value:'ITI'}],
actions: [
{type:'removeInput',handle:'All'}, //Cannot respond anymore
{type:'hideStim', handle: 'All'}, // hide everything
{type:'trigger',handle:'end', duration:piCurrent.ITIDuration} // Continue to the ITI, after that error fb has been displayed
]
},
// end after ITI
{
conditions: [{type:'inputEquals',value:'end'}],
actions: [
{type:'endTrial'}
]
},
// skip block: enter and then ESC
{
conditions: [{type:'inputEquals',value:'skip1'}],
actions: [
{type:'setInput',input:{handle:'skip2', on:'enter'}} // allow skipping if next key is enter.
]
},
// skip block: then ESC
{
conditions: [{type:'inputEquals',value:'skip2'}],
actions: [
{type:'goto', destination: 'nextWhere', properties: {blockStart:true}},
{type:'endTrial'}
]
}
]
});
/**
* Create default instructions trials
*/
API.addTrialSets('instructions', [
// generic instructions trial, to be inherited by all other inroduction trials
{
// set block as generic so we can inherit it later
data: {blockStart:true, condition:'instructions', score:0, block:0},
// create user interface (just click to move on...)
input: [
proceedInput
],
interactions: [
// display instructions
{
conditions: [{type:'begin'}],
actions: [
{type:'showStim',handle:'All'}
]
},
// space hit, end trial soon
{
conditions: [{type:'inputEquals',value:'space'}],
actions: [
{type:'hideStim', handle:'All'},
{type:'removeInput', handle:'space'},
{type:'log'},
{type:'trigger', handle:'endTrial', duration:500}
]
},
{
conditions: [{type:'inputEquals',value:'endTrial'}],
actions: [{type:'endTrial'}]
}
]
}
]);
/**
* All basic trials.
*/
//Helper function to create a basic trial for a certain category (or attribute)
//as an in or out trial (right is in and left is out).
function createBasicTrialSet(params)
{//params: side is left or right. stimSet is the name of the stimulus set.
var set = [{
inherit : 'sort',
data : {corResp : params.side},
stimuli :
[
{inherit:{type:'exRandom',set:params.stimSet}},
{inherit:{set:'error'}}
]
}];
return set;
}
var basicTrialSets = {};
//Four trials for the attributes.
basicTrialSets.att1left =
createBasicTrialSet({side:'left', stimSet: 'att1'});
basicTrialSets.att1right =
createBasicTrialSet({side:'right', stimSet: 'att1'});
basicTrialSets.att2left =
createBasicTrialSet({side:'left', stimSet: 'att2'});
basicTrialSets.att2right =
createBasicTrialSet({side:'right', stimSet: 'att2'});
//Four trials for the categories.
basicTrialSets.cat1left =
createBasicTrialSet({side:'left', stimSet: 'cat1'});
basicTrialSets.cat1right =
createBasicTrialSet({side:'right', stimSet: 'cat1'});
basicTrialSets.cat2left =
createBasicTrialSet({side:'left', stimSet: 'cat2'});
basicTrialSets.cat2right =
createBasicTrialSet({side:'right', stimSet: 'cat2'});
API.addTrialSets(basicTrialSets);
/**
* Stimulus Sets
*/
//Basic stimuli
API.addStimulusSets({
// This Default stimulus is inherited by the other stimuli so that we can have a consistent look and change it from one place
Default: [
{css:{color:piCurrent.fontColor,'font-size':'2em'}}
],
instructions: [
{css:{'font-size':'1.4em',color:'black', lineHeight:1.2}, nolog:true,
location: {left:0,top:0}, size:{width:piCurrent.instWidth}}
],
target: [{
data : {handle:'targetStim'}
}],
att1 :
[{
data: {alias:att1.name},
inherit : 'target',
css:att1.stimulusCss,
media : {inherit:{type:'exRandom',set:'att1'}}
}],
att2 :
[{
data: {alias:att2.name},
inherit : 'target',
css:att2.stimulusCss,
media : {inherit:{type:'exRandom',set:'att2'}}
}],
cat1 :
[{
data: {alias:cat1.name},
inherit : 'target',
css:cat1.stimulusCss,
media : {inherit:{type:'exRandom',set:'cat1'}}
}],
cat2 :
[{
data: {alias:cat2.name},
inherit : 'target',
css:cat2.stimulusCss,
media : {inherit:{type:'exRandom',set:'cat2'}}
}],
// this stimulus used for giving feedback, in this case only the error notification
error : [{
handle:'error', location: {top: 75}, css:{color:'red','font-size':'4em'}, media: {word:'X'}, nolog:true
}],
touchInputStimuli: [
{media:{html:'<div></div>'}, size:{height:48,width:30},css:{background:'#00FF00', opacity:0.3, zindex:-1}, location:{right:0}, data:{handle:'right'}},
{media:{html:'<div></div>'}, size:{height:48,width:30},css:{background:'#00FF00', opacity:0.3, zindex:-1}, location:{left:0}, data:{handle:'left'}}
]
});
/**
* Media Sets
*/
API.addMediaSets({
att1 : att1.stimulusMedia, att2 : att2.stimulusMedia,
cat1 : cat1.stimulusMedia, cat2 : cat2.stimulusMedia
});
/**
* Create the Task sequence
*/
//helper Function for getting the instructions HTML.
function getInstFromTemplate(params)
{//params: instTemplate, blockNum, nBlocks, leftCat, rightCat, leftAtt, rightAtt.
var retText = params.instTemplate
.replace(/leftCategory/g, params.leftCategory)
.replace(/rightCategory/g, params.rightCategory)
.replace(/leftAttribute/g, params.leftAttribute)
.replace(/rightAttribute/g, params.rightAttribute)
.replace(/blockNum/g, params.blockNum)
.replace(/nBlocks/g, params.nBlocks);
return retText;
}
//Helper function to create the trial's layout
function getLayout(params)
{
function buildContent(layout){
if (!layout){return '';}
var isImage = !!layout.image;
var content = layout.word || layout.html || layout.image || layout;
if (_.isString(layout) || layout.word) {content = _.escape(content);}
return isImage ? '<img src="' + piCurrent.base_url.image + content + '" />' : content;
}
function buildStyle(css){
css || (css = {});
var style = '';
for (var i in css) {style += i + ':' + css[i] + ';';}
return style;
}
var template = '' +
' <div style="margin:0 1em; text-align:center"> ' +
' <div style="font-size:0.8em; <%= stimulusData.keysCss %>; visibility:<%= stimulusData.isTouch ? \'hidden\' : \'visible\' %>"> ' +
' <%= stimulusData.isLeft ? stimulusData.leftKeyText : stimulusData.rightKeyText %> ' +
' </div> ' +
' ' +
' <div style="font-size:1.3em;<%= stimulusData.firstCss %>"> ' +
' <%= stimulusData.first %> ' +
' </div> ' +
' ' +
' <% if (stimulusData.second) { %> ' +
' <div style="font-size:2.3em; <%= stimulusData.orCss %>"><%= stimulusData.orText %> </div> ' +
' <div style="font-size:1.3em; max-width:100%; <%= stimulusData.secondCss %>"> ' +
' <%= stimulusData.second %> ' +
' </div> ' +
' <% } %> ' +
' </div> ';
//Attributes are above the categories.
var layout = [
{
location:{left:0, top:0},
media:{html:template},
data: {
first: buildContent(_.get(params, 'left1.title.media')),
firstCss: buildStyle(_.get(params, 'left1.title.css')),
second: buildContent(_.get(params, 'left2.title.media')),
secondCss: buildStyle(_.get(params, 'left2.title.css')),
leftKeyText : buildContent(_.get(piCurrent, 'leftKeyText')),
rightKeyText : buildContent(_.get(piCurrent, 'rightKeyText')),
keysCss : buildStyle(_.get(piCurrent, 'keysCss')),
orText : buildContent(_.get(piCurrent, 'orText')),
orCss : buildStyle(_.get(piCurrent, 'orCss')),
isTouch: isTouch,
isLeft: true
}
},
{
location:{right:0, top:0},
media:{html:template},
data: {
first: buildContent(_.get(params, 'right1.title.media')),
firstCss: buildStyle(_.get(params, 'right1.title.css')),
second: buildContent(_.get(params, 'right2.title.media')),
secondCss: buildStyle(_.get(params, 'right2.title.css')),
leftKeyText : buildContent(_.get(piCurrent, 'leftKeyText')),
rightKeyText : buildContent(_.get(piCurrent, 'rightKeyText')),
keysCss : buildStyle(_.get(piCurrent, 'keysCss')),
orText : buildContent(_.get(piCurrent, 'orText')),
orCss : buildStyle(_.get(piCurrent, 'orCss')),
isTouch: isTouch,
isLeft: false
}
}
];
if (!params.isInst && params.remindError)
{
layout.push({
location:{bottom:1}, css: {color:piCurrent.fontColor,'font-size':'1em'},
media : {html: isTouch ? params.remindErrorTextTouch : params.remindErrorText}
});
}
if (!params.isInst && isTouch){
layout.push({inherit:{type:'byData', set:'touchInputStimuli', data:{handle:'right'}}});
layout.push({inherit:{type:'byData', set:'touchInputStimuli', data:{handle:'left'}}});
}
return layout;
}
//helper function for creating an instructions trial
function getInstTrial(params)
{
var instParams = {isInst : true};
//The names of the category and attribute labels.
if (params.nCats == 2)
{//When there are only two categories in the block, one two of these will appear in the instructions.
instParams.leftAttribute = params.left1.name;
instParams.rightAttribute = params.right1.name;
instParams.leftCategory = params.left1.name;
instParams.rightCategory = params.right1.name;
}
else
{
instParams.leftAttribute = params.left1.name;
instParams.rightAttribute = params.right1.name;
instParams.leftCategory = params.left2.name;
instParams.rightCategory = params.right2.name;
}
_.extend(instParams, params);
var instLocation={bottom:1};
if (isTouch == true)
{
instLocation={left:0,top:(params.nCats == 2) ? 7 : 10};
}
var instTrial = {
inherit : 'instructions',
data: {blockStart:true},
layout : getLayout(instParams),
stimuli : [
{
inherit : 'instructions',
media : {html : getInstFromTemplate(instParams)},
location : instLocation,
nolog:true
},
{
data : {handle:'dummy', alias:'dummy'},
media : {word:' '},
location : {top:1}
}
]
};
return instTrial;
}
//Get a mixer for a mini-block in a 2-categories block.
function getMiniMixer2(params)
{//{nTrialsInMini : , currentCond : , rightTrial : , leftTrial : , blockNum : , blockLayout : )
var mixer = {
mixer : 'repeat',
times : params.nTrialsInMini/2,
data :
[
{
inherit : params.rightTrial,
data : {condition : params.currentCond, block : params.blockNum},
layout : params.blockLayout
},
{
inherit : params.leftTrial,
data : {condition : params.currentCond, block : params.blockNum},
layout : params.blockLayout
}
]
};
return ({
mixer : 'random',
data : [mixer] //Completely randomize the repeating trials.
});
}
//Get a mixer for a mini-block in a 4-categories block.
function getMiniMixer4(params)
{//{nTrialsInMini : , currentCond : , cong: , rightTrial1 : , leftTrial1 : , rightTrial2 : , leftTrial2 : , blockNum : , blockLayout : , parcel :)
////Because of the alternation, we randomize the trial order ourselves.
var atts = [];
var cats = [];
var iTrial;
//Fill
for (iTrial = 1; iTrial <= params.nTrialsInMini; iTrial+=4)
{
atts.push(1);
atts.push(2);
cats.push(1);
cats.push(2);
}
//Randomize order
atts = _.shuffle(atts);
cats = _.shuffle(cats);
var mixerData = [];
var iCat = 0;
var iAtt = 0;
for (iTrial = 1; iTrial <= params.nTrialsInMini; iTrial+=2)
{
mixerData.push(
{
inherit : (cats[iCat] == 1) ? params.leftTrial2 : params.rightTrial2,
data : {condition : params.currentCond, block : params.blockNum, parcel:params.parcel, cong:params.cong},
layout : params.blockLayout
});
iCat++;
mixerData.push(
{
inherit : (atts[iAtt] == 1) ? params.leftTrial1 : params.rightTrial1,
data : {condition : params.currentCond, block : params.blockNum, parcel:params.parcel, cong:params.cong},
layout : params.blockLayout
});
iAtt++;
}
return ({
mixer : 'wrapper',
data : mixerData
});
}
////////////////////////////////////////////////////////////////
////AFTER ALL the helper functions, it is time to create the trial sequence.
var trialSequence = [];
var globalObj = piCurrent;
//Count the number of blocks in this task
var nBlocks = (globalObj.blockAttributes_nTrials<1 ? 0 : 1) +
(globalObj.blockCategories_nTrials<1 ? 0 : 1) +
(globalObj.blockFirstCombined_nTrials<1 ? 0 : 2) +
(globalObj.blockSecondCombined_nTrials<1 ? 0 : 2) +
(globalObj.blockSwitch_nTrials<1 ? 0 : 1);
//These parameters are used to create trials.
var blockParamsAtts = {
nBlocks : nBlocks,
remindError : globalObj.remindError,
remindErrorText : globalObj.remindErrorText,
remindErrorTextTouch : globalObj.remindErrorTextTouch
};
//////////////////////////////
////Block 1: Categories block
var iBlock = 1;
var blockParamsCats = {
nBlocks : nBlocks,
remindError : globalObj.remindError,
remindErrorText : globalObj.remindErrorText,
remindErrorTextTouch : globalObj.remindErrorTextTouch
};
//Set sides
var rightCatName = (globalObj.randomBlockOrder ? (Math.random() >= 0.5 ? cat1.name : cat2.name) : cat2.name);
var leftCatTrial = 'cat1left';
blockParamsCats.left1 = cat1;
var rightCatTrial = 'cat2right';
blockParamsCats.right1 = cat2;
if (rightCatName == cat1.name)
{
blockParamsCats.right1 = cat1;
rightCatTrial = 'cat1right';
blockParamsCats.left1 = cat2;
leftCatTrial = 'cat2left';
}
var blockCondition = blockParamsCats.left1.name + ',' + blockParamsCats.right1.name;
blockParamsCats.nMiniBlocks = globalObj.blockCategories_nMiniBlocks;