psychopy.org | Reference | Downloads | Github

Getting inconsistent values when summing up response times

OS: Ubuntu 20.04
PsychoPy version: 2020.2.10
Standard Standalone? (y/n): yes

What are you trying to achieve?:

I created a task that works both on my desktop and online, but when I sum up values to provide feedback, the results are inconsistent.

Briefly, the participant has to click 10 successive targets (= 1 trial) as fast as possible (similar to a serial reaction time task).

What did you try to make it work?:

Following a suggestion given by Jonh Pierce (here: Provide feedback (mean RT and number of stops) after a block in a SST task - #3 by Hakl), I created a variable before the loop

rts = []

And then, after every iteration, I used

rts.append(animation_mouse.time)

I want to sum up the 10 response times inside rts and provide the result as feedback.
Since I could not get the summation, because the values inside rts are organized as a list like this

[[1], [2], [3]]

I used the code below to flat the list of values before summing them:

flat_list = []

for element in rts:
    if type(element) is list:
        for item in element:
            flat_list.append(item)
    else:
        flat_list.append(element)

total_time = round(sum(flat_list), 2)

What specifically went wrong when you tried that?:

In the same code component, I added

thisExp.addData('total_time', total_time)

to keep track of the feedback I was providing.

The problem is: when I get the results file and sum the values in the column animation_mouse.time they are not always similar to the ones I get in the column total_time. In some trials I get the exact same values (as expected), and in others I get totally different ones. I just can’t figure out why…

I would really appreciated any advice.

code_JS
I think it is important to add that I have a code component at the beginning of my experiment, as recommended here: PsychoPy Python to Javascript crib sheet - Google Docs

thisExp=psychoJS.experiment;
win=psychoJS.window;
event=psychoJS.eventManager;
shuffle = util.shuffle;
Array.prototype.append = [].push;
sum = (arr) =>arr.reduce((a,b)=>a+b);
round = function(num, n=0) {    
    return +(Math.round(num + ("e+" + n))  + ("e-" + n));
}

Example of the results I’m getting

Here is a results’ file with some trials:
1_srt_interference_2021_fev_08_2257.csv (35.2 KB)

Best wishes,
Flavio

It is always a better morning when you find your own bugs :slight_smile:

The different total times I was getting was caused by additional clicks registered inside some iterations of animation_mouse.time.

So, instead of using

I just get the first value in the array

rts.append(animation_mouse.time[0])

Now, I don’t even have to flat lists anymore :wink:

I’m not used to Builder so I’m still learning how to debug using it.
I would like to thank @Becca and @wakecarter for all the great contributions to this forum.
They are helping me a lot :slight_smile:

I hope this, at list, helps someone else.

Best,
Flavio

1 Like