Guest User

Untitled

a guest
Jul 23rd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.88 KB | None | 0 0
  1. ---
  2. API: 2
  3. OpenSesame: 3.1.6
  4. Platform: nt
  5. ---
  6. set width 1280
  7. set uniform_coordinates no
  8. set title "Test Task"
  9. set synth_backend legacy
  10. set subject_parity even
  11. set subject_nr 0
  12. set start experiment
  13. set sound_sample_size -16
  14. set sound_freq 48000
  15. set sound_channels 2
  16. set sound_buf_size 1024
  17. set sampler_backend legacy
  18. set round_decimals 2
  19. set mouse_backend droid
  20. set keyboard_backend droid
  21. set height 800
  22. set fullscreen no
  23. set form_clicks no
  24. set foreground black
  25. set font_underline no
  26. set font_size 18
  27. set font_italic no
  28. set font_family sans
  29. set font_bold no
  30. set experiment_path "C:\\Users\\ms\\Desktop"
  31. set disable_garbage_collection yes
  32. set description "Default description"
  33. set coordinates relative
  34. set compensation 0
  35. set color_backend legacy
  36. set clock_backend legacy
  37. set canvas_backend droid
  38. set bidi no
  39. set background white
  40. set _run ""
  41.  
  42. define sketchpad blank
  43.     set duration 700
  44.     set description "Displays stimuli"
  45.  
  46. define sketchpad end_of_test
  47.     set duration keypress
  48.     set description "Displays stimuli"
  49.     draw textline center=1 color="#000000" font_bold=yes font_family=Calibri font_italic=no font_size=50 html=yes show_if=always text="Well done!" x=0 y=0 z_index=0
  50.     draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=18 html=yes show_if=always text="[reaction_mean]" x=-544 y=288 z_index=0
  51.     draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=18 html=yes show_if=always text="[reaction_median]" x=-544 y=320 z_index=0
  52.     draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=18 html=yes show_if=always text="[responses_correct]" x=-544 y=352 z_index=0
  53.     draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=18 html=yes show_if=always text="[logfile]" x=-544 y=384 z_index=0
  54.  
  55. define sequence experiment
  56.     set flush_keyboard yes
  57.     set description "Runs a number of items in sequence"
  58.     run setup always
  59.     run intro always
  60.     run experimental_loop always
  61.     run shim_loop always
  62.  
  63. define loop experimental_loop
  64.     set source_file ""
  65.     set source table
  66.     set skip 0
  67.     set repeat 10
  68.     set order random
  69.     set offset no
  70.     set item experimental_sequence
  71.     set description "Repeatedly runs another item"
  72.     set cycles 4
  73.     set continuous no
  74.     set column_order "correct_key;response_key;fish"
  75.     set break_if_on_first yes
  76.     set break_if never
  77.     setcycle 0 fish ll
  78.     setcycle 0 correct_key z
  79.     setcycle 1 fish lr
  80.     setcycle 1 correct_key z
  81.     setcycle 2 fish rr
  82.     setcycle 2 correct_key m
  83.     setcycle 3 fish rl
  84.     setcycle 3 correct_key m
  85.     run experimental_sequence
  86.  
  87. define sequence experimental_sequence
  88.     set flush_keyboard yes
  89.     set description "Runs a number of items in sequence"
  90.     run blank always
  91.     run star always
  92.     run fish_lr "[fish]=lr"
  93.     run fish_ll "[fish]=ll"
  94.     run fish_rr "[fish]=rr"
  95.     run fish_rl "[fish]=rl"
  96.     run timing always
  97.  
  98. define sketchpad fish_ll
  99.     set duration 0
  100.     set description "Displays stimuli"
  101.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=-410 y=0 z_index=0
  102.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=0 y=0 z_index=0
  103.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=410 y=0 z_index=0
  104.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=-210 y=0 z_index=0
  105.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=210 y=0 z_index=0
  106.  
  107. define sketchpad fish_lr
  108.     set duration 0
  109.     set description "Displays stimuli"
  110.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=-410 y=0 z_index=0
  111.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=0 y=0 z_index=0
  112.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=410 y=0 z_index=0
  113.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=-210 y=0 z_index=0
  114.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=210 y=0 z_index=0
  115.  
  116. define sketchpad fish_rl
  117.     set duration 0
  118.     set description "Displays stimuli"
  119.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=-410 y=0 z_index=0
  120.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=0 y=0 z_index=0
  121.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=410 y=0 z_index=0
  122.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=-210 y=0 z_index=0
  123.     draw image center=1 file="fish_left_150.png" scale=0.7 show_if=always x=210 y=0 z_index=0
  124.  
  125. define sketchpad fish_rr
  126.     set duration 0
  127.     set description "Displays stimuli"
  128.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=-410 y=0 z_index=0
  129.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=0 y=0 z_index=0
  130.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=410 y=0 z_index=0
  131.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=-210 y=0 z_index=0
  132.     draw image center=1 file="fish_right_150.png" scale=0.7 show_if=always x=210 y=0 z_index=0
  133.  
  134. define sketchpad intro
  135.     set duration keypress
  136.     set description "Displays stimuli"
  137.     draw textline center=1 color="#000000" font_bold=yes font_family=Calibri font_italic=no font_size=40 html=yes show_if=always text="Here is a fish!<br />" x=0 y=-180 z_index=0
  138.     draw image center=1 file="fish_left_150.png" scale=1 show_if=always x=0 y=0 z_index=0
  139.     draw textline center=1 color="#000000" font_bold=yes font_family=Calibri font_italic=no font_size=40 html=yes show_if=always text="This is the mouth" x=-320 y=-64 z_index=0
  140.     draw textline center=1 color="#000000" font_bold=yes font_family=Calibri font_italic=no font_size=40 html=yes show_if=always text="This is the tail" x=288 y=-96 z_index=0
  141.     draw arrow arrow_body_length=0.7 arrow_body_width=0.2 arrow_head_width=30 color="#000000" fill=1 penwidth=2 show_if=always x1=-192 x2=-128 y1=-32 y2=0 z_index=0
  142.     draw arrow arrow_body_length=0.7 arrow_body_width=0.2 arrow_head_width=30 color="#000000" fill=1 penwidth=2 show_if=always x1=192 x2=128 y1=-64 y2=-32 z_index=0
  143.     draw textline center=1 color="#000000" font_bold=no font_family=Calibri font_italic=no font_size=25 html=yes show_if=always text="The fish is pointing this" x=-96 y=160 z_index=0
  144.     draw arrow arrow_body_length=0.65 arrow_body_width=0.1 arrow_head_width=31 color="#000000" fill=1 penwidth=2 show_if=always x1=96 x2=32 y1=160 y2=160 z_index=0
  145.     draw textline center=1 color="#000000" font_bold=no font_family=Calibri font_italic=no font_size=25 html=yes show_if=always text="way." x=128 y=160 z_index=0
  146.     draw textline center=1 color="#000000" font_bold=no font_family=Calibri font_italic=no font_size=25 html=yes show_if=always text="The way the fish is swimming." x=0 y=224 z_index=0
  147.     draw textline center=1 color="#000000" font_bold=yes font_family=Calibri font_italic=no font_size=40 html=yes show_if=always text="" x=0 y=224 z_index=0
  148.     draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=12 html=yes show_if=always text="Touch to continue." x=416 y=352 z_index=0
  149.  
  150. define inline_script setup
  151.     set description "Executes Python code"
  152.     ___run__
  153.     reaction_times = []
  154.     responses_correct = 0
  155.    
  156.     import datetime
  157.     from time import strftime
  158.     logfile = strftime("%Y-%m-%d-%H-%M-%S") + '.csv'
  159.     print 'Using logfile: ' + logfile
  160.     log.open(logfile)
  161.     exp.set('logfile', logfile)
  162.    
  163.     log.write('correct_key, response, reaction_time')
  164.    
  165.     def median(lst):
  166.         sortedLst = sorted(lst)
  167.         lstLen = len(lst)
  168.         index = (lstLen - 1) // 2
  169.         if (lstLen % 2):
  170.             return sortedLst[index]
  171.         else:
  172.             return (sortedLst[index] + sortedLst[index + 1])/2.0
  173.     __end__
  174.     set _prepare ""
  175.  
  176. define loop shim_loop
  177.     set source_file ""
  178.     set source table
  179.     set repeat 1
  180.     set order random
  181.     set description "Repeatedly runs another item"
  182.     set cycles 1
  183.     set continuous no
  184.     set break_if_on_first yes
  185.     set break_if never
  186.     setcycle 0 empty_column ""
  187.     run end_of_test
  188.  
  189. define sketchpad star
  190.     set duration 1000
  191.     set description "Displays stimuli"
  192.     draw image center=1 file="star_75.png" scale=1 show_if=always x=0 y=0 z_index=0
  193.  
  194. define inline_script timing
  195.     set description "Executes Python code"
  196.     ___run__
  197.     correct_key = exp.get('correct_key')
  198.    
  199.     print 'Expected: ' + correct_key
  200.    
  201.     my_keyboard = keyboard()
  202.     time_before = self.time()
  203.     response, time_after = my_keyboard.get_key(keylist=['z', 'm'])
  204.     reaction_time = time_after - time_before
  205.     reaction_times.append(reaction_time)
  206.     exp.set('reaction_mean', sum(reaction_times) / float(len(reaction_times)))
  207.     exp.set('reaction_median', median(reaction_times))
  208.     if response is None:
  209.         print(u'A timeout occurred!')
  210.     else:
  211.         print 'Response: ' + response
  212.    
  213.     print reaction_time
  214.    
  215.     if response == correct_key:
  216.         print 'CORRECT!'
  217.         responses_correct += 1
  218.         exp.set('responses_correct', responses_correct)
  219.     else:
  220.         print 'INCORRECT!'
  221.        
  222.     log.write('%s, %s, %d' % (correct_key, response, reaction_time))
  223.        
  224.     print
  225.     __end__
  226.     set _prepare ""
Advertisement
Add Comment
Please, Sign In to add comment