I was wondering if could help me figure out what is the best way to record the actual time each subject took to take an online experiment.
A way I was thinking about, for example, was to look at the time of creation and modification of the data files, but I do not know much about how datafiles are created in Pavlovia. It seems that the server stores the data and put into a csv file only when the experiment is over (i.e., when the pop-up window shows up).
Another way would be to implement an actual Clock
object, make it start at the very beginning of the experiment (e.g., right after the diag box) and stop after the very last trial (i.e., right before the pop-up window shows up) and print that value in the csv file with psychoJS.experiment.addData()
.
Thoughts? Thanks!
Hi @rob-linguistics13, PsychoPy and PsychoJS both have a built-in clock called globalClock
, which is created at the beginning of the experiment. All you need to do is make a call to get the time of that clock at the end of your experiment:
psychoJS.experiment.addData("globalClock", globalClock.getTime())
1 Like
Sorry, @dvbridges - where should I put that string of code?
function endLoopIteration(thisScheduler, thisTrial) {
// ------Prepare for next entry------
return function () {
// ------Check if user ended loop early------
if (currentLoop.finished) {
thisScheduler.stop();
} else if (typeof thisTrial === 'undefined' || !('isTrials' in thisTrial) || thisTrial.isTrials) {
psychoJS.experiment.nextEntry();
}
return Scheduler.Event.NEXT;
};
}
function importConditions(loop) {
const trialIndex = loop.getTrialIndex();
return function () {
loop.setTrialIndex(trialIndex);
psychoJS.importAttributes(loop.getCurrentTrial());
return Scheduler.Event.NEXT;
};
}
function quitPsychoJS(message, isCompleted) {
psychoJS.window.close();
psychoJS.quit({message: 'The experiment is now complete. Thank you for your participation!\nPlease copy-and-paste the following password into Mechanical Turk so that we can confirm your participation: ASYMPTOTE.\nOnce you do that, you can close this page.', isCompleted: isCompleted});
return Scheduler.Event.QUIT;
}
I tried to put between the two functions above, but an error popped up; I tried to put it inside the quitPsychoJS
function, but the experiment would go through without storing the variable.
I would put it in the last occuring RoutineEnd
function in your task, for example if you had an end screen thanking the participant etc.
There is no End
routine. The diag box pops up as soon as all the items are presented. Any alternative solution? Maybe some sort of if
statement on the last routine, e.g.:
#End Routine
if (loop.nRemaning==0){
psychoJS.experiment.addData("globalClock", globalClock.getTime());
}
Ah i see, I thought you were editing the JS. No need for an if statement. You could add it to the End Routine tab of a code component in the last routine and just take the last entry in your datafile as the end exp time.
Sorry @dvbridges I misunderstood what you were saying. Yes, I am editing the JS script. The thing is that my last routine is within a loop. I fear that if I don’t include an if-statement, the clock variable will not get the time at the end of the experiment (actually, it will in the end but I think it will get update at each repeat of the loop which might slow down the whole presentation).
What do you mean by this exactly?