-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCL.osexp
982 lines (809 loc) · 29.4 KB
/
RCL.osexp
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
---
API: 2.1
OpenSesame: 3.2.5
Platform: nt
---
set width 1024
set uniform_coordinates yes
set title "Resetting Capacity Limitations"
set subject_parity even
set subject_nr 0
set start program
set sound_sample_size -16
set sound_freq 48000
set sound_channels 2
set sound_buf_size 1024
set sampler_backend legacy
set round_decimals 2
set mouse_backend legacy
set keyboard_backend legacy
set height 768
set fullscreen no
set form_clicks no
set foreground black
set font_underline no
set font_size 32
set font_italic no
set font_family mono
set font_bold no
set experiment_path "D:/User/OpenSesameProjects/RCL"
set disable_garbage_collection yes
set description "A template containing a practice and an experimental phase"
set coordinates uniform
set compensation 0
set color_backend legacy
set clock_backend legacy
set canvas_backend legacy
set bidi yes
set background grey
define inline_script Version
set description "Executes Python code"
___run__
var.program_version = "1.3"
"""
GitHub
Projekt: https://github.com/PsychoProjects/RCL
Source: https://github.com/PsychoProjects/RCL/blob/master/RCL.osexp
Dokumentation: https://github.com/PsychoProjects/RCL/wiki or
http://bit.ly/RCL-Project
--- Change Log ---
1.3
- Die Sprache wird jetzt beim Programmstart abgefragt
1.2.1
- Es wird jetzt mitprotokolliert, welche Ziffern der Proband eingegeben hat und ob diese in (T1,T2) enthalten sind
1.2
- Auswahl der Programm-Modi verändert
-- Dokumentation unter https://github.com/PsychoProjects/RCL/wiki/Programmablauf
-- Vortest und Nachtest aufgenommen
--- Um im Log-File mitprotokollieren zu können, ob es sich um einen Pre-Test oder einen Nach-Test handelt, muss dies explizit angegeben werden können
--- Daher werden jetz Vor- und Nach-Test zur Auswahl angeboten
--- Dadurch wird jetz im Logfile festgehalten, ob es sich um den Pre-test oder den Nach-Test handelt
-- Übungsphase als weiteren Modus aufgenommen
--- Damit kann der Proband sich erst einmal an das Programm und die Bedienung gewöhnen
--- Dies wird ebenfalls im Log-File protokolliert
-- Das Training ohne hervorgehobener Ziffer ist entfallen
- <intern> Die Rundenzahlen können jetzt für jeden Modus separat festgelegt werden (global_settings)
- <intern> Strings auf Unicode umgestellt
1.1.1
- <intern> Dokumentation der Programmstruktur hinzugefügt: https://github.com/PsychoProjects/RCL/wiki/Programmstruktur
1.1
- Die Eingabe der Ziffern kann in beliebiger Reihenfolge stattfinden
- Größe der Stimuli auf 54 erhöht
- Standardfarbe für den salienten Stimulus auf blau geändert
- Runden eingeführt
-- Die Anzahl der Runden wird in den global_settings festgelegt
-- Vor jeder Runde erhält der Proband eine Meldung, in welcher Runde er sich befindet und wie viele Runden noch vor ihm liegen
- Die Registrierung neuer Sprachen vereinfacht
1.0.2
- <intern> Den Code etwas gesäubert / refactored
1.0.1
- <intern> Anzeigeroutine für die UI-Texte zentralisiert
1.0 RC2
- Support für mehrsprachige Dialoge eingeführt. Die Sprache kann in den global_settings eingestellt werden.
-- aktuell werden Deutsch (Languages.DE) und Englisch (Languages.EN) unterstützt
- <intern> Programm vereinfacht, in dem unnötige Loops entfernt wurden
0.7 RC1
- Font-Size vergrößert, damit die Stimuli besser zu erkennen sind.
-- https://github.com/AchimImKaff/RCL/issues/2#issue-377982251
-- Außerdem sollte damit die Größe der Stimuli bei allen Back-Ends gleich sein
-- Die Definition des Font-Size findet sich im global_settings_script --> [fontSize]
- <intern> Die Anzahl der Durchläufe wird jetzt ebenfalls im global_settings_script festgelegt --> [numOfTrials]
- <intern> Die durchschnittlichen Anzeigedauern (average_letter_duration, average_total_duration) werden mit in die Log-Datei geschrieben.
0.6
- Bugfix: die Preparation-Section wird offenbar unabhängig von der Bedingung immer ausgeführt.
-- Dies führte seltsamerweise bei Back-Ends <> Psycho zum Umschalten des Grafikmodus und der Anzeige-Screen verschwand im Hintergrund.
-- Daher wird dort jetzt am Anfang das Backend geprüft (if isPsychoBackend == 0|1)
- Da 15ms offenbar für viele Monitore zu kurz ist, wurde die Anzeigedauer für die Buchstaben auf 33ms (2 Frames) angepasst und ISI auf 66ms
- <intern> Minor Bugfix: Fixation-point: es lagen zwei FP übereinander (weiß und schwarz)
0.5
- Unterstützung auch für andere Backends als PsychoPy eingeführt (show_stim_any_backend, show_stim_psycho_backend)
-- hierfür Code nach create_stim_list verlagert und Hilfsfunktionen (helper_functions) eingeführt
- die zentralen Parameter für die Anzeigedauer der Stimuli ins global_settings_script verlegt
- Anzeigefarben für die Stimuli zentral im global_settings_script festgelegt
- die Gesamtzeit (SOA) wird ebenfalls in die Log-Datei geschrieben
- Bugfix: Es konnten immer noch B, I, O, Q auftauchen
- Versionierung mit Git via GitHub auf https://github.com/AchimImKaff/RCL
0.4
- letter duration auf 15 ms und ISI auf 75 ms (wie bei Shapiro)
- Durchlaufzahl: 90 statt 10 (wie bei Shapiro)
- Der Begrüßungstext ist jetzt ebenfalls in der 2. Person Singular
0.3
- Einführung eines Change Log
- Anzeige einer Versionsnummer im Start-Dialog
- alle Dialoge jetzt auf Deutsch
- Die Ziffern 0 und 1 und die Buchstaben B, I, O und Q werden nicht mehr verwendet.
- Die tatsächlichen Anzeigezeiten der Buchstaben werden in die Log-Datei geschrieben
"""
__end__
set _prepare ""
define inline_script ask_for_T1_and_T2
set description "Executes Python code"
___run__
from sets import Set
allowed_keys = ['1','2','3','4','5','6','7','8','9','0']
k1 = showText(curLanguage.ask_for_T1_text(), wait_for_key = True, keylist = allowed_keys)
k2 = showText(curLanguage.ask_for_T2_text(), wait_for_key = True, keylist = allowed_keys)
var.user_input1 = char2int(k1)
var.user_input2 = char2int(k2)
s1 = Set([var.user_input1, var.user_input2])
s2 = Set([var.T1, var.T2])
var.correct_response = (s1 == s2)
var.correct_user_input1 = var.user_input1 in s2
var.correct_user_input2 = var.user_input2 in s2
__end__
set _prepare ""
define form_multiple_choice choice_of_mode
set timeout infinite
set spacing 10
set question "[com_caption]"
set options "[com_selection]"
set margins "50;50;50;50"
set form_var chosen_mode
set form_title "RCL-Experiment Version [program_version]"
set description "A simple multiple choice item"
set button_text Ok
set allow_multiple no
set advance_immediately yes
set _theme gray
define inline_script create_stim_list
set description "Executes Python code"
set _run ""
___prepare__
"""
Creates the list of stimuli including T1 and T2: stim_list[]
"""
import random
import string
# The position of T1 is random between 7 and 15. Note that the first position is
# 0, so the position indicates the number of preceding stimuli.
var.T1_pos = random.randint(7, 15)
# the position of T2 varies between shortSOA and longSOA
var.T2_pos = var.T1_pos + var.lag
# The maximum lag, i.e. the number of letters that follow T1.
var.max_lag = 8
# The length of the stream is the position of T1 + the maximum lag + 1. We need
# to add 1, because we count starting at 0, so the length of a list is always
# 1 larger than its maximum index.
var.stream_len = var.T1_pos + var.max_lag + 1
# We take all uppercase letters, which have been predefined in the `string`
# module. Converting to a `list` creates a list of characters.
letters = list(string.ascii_uppercase)
letters.remove('B')
letters.remove('I')
letters.remove('O')
letters.remove('Q')
# As we remove 4 letters, there are not enough letters left to fill the sequence. Hence we add it twice.
letters += letters;
# Randomly sample a `stream_len` number of letters
stim_list = random.sample(letters, var.stream_len)
# T1 is a random digit at position T1_pos
var.T1 = "{0}".format(random.randint(2, 9))
stim_list[var.T1_pos] = var.T1
# T2 is a random digit at position T2_pos
var.T2 = "{0}".format(random.randint(2, 9))
stim_list[var.T2_pos] = var.T2
__end__
define inline_script end_text
set description "Executes Python code"
set _run "showText(curLanguage.end_text())"
set _prepare ""
define inline_script evaluate_choice
set description "Executes Python code"
___run__
# Evaluate the choice
assert(var.chosen_mode != "no") # a choice has to be made
if var.chosen_mode == curLanguage.choice_of_mode_text_experiment_pre_test():
var.isPreTest = 1
var.num_of_laps = num_of_laps_experiment
if var.chosen_mode == curLanguage.choice_of_mode_text_experiment_post_test():
var.isPostTest = 1
var.num_of_laps = num_of_laps_experiment
if var.chosen_mode == curLanguage.choice_of_mode_text_excercise():
var.isExcercise = 1
var.num_of_laps = num_of_laps_excercise
if var.chosen_mode == curLanguage.choice_of_mode_text_training_salient():
var.isTraining = 1
var.isSalient = 1
var.num_of_laps = num_of_laps_training
# There are two ways to create the stimuli implemented in this program depending on the chosen backend
if var.canvas_backend == "psycho":
var.isPsychoBackend = 1
else:
var.isPsychoBackend = 0
# Delete workaround variables
del var.com_caption
del var.com_selection
__end__
___prepare__
var.isTraining = 0
var.isPreTest = 0
var.isPostTest = 0
var.isSalient = 0
var.isExcercise = 0
__end__
define inline_script evaluate_language_selection
set description "Executes Python code"
___run__
del(var.language_options) # not needed anymore
for language in LanguageFactory():
if var.selected_language == language.language_name():
var.dialog_language = language.language_id()
assert(not var.dialog_language is None)
__end__
set _prepare ""
define sequence experiment
set flush_keyboard yes
set description "A sequence containing a single block of trials followed by feedback to the participant"
run experiment_instructions always
run reset_statistics always
run reset_feedback always
run experiment_laps_loop always
run give_feedback always
define loop experiment_block_loop
set source_file ""
set source table
set skip 0
set repeat 1
set order random
set offset no
set item trial_sequence
set description "A single block of trials"
set cycles 10
set continuous no
set column_order ""
set break_if_on_first yes
set break_if never
setcycle 0 lag "[shortSOA]"
setcycle 1 lag "[shortSOA]"
setcycle 2 lag "[shortSOA]"
setcycle 3 lag "[shortSOA]"
setcycle 4 lag "[shortSOA]"
setcycle 5 lag "[longSOA]"
setcycle 6 lag "[longSOA]"
setcycle 7 lag "[longSOA]"
setcycle 8 lag "[longSOA]"
setcycle 9 lag "[longSOA]"
run trial_sequence
define inline_script experiment_instructions
set description "Executes Python code"
set _run "showText(curLanguage.experiment_instructions_text())"
set _prepare ""
define loop experiment_laps_loop
set source_file ""
set source table
set repeat "[num_of_laps]"
set order random
set description "Repeatedly runs another item"
set cycles 1
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 empty_column ""
run experiment_laps_sequence
define sequence experiment_laps_sequence
set flush_keyboard yes
set description "Runs a number of items in sequence"
run lap_info_text always
run experiment_block_loop always
define sketchpad fixation_point
set start_response_interval no
set duration 955
set description "Displays stimuli"
draw fixdot color=black show_if=always style=default x=0 y=0 z_index=0
define inline_script give_feedback
set description "Executes Python code"
___run__
showText(curLanguage.feedback_text().format(var.acc))
__end__
set _prepare ""
define inline_script global_settings
set description "Executes Python code"
___run__
# initializing the language
curLanguage = LanguageFactory().language(var.dialog_language)
# Just a workaround: standard os-diaglogs can't handle function calls. Therefore we put the strings for the choice_of_mode dialog into global variables.
var.com_caption = curLanguage.choice_of_mode_text_caption()
var.com_selection = u"{0}\n{1}\n{2}\n{3}".format(
curLanguage.choice_of_mode_text_excercise(),
curLanguage.choice_of_mode_text_experiment_pre_test(),
curLanguage.choice_of_mode_text_training_salient(),
curLanguage.choice_of_mode_text_experiment_post_test())
__end__
___prepare__
"""
global settings for experiment and training
"""
# Duration that letters are shown
# it may be that they must be adjusted to a value compatible with refresh rate of the monitor
var.letter_dur = 33
var.isi = 66 # inter sitmulus interval
# number of laps and trials used in experiment and training
# each lap has 10 trials
num_of_laps_experiment = 9 # 90 stimulus sequences corresponding to Raymond & Shapiro
num_of_laps_excercise = 1
num_of_laps_training = 5
# Position of T2 in relation to T2 according to experiment 1
# SOA = stimulus onset asynchrony
var.shortSOA = 2
var.longSOA = 6
# settings for character presentation
var.standardColor = 'white'
var.salientColor = 'blue'
var.fontSize = 54
__end__
define inline_script helper_functions
set description "Executes Python code"
___run__
import numpy
""" cleanString
Removing CR/LF from a string
in: s -> str
return: -> str
"""
def cleanString(s):
return(str(s).replace("\r", "").replace("\n", ""))
""" calcDuration
Calculating a list of durations from two lists of times and formatting it as a string without CR/LF
in: list1 -> [], list2 -> []
return: String of durations -> str, average_duration -> int
"""
def calcDuration (list1, list2):
time1 = numpy.array(list1)
time2 = numpy.array(list2)
duration = time2 - time1
average_duration = int(numpy.average(duration))
return(cleanString(duration), average_duration)
""" showText
Showing a dialog with text
in: text -> str
text to be displayed
in: wait_for_key -> bool
if True the text is displayed until keyboard input
return: -> str
key pressed by user (if any)
"""
def showText(text = "", wait_for_key = True, keylist=[]):
textCanvas = Canvas()
textCanvas.text(text, font_size = curLanguage.font_size())
textCanvas.show()
if wait_for_key:
keyboard = Keyboard()
keyboard.flush()
if keylist != []:
keyboard.keylist = keylist
s, t = keyboard.get_key()
return(s)
""" char2int
converts a character to an integer value
in: c -> char
return: -> int
the value represented by c as integer ('1' -> 1)
"""
def char2int(c):
return(ord(c)-ord('0'))
__end__
set _prepare ""
define inline_script language_english
set description "Executes Python code"
set _run ""
___prepare__
class EnglishLanguage(ILanguageSupport):
def __init__(self):
pass
def language_id(self):
return(Languages.EN)
def language_name(self):
return(u"English")
def experiment_instructions_text(self):
return(u"""
INSTUCTIONS
You will see a series of letters and two digts at randomly chosen positions.
Afterwards, you will be asked to enter these two digits.
Press any key to continue...
""")
def training_instructions_text(self):
return(u"""
INSTUCTIONS
You will see a series of letters and two digts at randomly chosen positions.
The second digit will always appear two letters after the first one.
Afterwards, you will be asked to enter these two digits.
Press any key to continue...
""")
def experiment_lap_info_text(self):
return(u"""
Lap {0} of {1}
Press any key to continue...
""")
def choice_of_mode_text_caption(self):
return(u"Please select")
def choice_of_mode_text_experiment_pre_test(self):
return(u"Experiment (pre-test)")
def choice_of_mode_text_experiment_post_test(self):
return(u"Experiment (post_test)")
def choice_of_mode_text_excercise(self):
return(u"Excercise")
def choice_of_mode_text_training_salient(self):
return(u"Training with salient digit")
def choice_of_mode_text_training_nonsalient(self):
return(u"Training with non-salient digit")
def ask_for_T1_text(self):
return(u"Please type the digits")
def ask_for_T2_text(self):
return(u"And the other digit?")
def feedback_text(self):
return(u"""
End of block
Your accuracy was {0}%
Press any key to continue...
""")
def end_text(self):
return(u"Press any key to finish...")
__end__
define inline_script language_german
set description "Executes Python code"
set _run ""
___prepare__
class GermanLanguage(ILanguageSupport):
def __init__(self):
pass
def language_id(self):
return(Languages.DE)
def language_name(self):
return(u"Deutsch")
def experiment_instructions_text(self):
return(u"""
ANLEITUNG
In einer Serie von Buchstaben werden zwei Ziffern an zufällig ausgewählten Positionen gezeigt.
Bitte identifiziere im Anschluss die beiden Zahlen per Tastatureingabe.
Weiter mit beliebiger Taste...
""")
def training_instructions_text(self):
return(u"""
TRAININGS-ANLEITUNG
In einer Serie von Buchstaben werden zwei Ziffern an zufällig ausgewählten Positionen gezeigt.
Die zweite Ziffer erscheint immer zwei Zeichen nach der ersten.
Bitte identifiziere im Anschluss die beiden Zahlen per Tastatureingabe.
Weiter mit beliebiger Taste...
""")
def choice_of_mode_text_caption(self):
return(u"Bitte wählen")
def experiment_lap_info_text(self):
return(u"""
Runde {0} von {1}
Weiter mit beliebiger Taste...
""")
def choice_of_mode_text_experiment_pre_test(self):
return(u"Experiment (Vor-Test)")
def choice_of_mode_text_experiment_post_test(self):
return(u"Experiment (Nach-Test)")
def choice_of_mode_text_excercise(self):
return(u"Übungsdurchgang")
def choice_of_mode_text_training_salient(self):
return(u"Training mit hervorgehobener Ziffer")
def choice_of_mode_text_training_nonsalient(self):
return(u"Training ohne hervorgehobener Ziffer")
def ask_for_T1_text(self):
return(u"Bitte gib ein, welche Ziffern du gesehen hast:")
def ask_for_T2_text(self):
return(u"Und welche Ziffer noch?")
def feedback_text(self):
return(u"""
Ende des Blocks
Die Trefferquote lag bei {0}%
Weiter mit beliebiger Taste...
""")
def end_text(self):
return(u"Zum Beenden eine beliebige Taste drücken...")
__end__
define inline_script language_selection_string
set description "Executes Python code"
___run__
var.language_options = "" # string used to show language selection options.
for language in LanguageFactory():
if var.language_options != "":
var.language_options += "\n"
var.language_options += language.language_name()
__end__
set _prepare ""
define sequence language_settings
set flush_keyboard yes
set description "Runs a number of items in sequence"
run language_support always
run language_german always
run language_english always
run language_selection_string always
run select_language always
run evaluate_language_selection always
define inline_script language_support
set description "Executes Python code"
___run__
# register all UI languages
LanguageFactory.register(GermanLanguage())
LanguageFactory.register(EnglishLanguage())
__end__
___prepare__
"""
Module for handling UI language selection.
Adding a new language is easy:
1. add a new language selector to the Languages enum (e.g. IT = 3)
2. add a new class language_<language> derived from ILanguageSupport and overwrite the text-methods.
Probably the easiest way is to copy an existing class like language_german.
3. register the new language in rhe Run-section of this script
See also https://github.com/PsychoProjects/RCL/wiki/Anlegen-einer-neuen-Sprache
"""
from enum import Enum
class Languages(Enum):
NONE = 0
DE = 1
EN = 2
# Factory class to create language instances
class LanguageFactory:
__languageDict = {}
def __init__(self):
pass
# nothing to to
@classmethod
def register(self, language_obj):
LanguageFactory.__languageDict[language_obj.language_id()] = language_obj
def language(self, languageID = Languages.DE):
return(LanguageFactory.__languageDict[languageID])
def __iter__(self):
self.__iter = 0
return(self)
def next(self):
if self.__iter >= len(LanguageFactory.__languageDict.keys()):
raise StopIteration
else:
v = LanguageFactory.__languageDict.values()[self.__iter]
self.__iter += 1
return(v)
# base class for language support classes
class ILanguageSupport:
def __init__(self):
print(u"""Missing Language""")
def language_id(self):
return(Languages.NONE)
def language_name(self):
return(u"None")
def font_size(self):
return(24)
def experiment_instructions_text(self):
return(u"""Missing experiment_instructions_text""")
def training_instructions_text(self):
return(u"""Missing training_instructions_text""")
def experiment_lap_info_text(self):
return(u"""Missing experiment_lap_info_text""")
def choice_of_mode_text_caption(self):
return(u"Missing choice_of_mode_text_caption")
def choice_of_mode_text_experiment_pre_test(self):
return(u"Missing choice_of_mode_text_experiment_pre_test")
def choice_of_mode_text_experiment_post_test(self):
return(u"Missing choice_of_mode_text_experiment_post_test")
def choice_of_mode_text_excercise(self):
return(u"Missing choice_of_mode_text_excercise")
def choice_of_mode_text_training_salient(self):
return(u"Missing choice_of_mode_text_training_salient")
def choice_of_mode_text_training_nonsalient(self):
return(u"Missing choice_of_mode_text_training_nonsalient")
def ask_for_T1_text(self):
return(u"Missing ask_for_T1_text")
def ask_for_T2_text(self):
return(u"Missing ask_for_T2_text")
def feedback_text(self):
return(u"Missing feedback_text")
def end_text(self):
return(u"Missing end_text")
__end__
define inline_script lap_info_text
set description "Executes Python code"
___run__
var.lap_counter += 1
showText(curLanguage.experiment_lap_info_text().format(var.lap_counter, var.num_of_laps))
__end__
set _prepare ""
define logger logger
set description "Logs experimental data"
set auto_log yes
define sequence preparation
set flush_keyboard yes
set description "Runs a number of items in sequence"
run language_settings always
run global_settings always
run choice_of_mode always
run evaluate_choice always
run helper_functions always
define sequence program
set flush_keyboard yes
set description "The main sequence of the experiment"
run Version always
run preparation always
run experiment "[isTraining] = 0"
run training "[isTraining] = 1"
run end_text always
define reset_feedback reset_feedback
set description "Resets the feedback variables, such as 'avg_rt' and 'acc'"
define inline_script reset_statistics
set description "Executes Python code"
___run__
# statistics are maintained manually
var.acc = 0
# resetting the lap-counter
var.lap_counter = 0
var.count_correct_answers = 0
var.count_loops = 0
__end__
set _prepare ""
define form_multiple_choice select_language
set timeout infinite
set spacing 10
set question "Select a language"
set options "[language_options]"
set margins "50;50;50;50"
set form_var selected_language
set form_title "RCL-Experiment Version [program_version]"
set description "A simple multiple choice item"
set button_text Ok
set allow_multiple no
set advance_immediately yes
set _theme gray
define inline_script show_stim_any_backend
set description "Executes Python code"
___run__
"""
Creates canvas from the list of stimuli (stim_list) and puts them onto the screen
"""
create_canvas()
show_canvas()
__end__
___prepare__
if var.isPsychoBackend == 0:
import time
# Create an empty list for the canvas objects.
letter_canvas_list = []
# We also need to create a blank canvas to show during the inter-stimulus interval:
blank_canvas = canvas()
"""
Creates a list of canvas containing stimuli
"""
def create_canvas():
# prepare a list of canvas
for i, stim in enumerate(stim_list):
# Create a `canvas` object.
letter_canvas = canvas()
var.T2_color = var.standardColor
# while training with salient color, T2 is printed in red
if (var.isTraining == 1) and (var.isSalient == 1):
if i == var.T2_pos:
var.T2_color = var.salientColor
letter_canvas.set_fgcolor(var.T2_color)
# Draw the letter!
letter_canvas.text(stim, font_size = var.fontSize)
# And add the canvas to the list.
letter_canvas_list.append(letter_canvas)
"""
Puts the canvas onto the screen using the defined timing
"""
def show_canvas():
# Lists for timestamps
l_letter_time = []
l_blank_time = []
# Finally putting the canvas onto the screen
for letter_canvas in letter_canvas_list:
t1 = letter_canvas.show()
l_letter_time.append(t1)
clock.sleep(var.letter_dur)
t2 = blank_canvas.show()
l_blank_time.append(t2)
clock.sleep(var.isi)
(var.actual_letter_duration, var.average_letter_duration) = calcDuration(l_letter_time, l_blank_time)
__end__
define inline_script show_stim_psycho_backend
set description "Executes Python code"
___run__
"""
Creates psycho-visuals from the list of stimuli (stim_list) and puts them onto the screen
"""
create_stim_visuals()
show_stim_visuals()
__end__
___prepare__
if var.isPsychoBackend == 1:
import time
from psychopy import visual
textstim_list = []
"""
Creates a list of visuals containing stimuli
"""
def create_stim_visuals():
# prepare a list of visuals
for i, stim in enumerate(stim_list):
color = var.standardColor
# while training with salient color, T2 is printed in [salientColor]
if (var.isTraining == 1) and (var.isSalient == 1):
if i == var.T2_pos:
color = var.salientColor
# All stimuli require an psychopy.visual.Window object to be passed as first
# argument. In OpenSesame, this object is available as `win`.
textstim = visual.TextStim(win, text=stim, color=color, height = var.fontSize)
textstim_list.append(textstim)
"""
Puts the visuals onto the screen using the defined timing
"""
def show_stim_visuals():
# Lists for timestamps
l_letter_time = []
l_blank_time = []
l_total_time = []
# Finally putting the visuals onto the screen
for textstim in textstim_list:
textstim.draw()
win.flip()
l_letter_time.append(time.clock())
clock.sleep(var.letter_dur)
win.flip()
l_blank_time.append(time.clock())
clock.sleep(var.isi)
l_total_time.append(time.clock())
(var.actual_letter_duration, var.average_letter_duration) = calcDuration(l_letter_time, l_blank_time)
(var.actual_total_duration, var.average_total_duration) = calcDuration(l_letter_time, l_total_time)
__end__
define sequence training
set flush_keyboard yes
set description "Runs a number of items in sequence"
run training_instructions always
run reset_statistics always
run reset_feedback always
run training_laps_loop always
run give_feedback always
define loop training_block_loop
set source_file ""
set source table
set repeat 10
set order random
set description "Repeatedly runs another item"
set cycles 1
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 lag "[shortSOA]"
run trial_sequence
define inline_script training_instructions
set description "Executes Python code"
set _run "showText(curLanguage.training_instructions_text())"
set _prepare ""
define loop training_laps_loop
set source_file ""
set source table
set repeat "[num_of_laps]"
set order random
set description "Repeatedly runs another item"
set cycles 1
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 empty_column ""
run training_laps_sequence
define sequence training_laps_sequence
set flush_keyboard yes
set description "Runs a number of items in sequence"
run lap_info_text always
run training_block_loop always
define sequence trial_sequence
set flush_keyboard yes
set description "A single trial"
run fixation_point always
run create_stim_list always
run show_stim_psycho_backend "[isPsychoBackend] = 1"
run show_stim_any_backend "[isPsychoBackend] = 0"
run ask_for_T1_and_T2 always
run update_statistics always
run logger always
define inline_script update_statistics
set description "Executes Python code"
___run__
if var.correct_response == "yes":
var.count_correct_answers += 1
var.count_loops += 1
var.acc = 100.0 * var.count_correct_answers / var.count_loops
__end__
set _prepare ""