Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Custom Logging/Output

edited March 2014 in OpenSesame

I will be using OpenSesame as part of a cognitive training study (starting April 1), which involves subjects coming in for multiple sessions. I currently record and log Subject # and Session variables, but every time the same subject # is used, the logging file (e.g., subject-1.csv) is overwritten.

I could have the subject runners manually name the output files, but that introduces a lot of room for human error, especially with the amount of data that will be collected (hundreds of subjects completing 16 sessions each).

I would like to be able to either name the log file (sub_session_task.csv) or create a new custom output file from an inline script within the experiment. I've tried out a few commands that work from a Python terminal, but I haven't been able to create a text file from within OpenSesame using the Droid back-end on a Nexus 10. Any ideas?

Comments

  • edited March 2014

    You'll want to take a look at this discussion, which describes how you can choose custom logfile locations from within an inline_script:

    In your case, the idea should be the same, but you'll have to make sure that you choose a writable location for the logfile, for example in the /sdcard/ folder (but it's somewhat device dependent). So ...

    path = '%d-%d.csv' % (self.get('subject_nr'), session_nr)
    

    ... might become ...

    path = '/sdcard/%d-%d.csv' % (self.get('subject_nr'), session_nr)
    

    Cheers!

  • edited 10:16PM

    Thanks! I was able to get it to work based on the previous discussion and your suggested path. Here's the code that ended up working for me:

    #Imports modules for modifying filenames and getting a timestamp
    import os
    import time
    import datetime
    
    # Closes the current logfile
    exp._log.close()
    
    #Creates a timestamp
    rawtimestamp = time.time()
    timestamp =
    #Formats the timestamp into YYYYMMDDHHSS
    datetime.datetime.fromtimestamp(rawtimestamp).strftime('%Y%m%d%H%M%S')
    
    #Version 1 = colored Ps
    #Re-defines the name of the log file as Sub_Sess_TaskVers#_Timestamp.csv
    path = '/sdcard/ChangeDetectionData/Sub' + str(self.get('subject_nr')) + '_Sess' + str(self.get('Session')) + '_ChangeDetectionVers1_' + str(timestamp) + '.csv'
    exp.logfile = path
    
    # Reopens the logfile
    exp._log = None
    exp.init_log()
    
    

    It's working perfectly. I'm curious about something, though. I have a folder with all my stimulus images called TaskImages. In my stimulus display inline, I have the following code.

    Targets=['BA.bmp','BB.bmp']
    #Randomizes which image is first
    shuffle(Targets)
    #Defines the target as the first image (now shuffled)
    trialtarg=Targets[0]
    #Defines the path to the image
    trialtargpath='./TaskImages/'+ trialtarg
    

    But when I try to use a comparable command to define the output folder with a relative path, I get an error.

    path = './VisualSearchData/Sub' + str(self.get('subject_nr')) + '_Sess' + str(self.get('Session')) + '_VisualSearchVers1_' + str(timestamp) + '.csv'
    

    outputs this error in the debug file:
    "IOError: [Errno 2] No such file or directory: './VisualSearchData/Sub0_Sess4_VisualSearchVers1_20140317175935.csv'

    The script currently works great with the original script I attached at the top, so it's not critical, but I'm curious why './VisualSearchData' doesn't work.

  • edited 10:16PM

    The ./ indicates that the path is relative to the current directory, which (under Android) is the app directory that you don't (usually) have write access to. So it's simply a permissions issue.

    Cheers!

Sign In or Register to comment.