Guest User

Untitled

a guest
Jun 20th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. # Mind-wandering experiment 1, "zinka"
  2. # Jesse M. Edelstein <jedelstein@ucmerced.edu>
  3. # Programmed beginning 2/3/12
  4.  
  5. # This program is written in Ruby for the graphics toolkit Shoes.
  6. # Copyright Jesse Edelstein 2012. This is free software available under the MIT License. Some code reused from Shoes examples.
  7. # Task design based on: Stawarczyk, D., Majerus, S., Maj, M., Van der Linden, M., & D'Argembeau, A. (2011). Mind-wandering: Phenomenology and function as assessed with a novel experience sampling method. Acta Psychologica, 136(3), 370?381. Elsevier B.V. doi:10.1016/j.actpsy.2011.01.002
  8.  
  9. # imports, global vars
  10. require 'csv'
  11. $exptname = "zinka_v2"
  12. #$width, $height = 1920, 1200 # resolution; change me as needed
  13. $width, $height = 1280, 800
  14. #$multiple_uses_task_time = 300 # 5 minutes
  15. #$SART_trials = 300 # how many go/no-go trials in the second part
  16. $thought_probe_min_frequency = 15
  17. $thought_probe_max_frequency = 35
  18.  
  19. class PresentInstructions < Shoes::Widget
  20. def initialize(step,instructions)
  21. @step = step
  22. @s = stack :margin => 100 do
  23. para instructions, :font => "Arial 36px", :stroke => white
  24. @space_detector = edit_box :width => 1, :height => 1 do |e|
  25. self.stop if e.text[-1..-1] == ' '
  26. end
  27. end
  28. @s.hide
  29. end
  30.  
  31. def go
  32. debug 'zinka: presenting instructions...'
  33. @s.show
  34. #alert('now focusing I hope. I HOPE SO!!! Anyway have you ever really looked at your hand I mean really really loooooked at it? It\'s f\'n trippy man. i like ice cream and carrots')
  35. timer(0.01) {@space_detector.focus}
  36. end
  37.  
  38. def stop
  39. @s.remove
  40. $steps[@step+1].go
  41. end
  42.  
  43. end
  44.  
  45. class MultipleUsesTask < Shoes::Widget
  46. def initialize(step, time_to_run)
  47. @start_time = Time.now
  48. @step = step
  49. @responses = ['Response_MU_task_' + step.to_i.to_s]
  50. @timestamps = ['Timestamp']
  51. @runtime = time_to_run
  52. @outfile = open_csv (step)
  53. @s = stack :margin => 100 do
  54. @textdisplay = para "What uses can you think of for a brick? Type them into the box below, and hit Enter after each one." , :font => "Arial 36px", :stroke => white
  55. @freeresponse = edit_box :width => 400, :height => 200 do |e|
  56. if e.text[-1..-1] == "\n" # detect when user hits Enter
  57. @freeresponse.text.slice!(-1)
  58. @responses += [@freeresponse.text]
  59. @timestamps += [Time.now - @start_time]
  60. e.text = ''
  61. end
  62. end
  63. @countdown = para "" , :font => "Arial 24px", :stroke => white
  64. end
  65. @s.hide
  66. end
  67.  
  68. def go
  69. @s.show
  70. @freeresponse.focus
  71. countdown_and_collect
  72. end
  73.  
  74. def countdown_and_collect
  75. stopped = false
  76. start_time = Time.now
  77. a = animate(10) do
  78. time_remaining = (@runtime - (Time.now - start_time)).to_i
  79. mins_left = (time_remaining / 60).ceil.to_s
  80. secs_left = (time_remaining % 60).to_s
  81. secs_left = ('0' + secs_left) if secs_left.length == 1
  82. @countdown.replace "time_remaining: #{time_remaining}"
  83. #@countdown.replace 'Time remaining: ' + mins_left + ':' + secs_left
  84. if (time_remaining <= 0 && !stopped)
  85. stopped = true
  86. collect_remaining_entry
  87. a.stop and self.stop
  88. end
  89. end
  90. end
  91.  
  92. def collect_remaining_entry
  93. # after 5 minutes or whatever, collect whatever remains in the textbox
  94. # THIS SHOULD ONLY RUN AFTER THE TRIAL IS COMPLETE!!
  95. @freeresponse.text.slice!(-1)
  96. @responses += [@freeresponse.text]
  97. @timestamps += [Time.now - @start_time]
  98. end
  99.  
  100. def stop
  101. @s.remove
  102. write_and_close_csv(@outfile, [@responses, @timestamps])
  103. $steps[@step+1].go
  104. end
  105.  
  106. def open_csv (filenumber)
  107. filename = $filename_base + '_pt' + filenumber.to_i.to_s + '.csv'
  108. return CSV.open(filename,'w')
  109. end
  110.  
  111. def write_and_close_csv (outfile, data_columns)
  112. # writes columns to the CSV file & closes it
  113. # is this better than doing it in realtime? maybe, as long as the writes aren't TOO huge
  114. for i in 0..(data_columns[0].length)
  115. new_row = []
  116. data_columns.each do |column|
  117. new_row += [column[i]]
  118. end
  119. outfile << new_row
  120. end
  121. outfile.close
  122. end
  123.  
  124. end
  125.  
  126. class SART_Task < Shoes::Widget
  127.  
  128. def initialize(step, trials_to_run)
  129. @step = step
  130. end
  131.  
  132. def go
  133. debug 'zinka: SART task...'
  134. @s = stack(:margin => 100){para 'SART task... Now under construction. Wait 10sec.',
  135. :font => "Arial 36px", :stroke => white}
  136. timer(10){stop}
  137. end
  138.  
  139. def stop
  140. @s.remove
  141. $steps[@step+1].go
  142. end
  143.  
  144. def open_csv (filenumber)
  145. filename = $filename_base + '_pt' + filenumber + '.csv'
  146. return CSV.open(filename,'w')
  147. end
  148.  
  149. def write_and_close_csv (outfile, data_columns)
  150. # writes columns to the CSV file & closes it
  151. # is this better than doing it in realtime? maybe, as long as the writes aren't TOO huge
  152. for i in 0..(data_columns[0].length)
  153. new_row = []
  154. data_columns.each do |column|
  155. new_row += [column[i]]
  156. end
  157. outfile << new_row
  158. end
  159. outfile.close
  160. end
  161. end
  162.  
  163. class GoodBye < Shoes::Widget
  164.  
  165. def initialize
  166. @s = stack :margin => 100 do
  167. para "The experiment is complete! Please contact the experimenter." , :font => "Arial 36px", :stroke => white
  168. end
  169. @s.hide
  170. end
  171.  
  172. def go
  173. @s.show
  174. timer(10) {exit}
  175. end
  176.  
  177. end
  178.  
  179.  
  180. # fullscreen works okay under Win7; not really under OS X 10.7
  181. Shoes.app :width => $width, :height => $height do
  182.  
  183. def get_subject_name
  184. welcome_string = "This is #{$exptname}. Enter subject ID number. "
  185. filename1 = ''
  186. loop do
  187. subject = ask(welcome_string).to_s
  188. $filename_base = $exptname + '_' + subject
  189. test_filename = $filename_base + '_pt1.csv'
  190. if subject == ''
  191. welcome_string = 'How about a non-empty subject ID?'
  192. redo
  193. elsif FileTest::exist?(filename1)
  194. welcome_string = "Whoops, file #{test_filename}\n already exists. New ID?"
  195. redo
  196. else
  197. break
  198. end
  199. end
  200. end
  201.  
  202.  
  203. # Actual program flow goes here!
  204. # First, set up all our objects (all start onscreen but hidden)
  205. debug 'zinka: setting up objects...'
  206. background black # (per Stawarczyk)
  207. get_subject_name
  208. $steps = []
  209. $steps[0] = present_instructions(0, 'Time for the first task about bricks. Press space to go.')
  210. $steps[1] = multiple_uses_task(1,10) # normally set to 300 seconds
  211. $steps[2] = present_instructions(2,'Now for a task where you have to hit the spacebar, except when you don\'t.')
  212. $steps[3] = sart_task(3,300)
  213. $steps[4] = present_instructions(4,'Brick time again!!')
  214. $steps[5] = multiple_uses_task(5, 10)
  215. $steps[6] = good_bye()
  216.  
  217. $steps[0].go
  218.  
  219. end
Add Comment
Please, Sign In to add comment