-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMMTMM_Temporal.html
1440 lines (1204 loc) · 53.6 KB
/
SMMTMM_Temporal.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
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
<!--
Changed from SMM_TMM
SMMTMM_Full_Instructions.html
Show n object, then show 2 n object, ask old new location, time
Four conditions, 1 - tell both 2 - tell spatial 3 - tell temporal 4 - tell nothing
to do:
- change instruction
- record the timestamp when each item was shown during viewing
Note, search DDD for lines that could be deleted
-->
<!--Load Library-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="https://timbrady.org/turk/TimTurkTools.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<?php include 'save_data.php';?>
<style>
body {
min-height: 100vh;
font-family: "Gill Sans", "Helvetica Neue", sans-serif;
font-size: 1.2rem;
display: inline
}
.StartButton {
background-color: rgba(235, 235, 235, 0.5);
border-radius: 8px;
border-width: 0;
color: #333333;
cursor: pointer;
display: inline-block;
font-family: "Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif;
/* font-size: 14px; */
font-weight: 500;
line-height: 20px;
list-style: none;
margin: 5px;
padding: 10px 12px;
text-align: center;
transition: all 200ms;
vertical-align: baseline;
white-space: nowrap;
touch-action: manipulation;
}
.StartButton:hover {
background-color: rgba(235, 235, 235, 1);
}
.StartButton>a:hover {
color: #8EDE0B;
}
.headboard {
height: 5%;
text-align: center;
}
.ResponseButton {
/*background-color:rgba(196, 182, 233, 0.932);*/
width: 25vw;
height: 95vh;
float: right;
margin: 1rem 1rem auto auto;
border-radius: 10px;
}
.StimWindow {
float: right;
width: 95vh;
height: 95vh;
/* same as width */
text-align: center;
}
.DisplayWindow {
/*background-color:rgba(196, 182, 233, 0.932);*/
width: 20vw;
height: 50vw;
position: relative;
}
#DisplayWindow_img {
float: right;
margin-top: 80%;
margin-left: 50%;
padding-right: 10%
}
#DisplayWindow_instr {
float: right;
}
#ResponseButton_instr {
float: left;
margin-top: 90%;
}
#ResponseButton_instr>button {
background-color: rgba(235, 235, 235, 0.8);
border-radius: 8px;
border-width: 0;
color: #333333;
cursor: pointer;
display: inline-block;
font-family: "Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: 500;
line-height: 20px;
list-style: none;
margin: 5px;
padding: 10px 12px;
text-align: center;
transition: all 200ms;
vertical-align: baseline;
white-space: nowrap;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
}
#ResponseButton_instr>button:hover {
background-color: rgba(185, 185, 185, 0.8);
}
#Break,
#Break_retest {
text-align: center;
margin-top: 12%;
}
#Consent,
#OsRecord,
#demographic {
font-family: var(--font);
font-weight: 600;
font-size: 1rem;
line-height: 1;
margin: 0 auto;
width: 70%;
color: rgba(0, 0, 0, 0.562);
}
/* audio check button */
#ACButton {
font-size: 1rem;
background-color: white;
border: solid;
border-radius: 8px;
margin: 2%
}
#myBar {
width: 0%;
height: 3.5vh;
background-color: #86aa04;
/*text-align: center; To center it horizontally (if you want) */
line-height: 30px;
/* To center it vertically */
color: black;
cursor: 'crosshair'
}
#myBar_start {
float: left;
}
#myBar_now {
float: right;
}
#myProgress {
width: 98%;
background-color: #ddd;
display: none;
cursor: crosshair
}
/* hide from initial display */
.headboard,
#DisplayWindow_instr,
#Instruction2,
#EndPage,
#Break,
#Break_retest,
#Start_Experiment,
#audioCheck,
#demographic,
#PracticeEnd,
#TestingEnds,
#viewingEnd {
display: none
}
.consent-list {
line-height: 1.7rem;
}
</style>
<!------------------------------------------------------------------------------------------------>
<!DOCTYPE html>
<html lang="en">
<main>
<div id="Consent">
<br><br>
<h3>READ INSTRUCTIONS CAREFULLY BEFORE ACCEPTING TO PARTICIPATE:</h3>
<p>This study is part of a research project titled "Spatial and Temporal Massive Memory". The principal
investigator
in charge of this study is Jeremy Wolfe ([email protected]), Claire Wang, Visual Attention Lab, Brigham
and Women's Hospital. However, other research staff may be involved and can act on behalf of
the person in charge.</p>
<h4>Requirements:</h4>
<p> You need color vision for this task. </p>
<p> You need at least 20/25 visual acuity (with or without correction). </p>
<p> You have not participated in a similar study before. </p>
<p> Please complete this study on a desktop or laptop. </p>
<h4>Instructions:</h4>
<p><b>NOTE: </b>The experiment works in Safari, Brave, and Chrome, not Firefox or other browsers. If the experiment does not show in your browser, please notify the experimenter.</p>
There are two phases to this experiment: Training and Testing
<ul class="consent-list">
<li>In the training phase, we will show you pictures of objects on the screen one at a time for 3 seconds each. You should try to remember the following information (we will be testing you later)</li>
<ol>
<li>WHAT objects you saw</li>
<li>WHEN in the sequence of images each object was presented</li>
</ol>
<li>In the testing phase, we will test your memory for the previously seen objects. We will provide you with more instructions immediately before the testing phase begins.</li>
</ul>
<p>The experiment consists of around ~100 trials. You should be able to complete the experiment in ~30 minutes. You are allotted 60 minutes in total.
You will receive $8 per hour for your participation. <b>You will be compensated only if you complete all the
trials, correctly identify objects as natural or artificial/manmade at least 70% of the time in the training phase,
and correctly identify whether an item is old/new at least 60% of the time in the testing phase.</b> </p>
<p>By participating in this study, you will be part of the scientific effort to understand the
functioning of the human visual system and the decision making process. </b></p> <br>
<p> PLEASE READ THROUGH OUR CONSENT INFORMATION SHEET BEFORE CONSENTING TO PARTICIPATING IN OUR STUDY. <br>
<a href="https://search.bwh.harvard.edu/OnlineExperiment/Consent_InformationSheet_Online_Nov2021.pdf"
target="_blank"> >> CONSENT INFORMATION SHEET </a>
</p>
<label><input type="radio" class="checkbox"> BY CHECKING THIS BOX, YOU ACKNOWLEDGE THAT YOU READ THE
INSTRUCTIONS AND THE CONSENT INFORMATION SHEET, UNDERSTAND THE
TASK AND YOU CONSENT TO PARTICIPATE IN THIS STUDY.<br>
<br>
</label>
<br><br>
<div id="Start_Experiment">
<a href="javascript:consented()" id='consentHIT' class='PressButton'> Click Here to Start the Experiment</a>
</div>
<!--<a href = "javascript:startTesting()" id= 'consentHIT' class = 'PressButton'> Click Here to Start the Experiment</a> </div>
-->
<br><br> <br><br>
</div>
<div id="demographic">
<br><br><br>
<h3>mTurk ID:</h3>
<form>
<label for="mTurkId">If you are on mTurk, please enter your mTurk ID here:</label><br>
<input type="text" id="mTurkId" name="mTurkId"><br>
</form>
<br><br><br>
<a href="javascript:SaveData()" class='PressButton'>Submit</a>
<br><br><br><br>
</div>
<div class="TestScreen" id="TestScreen">
<body>
<div class="ResponseButton" id="ResponseButton">
<div id="ResponseButton_instr"></div>
</div>
<div class="StimWindow" id="StimWindow">
<div class="Instruction" style="font-size: 1.5rem">
<p>
<br><br>
<p style="color:red"> In this experiment, <br><br>your job is to REMEMBER <b>what</b> objects you saw and the <b>time</b> when you saw them <br></p>
<br>
Items will appear on the screen for 3 seconds each at different locations. Please indicate if the
object is natural (by pressing the left arrow) or artificial/manmade (by pressing the right arrow).
<br><br><br>
<i>If the image size is too small, please enter the browser into full screen, and refresh the webpage to restart. </i>
</p>
<div class='StartButton'>
<a href="javascript:startAudioCheck()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">NEXT</a>
</div>
</div>
<div class="audioCheck" id="audioCheck">
<br><br><br><br><br><br><br>
In the experiment, we will provide you with audio feedback. <br>
Before starting the experiment, please adjust your volume and make sure that you can clearly hear
the sound effect when clicking on the buttons below. <br>
<br><br>
<button onclick="playSound_pos()" id="ACButton" style="color:green; border-color: green"> CORRECT
</button>
<button onclick="playSound_neg()" id="ACButton" style="color:maroon; border-color: maroon "> WRONG
</button>
<br><br><br>
<div class='StartButton'>
<a href="javascript:startExp()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Click to Start the Experiment</a>
</div>
</div>
<div class="Instruction2" id="Instruction2">
<p>
<br><br><br>
You have finished part 1.
<br><br>
Now we will ask you again about the displays you saw earlier. Do your best.
<br><br>
</p>
<div class='StartButton'>
<a href="javascript:NextTrial_retest()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Click here to start Part 2 </a>
</div>
</div>
<div class="TestingEnds" id="TestingEnds">
<p>
<br><br><br><br><br><br>
You have completed the experiment. Your accuracy for the old/new response is <span
id="Practice_Accuracy"></span>%. <br><br>
<br><br> <br><br>
</p>
<div class='StartButton'>
<a href="javascript:ExpEnd()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Continue </a>
</div>
</div>
<div class="PracticeEnd" id="PracticeEnd">
<p>
<br><br><br>
Great! You have completed the practice. <br><br>
Now you will start the main experiment. Please answer as quickly and accurately as you can.
<br><br>
The main experiment takes about 45 min
<br><br>
</p>
<div class='StartButton'>
<a href="javascript:startTesting()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Click here to begin </a>
</div>
</div>
<div class="viewingEnd" id="viewingEnd">
<p>
<br><br><br>
You have viewed all the images. <br><br>
Now we will show you one image at a time. If you have seen the image before, click on the
location where you have seen it. <br><br>
Additionally, please estimate when that item appeared during the viewing block and respond using
the time bar. <br><br>
If you have not seen the image before, click on the purple button on the right.
<br><br>
</p>
<div class='StartButton'>
<a href="javascript:TestingBlock_setup()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Click here to begin </a>
</div>
</div>
<!--Break screen -->
<div class="Break" id="Break">
<p>
<br><br><br>
Click NEXT to start trial <span id="trleft">1</span>/<span id="tr-total">20</span>
</p>
<div class='StartButton'>
<a href="javascript:DisplaySetup()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Next</a>
</div>
</div>
<div class="EndPage" id="EndPage">
<p>
<br><br><br> <br><br><br>
Done! You have finished the experiment. You can close the window now.
<br><br>
Thanks.
<br><br>
</p>
</div>
<header class="headboard" id="headboard" style="background-color:transparent;"> </header>
<div class="myProgress" id="myProgress">
<div class="myBar" id="myBar">
<div id="myBar_start">Start</div>
<div id='myBar_now'>End</div>
</div>
</div>
<canvas id="StimCanvas" style="cursor:pointer"> </canvas>
</div>
<div class="DisplayWindow" id="DisplayWindow">
<div id="DisplayWindow_img"></div>
<div id="DisplayWindow_instr"> Click Old Location <br> or Click in New Box</div>
</div>
</body>
</div>
<!--Break screen -->
<div class="Break" id="Break">
<p>
<br><br><br>
Click NEXT to start trial <span id="trleft">1</span>/<span id="tr-total">20</span>
</p>
<div class='StartButton'>
<a href="javascript:DisplaySetup()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Next</a>
</div>
</div>
<div class="Break_retest" id="Break_retest">
<p>
<br><br><br>
Click NEXT to start retest trial <span id="trleft2">1</span>/<span id="tr-total2">20</span>
</p>
<div class='StartButton'>
<a href="javascript:NextTrial_retest()" class="nextButton" id="nextTrialButton"
style="text-decoration: none;">Next</a>
</div>
</div>
<audio id="audio_pos"
src="https://search.bwh.harvard.edu/OnlineExperiment/SpatialMassiveMemory/Sounds/Pos1.wav"></audio>
<audio id="audio_neu"
src="https://search.bwh.harvard.edu/OnlineExperiment/SpatialMassiveMemory/Sounds/Neutralclick.wav"></audio>
<audio id="audio_neg"
src="https://search.bwh.harvard.edu/OnlineExperiment/SpatialMassiveMemory/Sounds/Neg3.wav"></audio>
</main>
</html>
<script>
// ****** NOTE ******
// This code was modified several times, some of the variables and params listed below may come from
// an earlier version and no longer used in the current experiment
// PARAMETERS
var MemSetSize = 50 //150;//25;//15;
var PresentationTime = 3000//000//00//00;//2000; // Presentation time of each item, in millisec
var holdtime = 100; //
var trialtotal = 12;
var Num_boxes = 49;
var IncludeBackGroundBoxes = 1; // 1 = box visible, 0 = box unvisible
var imageSizeParam = 0.9;// default = 0.9;
var practiceOn = 0; // 1= include practice, 0 = go straight into experiment.
var viewingBlock_instr = "Try to remember the identity and order of appearance of each item" // temporal
// STIMULUS VARIABLES
var ImgList_all = [];
var AllTestImage = [];
var Tar_list;
var Dis_list;
var totalImgNum = 2400;
var save_jitterX = [];
var save_jitterY = [];
var trial_img_loc; // save image location in pix [x,y]
var trial_img_row_column;
var trial_jitter_x; // save jitter of box location for redrawing
var trial_jitter_y;// save jitter of box location for redrawing
var toggle1
var viewImgCounter = -1;
var testingCounter = -1;
var testingCounter_dis = -1;
var testingCounter_tar = -1;
var imageTypeQuiz = [0, 0, 0]; // correct, incorrect, no response
var trCount = document.querySelector("#trleft");
var trTotal = document.querySelector("#tr-total");
var trCount2 = document.querySelector("#trleft2");
var trTotal2 = document.querySelector("#tr-total2");
trTotal.textContent = trialtotal;
trTotal2.textContent = trialtotal;
var thisAccuracy;
var FinalAccuracy = document.querySelector("#Practice_Accuracy");
//n-Back new Variables
var count_Allimages = 0;
var OldList = [];
var isOld_item;
var imgClick;
var ImageOnTime;
var GetThisImageLoc;
var save_clickLoc;
var thisImageLoc;
var thisImage;
var ClickRegistered = 0;
var timer1;
var OldOrNewList;
var TimeBarLoc_1st = -1;
var timeBarLoc_resp = -1;
var test_accuracy = [];
// SAVE VARIABLES
var curID_save;
var trialResult_save;
var save_blockNum;
var save_blockName;
var save_response;
var save_isCorrect;
var itemLoc_appear;
var save_itemRowColumn;
var get_clickLoc;
var save_RT;
var thisImageID;
var save_allResult = [];
var test_timeStamp;
var view_timeStamp
var thisImage_viewInd;
//SET UP CANVAS CCC
// set canvas width and height equal to stimwindow.
var $StimCanvas = $('#StimCanvas'), $StimWin = $('.StimWindow');
$StimCanvas.attr({ width: $StimWin.width(), height: $StimWin.height() });
var CanvasHeight = document.getElementById('StimCanvas').clientHeight;
var CanvasWidth = document.getElementById('StimCanvas').clientWidth;
var BoxSize = CanvasHeight / 9//CanvasHeight/9;
var MarginLeft = -CanvasHeight / 14;
var MarginUp = -CanvasHeight / 10;// CanvasHeight/20;
var GapSize = CanvasHeight / 75;
const canvas = document.querySelector('#StimCanvas')
const respbutton = document.querySelector('#ResponseButton')
const myProgressBar = document.querySelector('#myProgress')
// PREPARE IMAGE LIST
function CreateImageList() {
for (var ImgInd = 1; ImgInd <= (50); ImgInd++) {
// var GetImg = ("https://search.bwh.harvard.edu/OnlineExperiment/SpatialMassiveMemory/Images/Object" + ImgInd + ".jpg");
var GetImg = ("https://search.bwh.harvard.edu/OnlineExperiment/SMM_TMM/round1-images/" + ImgInd + "-artificial.jpg");
// console.log(ImgInd); testing for images
var curItem = {
GetImg,
'id': ImgInd,
'type': "artificial"
};
ImgList_all.push(curItem);
}
for (var ImgInd = 51; ImgInd <= (100); ImgInd++) {
// var GetImg = ("https://search.bwh.harvard.edu/OnlineExperiment/SpatialMassiveMemory/Images/Object" + ImgInd + ".jpg");
var GetImg = ("https://search.bwh.harvard.edu/OnlineExperiment/SMM_TMM/round1-images/" + ImgInd + "-natural.jpg");
// console.log(ImgInd);
var curItem = {
GetImg,
'id': ImgInd,
'type': "natural"
};
ImgList_all.push(curItem);
}
ImgList_all = shuffle(ImgList_all);
Tar_list = ImgList_all.slice(0, MemSetSize);
Dis_list = ImgList_all.slice(MemSetSize, MemSetSize * 2)
AllTestImage = AllTestImage.concat(Tar_list, Dis_list)
AllTestImage = shuffle(AllTestImage);
//Tar_list_prac = ImgList_all.slice(MemSetSize*2, MemSetSize*2+MemSetSize_prac)
//Dis_list_prac = ImgList_all.slice(MemSetSize*2+MemSetSize_prac, MemSetSize*2+MemSetSize_prac*2)
}
CreateImageList()
// SET UP CANVAS
var c = document.getElementById("StimCanvas");
var ctx = c.getContext("2d");
/*-----------------------------------------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------------------------------------------------*/
$("#TestScreen").hide();
$('.checkbox').click(AcceptHIT);
function AcceptHIT() {
$('#Start_Experiment').show();
//openFullscreen()
}
//START TESTING
function consented() {
$("#Consent").hide();
$("#TestScreen").show();
window.scrollTo(0, 0)
}
function startAudioCheck() {
$(".Instruction").hide();
$("#audioCheck").show()
}
function startExp() {
experimentStartTime = (new Date()).getTime();
console.log('Experiment start at ' + experimentStartTime);
curID_save = experimentStartTime;
$("#audioCheck").hide();
$(".Instruction").hide();
$("#DisplayWindow").show(); // show the experimentation
$("#DisplayWindow_instr").show();
$("#StimCanvas").show();
$("#headboard").show();
$('#myProgress').hide();
document.getElementById("DisplayWindow").style = "background-color: white;"
if (practiceOn == 1) { startPractice(); } else { startTesting(); }
}
/*function startPractice (){
$("#PracticeEnd_notpass").hide();
$("#DisplayWindow").hide();
$("#DisplayWindow_instr").show();
$("#StimCanvas").show();
$("#headboard").show();
$('#myProgress').show();
save_blockNum = 1;
save_blockName = 'Practice';
OldOrNewList_prac=[];
OldList = [];
OldOrNewList = OldOrNewList_prac;
DisplaySetup();
test_accuracy = [];
}*/
function startTesting() {
$("#PracticeEnd").hide();
$("#DisplayWindow").show();
$("#DisplayWindow_instr").show();
$("#StimCanvas").show();
$("#headboard").show();
$('#myProgress').hide();
save_blockNum = 1;
save_blockName = 'Temporal';
OldList = [];;
DisplaySetup()
}
// A. START A TRIAL
function DisplaySetup() {
$("#TestScreen").show()
$("#Break").hide()
//clear and set up display
$("#DisplayWindow").hide();
document.getElementById("ResponseButton_instr").innerHTML = " ";
document.getElementById("ResponseButton").style = "background-color: white;"
//change headboard instruction
document.getElementById("headboard").innerHTML = viewingBlock_instr;// ccc
document.getElementById("headboard").style.fontSize = '100%'
//clean and set up canvas
ctx.clearRect(0, 0, CanvasHeight, CanvasWidth);
//DRAW BOXES AND SAVE LOCATIONS
var BoxCount = 0;
trial_img_loc = [];
trial_jitter_x = [];
trial_jitter_y = [];
trial_img_row_column = [];
for (var nbox = 1; nbox <= (7); nbox++) { //for each column
for (var nRow = 1; nRow <= (7); nRow++) { // for each row
// draw box to current loc
var jitterX = randomIntFromInterval(-CanvasHeight / 55, CanvasHeight / 55);
var jitterY = randomIntFromInterval(-CanvasHeight / 55, CanvasHeight / 55);
var xx = MarginLeft + (BoxSize * nbox) + GapSize * nbox + jitterX;
var yy = MarginUp + (BoxSize * nRow) + GapSize * nRow + jitterY;
if (IncludeBackGroundBoxes == 1) {
ctx.beginPath();
ctx.rect(xx, yy, BoxSize, BoxSize);
ctx.closePath();
ctx.lineWidth = 1;
ctx.stroke();
}
//save jtter for redrawing boxes
trial_jitter_x.push(jitterX);
trial_jitter_y.push(jitterY);
// save xy coor
trial_img_loc.push([xx, yy]);
trial_img_row_column.push([nRow, nbox])
}
}
ViewingBlock();
}
function ImageType(resp, id) {
// console.log("Response: " + (id >= 101 && resp || id < 101 && !resp) ? true : false);
if (id >= 51 && resp) {
// console.log("true");
imageTypeQuiz[0] += 1; // add one correct point
// document.getElementById('ResponseButton').style = "background-color: #6ed5fa";
// document.removeEventListener('keydown', function (event) { exit() })
return true;
} else if (id < 51 && !resp) {
// console.log("true");
imageTypeQuiz[0] += 1; // add one correct point
// document.getElementById('ResponseButton').style = "background-color: #6ed5fa";
// document.removeEventListener('keydown', function (event) { exit() })
return true;
} else if (id < 51 && resp || id >= 51 && !resp) {
// console.log('false');
imageTypeQuiz[1] += 1; // add one wrong point
// the goal is to have imageTypeQuiz = the number of images shown (50)
// document.getElementById('ResponseButton').style = "background-color: #6ed5fa";
// document.removeEventListener('keydown', function (event) { return; })
return false;
}
$(document).unbind('keyup', ImageType(300, false));
}
// show n images one by one, n = MemSetSize
function ViewingBlock() {
// loop func:Viewing Block until all target images are shown
if (viewImgCounter + 1 < MemSetSize) {
viewImgCounter++
// which image
thisImage = Tar_list[viewImgCounter];
thisImageID = thisImage.id; // find id of this image
thisImage = thisImage.GetImg;
// what location
itemLocInd_1st = randomIntFromInterval(0, Num_boxes - 1); // get a random location
// what time
TimeBarLoc_1st = (viewImgCounter + 1) / Tar_list.length * 100;
// LOAD IMAGE
GetThisImageLoc = trial_img_loc[itemLocInd_1st];
loadImage(thisImage, GetThisImageLoc);
// Remove Image after presentationtime
timer1 = setTimeout(function () { // after 3000ms
//clear present image
clearThisImage(GetThisImageLoc)
ViewingBlock();
}, PresentationTime);
// save to list
OldList.push([thisImage, thisImageID, itemLocInd_1st, viewImgCounter, TimeBarLoc_1st, ImageOnTime])
console.log("ID: " + thisImageID);
// new artificial and natural
// respbutton.addEventListener('click', (event) => {
// })
document.getElementById("ResponseButton_instr").innerHTML = "<p>Is this image natural (left arrow) or artificial (right arrow)?</p><br /><button id='left-arrow'> ←Natural</button><button id='right-arrow'>Artificial →</button>";
document.getElementById("ResponseButton_instr").style = "padding: 10px"
document.getElementById("ResponseButton").style = "background-color: #e0e6ed;"
function respNatural() {
// document.getElementById('ResponseButton').style = "background-color: #6ed5fa";
document.getElementById('left-arrow').style = "background-color: #f9fafc";
// $(document).unbind('keyup', respNatural); //QQQ
if (thisImageID >= 51) {
// console.log("correct, it is natural")
playSound_pos()
correctResponse(1);
return true;
} else if (thisImageID < 51) {
// console.log("incorrect, it is artificial")
playSound_neg()
correctResponse(2)
return true;
}
}
function respArtificial() {
// document.getElementById('ResponseButton').style = "background-color: #6ed5fa";
document.getElementById('right-arrow').style = "background-color: #f9fafc";
// $(document).unbind('keyup', respArtificial);
if (thisImageID < 51) {
// console.log("correct, it is artificial")
playSound_pos()
correctResponse(1);
return true;
} else if (thisImageID >= 51) {
// console.log("incorrect, it is natural")
playSound_neg()
correctResponse(2)
return true;
}
}
function correctResponse(correct) {
if (correct == 1) {
imageTypeQuiz[0] += 1;
// console.log("correct");
} else if (correct == 2) {
imageTypeQuiz[1] += 1;
// console.log("incorrect")
} else {
// console.log("no response")
}
// $(document).unbind('keyup', e => {if (e.keyCode == 37) respNatural(); else if (e.keyCode == 39) respArtificial(); else console.log("no unbinding")}); //QQQ
// $(document).unbind('keyup', respArtificial);
// $(document).unbind('keyup', respNatural);
// $(document).unbind('keyup');
}
$(document).bind('keyup', e => { if (e.keyCode == 37) { respNatural(); $(document).unbind('keyup'); } else if (e.keyCode == 39) { respArtificial(); $(document).unbind('keyup'); } else console.log("wrong key"); }); //QQQ
// $(document).bind('keyup', 'l', respArtificial); //QQQ
} else {
// if all targets have been shown, present testingBlock instruction
$("#DisplayWindow").hide();
$("#DisplayWindow_instr").hide();
$("#StimCanvas").hide();
$("#headboard").hide();
$('#myProgress').hide();
$('#responseButton').hide();
$("#viewingEnd").show();
document.getElementById("ResponseButton_instr").innerHTML = "There is nothing to do at the moment.";
}
}
function TestingBlock_setup() {
OldOrNewList_test = []; // 1 = new, 2 = old
var aaa = Array(MemSetSize).fill(1);
var bbb = Array(MemSetSize).fill(0);
OldOrNewList_test = OldOrNewList_test.concat(aaa, bbb);
OldOrNewList_test = shuffle(OldOrNewList_test);
$("#viewingEnd").hide();
$("#DisplayWindow").show();
$("#DisplayWindow_instr").show();
$("#responseButton").show();
$("#StimCanvas").show();
document.getElementById("headboard").innerHTML = " ";// ccc
$("#headboard").show();
$('#myProgress').show();
document.getElementById("ResponseButton_instr").innerHTML = "Click here if this is a new item";
document.getElementById("ResponseButton").style = "background-color:rgba(196, 182, 233, 0.932);"
TestingBlock()
var elem = document.getElementById("myBar");
var width = 100; // this is the width of the bar
elem.style.width = width + "%";
}
var view_timeStamp;
function TestingBlock() {
save_clickLoc = [-1, -1];
imgClick = 0; //reset click variable; 0 = no click has been registered
if (testingCounter + 1 < MemSetSize * 2) {
testingCounter++
//Reset previous location in case values are saved incorrectly
isOld_item = -1;
TimeBarLoc_1st = -1;
// 0 = new distractor
if (OldOrNewList_test[testingCounter] == 0) {
testingCounter_dis++
//get distractor image
thisImage = Dis_list[testingCounter_dis];
thisImageID = thisImage.id; // find id of this image
thisImage = thisImage.GetImg;
isOld_item = 0;
thisImage_viewInd = -1;
view_timeStamp = -1;
} else { //if 1 = old target
isOld_item = 1;
testingCounter_tar++;
// pick one old item randomly
var Rand_oldItem = randomIntFromInterval(0, OldList.length - 1);
var thisOldItem = OldList[Rand_oldItem]; // reture 2x2 array [thisImageID,itemLocInd_1st]
thisImage = thisOldItem[0];
thisImageID = thisOldItem[1];
itemLocInd_1st = thisOldItem[2];
thisImage_viewInd = thisOldItem[3];
TimeBarLoc_1st = thisOldItem[4];
view_timeStamp = thisOldItem[5];
// remove this image from old list
OldList.splice(Rand_oldItem, 1); //remove array with the current index, 1 stands for remove one array starting from 'Rand_oldItem' position
}
// LOAD IMAGES on the left of the screen and enable click
document.getElementById("DisplayWindow_img").innerHTML = "<img src = '" + thisImage + "' ImgId = '" + thisImageID + "' style = height:15%; width:15%" + ">"
test_timeStamp = (new Date()).getTime();
console.log('image test at ', test_timeStamp)
canvas.addEventListener('click', Click_canvas)
respbutton.addEventListener('click', Click_newLoc)
} else {
// get accuracy
var sum = test_accuracy.reduce(function (a, b) {
return a + b;
}, 0);
thisAccuracy = sum / test_accuracy.length * 100;
var roundedAccuracy = Math.round(thisAccuracy * 10) / 10;
FinalAccuracy.textContent = roundedAccuracy;
$("#TestingEnds").show();
$("#DisplayWindow").hide();
$("#DisplayWindow_instr").hide();
$("#StimCanvas").hide();
$("#headboard").hide();
$('#myProgress').hide();
document.getElementById("ResponseButton_instr").innerHTML = " ";
document.getElementById("ResponseButton").style = "background-color: white;"
}
}
function ExpEnd() {
$("#StimCanvas").hide();
$("#headboard").hide();
$("#TestScreen").hide();
$("#demographic").show();
document.getElementById("DisplayWindow").style = "background-color:rgba(196, 182, 233, 0.932);"
}
// -------------------------------------------------------------------------------------------------------------------------------------//
// -------------------------------------------------------- Helper functions -----------------------------------------------------------//
// -------------------------------------------------------------------------------------------------------------------------------------//
function moveBar() {
var elem = document.getElementById("myBar");
var width = (count_Allimages + 1) / OldOrNewList.length * 100; // this is the width of the bar
elem.style.width = width + "%";
//elem.innerHTML = width + "%";
}
function clearThisImage(GetThisImageLoc) {
ctx.clearRect(GetThisImageLoc[0] + BoxSize * 0.05, GetThisImageLoc[1] + BoxSize * 0.05, BoxSize * imageSizeParam, BoxSize * imageSizeParam);
}
function loadImage(thisImage, GetThisImageLoc) {
//Loading of the home test image
var showImage = new Image();
//drawing of the test image
showImage.onload = function () {
//draw background image
ctx.drawImage(showImage, GetThisImageLoc[0] + BoxSize * 0.05, GetThisImageLoc[1] + BoxSize * 0.05, BoxSize * imageSizeParam, BoxSize * imageSizeParam);
};