Howdy, Stranger!

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

Supported by

Logging dynamic variables

Hi everyone,


I am currently struggling with creating a well-structured logfile for my experiment. Since I need to log a few variables per task, I created dynamic variables, "reaction_time" for instance:

var.set('reaction_time_{}'.format(n_tasks), reaction_time)

Checking the variable inspector after a test-run, everything seemed to have worked just fine, as in logging reaction_time_1, reaction_time_2, ..., etc., but importing the *.csv to Excel results in only one column named "reaction_time" and value "NA".


Is there anything I missed out here to make dynamic variables be written properly to the logfile?

Comments

  • Hi,


    If you call your variable "reaction_time_1" you have to look for this one in file. Opensesame writes a number of variables automatically, even if they are undefined. Can you find this variable in your list?


    Eduard

  • Hi Eduard,


    thanks for your reply. I do see them in the variable inspector in OpenSesame after an experimental run:


    However, they do not appear in the *.csv-logfile, unless I manually add custom variables to the logger item and call them "reaction_time_1", "reaction_time_2", "reaction_time_3" and so on. But then again, it wouldn't make any sense to create dynamic variables if I still have to manually add each one to be logged + I don't know how many will be needed as they differ from participant to participant.

    In my experiment, participants are given a reaction task every 7-10 seconds and I need to log the reaction time for each task. Depending on how much time participants take on the primary task, the number of reaction tasks (secondary tasks) will vary individually (as will the number of reaction times respectively).


    So basically, I am looking for a way to add a dynamic variable such as "reaction_time_{}.format(n_tasks)" to the logger item, instead of having to add one for each task not knowing how many tasks will be performed.

  • Hi Mr. Fugbaum,

    why don't you just log different variables using long format?

    For example:

    var.RT = yourresponsetime

    var.N_task = yourNofTheTask

    You can later switch this easily and automatically to wide format using tidyr package in R (does not work in Excel).

    Just an idea ;)

    Stephan

  • Hi Stephan,

    thanks for your reply. What is the default logging format in OpenSesame and how do I change it from wide to long or vice versa? Using your example only results in the last response time & last task being logged instead of response time 1 + task 1, response time 2 + task 2, and so on in long format. That is why I thought it was necessary to create dynamic variables in the first place, I just need to find a way to log them and apparently I must be missing the crucial point on how to do that.


    Simply put:

    "var.RT = reaction_time" only logs one value, that is the last value of the variable reaction_time.

    "var.set('reaction_time_{}'.format(n_tasks), reaction_time)" shows reaction_time_X per task X in the variable inspector, but does not write it to the logfile.

  • edited October 2019

    Okay nevermind, I finally managed to find a workaround creating my own logfile using the following code:


    import csv
    
    with open(logger, "a") as logfile :
    	output = csv.writer(logfile, delimiter=";",lineterminator='\n')
    	output.writerow(['subject_id', 'task_id','trials', 'target', 'position', 'correct_response','reaction_time'])
            output.writerow([subject_id, n_tasks, n_trials, letter, position, correct_response, reaction_time])	
    


Sign In or Register to comment.