Deal with condition files on psychojs/pavlovia

In psychopy on the local machine, a lovely feature is that we can create the condition file for all subjects. When I upload the experiment online, I cannot manually assign condition files before each subject does the experiment. Is there a way around it? My colleagues told me that what they do is whenever an online subject begins the experiment, the code will extract all available condition files, randomly choose one for the subject, and then remove the condition file to another fold so that future subjects will not play this condition file. How can I implement this feature on PsychoJS?

Do you have a limited number of conditions files. Someone has previously used my VESPR Study Portal to assign 100 different conditions.

You can also use the shelf to monitor participants

https://psychopy.org/online/shelf.html#usingshelf

1 Like

This works! I can just use the app to pass in sequential participant ID and use that to index the condition files. Another follow-up question, do I have to load all condition files for all subjects each time? It seems that the resource loading phase precedes the input of participant ID so I canā€™t only load the condition file for this particular subject.

You need some code to load the file after the experiment has started but before the custom loop.

1 Like

I added the following line inside async function experimentInit() {

const i = Number.parseInt(expInfo["participant"]%nFiles), nBlocks = 6;
  var resources = [];
  for (let j = 0; j < nBlocks; j++){
    resources.push({name: 'condition_files/subj'+i+'/block'+j+'.csv', path: 'condition_files/subj'+i+'/block'+j+'.csv'})
  }
  psychoJS._serverManager.prepareResources(resources);

But after I type in the participant ID then click ok, I get:

Unfortunately we encountered the following error:

* when importing condition: condition_files/subj4/block0.csv
* when getting the value of resource: condition_files/subj4/block0.csv
* **condition_files/subj4/block0.csv is not available for use (yet), its current status is: "DOWNLOADING"**

It takes time to prepare the resources. Do you have an instructions routine before the first loop that needs one of the custom CSV files?

Oh I see. Yes the first routine is an instruction routine that actually does use the CSV file. So I should create another routine before that for the resourced to load? But how can I control the duration of that routine so that it ends immediately when the resources finish loading?

Hi! Any updates on this?

From my code component snippets

Have a setup routine that never ends and then add a JS code component:

Each Frame

try {
psychoJS.serverManager.getResource(resources[0]);
    continueRoutine = false;
} catch (e) {}

Change 0 to -1 if you need to wait for them all.

1 Like

Thank you so much! I finally got it to work, but also I struggled a bit so I figured I should share my journey here for other peopleā€™s reference. I created a routine called ā€˜loadResourceā€™ in the very beginning and added the code psychoJS._serverManager.prepareResources in the begin Routine part. I have two kinds of resources to load: condition files and some images. Right off the bat the condition files work just fine, however, the images just wouldnā€™t work. I have a line: example_image.setImage(im) to updated the image for each page of instruction. Even though psychoJS.serverManager.getResource shows the images are loaded, just like the conditions files, example_image.setImage just keeps giving me errors. I tried loading the images at various places in the code, with no success. Then I came to the conclusion that the images can only be loaded at PsychJS.start, in which case setImage works without a problem. Now in the final version, I load all the images as usual (thankfully I use the same images for everyone and thus it doesnā€™t depend on subject ID), then use psychoJS._serverManager.prepareResources to load the condition files later in the loadResources routine. While this works fine for the current experiment I am designing, I think it would be worth looking into why doesnā€™t setImage work when images are load through psychoJS._serverManager.prepareResources whereas condition_files can be loaded without bug.

2 Likes

Hi @HuangHam,
I have a similar problem to yours (I have to load over 400 images for my experiment), so thank you for explaining your journey. When you say ā€œin the final version, I load all the images as usualā€, do you load them through ā€œadditional resourcesā€ in the settings? I am still trying to load all my images and get error messages, so thank you in advance!

1 Like

Iā€™m glad it helped! This is what I meant:

psychoJS.start({
  expName: expName,
  expInfo: expInfo,
  resources: [
  {'name': "machines.png", 'path': "machines.png"},
  {'name': "targets.png", 'path': "targets.png"},
  {'name': "trial1.png", 'path': "trial1.png"},
  {'name': "all.png", 'path': "all.png"},
  {'name': "short.png", 'path': "short.png"},
  ]
})

Hi @HuangHam, thank you for your reply! Now, I actually managed to load images later than PsychJS.start (with version 2022.2.4). I added the resource manager component, used psychoJS._serverManager.prepareResources([ā€¦]) in ā€˜begin routineā€™, the try {ā€¦} catch (e) {] that was previously suggested in ā€˜each frameā€™, and changed the image components to ā€œset every repeatā€ instead of ā€œconstantā€.
All the best :slight_smile:

Great! I did the exact same thing but somehow it didnā€™t work for me. Maybe my version is outdated.

1 Like