| Reference | Downloads | Github

Save onset offset time 2020.2.10 online

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2020.2.10


I want to know the duration for which a stimulus was presented in my experiment. I set the time on 4 seconds, but participants are allowed to be faster than that by continuing the experiment before the 4 seconds are ofer.

In order to know the time they could have looked at the stimuli, I want to know the onset/offset times (which I asked for in the builder view > image properties > data).

In my offline (i.e. psychopy on desktop) csv file, I get two colomns:

prpaint.started → with values like 2512985889997790 and 27450827699969500
prpaint.stopped → None (So I assume something already goes wrong here?)

When I try my experiment online, I get neither.

My question is therefore: How do I get the image presentation duration in my csv file in my online study?

I tried adding this to the Py and JS End Routine Code components in the same routine as I presented the image.

thisExp.addData('prpaint.stopped', prpaint.stopped)

psychoJS.experiment("prpaint.stopped", prpaint.stopped);

This gave me the error:

thisExp.addData('prpaint.stopped', prpaint.stopped)

AttributeError: ‘ImageStim’ object has no attribute ‘stopped’

Thank you very much for any help

Hi There,

You are correct that start and stop times are stored locally but not online. To save a stims start time online you would add a code component, set code type to JS and use:

// save the onset times of stimuli
thisExp.addData('stimName.tStart', stimName.tStart)

// save the onset times of stimuli (taking into account frames
thisExp.addData('stimName.frameNStart', stimName.frameNStart)

Saving offsets is a little tricker. What is stopping your stimulus from being presented? is it a keyboard response that ends the routine? in which case the response time from that key response would serve as your end time) is it a time when the stimulus is moved offscreen by something else? What you would need is a component something like this (code type set to auto → JS):

if myStim.pos[0] == -300:# checking when a stims x coordinate is -300 for example
    stopTime = myRoutineNameClock.getTime()

thisExp.addData('stopTime', stopTime)

Remember, as per the crib sheet, PsychoPy Python to Javascript crib sheet - Google Docs to add a code component to the very start of your experiment, code type JS, and add thisExp=psychoJS.experiment; (so that the javascript version of your experiment knows what you are referring to when you save data to thisExp).

Hope this is helpful,

Thank you very much for your thorough reply!

I will try this online as soon as it is possible again.

Thanks for this @Becca . Does it matter which tab (Begin Routine, End Routine, etc.) this code goes in? Thanks!

It needs to be in the “end routine” tab, as at the beginning of the routine, those values haven’t yet been measured (i.e. the stimulus hasn’t appeared at the time that code section runs).

1 Like