Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Mind-wandering experiment 1, "zinka"
- # Jesse M. Edelstein <jedelstein@ucmerced.edu>
- # Programmed beginning 2/3/12
- # This program is written in Ruby for the graphics toolkit Shoes.
- # Copyright Jesse Edelstein 2012. This is free software available under the MIT License. Some code reused from Shoes examples.
- # 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
- # imports, global vars
- require 'csv'
- $exptname = "zinka_v2"
- #$width, $height = 1920, 1200 # resolution; change me as needed
- $width, $height = 1280, 800
- #$multiple_uses_task_time = 300 # 5 minutes
- #$SART_trials = 300 # how many go/no-go trials in the second part
- $thought_probe_min_frequency = 15
- $thought_probe_max_frequency = 35
- class PresentInstructions < Shoes::Widget
- def initialize(step,instructions)
- @step = step
- @s = stack :margin => 100 do
- para instructions, :font => "Arial 36px", :stroke => white
- @space_detector = edit_box :width => 1, :height => 1 do |e|
- self.stop if e.text[-1..-1] == ' '
- end
- end
- @s.hide
- end
- def go
- debug 'zinka: presenting instructions...'
- @s.show
- #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')
- timer(0.01) {@space_detector.focus}
- end
- def stop
- @s.remove
- $steps[@step+1].go
- end
- end
- class MultipleUsesTask < Shoes::Widget
- def initialize(step, time_to_run)
- @start_time = Time.now
- @step = step
- @responses = ['Response_MU_task_' + step.to_i.to_s]
- @timestamps = ['Timestamp']
- @runtime = time_to_run
- @outfile = open_csv (step)
- @s = stack :margin => 100 do
- @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
- @freeresponse = edit_box :width => 400, :height => 200 do |e|
- if e.text[-1..-1] == "\n" # detect when user hits Enter
- @freeresponse.text.slice!(-1)
- @responses += [@freeresponse.text]
- @timestamps += [Time.now - @start_time]
- e.text = ''
- end
- end
- @countdown = para "" , :font => "Arial 24px", :stroke => white
- end
- @s.hide
- end
- def go
- @s.show
- @freeresponse.focus
- countdown_and_collect
- end
- def countdown_and_collect
- stopped = false
- start_time = Time.now
- a = animate(10) do
- time_remaining = (@runtime - (Time.now - start_time)).to_i
- mins_left = (time_remaining / 60).ceil.to_s
- secs_left = (time_remaining % 60).to_s
- secs_left = ('0' + secs_left) if secs_left.length == 1
- @countdown.replace "time_remaining: #{time_remaining}"
- #@countdown.replace 'Time remaining: ' + mins_left + ':' + secs_left
- if (time_remaining <= 0 && !stopped)
- stopped = true
- collect_remaining_entry
- a.stop and self.stop
- end
- end
- end
- def collect_remaining_entry
- # after 5 minutes or whatever, collect whatever remains in the textbox
- # THIS SHOULD ONLY RUN AFTER THE TRIAL IS COMPLETE!!
- @freeresponse.text.slice!(-1)
- @responses += [@freeresponse.text]
- @timestamps += [Time.now - @start_time]
- end
- def stop
- @s.remove
- write_and_close_csv(@outfile, [@responses, @timestamps])
- $steps[@step+1].go
- end
- def open_csv (filenumber)
- filename = $filename_base + '_pt' + filenumber.to_i.to_s + '.csv'
- return CSV.open(filename,'w')
- end
- def write_and_close_csv (outfile, data_columns)
- # writes columns to the CSV file & closes it
- # is this better than doing it in realtime? maybe, as long as the writes aren't TOO huge
- for i in 0..(data_columns[0].length)
- new_row = []
- data_columns.each do |column|
- new_row += [column[i]]
- end
- outfile << new_row
- end
- outfile.close
- end
- end
- class SART_Task < Shoes::Widget
- def initialize(step, trials_to_run)
- @step = step
- end
- def go
- debug 'zinka: SART task...'
- @s = stack(:margin => 100){para 'SART task... Now under construction. Wait 10sec.',
- :font => "Arial 36px", :stroke => white}
- timer(10){stop}
- end
- def stop
- @s.remove
- $steps[@step+1].go
- end
- def open_csv (filenumber)
- filename = $filename_base + '_pt' + filenumber + '.csv'
- return CSV.open(filename,'w')
- end
- def write_and_close_csv (outfile, data_columns)
- # writes columns to the CSV file & closes it
- # is this better than doing it in realtime? maybe, as long as the writes aren't TOO huge
- for i in 0..(data_columns[0].length)
- new_row = []
- data_columns.each do |column|
- new_row += [column[i]]
- end
- outfile << new_row
- end
- outfile.close
- end
- end
- class GoodBye < Shoes::Widget
- def initialize
- @s = stack :margin => 100 do
- para "The experiment is complete! Please contact the experimenter." , :font => "Arial 36px", :stroke => white
- end
- @s.hide
- end
- def go
- @s.show
- timer(10) {exit}
- end
- end
- # fullscreen works okay under Win7; not really under OS X 10.7
- Shoes.app :width => $width, :height => $height do
- def get_subject_name
- welcome_string = "This is #{$exptname}. Enter subject ID number. "
- filename1 = ''
- loop do
- subject = ask(welcome_string).to_s
- $filename_base = $exptname + '_' + subject
- test_filename = $filename_base + '_pt1.csv'
- if subject == ''
- welcome_string = 'How about a non-empty subject ID?'
- redo
- elsif FileTest::exist?(filename1)
- welcome_string = "Whoops, file #{test_filename}\n already exists. New ID?"
- redo
- else
- break
- end
- end
- end
- # Actual program flow goes here!
- # First, set up all our objects (all start onscreen but hidden)
- debug 'zinka: setting up objects...'
- background black # (per Stawarczyk)
- get_subject_name
- $steps = []
- $steps[0] = present_instructions(0, 'Time for the first task about bricks. Press space to go.')
- $steps[1] = multiple_uses_task(1,10) # normally set to 300 seconds
- $steps[2] = present_instructions(2,'Now for a task where you have to hit the spacebar, except when you don\'t.')
- $steps[3] = sart_task(3,300)
- $steps[4] = present_instructions(4,'Brick time again!!')
- $steps[5] = multiple_uses_task(5, 10)
- $steps[6] = good_bye()
- $steps[0].go
- end
Add Comment
Please, Sign In to add comment