Preloading resources by experiment list

PennController for IBEX Forums Support Preloading resources by experiment list

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #6587
    emorgan
    Participant

    I’ve gotten preloading resources to work in general, but I’m running an experiment with a large number of sound files, so I’d like to only preload the files that are necessary for the particular experiment group that a participant has been assigned to. Is there a way to access the internal counter to know which group I’m on (and hence which .zip file to preload)? Or is there another standard way to achieve this?

    Thank you for your help!

    #6589
    Jeremy
    Keymaster

    Hi,

    I understand you are talking about preloading resources for different groups from a zip file. To be clear, when not part of a zip file, only the resources used in the trials effectively presented to the current group are fetched.

    If you need to preload different zip files depending on group, you can use the variable __counter_value_from_server__. Say you have a total of 4 groups:

    EDIT: this code will not immediately work on https://expt.pcibex.net or https://ibex.spellout.net/ — see this message if you’re running your study at one of those two domains

    switch (__counter_value_from_server__ % 4) {
      case 0:
        PreloadZip("https://my.server/path/to/zip_a.zip");
        break;
      case 1:
        PreloadZip("https://my.server/path/to/zip_b.zip");
        break;
      case 2:
        PreloadZip("https://my.server/path/to/zip_c.zip")
        break;
      case 3:
      default:
        PreloadZip("https://my.server/path/to/zip_d.zip")
        break;
    }

    Let me know if you have any questions

    Jeremy

    #6590
    emorgan
    Participant

    Yes, thanks for clarifying–I did mean preloading from a zip file, and that solution is exactly what I was looking for! Thank you!

    #6610
    emorgan
    Participant

    Hi Jeremy,
    To follow up on this, our template is designed with a variable and plays a specific audio file from a group. It seems that in order to use the __counter_value_from_server__, we need to be inside the template. Is that right? If so, where would that switch statement go if the code structure looks like:

    Template(“myTable.csv”, variable =>
    newTrial(“music”,
    newText (“Listen carefully to the melody.”)
    .center()
    .print()
    ,
    newButton(“Play”)
    .center()
    .print()
    .wait()
    ,

    Thank you again for your help!

    -Emily

    #6611
    Jeremy
    Keymaster

    Hi Emily,

    The switch statement from my previous message lets you execute different PreloadZip commands depending of the value of __counter_value_from_server__ (which goes to show that it is available from outside Template). This is a rather specific need

    The Template function readily implements group designs by looking up a Group/List column in your table and selecting a subset of rows that share a single value for that column, so you don’t need to manually check __counter_value_from_server__. Since you should have the option of specifying the name of the audio file you want to play directly in a column in your table, I am not sure why you would need to access __counter_value_from_server__ from within the Template command

    Jeremy

    #6612
    emorgan
    Participant

    Thank you for such a quick response! I realized I glossed over too much in my question. We really do want to execute different PreloadZip commands depending on the counter value (because otherwise the amount of data to be loaded is way too large if we have to load all possible files for every participant). When we first tried to use the __counter_value_from_server__ variable (in a switch statement outside of the Template function), we got the error:

    Unrecognized expression ‘__counter_value_from_server__’ (line 250) (PennController: 9)

    We thought perhaps the problem was that that variable was only defined inside the Template, but clearly that’s not the problem. Do you know what the issue might be? Thank you again!

    Best,
    Emily

    #6613
    Jeremy
    Keymaster

    My bad, I tested my code at https://farm.pcibex.net/, where __counter_value_from_server__ is accessible from the start, which is not the case at https://expt.pcibex.net.

    If you’re running your study on the expt Farm (or on the original Ibex Farm for that matter) you’ll need a little trick to detect when __counter_value_from_server__ is being set:

    let myOwnCounter = 0, preloadZipSent = false;
    Object.defineProperty(window, '__counter_value_from_server__', {
        set(v){
            myOwnCounter = v;
            if (preloadZipSent) return;
            preloadZipSent = true;
            switch (v % 4) {
              case 0:
                PreloadZip("https://my.server/path/to/zip_a.zip");
                break;
              case 1:
                PreloadZip("https://my.server/path/to/zip_b.zip");
                break;
              case 2:
                PreloadZip("https://my.server/path/to/zip_c.zip")
                break;
              default:
              case 3:
                PreloadZip("https://my.server/path/to/zip_d.zip")
                break;
            }
        }, 
        get(){
            return myOwnCounter;
        }
    });

    Jeremy

    #6639
    emorgan
    Participant

    Thanks very much!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.