Howdy, Stranger!

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

Supported by

[solved] inline script logging fails

edited May 2014 in OpenSesame

Hi,

because i collect this variables in another thread, I have this code in my script:


# log to experiment
def logToExperiment():
    for x in toneStartLog:
        print 'toneStartLog', x
        exp.set('ToneStartTime_RTT',x)
    for x in strokeResponseLog:
        print 'strokeResponseLog', x
        self.experiment.set('strokeResponse_RTT',x)
    for x in responseTimeLog:
        print 'responseTimeLog', x
        exp.set('responseTime_RTT',x)
    exp.set('keyStrokes_RTT',keyStrokes)
    print 'keyStrokes', keyStrokes

the following is printed:

toneStartLog
12.0241760706
strokeResponseLog
12.96 (...)
responseTimeLog
0.94934 (...)
keyStrokes
51

I log the variables with a logger, but the logged file only says "NA" under all these variables.

Anybody knows why this is failing ?
Thanks in advance :)

Comments

  • edited 11:46PM

    Hi,

    What you are doing with the exp.set function is making a variable on the OpenSesame GUI level. This does not actually log the variable, nor it's value! What you probably want to do, is use the inline_script's self.log function. See here for it's documentation.

    In your case, this would result in something like the following:

    # log to experiment
    def logToExperiment():
        for x in toneStartLog:
            print 'toneStartLog', x
            self.log('ToneStartTime_RTT,' + str(x))
        for x in strokeResponseLog:
            print 'strokeResponseLog', x
            self.log('strokeResponse_RTT,' + str(x))
        for x in responseTimeLog:
            print 'responseTimeLog', x
            self.log('responseTime_RTT,' + str(x))
        self.log('keyStrokes_RTT,' + str(keyStrokes))
        print 'keyStrokes', keyStrokes
    

    This wouldn't result in the prettiest log file ever, but you can of course think of other ways to do this! Another option is to create your own logfile:

    # open log
    exp.my_log = open('custom_log_%d' % self.get(subject_nr), 'w')
    # write header to log
    exp.my_log.write("var_a,var_b,var_c\n")
    # write some random values to log
    for i in range(3):
        exp.my_log.write("%d,%d,%d\n" % i, 2*i, i+3)
    # neatly close log
    exp.my_log.close()
    

    Good luck!

  • edited 11:46PM

    Hi Edwin, thanks very much for the answer and help.

    Yes i saw the possibility to log text, but this indeed would result in a non-handable logfile for later analysis.

    My initial question was aiming at if it is possible log with loops, in this case I would have thought every assignment of a variable would be a new line in the log file but this is unfortunately not the case.

    i ended up logging every single value to a variable (attaching a logger).

    exp.set('responseTime_RTT1',responseTimeLog[0])
    exp.set('responseTime_RTT2',responseTimeLog[1])
    exp.set('responseTime_RTT3',responseTimeLog[2])
    (...)
    

    As a complete logfile with the other variables from the experiment is prefered, this solution is not pretty but acceptable.

    I guess I just did not completely understand the logging concept of OS ;)

    Thank you very much!

Sign In or Register to comment.