-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRate.osexp
687 lines (636 loc) · 19.3 KB
/
Rate.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
---
API: 2
OpenSesame: 3.1.6
Platform: posix
---
set width 1024
set uniform_coordinates yes
set title "New experiment"
set subject_parity even
set subject_nr 0
set start experiment
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 white
set font_underline no
set font_size 18
set font_italic no
set font_family mono
set font_bold no
set experiment_path "/Users/cyrus/src/FunnyNonWords"
set disable_garbage_collection yes
set description "The main experiment item"
set coordinates uniform
set compensation 0
set color_backend legacy
set clock_backend legacy
set canvas_backend legacy
set bidi no
set background black
define form_text_input Directory
set timeout infinite
set spacing 10
set rows "1;1;6"
set only_render no
set margins "50;50;50;50"
set form_var dire
set form_title Title
__form_question__
Where is your NonFunnyWords file?
(Ex:/home/bob/GitHub/)
__end__
set cols 1
set _theme gray
widget 0 0 1 1 label text="[form_title]"
widget 0 1 1 1 label center=no text="[form_question]"
widget 0 2 1 1 text_input focus=yes return_accepts=yes stub="" var="[form_var]"
define form_multiple_choice TestingFeatures
set timeout infinite
set spacing 10
set question "Would you like to run only one section of the experiment?"
__options__
Pick
Rate
Both
__end__
set margins "50;50;50;50"
set form_var toRun
set form_title "Form title"
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 createFeedbackPick
set description "Executes Python code"
___run__
import csv
import os
num = var.subject_nr
dirPath = var.experiment_path
group = var.subGroup
var.timekeeper = 0
header = ['stringA', 'stringB', 'itemNum', 'type','choice']
format_string = "{:<10}{:<10}{:<10}{:<10}{:<10}"
location = dirPath + '/Files/DATA/Pick/participant' + str(num) + 'DATA.txt'
var.path = dirPath + '/Files/CSV/Pick/stim' + group + '/participant' + str(num) + '.csv'
with open(location, 'a') as file:
file.write(format_string.format(*header))
file.write('\n')
__end__
set _prepare ""
define inline_script createFeedbackRate
set description "Executes Python code"
___run__
import csv
import os
import serial as s
num = var.subject_nr
dirPath = var.experiment_path
group = var.subGroup
var.timekeeper = 0
var.stimCounter = 1
header = ['stringA', 'rate', 'time']
format_string = "{:<10}{:<10}{:<10}"
location = dirPath + '/Files/DATA/Rate/participant' + str(num) + 'DATA.txt'
var.path = dirPath + '/Files/CSV/stims' + group + '/rate/participant' + str(num) + '.csv'
with open(location, 'a') as file:
file.write(format_string.format(*header))
file.write('\n')
var.ser = s.Serial('/dev/cu.usbserial-ALHCTCQ',57600)
__end__
set _prepare ""
define inline_script displayPracWords
set description "Executes Python code"
___run__
import string
import csv
import time as t
#Get all CSV colloms
strA = var.stringA
strB = var.stringB
inum = var.itemNumber
typpe = var.type
format_string = "{:<10}{:<10}{:<10}{:<10}{:<10}"
###################
def getInput():
my_keyboard = keyboard()
k = my_keyboard.get_key(keylist=[u'left', u'right'])
return k
def writeResults(choice):
result = [strA, strB, inum, typpe, choice]
with open(location, 'a') as file:
file.write(format_string.format(*result))
file.write('\n')
def displayWord():
string = strA + " " + strB
my_canvas.text(string)
my_canvas.show()
key = getInput()
my_canvas.clear()
print(key)
if key[0] == u'left':
my_canvas.text(strA)
else:
my_canvas.text(strB)
my_canvas.show()
t.sleep(.5)
my_canvas = canvas()
my_canvas.set_font('mono', 30 )
displayWord()
__end__
set _prepare ""
define inline_script displayPracWords_1
set description "Executes Python code"
___run__
import string
import csv
import time as t
#Get all CSV colloms
strA = var.stringA
strB = var.stringB
inum = var.itemNumber
typpe = var.type
format_string = "{:<10}{:<10}{:<10}{:<10}{:<10}"
###################
def getInput():
my_keyboard = keyboard()
k = my_keyboard.get_key(keylist=[u'left', u'right'])
return k
def writeResults(choice):
result = [strA, strB, inum, typpe, choice]
with open(location, 'a') as file:
file.write(format_string.format(*result))
file.write('\n')
def displayWord():
string = strA + " " + strB
my_canvas.text(string)
my_canvas.show()
key = getInput()
my_canvas.clear()
print(key)
if key[0] == u'left':
my_canvas.text(strA)
else:
my_canvas.text(strB)
my_canvas.show()
t.sleep(.5)
my_canvas = canvas()
my_canvas.set_font('mono', 30 )
displayWord()
__end__
set _prepare ""
define inline_script displayWords
set description "Executes Python code"
___run__
import string
import csv
import time as t
#Get all CSV colloms
strA = var.stringA
strB = var.stringB
inum = var.itemNumber
typpe = var.type
format_string = "{:<10}{:<10}{:<10}{:<10}{:<10}{:<10}"
###################
#main
my_canvas = canvas()
my_canvas.set_font('mono', 30 )
displayWord()
#####
#functions
def getInput(): #gets input from keyboard | k[0] = (right or left), k[1] = (timestamp)
my_keyboard = keyboard()
k = my_keyboard.get_key(keylist=[u'left', u'right'])
return k
def toEEG(signal): #This is were a signal would be sent to the eeg in later version
#do nothing
def writeResults(choice): #Writes all data to .../DATA/participant' + str(num) + 'DATA.txt'
result = [strA, strB, inum, typpe, choice[0], (choice[1]-var.timekeeper)]
with open(location, 'a') as file:
file.write(format_string.format(*result))
file.write('\n')
var.timekeeper = choice[1]
def displayWord():#Display canvas and calls all other functions
string = strA + " " +strB
my_canvas.text(string)
my_canvas.show()
toEEG(inum)
key = getInput()
my_canvas.clear()
if key[0] == u'left':
my_canvas.text(strA)
else:
my_canvas.text(strB)
writeResults(key)
my_canvas.show()
toEEG(0)
t.sleep(.5)
##########
__end__
set _prepare ""
define inline_script displayWords_1
set description "Executes Python code"
___run__
import string
import csv
import time as t
#Get all CSV colloms
strA = var.stringA
strB = var.stringB
inum = var.itemNumber
typpe = var.type
format_string = "{:<10}{:<10}{:<10}{:<10}{:<10}{:<10}"
###################
#main
my_canvas = canvas()
my_canvas.set_font('mono', 30 )
displayWord()
#####
#functions
def getInput(): #gets input from keyboard | k[0] = (right or left), k[1] = (timestamp)
my_keyboard = keyboard()
k = my_keyboard.get_key(keylist=[u'left', u'right'])
return k
def toEEG(signal): #This is were a signal would be sent to the eeg in later version
print("Signal sent: " + signal)
def writeResults(choice): #Writes all data to .../DATA/participant' + str(num) + 'DATA.txt'
result = [strA, strB, inum, typpe, choice[0], (choice[1]-var.timekeeper)]
with open(location, 'a') as file:
file.write(format_string.format(*result))
file.write('\n')
var.timekeeper = choice[1]
def displayWord():#Display canvas and calls all other functions
string = strA + " " +strB
my_canvas.text(string)
my_canvas.show()
toEEG(str(inum) + "has started")
key = getInput()
my_canvas.clear()
if key[0] == u'left':
my_canvas.text(strA)
else:
my_canvas.text(strB)
writeResults(key)
my_canvas.show()
toEEG(str(inum) + " has ended")
t.sleep(.5)
##########
__end__
set _prepare ""
define inline_script ending
set description "Executes Python code"
set _run ""
set _prepare ""
define loop expLoop_Pick
set source_file "[path]"
set source file
set repeat 1
set order sequential
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 displayWords
define loop expLoop_Pick_1
set source_file "[path]"
set source file
set repeat 1
set order sequential
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 displayWords_1
define sequence experiment
set flush_keyboard yes
set description "Runs a number of items in sequence"
run subjectCorrectBlock "[subject_nr] > 0 and [subject_nr] <= 60"
run subjectNumError "[subject_nr] <= 0 or [subject_nr] > 60"
define sequence gap
set flush_keyboard yes
set description "Runs a number of items in sequence"
define notepad getting_started
__note__
Welcome to OpenSesame 3.1 "Jazzy James"!
If you are new to OpenSesame, it is a good idea to follow one of the tutorials,
which can be found on the documentation site:
- <http://osdoc.cogsci.nl/>
You can also check out the examples. These can be opened via:
- Menu -> Tools -> Example experiments.
And feel free to ask for help on the forum:
- <http://forum.cogsci.nl/>
Have fun with OpenSesame!
__end__
set description "A simple notepad to document your experiment. This plug-in does nothing."
define inline_script init_time
set description "Executes Python code"
___run__
var.timekeeper=var.time_pracTrial
__end__
set _prepare ""
define inline_script initialize_time
set description "Executes Python code"
set _run ""
set _prepare ""
define sketchpad instuctAgain
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=20 html=yes show_if=always text="Instuctions:<br />Choice the funniest word by<br />press either the left or right arrow key.<br />________________________ <br /><br />The real trial is about to start. <br />There wil be 60 sets of word.<br />" x=0 y=-32 z_index=0
define sketchpad instuctAgain_1
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=20 html=yes show_if=always text="Instuctions:<br />Choice the funniest word by<br />press either the left or right arrow key.<br />________________________ <br /><br />The real trial is about to start. <br />There wil be 60 sets of word.<br />" x=0 y=-32 z_index=0
define sketchpad instuctions
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=20 html=yes show_if=always text="Instuctions:<br />Choice the funniest word by<br />press either the left or right arrow key. <br />______________________________<br /><br />You will have 5 pactice words.<br />Afterwards a message will notify you <br />the real trial is starting.<br />" x=0 y=0 z_index=0
define sketchpad instuctions_1
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=20 html=yes show_if=always text="Instuctions:<br />Choice the funniest word by<br />press either the left or right arrow key. <br />______________________________<br /><br />You will have 5 pactice words.<br />Afterwards a message will notify you <br />the real trial is starting.<br />" x=0 y=0 z_index=0
define inline_script new_inline_script
set description "Executes Python code"
___run__
mycanvas = canvas()
mycanvas.text(var.toRun)
mycanvas.show()
__end__
set _prepare ""
define keyboard_response new_keyboard_response
set timeout infinite
set flush yes
set duration keypress
set description "Collects keyboard responses"
set correct_response no
set allowed_responses ",;."
define logger new_logger
set description "Logs experimental data"
set auto_log yes
define mouse_response new_mouse_response
set timeout infinite
set show_cursor yes
set flush yes
set duration mouseclick
set description "Collects mouse responses"
define sequence new_sequence
set flush_keyboard yes
set description "Runs a number of items in sequence"
run welcome always
define sequence new_sequence_1
set flush_keyboard yes
set description "Runs a number of items in sequence"
define sequence new_sequence_2
set flush_keyboard yes
set description "Runs a number of items in sequence"
define sequence new_sequence_3
set flush_keyboard yes
set description "Runs a number of items in sequence"
define sketchpad new_sketchpad
set duration keypress
set description "Displays stimuli"
define sketchpad new_sketchpad_1
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="Running [toRun]" x=0 y=0 z_index=0
define sketchpad new_sketchpad_2
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="[toRun]" x=0 y=0 z_index=0
define sketchpad new_sketchpad_3
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="[subGroup] [toRun]" x=0 y=0 z_index=0
define sequence pickTrial
set flush_keyboard yes
set description "Runs a number of items in sequence"
run instuctions_1 always
run pracTrail_1 always
run instuctAgain_1 always
run realTrail_1 always
define sequence pickTrial_1_1
set flush_keyboard yes
set description "Runs a number of items in sequence"
run instuctions always
run pracTrail always
run instuctAgain always
run realTrail always
define loop pracLoop_Pick
set source_file ""
set source table
set repeat 1
set order random
set description "Repeatedly runs another item"
set cycles 5
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 stringA cat
setcycle 0 stringB dog
setcycle 0 itemNumber 1
setcycle 0 type prac
setcycle 1 stringA jim
setcycle 1 stringB lap
setcycle 1 itemNumber 2
setcycle 1 type prac
setcycle 2 stringA stuff
setcycle 2 stringB kind
setcycle 2 itemNumber 3
setcycle 2 type prac
setcycle 3 stringA lip
setcycle 3 stringB sat
setcycle 3 itemNumber 4
setcycle 3 type prac
setcycle 4 stringA "stick "
setcycle 4 stringB floating
setcycle 4 itemNumber 5
setcycle 4 type prac
run displayPracWords
define loop pracLoop_Pick_1
set source_file ""
set source table
set repeat 1
set order random
set description "Repeatedly runs another item"
set cycles 5
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 stringA cat
setcycle 0 stringB dog
setcycle 0 itemNumber 1
setcycle 0 type prac
setcycle 1 stringA jim
setcycle 1 stringB lap
setcycle 1 itemNumber 2
setcycle 1 type prac
setcycle 2 stringA stuff
setcycle 2 stringB kind
setcycle 2 itemNumber 3
setcycle 2 type prac
setcycle 3 stringA lip
setcycle 3 stringB sat
setcycle 3 itemNumber 4
setcycle 3 type prac
setcycle 4 stringA "stick "
setcycle 4 stringB floating
setcycle 4 itemNumber 5
setcycle 4 type prac
run displayPracWords_1
define loop pracLoop_Rate
set source_file "[path]"
set source file
set repeat 1
set order random
set description "Repeatedly runs another item"
set cycles 4
set continuous no
set break_if_on_first yes
set break_if never
setcycle 0 string dog
setcycle 1 string cat
setcycle 2 string fish
setcycle 3 string plop
run sliderScipt
define sequence pracTrail
set flush_keyboard yes
set description "Runs a number of items in sequence"
run pracLoop_Pick always
define sequence pracTrail_1
set flush_keyboard yes
set description "Runs a number of items in sequence"
run pracLoop_Pick_1 always
define sequence pracTrial
set flush_keyboard yes
set description "Runs a number of items in sequence"
run init_time always
run pracLoop_Rate always
define sequence rateTrial
set flush_keyboard yes
set description "Runs a number of items in sequence"
run pracTrial always
define sequence realTrail
set flush_keyboard yes
set description "Runs a number of items in sequence"
run expLoop_Pick always
define sequence realTrail_1
set flush_keyboard yes
set description "Runs a number of items in sequence"
run expLoop_Pick_1 always
define inline_script sliderScipt
set description "Executes Python code"
___run__
my_canvas = canvas()
my_mouse = mouse(timeout=20)
# Set slider dimensions. This assumes that 0,0 is the display center, which is
# the default in OpenSesame >= 3.
slider_w = 500
slider_h = 10
slider_x = -slider_w/2
slider_y = -slider_h/2
strA = var.String
format_string = "{:<10}{:<10}{:<10}"
def writeResults(r, time):
result = [strA, r, time-var.timekeeper]
with open(location, 'a') as file:
file.write(format_string.format(*result))
file.write('\n')
var.timekeeper = time
def toEEG(inum): #A 1 will be the parameriter for begin and a 0 for end
toSend = bytearray([inum])
var.ser.write(toSend)
toEEG(var.stimCounter)#begin trigger
while True:
# Determine the slider fill based on the mouse position
pos, time = my_mouse.get_pos()
x, y = pos
slider_fill = min(slider_w, max(0, x-slider_x))
my_canvas.clear()
# Draw some text (this can be anything)
my_canvas.text(strA, y=slider_y-100)
# Draw the slider frame
my_canvas.rect(slider_x, slider_y, slider_w, slider_h)
# Draw the slider fill
my_canvas.rect(slider_x, slider_y, slider_fill, slider_h, fill=True)
# Draw the mouse cursor
my_canvas.arrow(x+5, y+10, x, y)
my_canvas.show()
button, position, timestamp = my_mouse.get_click()
rate = 100.0*slider_fill/slider_w
# Poll the mouse for buttonclicks
if button is not None:
my_canvas.clear()
toEEG(0)#end trigger
writeResults(rate, timestamp)
break
button = None
var.stimCounter += 1
while True:
pos, time = my_mouse.get_pos()
x, y = pos
#print (str(x) + ", " + str(y))
my_canvas.clear()
my_canvas.text("Next")
my_canvas.rect(-25, -10, 50, 20, fill=False)
my_canvas.arrow(x+5, y+10, x, y)
my_canvas.show()
b = my_mouse.get_click()
button = b[0]
p = b[1]
if button is not None:
if x >= -23 and x <= 30 and y >= -12 and y <= 8:
my_canvas.clear()
break
# Set the slider response as an experimental variable
__end__
set _prepare ""
define sequence subjectCorrectBlock
set flush_keyboard yes
set description "Runs a number of items in sequence"
run subjectGroup always
run createFeedbackRate always
run rateTrial always
run ending always
define form_multiple_choice subjectGroup
set timeout infinite
set spacing 10
set question "What is the subject group?"
__options__
A
B
__end__
set margins "50;50;50;50"
set form_var subGroup
set form_title "Subject Group"
set description "A simple multiple choice item"
set button_text Ok
set allow_multiple no
set advance_immediately yes
set _theme gray
define sequence subjectNumError
set flush_keyboard yes
set description "Runs a number of items in sequence"
run wrongSubjectNum always
define sketchpad welcome
set start_response_interval no
set reset_variables no
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=serif font_italic=no font_size=32 html=yes show_if=always text="[stringA] [stringB]" x=0 y=0 z_index=0
define sketchpad wrongSubjectNum
set duration keypress
set description "Displays stimuli"
draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="Your entered: [subject_nr] <br />This is not a valid subject number!<br />Please enter a number from 1 to 60<br />Press ESC then Q ;D" x=0 y=-96 z_index=0