coglabuzh / online-exps

Unleash the full potential of JavaScript and supercharge your web experiments with this library for experimental programming - based on jsPsych - work in progress! 🎯
2 stars 0 forks source link

Create timeline based on Batch jatos information #11

Open AnaRodMa opened 11 months ago

AnaRodMa commented 11 months ago

I would like to generate a timeline using information retrieved from a Jatos array. In the code, my plan is to initiate an array on Jatos (if it's not already present), with index for instance that could be linked to specific information that should be included in the trials. Subsequently, I aim to retrieve specific data from the array (e.g., a number), such as Jatosarray[0], and utilize this information to dynamically create the necessary trials for inputting into the timeline. Given the distinct conditions and combinations assigned to different participants, I want to avoid the creation of predefined timelines for each combination in advance (as I currently do).

ajit283 commented 11 months ago

Thanks for the question, I'll get back to you on this!

ajit283 commented 11 months ago

Hi, I understand that you want to make a trial where every participant has different experiment conditions. If you have only a few variable conditions, I would create an array conditions in the experiment. conditions[i] would then contain the conditions that are unique to participant i. The number of the current participant can be accessed in the experiment through jatos.workerId. This is a number which starts at 1 and is incremented for each participant. I hope this helps, feel free to share the code if you need more specific advice!

chenyu-psy commented 11 months ago

Hi Ajit,

I have a similar issue. Assigning participants to different conditions is not a problem for us. The problem is that we have to prepare varied timelines for participants in different conditions.

For example, I have two groups A and B. Participants in group A are required to complete the experiment in the order of 1, 2, 3, and 4. Conversely, participants in the other group must follow the order of 3, 4, 1, and 2. At the moment, we need to prepare two timelines and use both of them. If participants are assigned to group A, they will skip the second timeline, and participants in group B will skip the first timeline.

We always have to prepare the timeline with an equal number of conditions. When there are more than 5 conditions, it's quite annoying.

ajit283 commented 11 months ago

Hi Chenyu,

could you share en example experiment where this problem occurs? I can create a function which e.g. generates all permutations of an array or all combinations of different conditions, would this help solve the issue?

chenyu-psy commented 11 months ago

Hi Ajit,

Yes, I will send the experiment to you by email and show you the problem.

ajit283 commented 11 months ago

Hi Chenyu,

I see that you currently generate all possible timelines and use the conditional_function parameter to filter out the relevant timeline. Just to check, have you already tried approaches like this?

image

In a similar way, you could also call a single generateTimeline() function where you just pass in the expInfo.DESIGN parameter:

timeline.push(generateTimeline(expInfo.DESIGN)).

If this doesn't work with JATOS though, another approach would be to use jsPsych.addNodeToEndOfTimeline(), which can dynamically change the timeline at runtime: https://www.jspsych.org/7.0/reference/jspsych/#jspsychaddnodetoendoftimeline

Let's talk about this in the next meeting in more detail!

ajit283 commented 10 months ago

Dear Chenyu,

I have identified the problem. The timeline.push() statements are run after before the on_finish function of preload_screen, causing the experiment to always choose the default value from the settings, "preRe". The solution for this is to add an invisible timeline element to the end of the trial and add the correct timeline in the on_finish function of that trial:

timeline.push({
    type: HtmlKeyboardResponsePlugin,
    stimulus: "<div></div>",
    trial_duration: 0,
    on_finish: () => {
      if (expInfo.DESIGN == "preRe") {
        console.log("preRe is being run");
        jsPsych.addNodeToEndOfTimeline(experiment_preRe_timeline);
      } else {
        console.log("rePre is being run");
        jsPsych.addNodeToEndOfTimeline(experiment_rePre_timeline);
      }
    },

I have sent you the full code via email. Best, Ajit

chenyu-psy commented 10 months ago

Hi Ajit,

Thank you for your effort; it looks very convenient. However, I didn't receive the email. Could you please check if you sent it to the correct email address?