Pandas Equivalent in PsyJS - Initializing screen

I have an experiment that works locally in the builder using pandas to convert a list into an array, then get the average of the entire array, and then multiply it by a variable number. The code is below - multiNum is a variable (number) that gets read in from an excel sheet.

## Begin Experiment
rt_list = []

## Begin Routine
#if the array is not empty then do the mean calculation and the multiplying calculation
rt_array = np.array(rt_list)
if len(rt_array > 0): 
    rt_mean = rt_array.mean()
    newTime = rt_mean*multiNum

## End Routine 
#add response time to the array
rt_list.append(key_resp_5.rt) 

I first tried to import pandas explicitly (import pandas as np) because I was getting an error that “np” wasn’t recognized. When I tried to explicitly import pandas, it got stuck on the initializing screen. I saw in the cribsheet that pandas doesn’t work online, so then I tried to remove pandas entirely and change the code in the Begin Routine section to do mathematical computations on the list:

##Begin Routine
if len(rt_list > 0): 
    rt_mean = rt_list.mean()
    newTime = rt_mean*multiNum

But when I try to run it, I am still stuck on the initializing screen. I can’t tell if this code will work and the frozen screen is another issue, or if the frozen initializing screen is from this code. I’ve been having trouble getting the experiment to run in JS locally, so I’ve been forced to push it to Pavlovia, put it in pilot mode, test it, take it out of pilot mode, fix an error, and repeat - so I can’t tell if the initializing screen is just some other issue related whatever is going on there, or something separate.

Essentially, I need to know how to do mathematical computations to lists, or create arrays without the use of pandas. If we can troubleshoot the frozen screen at the same time, that’s great. Thanks!

Hello

you can not import Python-libraries for online-experiment because there is no JavaScript equivalent. The Builder interface imports all libraries useable for online-experiments.

The following code adds a RT of a correct response at the end of a routine

if key_crt.corr:
    meanWahlRT += key_crt.rt
    corWahlRT += 1
meanWahlRT = 0
corWahlRT = 0

had initialized at experiment begin.

Does this help?

Best wishes Jens

Jens,

This doesn’t work for my case, but it did give me an idea that worked!

I have the same number of trials (40) in every block, so I created a variable where the new reaction time was added after each trial, and then the average was calculated by dividing it by the number of trials.

##Begin Experiment
#rt variable
rt_trial = 0

##End Routine
rt_trial += key_resp_5.rt
rtMean = rt_trial/40
newTime = rtMean*multiNum