psychopy.org | Reference | Downloads | Github

Conditions file parameters missing from data files using Pavlovia

Hello! This is my first time using the forum in any capacity. Please let me know if there is a better sub-forum or format for my issue.

OS: Win 10
PsychoPy version: 3.1.2
Standard Standalone : Y

What are you trying to achieve?:
I’m trying to make sure condition file parameters are recorded in the data files.

What did you try to make it work?:
Ran the program through Psychopy locally and the condition file parameters as well as participant response time and accuracy (keyboard) are recorded in data set. Stimuli appear as indexed via the condition file as well.

What specifically went wrong when you tried that?:
The same program, when run through Pavlovia, does not record the condition file parameters but does record participant response time and accuracy. Accuracy is determined by the condition file and the stimuli would not appear without the program reading the file.

Hi dey.a,

This is a recent issue that the Psychopy/psychoJS developers are working on resolving. There is a hack solution to record your condition file parameters that I reference here.

Until the problem is resolved, you need to put in code manually at the end of the routine within the trial loop to record those trial parameters. You can use a code component for this in the Builder interface or put it into your javascript file after it’s been created. If your TrialHandler object is called trials and you want to record the displayed stimulus via its parameter stim_id, then you would put this code at the end of the routine:

psychoJS.experiment.addData("stim_id", trials.trialList[trials.thisIndex]["stim_id"]);

Hi kevinhroberts,

Thank you for your response and link to the other thread. Manually adding the parameters to the log after the routine seems to be working!

Hi @kevinhroberts

I’m having the same problem, so many thanks for your advice.

I tried your suggestion as JS code in Builder, but this stopped the study running online. I then tried to add the code directly into the JS file as well, which gets the study up and running again, but this hasn’t made any difference to the data files it’s creating. I’m evidently getting something wrong here. I edited the ‘study_name’.js file in the html folder, added the new code in front of the existing ‘addData’ code after each routine and then synced the project again to Pavlovia. Does that sound about right, or did I miss something?

Many thanks,
Katie

Hi Katie,

I’m not sure what went wrong with your experiment, it sounds like you were doing things correctly. If you are implementing this through Builder, you would put the JS code in the “End Routine” tab of a code component for the routine that you want to log the variables for.

If you’re putting the code directly into the JS (not generally recommended by the developers) then it should be placed in the function for the end of the routine. For example, I have a routine called “questions” which has this function which I added the recording of two variables, “stim_id” and “stim_type”:

function questionsRoutineEnd() {
  //------Ending Routine 'questions'-------
  for (const thisComponent of questionsComponents) {
    if (typeof thisComponent.setAutoDraw === 'function') {
      thisComponent.setAutoDraw(false);
    }
  }
  psychoJS.experiment.addData('key_resp_2.keys', key_resp_2.keys);
  if (typeof key_resp_2.keys !== undefined) {  // we had a response
      psychoJS.experiment.addData('key_resp_2.rt', key_resp_2.rt);
      routineTimer.reset();
      }
  
  key_resp_2.stop();

  //Variables from the spreadsheet to record manually
  psychoJS.experiment.addData('stim_id', trials.trialList[trials.thisIndex]["stim_id"]);
  psychoJS.experiment.addData('stim_type', trials.trialList[trials.thisIndex]["stim_type"]);

  // the Routine "questions" was not non-slip safe, so reset the non-slip timer
  routineTimer.reset();
  
  return Scheduler.Event.NEXT;
}

Did you give the correct name for your TrialHandler? This is the name of your loop in the Builder interface. In the code above, the TrialHandler is named “trials”. You’ll need to change your code according to the name of your TrialHandler.

If this isn’t working for you (though it really should, if implemented correctly!) you can also try what is suggested by the developers, over here

Hi Kevin,

Thanks for your reply. My TrialHandler is also called ‘trials’, so naming shouldn’t be the issue, but reassuring to know I’ve tried the right things. I’ll try setting the version to 3.1.0 (although I’ve been advised previously to use a different version for other reasons) and inserting the code into the JS file again, hopefully one of these will solve things.

Many thanks,
Katie

Hi there,

Sorry about this. For what it’s worth, it turns out we had an issue where we were mixing two incompatible versions of the JS code - PsychoPy was outputting code in a way that was only compatible with a previous version of the PsychoJS lib.

We have now fixed the issue for all versions (the PsychoJS lib now handles the issue, whether or not the code exported from PsychoPy was written “correctly”). Your data file should now be collecting the conditions info correctly but let me know if you find any further occurences of this issue and if it has affected you badly for any “real” data collection.

Our apologies for the error
Jon