psychopy.org | Reference | Downloads | Github

How can I have the total experiment time?

Hi, I have an experiment on which I need to measure the total experiment time.

I’ve tried to use these other forum codes :

"Psychopy has an internal clock which starts when the experiment starts. You can read the time using core.monotonicClock.getTime(). The timing of this clock starts almost immediately as you hit “run”, i.e. before the dialogue box, so it doesn’t read the time since the first routine started. However, you can get that duration by first recording the time of the clock in a code component when you want time zero to be defined:

time_zero = core.monotonicClock.getTime()
… and then record the time elapsed doing

thisExp.addData(‘cumulative_duration’, core.monotonicClock.getTime() - time_zero)
Note that if you want to do this only for particular loops (e.g. define time_zero in the first loop and record cumulative_duration in the last loop) require the condition to be satisfied:

If this is the first iteration of the loop (no matter the name of the loop)

if currentLoop.thisN == 0:
time_zero = core.monotonicClock.getTime() "

I’ve written it in the “Begin Eperiment” and in the “End Eperiment”, but it’s not working…

I’m a beginner , so I would really appreciate your help!

Hi @Rafael_Gramza, please surround your code with back ticks to improve readability - see here.

It seems that you are using Builder with a code component, as you have the Begin and End experiment tabs, if not please let me know. If using Builder, this will create a variable called globalClock, which tracks the time from when the experiment started. So, in the “End Experiment” tab, you can add the following to get the final time in your data file:

thisExp.addData("globalClockTime", globalClock.getTime())
thisExp.nextEntry()

This works when I run the experiment on my computer, but not when I run it online. I have it in js (end experiment)
psychoJS.experiment.addData(“globalClockTime”, globalClock.getTime())
thisExp.nextEntry()

In the output data file, there’s no column named “globalClockTime”

should I write the code differently?

This works when I run the experiment on my computer, but not when I run it online. I have it in js (end experiment)
psychoJS.experiment.addData(“globalClockTime”, globalClock.getTime())
thisExp.nextEntry()

In the output data file, there’s no column named “globalClockTime”

should I write the code differently?

See Get total experiment time for the online version