Experiment stuck initializing the experiment

URL of experiment: https://pavlovia.org/yyamani/marketing-online-study

Description of the problem: This experiment gets stuck on the initializing the experiment page.

I noticed that the experiment would not run offline until the Experiment Settings, Data tab, Data filename field was changed to u’data/%s_%s_%s’ % (expInfo[‘Participant ID’], expName, expInfo[‘date’]), because the name of the participant field has been changed to from the default ‘participant’ to ‘Participant ID’, causing a key not found error.

Even after that the experiment gets stuck initialising online. If I had to guess where the problem lies, then I would say it was in the RandomizationCode code component. Perhaps much of its functionality could be translated into Builder loops drawing from one or more conditions files, reducing some (if not all of) the need to include a code component?

You will need to rewrite your experiment to avoid imports.

import pandas as pd
import numpy as np

and revert to “participant”.

Please check my crib sheet:

Best wishes,

Wakefield

Thanks. It now runs at least offline.

I have the same problem the experiment stucks at the initializing phase (showing “initializing…”" in a white background forever).

That means the experiment is not properly translated into javascript or it may be problem with the ssh key ? (as I understand probably is the first ?)

Please help as I am stuck and cannot pilot test the Exp :confused: .

Thank you.

@Yusuke_Yamani What was the issue and you did to solve this problem ? thank you in advance!!

It seems that Python code not translating correctly to JavaScript is a major source of the problem. Obviously “cvs” and “pandas” libraries do not work in PsychoJS. I am trying to figure out what functions of NumPy are working…

I rewrote it avoiding pandas. Does Python code using NumPy correctly translate to PsychoJS? I am stuck. Please help.

Best,
Yusuke

I use loops to read Excel files into arrays using append (= push in Javascript)

Remember to add a shuffle function.

Thanks for the suggestions. I avoided importing libraries and added a shuffle function defined at the beginning of the JS code. Unfortunately it still gets stuck. What else could go wrong when running it online?

Numpy does not exist in PsychoJS, so if you have any numpy functions those will need to be replaced as well.

When you attempt to run your experiment, what do you get in the JS console? You can open this console in Chrome by going to view -> developer. If it gets stuck on “initializing” it should display an error of some kind that will identify a line number in your JS file.

Thanks. After entering participant number etc., I got an error "TypeError: null is not an object(evaluating ‘_pj_a.length’). What does this mean? Sorry, I am not familiar with JavaScript at all…

Are you checking the length of an array at some point. I think there may be a problem with the array itself…it’s empty.

It looks like the fundamental problem is that you can’t read in a CSV file as part of a code component online, which is what I see you are trying to do in your “begin experiment” code.

I’m trying to understand what the overall goal of this code is. It looks like you’re trying to read in a list of hotels, authors, and reviews, and then stitch them together in a random way, then feeding the stitched-together units into myStim.csv, which is the condition file for one of your trial loops. That file has the columns T1 through T6 and Hotel, which are then used to fill in the text components text_1 through text_6 and hotel_text in the trial itself. Is that correct?

I think there is a way to do that online, but to be blunt, it’s going to be a little difficult and complicated. Basically, you can’t do it by reading in CSVs and saving the condition file on the spot. You just can’t read and write CSV files like that in JS, and you can’t define your condition file after the experiment has loaded in PsychoJS as far as I know.

One builder-based solution would be to create six loops, all around the same trial(s) that TrialsPositive currently covers, one loop per csv file you have now, and each one set to random. They should randomize separately (I think, I’m not sure), which will effectively do what you’re trying to do now with this code component.

The alternative is something entirely code-based. In short, you could not use CSVs at all, just put the raw text currently stored in your CSVs into the code component directly as lists, shuffle those lists, and call the contents of the list to fill your text components rather than referring to the columns of a condition file. The main problem is that you would not automatically record what each trial consisted of, that is, because it’s not part of the condition file it would not be part of the data file. However, you could manually record the text from each list to the data file using psychoJS.experiment.addData. Essentially you are manually re-creating everything that the trial loop would normally do automatically in your code component, and make it harder to change the text later (i.e., you would have to rewrite the code manually rather than just updating the CSV files).

There are upsides and downsides to each solution, so I would do whichever you feel more comfortable with. The Python solution you developed is fairly elegant, but simply unavailable in JS.

Yes, you are right about the goal of the program. Thanks much for your detailed response and suggestions. I will go with the second option. How do I call an element of a list defined in the code? (e.g., “T1” element for trial 1, 2, 3…)

Does that mean my solution in Pavlovia won’t work either? I can’t test it at the moment because an append=push update is failing to refresh.

I have pre trial loops to load the stimuli into arrays (in a random order) before the main loop.
Begin Experiment: targetlist =
Begin Routine: targetlist.append(Target) (append changed to push in JS)

Also:

I’ll have to search the forum for my last error on this.

At a glance that should work OK, because you’re basically taking the second solution I described and doing it entirely in code. The problem is in trying to read that kind of information into or out of a CSV in a code component.

You can create code components at the beginning of the relevant routine that say something like this:

text_1.setText(T1[n]);
// ...and the same for all the other components
n = n+1;

And in your begin experiment code:

n=0;

That should work for one loop.

OK, I defined T1 and all the other components in the code at the beginning separately, and wrote a code as suggested to call each element.

at “Begin Experiment”
t = 0

at “Begin Routines”
text_1.setText(T1[t]);
text_2.setText(T2[t]);
text_3.setText(T3[t]);
text_4.setText(T4[t]);
text_5.setText(T5[t]);
text_6.setText(T6[t]);
Hotel.text.setText(Hotel[t]);

t = t+1;

I got this error:

text_1.setText(T1[t]);

TypeError: list indices must be integers or slices, not numpy.float64

What would be a solution to avoid this error?

t is a PsychoPy variable for time since the start of the routine. You need to use a different variable name or trials.thisN

Best wishes

Wakefield (woken up by his two year old)