-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp2.js
1434 lines (1279 loc) · 64.3 KB
/
exp2.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
const jsPsych = initJsPsych({
/* auto_update_progress_bar: true,
extensions: {
type: naodao,
}*/
on_finish: function() {
jsPsych.data.get().localSave('csv', 'exp2' + info["ID"] + '.csv');
document.exitFullscreen(); // 退出全屏
let bodyNode = document.getElementsByTagName("body"); // 获取Body窗体
}
});
var timeline = [] //设置一个时间线
const images = ['img/C_ambi40.png',
'img/S_ambi40.png',
'img/T_ambi40.png']
const preload = {
type: jsPsychPreload,
images: images,
}
timeline.push(preload);//preload图片
var welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `
<p>您好,欢迎参加本次实验。</p>
<p>为充分保障您的权利,请确保您已经知晓并同意《参与实验同意书》以及《数据公开知情同意书》。</p>
<p>如果您未见过上述内容,请咨询实验员。</p>
<p>如果您选择继续实验,则表示您已经清楚两份知情同意书的内容并同意。</p>
<p> <div style = "color: green"><按任意键至下页></div> </p>
`,
choices: "ALL_KEYS",
};
timeline.push(welcome);
var basic_information = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `
<p>本实验首先需要您填写一些基本个人信息。</p>
<p> <div style = "color: green"><按任意键至下页></div></p>
`,
choices: "ALL_KEYS",
};
timeline.push(basic_information);
var info = []
/* basic data collection jsPsychInstructions trial 被试基本信息收集 */
var information = {
timeline: [{
// 实验被试信息收集
type: jsPsychCallFunction, //探测被试显示器数据
func: function () {
if ($(window).outerHeight() < 500) {
alert("您设备不支持实验,请进入全屏模式。若已进入全屏,请换一台高分辨率的设备,谢谢。");
window.location = "";
}
}
}, {
type: jsPsychSurveyHtmlForm,
preamble: "<p style =' color : white'>您的实验编号是</p>",
html: function () {
let data = localStorage.getItem(info["subj_idx"]) ? JSON.parse(localStorage.getItem(info["subj_idx"]))["Name"] : "";
return "<p><input name='Q0' type='text' value='" + data + "' required/></p>";
},
button_label: "继续",
on_finish: function (data) {
info["ID"] = data.response.Q0;
word = permutation(texts, 3) //对应的文字
texts = word[parseInt(info["ID"]) % 6] //被试id除以6,求余数
key = permutation(key, 2)[parseInt(info["ID"]) % 2] //对应的按键
view_texts_images = [] //指导语中呈现的图片和文字对应关系
jsPsych.randomization.shuffle(images).forEach((v, i) => { //将image随机
view_texts_images.push(`<img src="${v}" width=150 style="vertical-align:middle">---${texts[images.indexOf(v)]}`); //image编号和文字对应
})
console.log(`match : ${key[0]}; \nmismatch : ${key[1]};`)
console.log(images);
console.log(texts);
}
}
, {
type: jsPsychHtmlButtonResponse,
stimulus: "<p style = 'color : white'>您的性别</p>",
choices: ['男', '女', '其他'],
on_finish: function (data) {
info["Sex"] = data.response == 0 ? "Male" : (data.response == 1 ? "Female" : "Other")
}
}, {
type: jsPsychSurveyHtmlForm,
preamble: "<p style = 'color : white'>您的出生年</p>",
html: function () {
let data = localStorage.getItem(info["subj_idx"]) ? JSON.parse(localStorage.getItem(info["subj_idx"]))["BirthYear"] : "";
return `<p>
<input name="Q0" type="number" value=${data} placeholder="1900~2023" min=1900 max=2023 oninput="if(value.length>4) value=value.slice(0,4)" required />
</p>`
},
button_label: '继续',
on_finish: function (data) {
info["BirthYear"] = data.response.Q0;
}
}, {
type: jsPsychSurveyHtmlForm,
preamble: "<p style = 'color : white'>您的教育经历是</p>",
html: function () {
return `
<p><select name="Q0" size=10>
<option value=1>小学以下</option>
<option value=2>小学</option>
<option value=3>初中</option>
<option value=4>高中</option>
<option value=5>大学</option>
<option value=6>硕士</option>
<option value=7>博士</option>
<option value=8>其他</option>
</select></p>`
},
on_load: function () {
$("option[value=" + (["below primary school", "primary school", "junior middle school", "high school", "university", "master", "doctor", "other"].indexOf(localStorage.getItem(info["subj_idx"]) ? JSON.parse(localStorage.getItem(info["subj_idx"]))["Education"] : "") + 1) + "]").attr("selected", true);
},
button_label: '继续',
on_finish: function (data) {
let edu = ["below primary school", "primary school", "junior middle school", "high school", "university", "master", "doctor", "other"];
info["Education"] = edu[parseInt(data.response.Q0) - 1];
}
}
] };
timeline.push(information);
var chinrest = {
type: jsPsychVirtualChinrest,
blindspot_reps: 3,
resize_units: "deg",
pixels_per_unit: 50,
item_path:'img/card.png',
adjustment_prompt: function(){
let html = `<p style = "font-size: 28px">首先,我们将快速测量您的显示器上像素到厘米的转换比率。</p>`;
html += `<p style = "font-size: 28px">请您将拿出一张真实的银行卡放在屏幕上方,单击并拖动图像的右下角,直到它与屏幕上的信用卡大小相同。</p>`;
html += `<p style = "font-size: 28px">您可以使用与银行卡大小相同的任何卡,如会员卡或驾照,如果您无法使用真实的卡,可以使用直尺测量图像宽度至85.6毫米。</p>`;
html += `<p style = "font-size: 28px"> 如果对以上操作感到困惑,请参考这个视频: <a href='https://www.naodao.com/public/stim_calibrate.mp4' target='_blank' style='font-size:24px'>参考视频</a></p>`;
return html
},
blindspot_prompt: function(){
return `<p style="text-align:left">现在,我们将快速测量您和屏幕之间的距离:<br>
请把您的左手放在 空格键上<br>
请用右手遮住右眼<br>
请用您的左眼专注于黑色方块。将注意力集中在黑色方块上。<br>
如果您已经准备好了就按下 空格键 ,这时红色的球将从右向左移动,并将消失。当球一消失,就请再按空格键<br>
如果对以上操作感到困惑,请参考这个视频:<a href='https://www.naodao.com/public/stim_calibrate.mp4' target='_blank' style='font-size:24px'>参考视频</a><br>
<a style="text-align:center">准备开始时,请按空格键。</a></p>`
},
blindspot_measurements_prompt: `剩余测量次数:`,
on_finish: function(data){
console.log(data)
},
redo_measurement_button_label: `还不够接近,请重试`,
blindspot_done_prompt: `是的`,
adjustment_button_prompt: `图像大小对准后,请单击此处`,
viewing_distance_report: `<p>根据您的反应,您坐在离屏幕<span id='distance-estimate' style='font-weight: bold;'></span> 的位置。<br>这大概是对的吗?</p> `,
};
timeline.push(chinrest)
var fullscreen_trial = {
type: jsPsychFullscreen,
fullscreen_mode: true,
message: "<p><span class='add_' style='color:white; font-size: 25px;'> 实验需要全屏模式,实验期间请勿退出全屏。 </span></p >",
button_label: " <span class='add_' style='color:black; font-size: 20px;'> 点击这里进入全屏</span>"
}
timeline.push(fullscreen_trial);//将全屏设置放入到时间线里
function permutation(arr, num) { //定义排列组合的function
var r = [];
(function f(t, a, n) {
if (n == 0) return r.push(t);
for (var i = 0, l = a.length; i < l; i++) {
f(t.concat(a[i]), a.slice(0, i).concat(a.slice(i + 1)), n - 1);
}
})([], arr, num);
return r;
}
var texts = ["好人", "常人", "坏人"]//储存文字
var key = ['f', 'j']//按键
//正确率60%
let acc = 60;
let view_texts_images = [];
var Instructions1 = {
type: jsPsychInstructions,
pages: function () {
let start = "<p class='header' style = 'font-size: 25px'>请您记住如下对应关系:</p>",
middle = "<p class='footer' style = 'font-size: 25px'>如果对本实验还有不清楚之处,请立即向实验员咨询。</p>",
end = "<p style = 'font-size: 25px; line-height: 30px;'>如果您明白了规则:请点击 继续 进入刺激呈现顺序为<span style='color: yellow;'>先图形后文字条件</span>的练习</span></p><div>";
let tmpI = "";
view_texts_images.forEach(v => {
tmpI += `<p class="content">${v}</p>`;
});
return ["<p class='header' style = 'font-size: 25px'>实验说明:</p><p style='color:white; font-size: 25px;line-height: 30px;'>您好,欢迎参加本实验。本次实验大约需要50分钟完成。</p><p style='color:white; font-size: 25px;'>在本实验中,您需要完成一个简单的知觉匹配任务。</p><p style='color:white; font-size: 25px;'>您将学习几种几何图形与不同标签的对应关系。</p>",
start + `<div class="box">${tmpI}</div>` +
`<p class='footer' style='font-size: 30px; line-height: 35px;'>您的任务是在不同图形和文字呈现顺序的条件下判断几何图形与图形名称或文字标签是否匹配,</p><p class='footer' style='color:white; font-size: 25px;'>如果二者匹配,请按<span style="color: lightgreen; font-size:25px">${key[0]}键</span></p><p class='footer' style='color:white; font-size: 25px;'>如果二者不匹配,请按<span style="color: lightgreen; font-size:25px"> ${key[1]}键</p></span><p class='footer' style='color:white; font-size: 20px;'>请在实验过程中将您的<span style="color: lightgreen;">食指</span>放在电脑键盘的相应键位上准备按键。</p></span>`,
`<p style='color:white; font-size: 25px; line-height: 30px;'>您将首先完成三组不同的刺激呈现顺序:<span style="color: yellow; ">先图形后文字、先文字后图形以及图形和文字同时呈现</span>条件下,每24次按键的匹配任务练习。</p><p style='color:white; font-size: 25px; line-height: 30px;'>完成匹配任务的练习之后,您将完成每个条件下4组匹配任务,每组包括60次按键反应,每组完成后会有休息时间。</p><p style='color:white; font-size: 22px; line-height: 25px;'>完成一组任务大约需要7分钟,整个实验将持续大约50分钟。</p>`,//实验时间待修改
middle + end];
},
show_clickable_nav: true,
button_label_previous: " <span class='add_' style='color:black; font-size: 20px;'> 返回</span>",
button_label_next: " <span class='add_' style='color:black; font-size: 20px;'> 继续</span>",
on_load: () => {
$("body").css("cursor", "default");
},
on_finish: function () {
$("body").css("cursor", "none");
} //鼠标消失术,放在要消失鼠标的前一个事件里
}
timeline.push(Instructions1);
let prac_i = {
timeline:[
{
type:jsPsychPsychophysics,
stimuli:[
{
obj_type: 'cross',
startX: "center", // location of the cross's center in the canvas
startY: "center",
line_length: 40,
line_width: 5,
line_color: 'white', // You can use the HTML color name instead of the HEX color.
show_start_time: 500,
show_end_time: 1000// ms after the start of the trial
},
{
obj_type:"image",
file: function(){return jsPsych.timelineVariable("Image")},
startX: "center", // location of the cross's center in the canvas
startY: "center",
width: 190, // 调整图片大小 视角:3.8° x 3.8°
heigth: 190, // 调整图片大小 视角:3.8° x 3.8°
show_start_time: 1000, // ms after the start of the trial
show_end_time: 1050,//出现50ms
origin_center: true//待确定
},//上一组end时间减去下一组show时间就是空屏的100ms
{
obj_type: 'text',
startX: "center",
startY: "center", //图形和文字距离 与加号等距
content: function () {
return jsPsych.timelineVariable('word', true)();//记得后面要加括号
},
font: `${80}px 'Arial'`, //字体和颜色设置 文字视角:3.6° x 1.6°
text_color: 'white',
show_start_time: 1150, // ms after the start of the trial
show_end_time: 1200,//出现50ms
origin_center: true//带确定
}
],
choices: ['f', 'j'],
response_start_time:1150,//开始作答时间,第二个刺激开始计算
trial_duration:2650,//结束时间,一共作答时间持续1500ms
data:function(){return jsPsych.timelineVariable("identify")},
on_finish: function(data){
data.correct_response = jsPsych.timelineVariable("identify", true)();
data.correct = data.correct_response == data.key_press;//0错1对
data.Image = jsPsych.timelineVariable("Image");
data.word = jsPsych.timelineVariable("word", true)();//加括号
data.condition = "prac_image_first"
}
},
{
data:{
screen_id: "feedback_test"//这里为反馈
},
type:jsPsychHtmlKeyboardResponse,
stimulus:function(){
let keypress = jsPsych.data.get().last(1).values()[0].key_press; // 被试按键
//let trial_keypress = jsPsych.data.get().last(1).values()[0].correct; //该trial正确的按键
let time = jsPsych.data.get().last(1).values()[0].rt;
let trial_correct_response = jsPsych.data.get().last(1).values()[0].correct_response;//该trial正确的按键
if (time > 1500 || time === null) { //大于1500或为null为过慢
return "<span class='add_' style='color:yellow; font-size: 70px;'> 太慢! </span>"
} else if (time < 200) { //小于两百为过快反应
return "<span style='color:yellow; font-size: 70px;'>过快! </span>"
} else {
if (keypress == trial_correct_response) { //如果按键 == 正确按键
return "<span style='color:GreenYellow; font-size: 70px;'>正确! </span>"
}
else {
return "<span style='color:red; font-size: 70px;'>错误! </span>"
}
}
},
choices:"NO_KEYS",
trial_duration:300,//300ms反馈
}
],
timeline_variables:[
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
{Image:images[0], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
],
randomize_order:true,
repetitions:2,//正是实验时改为6
on_finish:function(){
// $("body").css("cursor", "default"); //鼠标出现
}
}
var feedback_p = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
let trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24); // 运行逻辑:先挑出data里的所有的correct:true/false的数据行,成为新的数组,然后对倒数的某几组进行计算
//这里填入timeline_variables里面的trial数量
let correct_trials = trials.filter({
correct: true
});
let accuracy = Math.round(correct_trials.count() / trials.count() * 100);
let rt = Math.round(correct_trials.select('rt').mean());
return "<style>.context{color:white; font-size: 35px; line-height:40px}</style>\
<div><p class='context'>您正确回答了" + accuracy + "% 的试次。</p>" +
"<p class='context'>您的平均反应时为" + rt + "毫秒。</p>";
}
}
var feedback_continue_practice1 = { //在这里呈现文字recap,让被试再记一下
type: jsPsychInstructions,
pages: function () {
let start = "<p class='header' style='font-size:25px; line-height:30px;'>请您努力记下如下匹配对应关系,再次进行练习。</p>",
middle = "<p class='footer' style='font-size:25px; line-height:30px;'>如果对本实验还有不清楚之处,请立即向实验员咨询。</p>",
end = "<p style='font-size:25px; line-height:30px;'>如果您明白了规则:</p><p style='font-size:22px; line-height:25px;'>请按 继续 进入练习</p><div>";
let tmpI = "";
view_texts_images.forEach(v => {
tmpI += `<p class="content" style='font-size:25px'>${v}</p>`;
});
return ["<p class='header' style='font-size:25px; line-height:30px;'>您的正确率未达到进入下一阶段练习的要求。</p>",
start + `<div class="box">${tmpI}</div>` +
`<p class='footer' style='font-size:25px; line-height:30px;'>您的任务是判断几何图形与图形名称或文字标签是否匹配,</p><p class='footer' style='font-size:25px; line-height:30px;'>如果二者匹配,请按 <span style="color: lightgreen;">${key[0]} 键</span></p><p class='footer' style='font-size:25px'>如果二者不匹配,请按<span style="color: lightgreen;"> ${key[1]} 键</p></span><p class='footer' style='font-size:22px; line-height:25px;'>请在实验过程中将您的<span style="color: lightgreen;">食指</span>放在电脑键盘的相应键位上进行按键。</p></span>`,
middle + end];
},
show_clickable_nav: true,
button_label_previous: " <span class='add_' style='color:black; font-size: 20px;'> 返回</span>",
button_label_next: " <span class='add_' style='color:black; font-size: 20px;'> 继续</span>",
on_finish: function () {
$("body").css("cursor", "none");
},
on_load: () => {
$("body").css("cursor", "default");
}
}
var if_node1 = { //if_node 用于判断是否呈现feedback,feedback_continue_practice
timeline: [feedback_p, feedback_continue_practice1],
conditional_function: function (data) {
var trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);//这里注意:只需要上一组的练习数据,而不是所有的数据!! 如何实现:.last() 取data最后的几组数据(上一组练习数据)
var correct_trials = trials.filter({
correct: true
});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
if (accuracy >= acc) {
return false;//达标就skip掉feedback_continue_practice这一段
} else if (accuracy < acc) { //没达标反馈feedback,feedback_continue_practice
return true;
}
}
}
var loop_node1 = {
timeline: [prac_i, if_node1],
loop_function: function () {
var trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);//记得改,取数据
var correct_trials = trials.filter({
correct: true
});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
if (accuracy >= acc) {
return false;//end 进入正式实验前的反馈
} else if (accuracy < acc) { // repeat
return true;
}
}
}
timeline.push(loop_node1);
var prac_w = {
timeline:[
{
type:jsPsychPsychophysics,
stimuli:[
{
obj_type: 'cross',
startX: "center", // location of the cross's center in the canvas
startY: "center",
line_length: 40,//pixels 视角:0.8° x 0.8°
line_width: 5,
line_color: 'white', // You can use the HTML color name instead of the HEX color.
show_start_time: 500,
show_end_time: 1000// ms after the start of the trial
},
{
obj_type:"image",
file: function(){return jsPsych.timelineVariable("Image")},
startX: "center", // location of the cross's center in the canvas
startY: "center",
width: 190, // 调整图片大小 视角:3.8° x 3.8°
heigth: 190, // 调整图片大小 视角:3.8° x 3.8°
show_start_time: 1150, // ms after the start of the trial
show_end_time: 1200,//出现50ms
},//上一组end时间减去下一组show时间就是空屏的100ms
{
obj_type: 'text',
file: function(){return jsPsych.timelineVariable("word")},
startX: "center",
startY: "center", //图形和文字距离 与加号等距
content: function () {
return jsPsych.timelineVariable('word', true)();
},
font: `${80}px 'Arial'`, //字体和颜色设置 文字视角:3.6° x 1.6°, //字体和颜色设置 文字视角:3.6° x 1.6°
text_color: 'white',
show_start_time: 1000, // ms after the start of the trial
show_end_time: 1050,//出现50ms
origin_center: true
}
],
choices: ['f', 'j'],
response_start_time:1150,//开始作答时间,第二个刺激开始计算
trial_duration:2650,//结束时间,一共作答时间持续1500ms
data:function(){return jsPsych.timelineVariable("identify")},
on_finish: function(data){
data.correct_response = jsPsych.timelineVariable("identify", true)();
data.correct = data.correct_response == data.key_press;//0错1对
data.Image = jsPsych.timelineVariable("Image");
data.word = jsPsych.timelineVariable('word', true)();
data.condition = "prac_word_first"
}
},
{
data:{
screen_id: "feedback_test"//这里为反馈
},
type:jsPsychHtmlKeyboardResponse,
stimulus:function(){
let keypress = jsPsych.data.get().last(1).values()[0].key_press; // 被试按键
//let trial_keypress = jsPsych.data.get().last(1).values()[0].correct; //该trial正确的按键
let time = jsPsych.data.get().last(1).values()[0].rt;
let trial_correct_response = jsPsych.data.get().last(1).values()[0].correct_response;//该trial正确的按键
if (time > 1500 || time === null) { //大于1500或为null为过慢
return "<span class='add_' style='color:yellow; font-size: 70px;'> 太慢! </span>"
} else if (time < 200) { //小于两百为过快反应
return "<span style='color:yellow; font-size: 70px;'>过快! </span>"
} else {
if (keypress == trial_correct_response) { //如果按键 == 正确按键
return "<span style='color:GreenYellow; font-size: 70px;'>正确! </span>"
}
else {
return "<span style='color:red; font-size: 70px;'>错误! </span>"
}
}
},
choices:"NO_KEYS",
trial_duration:300,//300ms反馈
}
],
timeline_variables:[
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
{Image:images[0], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
],
randomize_order:true,
repetitions:2,
on_finish:function(){
// $("body").css("cursor", "default"); //鼠标出现
}
}
var feedback_gow = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
let trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);
let correct_trials = trials.filter({
correct: true
});
let accuracy = Math.round(correct_trials.count() / trials.count() * 100);
let rt = Math.round(correct_trials.select('rt').mean());
return "<style>.context{color:white; font-size: 35px; line-height:40px}</style>\
<div><p class='context'>您正确回答了" + accuracy + "% 的试次。</p>" +
"<p class='context'>您的平均反应时为" + rt + "毫秒。</p>" +
"<p class='context'>恭喜您完成这一阶段的练习。按任意键进入<span style='color: yellow;'>先文字后图形条件</span>的练习。</p></div>";
},
on_finish: function () {
$("body").css("cursor", "none");
}
}
timeline.push(feedback_gow);
var feedback_continue_practice2 = { //在这里呈现文字recap,让被试再记一下
type: jsPsychInstructions,
pages: function () {
let start = "<p class='header' style='font-size:25px; line-height:30px;'>请您努力记下如下匹配对应关系,再次进行练习。</p>",
middle = "<p class='footer' style='font-size:25px; line-height:30px;'>如果对本实验还有不清楚之处,请立即向实验员咨询。</p>",
end = "<p style='font-size:25px; line-height:30px;'>如果您明白了规则:</p><p style='font-size:22px; line-height:25px;'>请按 继续 进入练习</p><div>";
let tmpI = "";
view_texts_images.forEach(v => {
tmpI += `<p class="content" style='font-size:25px'>${v}</p>`;
});
return ["<p class='header' style='font-size:25px; line-height:30px;'>您的正确率未达到进入下一阶段练习的要求。</p>",
start + `<div class="box">${tmpI}</div>` +
`<p class='footer' style='font-size:25px; line-height:30px;'>您的任务是判断几何图形与图形名称或文字标签是否匹配,</p><p class='footer' style='font-size:25px; line-height:30px;'>如果二者匹配,请按 <span style="color: lightgreen;">${key[0]} 键</span></p><p class='footer' style='font-size:25px'>如果二者不匹配,请按<span style="color: lightgreen;"> ${key[1]} 键</p></span><p class='footer' style='font-size:22px; line-height:25px;'>请在实验过程中将您的<span style="color: lightgreen;">食指</span>放在电脑键盘的相应键位上进行按键。</p></span>`,
middle + end];
},
show_clickable_nav: true,
button_label_previous: " <span class='add_' style='color:black; font-size: 20px;'> 返回</span>",
button_label_next: " <span class='add_' style='color:black; font-size: 20px;'> 继续</span>",
on_finish: function () {
$("body").css("cursor", "none");
},
on_load: () => {
$("body").css("cursor", "default");
}
}
var if_node2 = { //if_node 用于判断是否呈现feedback,feedback_continue_practice
timeline: [feedback_p, feedback_continue_practice2],
conditional_function: function (data) {
var trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);//这里注意:只需要上一组的练习数据,而不是所有的数据!! 如何实现:.last() 取data最后的几组数据(上一组练习数据)
var correct_trials = trials.filter({
correct: true
});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
if (accuracy >= acc) {
return false;//达标就skip掉feedback_continue_practice这一段
} else if (accuracy < acc) { //没达标反馈feedback,feedback_continue_practice
return true;
}
}
}
var loop_node2 = {
timeline: [prac_w, if_node2],
loop_function: function () {
var trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);//记得改,取数据
var correct_trials = trials.filter({
correct: true
});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
if (accuracy >= acc) {
return false;//end 进入正式实验前的反馈
} else if (accuracy < acc) { // repeat
return true;
}
}
}
timeline.push(loop_node2);
var prac_s = {
timeline:[
{
type:jsPsychPsychophysics,
stimuli:[
{
obj_type: 'cross',
startX: "center", // location of the cross's center in the canvas
startY: "center",
line_length: 40, // pixels 视角:0.8° x 0.8°
line_width: 5,
line_color: 'white', // You can use the HTML color name instead of the HEX color.
show_start_time: 500,
show_end_time: 1100// ms after the start of the trial
},
{
obj_type:"image",
file: function(){return jsPsych.timelineVariable("Image")},
startX: "center", // location of the cross's center in the canvas
startY: -175, //图形和文字距离 与加号等距
width: 190, // 调整图片大小 视角:3.8° x 3.8°
heigth: 190, // 调整图片大小 视角:3.8° x 3.8°
show_start_time: 1000, // ms after the start of the trial
show_end_time: 1100,//出现50ms
origin_center: true
},//上一组end时间减去下一组show时间就是空屏的100ms
{
obj_type: 'text',
file: function(){return jsPsych.timelineVariable("word")},
startX: "center",
startY: 175, //图形和文字距离 与加号等距2度
content: function () {
return jsPsych.timelineVariable('word', true)();
},
font: `${80}px 'Arial'`, //字体和颜色设置 文字视角:3.6° x 1.6°
text_color: 'white',
show_start_time: 1000, // ms after the start of the trial
show_end_time: 1100,//出现50ms
origin_center: true
}
],
choices: ['f', 'j'],
response_start_time:1000,//开始作答时间,第二个刺激开始计算
trial_duration:2500,//结束时间,一共作答时间持续1500ms
data:function(){return jsPsych.timelineVariable("identify")},
on_finish: function(data){
data.correct_response = jsPsych.timelineVariable("identify", true)();
data.correct = data.correct_response == data.key_press;//0错1对
data.Image = jsPsych.timelineVariable("Image");
data.word = jsPsych.timelineVariable('word', true)();
data.condition = "prac_simultaneous"
}
},
{
data:{
screen_id: "feedback_test"//这里为反馈
},
type:jsPsychHtmlKeyboardResponse,
stimulus:function(){
let keypress = jsPsych.data.get().last(1).values()[0].key_press; // 被试按键
//let trial_keypress = jsPsych.data.get().last(1).values()[0].correct; //该trial正确的按键
let time = jsPsych.data.get().last(1).values()[0].rt;
let trial_correct_response = jsPsych.data.get().last(1).values()[0].correct_response;//该trial正确的按键
if (time > 1500 || time === null) { //大于1500或为null为过慢
return "<span class='add_' style='color:yellow; font-size: 70px;'> 太慢! </span>"
} else if (time < 200) { //小于两百为过快反应
return "<span style='color:yellow; font-size: 70px;'>过快! </span>"
} else {
if (keypress == trial_correct_response) { //如果按键 == 正确按键
return "<span style='color:GreenYellow; font-size: 70px;'>正确! </span>"
}
else {
return "<span style='color:red; font-size: 70px;'>错误! </span>"
}
}
},
choices:"NO_KEYS",
trial_duration:300,//300ms反馈
}
],
timeline_variables:[
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
{Image:images[0], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
],
randomize_order:true,
repetitions:2,//正是实验时改为6
on_finish:function(){
// $("body").css("cursor", "default"); //鼠标出现
}
}
var feedback_gos = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
let trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);
let correct_trials = trials.filter({
correct: true
});
let accuracy = Math.round(correct_trials.count() / trials.count() * 100);
let rt = Math.round(correct_trials.select('rt').mean());
return "<style>.context{color:white; font-size: 35px; line-height:40px}</style>\
<div><p class='context'>您正确回答了" + accuracy + "% 的试次。</p>" +
"<p class='context'>您的平均反应时为" + rt + "毫秒。</p>" +
"<p class='context'>恭喜您完成练习。按任意键进入<span style='color: yellow;'>图形和文字同时呈现条件</span>的练习。</p></div>";
},
on_finish: function () {
$("body").css("cursor", "none");
}
}
timeline.push(feedback_gos);
var feedback_continue_practice3 = { //在这里呈现文字recap,让被试再记一下
type: jsPsychInstructions,
pages: function () {
let start = "<p class='header' style='font-size:25px; line-height:30px;'>请您努力记下如下匹配对应关系,再次进行练习。</p>",
middle = "<p class='footer' style='font-size:25px; line-height:30px;'>如果对本实验还有不清楚之处,请立即向实验员咨询。</p>",
end = "<p style='font-size:25px; line-height:30px;'>如果您明白了规则:</p><p style='font-size:22px; line-height:25px;'>请按 继续 进入练习</p><div>";
let tmpI = "";
view_texts_images.forEach(v => {
tmpI += `<p class="content" style='font-size:25px'>${v}</p>`;
});
return ["<p class='header' style='font-size:25px; line-height:30px;'>您的正确率未达到进入下一阶段练习的要求。</p>",
start + `<div class="box">${tmpI}</div>` +
`<p class='footer' style='font-size:25px; line-height:30px;'>您的任务是判断几何图形与图形名称或文字标签是否匹配,</p><p class='footer' style='font-size:25px; line-height:30px;'>如果二者匹配,请按 <span style="color: lightgreen;">${key[0]} 键</span></p><p class='footer' style='font-size:25px'>如果二者不匹配,请按<span style="color: lightgreen;"> ${key[1]} 键</p></span><p class='footer' style='font-size:22px; line-height:25px;'>请在实验过程中将您的<span style="color: lightgreen;">食指</span>放在电脑键盘的相应键位上进行按键。</p></span>`,
middle + end];
},
show_clickable_nav: true,
button_label_previous: " <span class='add_' style='color:black; font-size: 20px;'> 返回</span>",
button_label_next: " <span class='add_' style='color:black; font-size: 20px;'> 继续</span>",
on_finish: function () {
$("body").css("cursor", "none");
},
on_load: () => {
$("body").css("cursor", "default");
}
}
var if_node3 = { //if_node 用于判断是否呈现feedback,feedback_continue_practice
timeline: [feedback_p, feedback_continue_practice3],
conditional_function: function (data) {
var trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);//这里注意:只需要上一组的练习数据,而不是所有的数据!! 如何实现:.last() 取data最后的几组数据(上一组练习数据)
var correct_trials = trials.filter({
correct: true
});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
if (accuracy >= acc) {
return false;//达标就skip掉feedback_continue_practice这一段
} else if (accuracy < acc) { //没达标反馈feedback,feedback_continue_practice
return true;
}
}
}
var loop_node3 = {
timeline: [prac_s, if_node3],
loop_function: function () {
var trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);//记得改,取数据
var correct_trials = trials.filter({
correct: true
});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
if (accuracy >= acc) {
return false;//end 进入正式实验前的反馈
} else if (accuracy < acc) { // repeat
return true;
}
}
}
timeline.push(loop_node3);
var feedback_goformal = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
let trials = jsPsych.data.get().filter(
[{ correct: true }, { correct: false }]
).last(24);
let correct_trials = trials.filter({
correct: true
});
let accuracy = Math.round(correct_trials.count() / trials.count() * 100);
let rt = Math.round(correct_trials.select('rt').mean());
return "<style>.context{color:white; font-size: 35px; line-height:40px}</style>\
<div><p class='context'>您正确回答了" + accuracy + "% 的试次。</p>" +
"<p class='context'>您的平均反应时为" + rt + "毫秒。</p>" +
"<p class='context'>恭喜您完成练习。按任意键进入正式实验。</p>" +
"<p class='footer' style='font-size: 35px; line-height:40px;'>请在进入正式实验实验之前将您的<span style='color: lightgreen;'>食指</span>放在电脑键盘的相应键位上进行按键。</p>"
},
on_finish: function () {
$("body").css("cursor", "none");
}
}
timeline.push(feedback_goformal);
let image_first = {
timeline:[
{
type:jsPsychPsychophysics,
stimuli:[
{
obj_type: 'cross',
startX: "center", // location of the cross's center in the canvas
startY: "center",
line_length: 40,
line_width: 5,
line_color: 'white', // You can use the HTML color name instead of the HEX color.
show_start_time: 500,
show_end_time: 1000// ms after the start of the trial
},
{
obj_type:"image",
file: function(){return jsPsych.timelineVariable("Image")},
startX: "center", // location of the cross's center in the canvas
startY: "center",
width: 190, // 调整图片大小 视角:3.8° x 3.8°
heigth: 190, // 调整图片大小 视角:3.8° x 3.8°
show_start_time: 1000, // ms after the start of the trial
show_end_time: 1050,//出现50ms
origin_center: true//待确定
},//上一组end时间减去下一组show时间就是空屏的100ms
{
obj_type: 'text',
startX: "center",
startY: "center", //图形和文字距离 与加号等距
content: function () {
return jsPsych.timelineVariable('word', true)();
},
font: `${80}px 'Arial'`, //字体和颜色设置 文字视角:3.6° x 1.6°
text_color: 'white',
show_start_time: 1150, // ms after the start of the trial
show_end_time: 1200,//出现50ms
origin_center: true//带确定
}
],
choices: ['f', 'j'],
response_start_time:1150,//开始作答时间,第二个刺激开始计算
trial_duration:2650,//结束时间,一共作答时间持续1500ms
data:function(){return jsPsych.timelineVariable("identify")},
on_finish: function(data){
data.correct_response = jsPsych.timelineVariable("identify", true)();
data.correct = data.correct_response == data.key_press;//0错1对
data.Image = jsPsych.timelineVariable("Image");
data.word = jsPsych.timelineVariable("word", true)();
data.condition = "image_first"
}
},
{
data:{
screen_id: "feedback_test"//这里为反馈
},
type:jsPsychHtmlKeyboardResponse,
stimulus:function(){
let keypress = jsPsych.data.get().last(1).values()[0].key_press; // 被试按键
//let trial_keypress = jsPsych.data.get().last(1).values()[0].correct; //该trial正确的按键
let time = jsPsych.data.get().last(1).values()[0].rt;
let trial_correct_response = jsPsych.data.get().last(1).values()[0].correct_response;//该trial正确的按键
if (time > 1500 || time === null) { //大于1500或为null为过慢
return "<span class='add_' style='color:yellow; font-size: 70px;'> 太慢! </span>"
} else if (time < 200) { //小于两百为过快反应
return "<span style='color:yellow; font-size: 70px;'>过快! </span>"
} else {
if (keypress == trial_correct_response) { //如果按键 == 正确按键
return "<span style='color:GreenYellow; font-size: 70px;'>正确! </span>"
}
else {
return "<span style='color:red; font-size: 70px;'>错误! </span>"
}
}
},
choices:"NO_KEYS",
trial_duration:300,//300ms反馈
}
],
timeline_variables:[
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
{Image:images[0], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[2]}, identify:function(){return key[1]}},
{Image:images[1], word:function(){return texts[0]}, identify:function(){return key[1]}},
{Image:images[2], word:function(){return texts[1]}, identify:function(){return key[1]}},
{Image:images[0], word:function(){return texts[0]}, identify:function(){return key[0]}},
{Image:images[1], word:function(){return texts[1]}, identify:function(){return key[0]}},
{Image:images[2], word:function(){return texts[2]}, identify:function(){return key[0]}},
],
randomize_order:true,
repetitions:5,//正是实验时改为6
on_finish:function(){
// $("body").css("cursor", "default"); //鼠标出现
}
}
let word_first = {
timeline:[
{
type:jsPsychPsychophysics,
stimuli:[
{
obj_type: 'cross',
startX: "center", // location of the cross's center in the canvas
startY: "center",
line_length: 40,//pixels 视角:0.8° x 0.8°
line_width: 5,
line_color: 'white', // You can use the HTML color name instead of the HEX color.
show_start_time: 500,
show_end_time: 1000// ms after the start of the trial
},
{
obj_type:"image",
file: function(){return jsPsych.timelineVariable("Image")},
startX: "center", // location of the cross's center in the canvas
startY: "center",
width: 190, // 调整图片大小 视角:3.8° x 3.8°
heigth: 190, // 调整图片大小 视角:3.8° x 3.8°
show_start_time: 1150, // ms after the start of the trial
show_end_time: 1200,//出现50ms
},//上一组end时间减去下一组show时间就是空屏的100ms
{
obj_type: 'text',
file: function(){return jsPsych.timelineVariable("word")},
startX: "center",
startY: "center", //图形和文字距离 与加号等距
content: function () {
return jsPsych.timelineVariable('word', true)();