Commits

Anonymous committed 8c9b980

Everything works except: stopping in the middle and getting a results file, and the primer at the beginning

  • Participants
  • Parent commits 3174cea
  • Tags this_revision_worked

Comments (0)

Files changed (3)

 # The message that shows during the initial few seconds of an audio clip
 wait_message = Please wait...
 
+# The message that displays on the thank you screen
+thank_you_message = Thank you! Press any key to exit.
+
 # The directory in which to place the results file.
 results_dir = results

File experiment.py

 sound_clip = 'None'
 channel = None
 window_lock = threading.Condition()
+music_stopped = False
 
 
+class MusicStoppedException(Exception):
+    """Raise this when the music stops"""
+    pass
+
 class ExperimentSound:
     def __init__(self, name, media_dir):
         self.name = name
         global window_lock
         global sound_clip
         global channel
+        global music_stopped
                     
         # Initialze Our Mixer
         mixer.init()
         for clip in bag:
             # Get the lock
             if self.stop_asap:
+                channel.stop()
                 window_lock.release()
                 return
             # Start playing a sound...
 
         sound_clip = 'None'
         window_lock.release()
+        music_stopped = True
 
     def stop(self):
         self.stop_asap = True
 
+
 class Experiment(object):
     app_config = None
 
         global window_lock
         global sound_clip
         global channel
+        global music_stopped
 
         # Get our config values
         media_dir = self.get_config('media_dir')
         right_key = self.get_config('right_key')
         left_key = self.get_config('left_key')
         wait_message = self.get_config('wait_message')
+        thank_you_message = self.get_config('thank_you_message')
 
         word_stimuli = self.build_word_list()
-        trials = data.TrialHandler(word_stimuli, 1)
+        random.shuffle(word_stimuli)
+        trials = data.TrialHandler(word_stimuli, 1, method='sequential')
 
         # FIXME: can't use underscores in datatype names... bug? 
         # http://code.google.com/p/psychopy/source/browse/trunk/psychopy/data.py#279
         # Make our clock
         response_timer = core.Clock()
 
-
-
         # Build our window and display the instructions
-        w = visual.Window(fullscr=False)
+        w = visual.Window(fullscr=True)
         instruction_stim = visual.TextStim(w, text=instruction_text)
         instruction_stim.draw()
         w.flip()
         self.sound_player.start()
         core.wait(2)
 
-        for trial in trials:
-            window_lock.acquire()
-            # FIXME: there's probably some better way to randomize this
-            trial_key = {}
-            word_order = random.randint(0,2)
-            if word_order == 1:
-                trial_key[right_key] = 'content'
-                trial_key[left_key] = 'surface'
-            else:
-                trial_key[right_key] = 'surface'
-                trial_key[left_key] = 'content'
+        try:
+            for trial in trials:
+                window_lock.acquire()
+                # FIXME: there's probably some better way to randomize this
+                trial_key = {}
+                word_order = random.randint(0,2)
+                if word_order == 1:
+                    trial_key[right_key] = 'content'
+                    trial_key[left_key] = 'surface'
+                else:
+                    trial_key[right_key] = 'surface'
+                    trial_key[left_key] = 'content'
 
 
-            right_stim_text = "%s\n%s" % (trial[trial_key[right_key]], right_key)
-            left_stim_text = "%s\n%s" % (trial[trial_key[left_key]], left_key)
+                right_stim_text = "%s\n%s" % (trial[trial_key[right_key]], right_key)
+                left_stim_text = "%s\n%s" % (trial[trial_key[left_key]], left_key)
 
-            test_stim = visual.TextStim(w, text=trial['test'],
-                    bold=True,
-                    height=0.2)
-            right_stim = visual.TextStim(w, text=right_stim_text,
-                    pos=(0.5, -0.5),
-                    height=0.15)
-            left_stim = visual.TextStim(w, text=left_stim_text,
-                    pos=(-0.5, -0.5),
-                    height=0.15)
+                test_stim = visual.TextStim(w, text=trial['test'],
+                        bold=True,
+                        height=0.2)
+                right_stim = visual.TextStim(w, text=right_stim_text,
+                        pos=(0.5, -0.5),
+                        height=0.15)
+                left_stim = visual.TextStim(w, text=left_stim_text,
+                        pos=(-0.5, -0.5),
+                        height=0.15)
 
 
-            # Display the test word and wait a bit
-            test_stim.draw()
-            w.flip()
-            core.wait(test_word_wait_time)
+                # Display the test word and wait a bit
+                test_stim.draw()
+                w.flip()
+                core.wait(test_word_wait_time)
 
-            # Display the test word and the choices, make our timer
-            test_stim.draw()
-            right_stim.draw()
-            left_stim.draw()
-            w.flip()
+                # Display the test word and the choices, make our timer
+                test_stim.draw()
+                right_stim.draw()
+                left_stim.draw()
+                w.flip()
 
-            # Start the timer...
-            response_timer.reset()
-            keys_pressed = event.waitKeys(keyList=[right_key, left_key])
-            response_time = response_timer.getTime()
+                # Start the timer...
+                response_timer.reset()
+                keys_pressed = event.waitKeys(keyList=[right_key, left_key])
+                response_time = response_timer.getTime()
 
 
-            key_pressed = keys_pressed[0]
+                key_pressed = keys_pressed[0]
 
-            trials.data.add('choiceCategory', trial_key[key_pressed])
-            trials.data.add('choiceWord', trial[trial_key[key_pressed]])
-            trials.data.add('responseTime', response_time)
-            trials.data.add('instructionSet', instruction_set)
-            trials.data.add('soundClip', sound_clip)
-            trials.data.add('testWordWaitTime', test_word_wait_time)
-            trials.data.add('soundStopped', not channel.get_busy())
+                trials.data.add('choiceCategory', trial_key[key_pressed])
+                trials.data.add('choiceWord', trial[trial_key[key_pressed]])
+                trials.data.add('responseTime', response_time)
+                trials.data.add('instructionSet', instruction_set)
+                trials.data.add('soundClip', sound_clip)
+                trials.data.add('testWordWaitTime', test_word_wait_time)
+                trials.data.add('soundStopped', not channel.get_busy())
 
-            # Notify others about the lock....
+                if not channel.get_busy():
+                    window_lock.notify()
+                    window_lock.release()
 
-            if not channel.get_busy():
-                window_lock.notify()
-                window_lock.release()
+                    # Have to wait, otherwise soundplayer doesn't start again,
+                    # not sure why
+                    core.wait(0.5) 
+                else:
+                    window_lock.release()
 
-                # Have to wait, otherwise soundplayer doesn't start again,
-                # not sure why
-                core.wait(0.5) 
-            else:
-                window_lock.release()
+                # Check to see if our music stopped
+                if music_stopped:
+                    raise MusicStoppedException()
 
+        except MusicStoppedException:
+            pass
 
 
+
+        # Clean up
+        with window_lock:
+            self.sound_player.stop()
+            window_lock.notify_all()
+        self.sound_player.join()
+
+        # Save the data
         trials.saveAsText(self.results_filename,
                            stimOut=['test', 'content', 'surface'],
                            dataOut=['choiceCategory_raw',
                                     'testWordWaitTime_raw',
                                     'soundStopped_raw'],
                            delim=',')
-        with window_lock:
-            self.sound_player.stop()
-            window_lock.notify_all()
-        self.sound_player.join()
+
+        thank_you_stim = visual.TextStim(w, text=thank_you_message)
+        thank_you_stim.draw()
+        w.flip()
+        event.waitKeys()
 
     def stop(self):
         self.sound_player.stop()
     parser = optparse.OptionParser()
     options, args = parser.parse_args()
 
+    # Check to make sure we got the results filename
     if not args:
         print "Please type the trial_name as the first argument."
         sys.exit(1)
 
     e = Experiment(config_filename='config.ini', results_filename=results_filename)
 
+    # Check to make sure the results file doesn't already exist
     if os.path.exists(os.path.join(e.get_config('results_dir'),
                                    results_filename + '.dlm')):
         print "A results file with that name already exists.  Please " + \
     ('walk', 'tread', 'talk'),
     ('sweet', 'sugary', 'neat'),
     ('flower', 'bloom', 'tower'),
+    ('broom', 'sweeper', 'bloom'),
+    ('spot', 'mark', 'stop'),
+    ('feather', 'plume', 'weather'),
+    ('pole', 'dowel', 'poll'),
+    ('too', 'also', 'two'),
+    ('ramp', 'incline', 'tramp'),
+    ('place', 'location', 'race'),
+    ('coat', 'jacket', 'boat'),
+    ('development', 'growth', 'envelope'),
+    ('sea', 'ocean', 'seat'),
+    ('barrier', 'wall', 'carrier'),
+    ('porch', 'deck', 'torch'),
+    ('run', 'jog', 'gun'),
+    ('pale', 'white', 'rail'),
+    ('mosey', 'amble', 'rosy'),
+    ('best', 'premier', 'pest'),
+    ('consider', 'regard', 'litter'),
+    ('blond', 'golden', 'fond'),
+    ('mail', 'post', 'pale'),
+    ('thorough', 'exhaustive', 'borough'),
+    ('partial', 'incomplete', 'martial'),
+    ('parched', 'dry', 'marched'),
+    ('save', 'keep', 'pave'),
+    ('cold', 'chilly', 'bold'),
+    ('heavy', 'weighty', 'steady'),
+    ('dawn', 'sunrise', 'fawn'),
+    ('slick', 'smooth', 'stick'),
+    ('apple', 'fruit', 'grapple'),
+    ('kind', 'nice', 'blind'),
+    ('onion', 'shallot', 'bunion'),
+    ('leak', 'drip', 'tweak'),
+    ('cry', 'weep', 'buy'),
+    ('jumble', 'mix', 'mumble'),
+    ('dump', 'spill', 'stump'),
+    ('vapor', 'fog', 'paper'),
+    ('brain', 'mind', 'train'),
+    ('page', 'sheet', 'sage'),
+    ('sleep', 'slumber', 'beep'),
+    ('poster', 'sign', 'roaster'),
+    ('cut', 'wound', 'nut'),
+    ('tie', 'bind', 'buy'),
+    ('slender', 'thin', 'bender'),
+    ('blame', 'accuse', 'tame'),
+    ('ask', 'inquire', 'task'),
+    ('feature', 'trait', 'creature'),
+    ('wine', 'complain', 'dine'),
+    ('trigger', 'cause', 'figure'),
+    ('symbol', 'sign', 'nimble'),
+    ('writing', 'script', 'fighting'),
+    ('anger', 'rage', 'angle'),
+    ('apex', 'peak', 'inspect'),
+    ('armor', 'shield', 'amoral'),
+    ('asphalt', 'blacktop', 'fault'),
+    ('beau', 'boyfriend', 'row'),
+    ('beef', 'meet', 'deep'),
+    ('bread', 'cash', 'break'),
+    ('bureau', 'agency', 'mirror'),
+    ('burlap', 'canvas', 'burden'),
+    ('butter', 'lard', 'studder'),
+    ('calf', 'cow', 'nap'),
+    ('carnage', 'slaughter', 'carp'),
+    ('cash', 'money', 'stash'),
+    ('cement', 'bond', 'mental'),
+    ('child', 'kid', 'chile'),
+    ('childhood', 'youth', 'chilled'),
+    ('chrome', 'metallic', 'home'),
+    ('clay', 'mud', 'staple'),
+    ('close', 'near', 'dose'),
+    ('clothing', 'garment', 'sloping'),
+    ('concrete', 'material', 'conquer'),
+    ('content', 'satisfied', 'truant'),
+    ('cool', 'chilly', 'coon'),
+    ('cotton', 'yarn', 'rotten'),
+    ('cranium', 'skull', 'crave'),
+    ('crawl', 'creep', 'sprawl'),
+    ('crisis', 'disaster', 'basis'),
+    ('crush', 'squash', 'hush'),
+    ('cuisine', 'food', 'quiz'),
+    ('dandruff', 'flakes', 'damper'),
+    ('decay', 'ruin', 'decal'),
+    ('dew', 'droplets', 'new'),
+    ('die', 'expire', 'why'),
+    ('dirt', 'muck', 'curt'),
+    ('drizzle', 'rain', 'dribble'),
+    ('dusk', 'twilight', 'risk'),
+    ('dust', 'powder', 'bus'),
+    ('earth', 'soil', 'heart'),
+    ('ease', 'simplicity', 'measley'),
+    ('elf', 'pixie', 'felt'),
+    ('ether', 'gas', 'weather'),
+    ('fail', 'disappoint', 'tail'),
+    ('feel', 'sense', 'feet'),
+    ('felt', 'fabric', 'fell'),
+    ('fervor', 'passion', 'ardor'),
+    ('filth', 'grime', 'fill'),
+    ('flesh', 'skin', 'best'),
+    ('flow', 'surge', 'goal'),
+    ('foot', 'bottom', 'toot'),
+    ('footwear', 'boot', 'nowhere'),
+    ('frenzy', 'craze', 'trends'),
+    ('genius', 'intelligent', 'generous'),
+    ('gold', 'buillion', 'sold'),
+    ('golf', 'links', 'gall'),
+    ('gore', 'pierce', 'bore'),
+    ('graphite', 'carbon', 'grate'),
+    ('gravel', 'rocks', 'gamble'),
+    ('gravy', 'sauce', 'navy'),
+    ('half', 'portion', 'have'),
+    ('hardware', 'tools', 'beware'),
+    ('hardwood', 'oak', 'fastfood'),
+    ('haste', 'rush', 'hate'),
+    ('havoc', 'chaos', 'hammock'),
+    ('hay', 'straw', 'ape'),
+    ('health', 'vitality', 'belt'),
+    ('henchman', 'stooge', 'winch'),
+    ('hunger', 'appetite', 'mumble'),
+    ('hurt', 'injure', 'herb'),
+    ('hygiene', 'sanitation', 'canteen'),
+    ('I', 'me', 'diad'),
+    ('incense', 'perfume', 'insinuate'),
+    ('jangle', 'clink', 'jungle'),
+    ('jargon', 'vocab', 'bargen'),
+    ('kill', 'murder', 'silouette'),
+    ('knife', 'blade', 'night'),
+    ('lack', 'need', 'attract'),
+    ('laughter', 'giggle', 'baffle'),
+    ('leaf', 'folio', 'keep'),
+    ('lean', 'slim', 'leader'),
+    ('left', 'forgotten', 'lept'),
+    ('lichen', 'shrub', 'beacon'),
+    ('lightning', 'flash', 'biting'),
+    ('linen', 'sheet', 'line'),
+    ('lint', 'fluff', 'tin'),
+    ('loot', 'spoils', 'who'),
+    ('maize', 'corn', 'hazed'),
+    ('mazn', 'humankind', 'and'),
+    ('milk', 'exploit', 'sill'),
+    ('mince', 'dice', 'inch'),
+    ('mister', 'sir', 'hamster'),
+    ('moisture', 'wetness', 'hoise'),
+    ('morphine', 'anesthesia', 'metamorphosis'),
+    ('mouse', 'rodent', 'moose'),
+    ('mucus', 'flem', 'focus'),
+    ('music', 'melody', 'muscle'),
+    ('mustard', 'condiment', 'student'),
+    ('mutton', 'meat', 'button'),
+    ('nectar', 'honey', 'spectator'),
+    ('news', 'gossip', 'muse'),
+    ('nightfall', 'dusk', 'tight'),
+    ('oatmeal', 'cereal', 'boast'),
+    ('opium', 'drug', 'hope'),
+    ('ox', 'bull', 'tax'),
+    ('peace', 'tranquility', 'steeple'),
+    ('peel', 'strip', 'pepper'),
+    ('pep', 'vigor', 'pop'),
+    ('polish', 'shine', 'rubbish'),
+    ('pork', 'bacon', 'torch'),
+    ('presence', 'being', 'scent'),
+    ('present', 'gift', 'press'),
+    ('prey', 'target', 'rate'),
+    ('prime', 'major', 'pride'),
+    ('princess', 'royalty', 'incessant'),
+    ('produce', 'make', 'deuce'),
+    ('quick', 'fast', 'quack'),
+    ('quiet', 'still', 'quite'),
+    ('refuse', 'deny', 'shuffle'),
+    ('revenge', 'retribution', 'revenue'),
+    ('rust', 'corrode', 'muscle'),
+    ('satin', 'silk', 'taint'),
+    ('seaman', 'sailor', 'teammate'),
+    ('sell', 'vend', 'belt'),
+    ('slang', 'vernacular', 'sling'),
+    ('sleep', 'dose', 'sleet'),
+    ('slime', 'ooze', 'slim'),
+    ('smart', 'chic', 'smack'),
+    ('soccer', 'football', 'sucker'),
+    ('soda', 'pop', 'coda'),
+    ('soup', 'stew', 'sow'),
+    ('stadium', 'arena', 'delirium'),
+    ('stout', 'heavy', 'stub'),
+    ('surf', 'waves', 'sure'),
+    ('thick', 'broad', 'think'),
+    ('thief', 'robber', 'theme'),
+    ('thyme', 'spice', 'tide'),
+    ('tooth', 'fang', 'boot'),
+    ('traction', 'grip', 'attract'),
+    ('trash', 'garbage', 'tramp'),
+    ('trim', 'neat', 'trip'),
+    ('unrest', 'turbulence', 'crest'),
+    ('venom', 'poison', 'denim'),
+    ('wealth', 'riches', 'stealth'),
+    ('wear', 'adorn', 'wet'),
+    ('wheat', 'grain', 'weigh'),
+    ('whirl', 'spin', 'grill'),
+    ('wife', 'spouse', 'wipe'),
+    ('wrath', 'anger', 'wrap'),
+    ('zeal ', 'enthusiasm', 'neal'),
+    ('fugitive', 'criminal', 'fugue'),
+    ('weapon', 'gun', 'crampon'),
+    ('car', 'automobile', 'bar'),
+    ('light', 'lamp', 'bright'),
+    ('shack', 'hut', 'hack'),
+    ('limb', 'appendage', 'trim'),
+    ('door', 'entry', 'cold'),
+    ('leap', 'jump', 'peep'),
+    ('deer', 'buck', 'fear'),
+    ('clouds', 'overcast', 'clown'),
+    ('wound', 'injury', 'spoon'),
+    ('string', 'twine', 'bring'),
+    ('ash', 'cinder', 'hash'),
+    ('strike', 'hit', 'kite'),
+    ('power', 'energy', 'powder'),
+    ('huge', 'enormous', 'hue'),
+    ('grounds', 'premises', 'trounce '),
+    ('elect', 'appoint', 'electrical'),
+    ('prefer', 'favor', 'reverb'),
+    ('mark', 'brand', 'dark'),
+    ('record', 'archive', 'recall'),
+    ('legend', 'fable', 'engine'),
+    ('agent', 'officer', 'aged'),
+    ('factory', 'warehouse', 'factual'),
+    ('copy', 'counterfeit', 'copper'),
+    ('model', 'standard', 'waddle'),
+    ('typical', 'common', 'pivotal'),
+    ('rare', 'exceptional', 'where'),
+    ('blaze', 'burn', 'craze'),
+    ('dazzle', 'glimmer', 'guzzle'),
+    ('radiate', 'diffuse', 'alleviate'),
+    ('increase', 'enlarge', 'release'),
+    ('advance', 'escalation', 'advant'),
+    ('transmit', 'communicate', 'rancid'),
+    ('climb', 'ascend', 'rhyme'),
+    ('forest', 'woods', 'forestall'),
+    ('speak', 'talk', 'peat'),
+    ('hoist', 'lift', 'foist'),
+    ('don', 'clothe', 'dot'),
+    ('book', 'text', 'boom'),
+    ('protect', 'guard', 'project'),
+    ('movie', 'cinema', 'move'),
+    ('plan', 'prepare', 'plain'),
+    ('reserve', 'hold', 'preserve'),
+    ('image', 'picture', 'imagine'),
+    ('peek', 'view', 'peak'),
+    ('lamp', 'light', 'vamp'),
+    ('flower', 'blossom', 'flowed'),
+    ('penal', 'disciplinary', 'petal'),
+    ('bread', 'biscuit', 'bead'),
+    ('plate', 'dish', 'plane'),
+    ('feed', 'nourish', 'feet'),
+    ('dispense', 'give', 'suspense'),
+    ('delegate', 'assign', 'denigrate'),
+    ('cast', 'hurl', 'cost'),
+    ('face', 'countenance', 'fact'),
+    ('demeanor', 'expression', 'demean'),
+    ('tranquil', 'calm', 'triangle'),
+    ('peace', 'accord', 'pace'),
+    ('cease', 'terminate', 'case'),
+    ('arrest', 'imprison', 'attest'),
+    ('lose', 'misplace', 'loose'),
+    ('forfeit', 'surrender', 'surfeit'),
+    ('victory', 'triumph', 'victim'),
+    ('dominion', 'realm', 'domicile'),
+    ('outside', 'exterior', 'oust'),
+    ('above', 'over ', 'abode'),
+    ('certain', 'assured', 'curtain'),
+    ('fearful', 'afraid', 'tearful'),
+    ('courageous', 'brave', 'outrageous'),
+    ('risky', 'dangerous', 'frisky'),
+    ('run', 'gallop', 'rut'),
+    ('travel', 'journey', 'ravel'),
+    ('swing', 'revolve', 'spring'),
+    ('waver', 'change', 'paver'),
+    ('consider', 'deliberate', 'insider'),
+    ('waiver', 'relinquishment', 'waiter'),
+    ('wafer', 'cookie', 'wader'),
+    ('cleave', 'split', 'clear'),
+    ('nice', 'kind', 'dice'),
+    ('sweet', 'sugary', 'suite'),
+    ('brook', 'stream', 'took'),
+    ('chair', 'seat', 'chart'),
+    ('plant', 'growth', 'plate'),
+    ('limb', 'branch', 'limp'),
+    ('frame', 'enclose', 'frayed'),
+    ('deceive', 'ensare', 'receive'),
+    ('compose', 'plan', 'compost'),
+    ('build', 'construct', 'bill'),
+    ('wheel', 'rotate', 'wheat'),
+    ('fib', 'lie', 'rib'),
+    ('fumble', 'mishandle', 'fume'),
+    ('crucial', 'important', 'crucible'),
+    ('critical', 'discerning', 'criteria'),
+    ('fussy', 'fastidious', 'fuse'),
+    ('exact', 'accurate', 'extract'),
+    ('express', 'convey', 'expense'),
+    ('import', 'deliverd', 'report'),
+    ('limit', 'threshold', 'lint '),
+    ('terminal', 'station', 'liminal'),
+    ('reveal', 'inform', 'revel'),
+    ('fold', 'bend', 'full'),
+    ('groove', 'ridge', 'grove'),
+    ('purse', 'bag', 'pure'),
+    ('crease', 'overlap', 'crass'),
+    ('crude', 'vulgar', 'cruel'),
+    ('poor', 'broke', 'cure'),
+    ('flat', 'plane', 'flax,'),
+    ('rough', 'coarse', 'tough'),
+    ('speed', 'velocity', 'speare'),
+    ('hustle', 'rush', 'huddle'),
+    ('force', 'power', 'fork'),
+    ('strain', 'effort', 'straight'),
+    ('stretch', 'augment', 'street'),
+    ('jaws', 'mouth', 'jobs'),
+    ('pursuit', 'quest', 'peruse'),
+    ('stalk', 'follow', 'stork'),
+    ('spike', 'fasten', 'spat'),
+    ('maintain', 'continue', 'mountain'),
+    ('endure', 'withstand', 'injure'),
+    ('surmount', 'overcome', 'sermon'),
+    ('snap', 'break', 'snack'),
+    ('sprang', 'bolt', 'spray'),
+    ('charge', 'condemn', 'charred'),
+    ('grow', 'expand', 'gross'),
+    ('physical', 'solid', 'cyclical'),
+    ('wild', 'feral', 'will'),
+    ('groan', 'cry', 'roam'),
+    ('differ', 'contradict', 'digger'),
+    ('conflict', 'rivalry', 'conflate'),
+    ('brush', 'caress', 'braze'),
+    ('cling', 'stick', 'clang'),
+    ('lock', 'seal', 'lack'),
+    ('complete', 'entire', 'compliant'),
 ]