psychopy.org | Reference | Downloads | Github

Streamlining downloading resources

Hello,

Simplified details of experiment: I have 3 unique conditions files (A.csv, B.csv, and C.csv) for 3 participants (A, B, and C). Each condition file has 3 different visual stimuli (A.csv has 1.jpg, 2.jpg, and 3.jpg; B.csv has 4.jpg, 5.jpg, and 6.jpg; C.csv has 7.jpg, 8.jpg, and 9.jpg). I’ve had it set up so that each conditions file and visual stimulus is downloaded as a resource for all participants. I also have code that connects the subject’s ID (provided by them at the experiment set up page) with their own conditions file.

Rather than need to download all 3 conditions files and 9 visual stimuli, I’d like to set up my script so that subjects need only to download their own conditions file and corresponding stimuli. How can the resources be constructed so that subject A gets images 1, 2, and 3?

Hey Adam,

Better support for dynamically downloading resources is high on the 2do list for PsychoJS, For the time being, I’m working on a kind of plugin that can do this for you. This is the current state of it:

  1. Works for images, not yet for spreadsheets (conditions)
  2. Still need to test it on multiple platforms; probably will do that in the coming two weeks.
  3. It uses rather funky programming concept, called a closure.

Having said this, below is some code that shows how it works. Create a routine that shows a text saying “One moment please…”, no end time, and add a code component with the script below.

This part goes into Begin Routine

var load = function(resources) {
  psychoJS.downloadResources(resources);
  return function() {
    // Check whether each resource is available
    try {
      for (var i = 0; i < resources.length; i++) {
        psychoJS.serverManager.getResource(resources[i].name);
      }
    } catch (e) {
      // Some resource not available yet; return true (continue routine)
      return true;
    }
    // All resources available; return false (end routine)
    return false;
  }
}
// StimA and StimB will be whatever image is specified via path
// You can use some code to change this per participant
window.checkProgress = load([
    {name: 'StimA', path: 'img/a.png'},
    {name: 'StimB', path: 'img/a.png'},
]);

This part goes into Each Frame

continueRoutine = window.checkProgress();

Thank you for your response. Can you please elaborate on the first issue (Works for images, not yet for spreadsheets (conditions))? What do you mean by this exactly?

Thanks.

For now I can’t be much more specific, but Wednesday I’ll pick this up again. Can I get back to you then?

Of course. Thanks for you help.