Pavlovia: only download relevant stimuli for participant

Try waiting 60 seconds

After waiting 60 seconds, I get this error if I input 1 as a participant number:

Unfortunately we encountered the following error:

  • when setting the image of ImageStim: exampleGratingLeft
  • TypeError: Cannot read property ‘toString’ of undefined

and if I leave it blank

Unfortunately we encountered the following error:

  • when setting the image of ImageStim: exampleGratingLeft
  • when getting the value of resource: demoPracticeGratingNaN_1.png
  • unknown resource

Are you getting a different error message?

Definitely don’t leave participant blank. The default of 1 in the dialogue box was a good idea.

Ok, that’s back in.

I feel like I’m seeing an error in the download now.

for (var Idx = 1, _pj_a = 5; (Idx <= _pj_a); Idx += 1) {
 stimuli.push({name: ("demoPracticeGrating" + expInfo['participant']+ "_" + Idx + ".png"),path: ("demoPracticeGrating" + expInfo['participant']+ "_" + Idx + ".png")});
 }
 
 for (var Idx = 1, _pj_a = 120; (Idx <= _pj_a); Idx += 1) {
 stimuli.push({name: ("practiceGrating" + expInfo['participant']+ "_" + Idx + ".png"),path: ("practiceGrating" + expInfo['participant']+ "_" + Idx + ".png")});
 }
 
 for (var Idx = 1, _pj_a = 1200; (Idx <= _pj_a); Idx += 1) {
 stimuli.push({name: ("grating" + expInfo['participant']+ "_" + Idx + ".png"),path: ("grating" + expInfo['participant']+ "_" + Idx + ".png")});
 }
 
 stimuli.push([{ name: ("conMat" + expInfo["participant"] + ".xlsx"), path: ("conMat" + expInfo["participant"] + ".xlsx")},
 { name: ("practiceConMat" + expInfo["participant"] + ".xlsx"), path: ("practiceConMat" + expInfo["participant"] + ".xlsx")},
 {name: ("bank-1300155_640.png"), path: ("bank-1300155_640.png")}]);

It might be worth charging Idx to Idx.toString() in the names and paths.

Please add console.log(stimuli);
just before the download in the JS code and print(‘gratingfile’,gratingfile) in demoCode

Ok, now it says

ReferenceError: demoGrating1 is not defined

Sorted.

The main issue was that at one point you were pushing an array of three items when you wanted to push them separately.

The next tip is that items should be added to the list in the order you need them. I’ve moved the practice xlsx file up above the practice gratings.

It seems to work but needs testing to see how likely it is for the participant to catch up with the downloading stimuli.

You should sync and then open the newly downloaded psyexp file before making any changes.

Amazing, it works, thank you so much!

I just pulled the files using git, is that what you mean by syncing?

Would I need to change anything in the psyexp file to redirect from Qualtrics?

There wasn’t an issue with expInfo[‘participant’] so sending a value from Qualtrics or one of my apps should be fine if the corresponding files exist in the repository.

Great, thanks a million for all your help!

Hi,

I am trying to do something similar–only download the resources that are needed for each condition (participants are assigned randomly to condition A, B, C or D).

I have added these lines to the .js file (except the psychoJS.start call–that I did not add or change, but did move):

 version = expInfo["version"];
  if ((version === "A")) {
      myblocklist = "VerA_blocklist.xlsx";
      mypracticeblocklist = "practice_blocklist_VerA.xlsx";
      myslide1 = "Slide9.JPG";
      myslide2 = "Slide10.JPG";
  } else {
      if ((version === "B")) {
          myblocklist = "VerB_blocklist.xlsx";
          mypracticeblocklist = "practice_blocklist_VerB.xlsx";
          myslide1 = "Slide9.JPG";
          myslide2 = "Slide10.JPG";
      } else {
          if ((version === "C")) {
              myblocklist = "VerC_blocklist.xlsx";
              mypracticeblocklist = "practice_blocklist_VerC.xlsx";
              myslide1 = "Slide11.JPG";
              myslide2 = "Slide12.JPG";
          } else {
              if ((version === "D")) {
                  myblocklist = "VerD_blocklist.xlsx";
                  mypracticeblocklist = "practice_blocklist_VerD.xlsx";
                  myslide1 = "Slide11.JPG";
                  myslide2 = "Slide12.JPG";
              }
          }
      }
  }

  psychoJS.start({
  expName: expName,
  expInfo: expInfo,
  resources: [
    {'name': 'ufo2.png', 'path': 'ufo2.png'},
    {'name': 'rocket.png', 'path': 'rocket.png'},
    {'name': 'Slide1.JPG', 'path': 'Slide1.JPG'},
    {'name': 'Slide3.JPG', 'path': 'Slide3.JPG'},
    {'name': 'Slide2.JPG', 'path': 'Slide2.JPG'}
  ]
});
resources.push({[name]: myblocklist, [path]: myblocklist}, {[name]: mypracticeblocklist, [path]: mypracticeblocklist}, {[name]: myslide1, [path]: myslide1}, {[name]: myslide2, [path]: myslide2});

psychoJS.downloadResources(resources)

However, when I try to run I get the error message “resources not defined” and the images do not load.

I was also puzzled because even before I started changing to the .js file, I did not see an existing “psychoJS.downloadResources” call.

@wakecarter any ideas?

It looks like this can now be handled with the static component and resource manager component?

I have a similar issue with my experiment here Simon Del Pin / NAPpav · GitLab

I have a total of 5400 images but I want each participant to only rate 540 of them. If it helps, I can define a csv file for each participant containing the images needed. I am also willing to create JS code that defines the images for each participant and then download those if that makes the job easier.

I have had a look at the documentation here Resource Manager Component — PsychoPy v2023.1.2 but it still does not appear to me how to solve the issue.

Currently, I am setting all images in the additional resources tab but then the experiment takes a looong time to download and wastes resources both for the participant and pavlovia. Is there any more standard solutions to this issue today?