Adding new columns to the log file in the data folder

Hi, it would make data anlysis a lot of easier if there was a way to add new columns to the log file. For example, in the image below it shows the timings of keyboard presses, I was hoping that there could be an extra column on the left, that tells you what trial this is. So for example for those keyboard presses it would have Trial 1 for each press as they are all for trial 1. Then so on for Trial 2. Is this possible?

Screenshot 2024-03-01 at 13.08.13

Thank you for any help, much appreciated.

Is there a reason why you are using the log file, not the csv file?

I am using a text box for participants to write text within the study, and I want to record what letters they wrote and the timings of each key that was pressed. This does not seem to be saving in the CSV file, but only in the log file.

This Each Frame code should work for that situation. In my case I was just timing spaces but you could adapt it:

nCharacters = len(textbox.text)
if oldLength > nCharacters:
    backspaceCount += 1
elif oldLength < nCharacters:
    if key_space.keys:
        if len(key_space.keys) > nSpaces:
        #    textbox_2.text[-1] == ' ':
            thisExp.nextEntry()
            thisExp.addData('WordTime',myClock.getTime()-wordTime)
            wordTime = myClock.getTime()
            thisExp.addData('Word',textbox_2.text[wordPos:-2])
            thisExp.addData('BackspaceCount',backspaceCount)
            thisExp.addData('TypingTime',myClock.getTime())
            wordPos = nCharacters-1
            nSpaces = len(key_space.keys)

oldLength = nCharacters

Hi, thank you for your reply. I have spent a lot of time trying to figure out how to adapt mine to this, but I am struggling. As I do not understand how to incorperate it to get letters that participants typed, what time they typed it and what trial it is.

What I am struggling to understand is where would I get the code that I need to adapt yours to mine. Where do I get the reference for key presses within the text box, the time of the key presses and what trial these key presses are from.

Currently, within the excel file I have the keys that were pressed for each trial, however, it displays it as one word, I need it as individual letters so I can see the timing of each letter pressed.

The principle of my method is to check when the length of textbox.text increases and then use next entry to add a line in the data file and save the current routine time t.

Try this code.

Begin Routine

oldLength = 0
myClock = core.Clock()

Each Frame

nCharacters = len(textbox.text)

if nCharacters > oldLength:
            thisExp.nextEntry()
            thisExp.addData('Letter',textbox.text[-1])
            thisExp.addData('RT',myClock.getTime())
            myClock.reset()
            oldLength = nCharacters

Hi, This worked!!! Thank you so much!

And all I have to do, if I want the timing of each letter rather than reaction time, is delete the code myClock.reset()

You could put this in Begin Routine or just use t instead which is the automatic routine timer.

1 Like