Pavlovia not logging data properly

Hi,

My experiment is saving data asymmetrically. We have a categorization study where we have to store the intensity of the stimuli as a number, and we have to store this for each stimuli (this is to measure learning rate of the participants). For some reason, it only stores this once and never again. To add further complication, we have an old study that does register this, and has virtually the same code, but when I try and replicate the same lines of code this doesn’t solve the issue.

I tried to add lines of code that psychopy generally does to store data (e.g., psychoJS.experiment.addData(‘key_resp.keys’, key_resp.keys)) but for some reason this doesn’t work. Additionally, I tried to declare the variables that we are trying to store but that doesn’t work either. Does anyone have experience with this? The most confusing part about this is how it only stores the data once and never afterwards.

Best,

Robert C (Cog Sci Phd @ Rutgers)

Hi,

My daily tip for today should answer your question.

Hi.

isTrials is checked. What are my other options?

Check that your keyboard component is set to save data.

Is the data supposed to be saved by the same keyboard component? Does the keyboard component end the trial.

Remove code you’ve added to save it manually and declare the variables. They might be causing an issue.

I think the answer to your question is yes? The keyboard doesn’t end the trial (though I am not sure exactly what you mean by trial). In any case, the thing that I want to store is this variable called Level.

"var level;
function PreTestLoopBeginIteration(snapshot) {
return async function() {
// ------Prepare for next entry------
level = PreTest.intensity;

return Scheduler.Event.NEXT;

}
}"

And for some reason it isn’t storing properly, nor does it seem to vary the numbers, and so a workaround I did was create a new level called “LevelJF = Level” and it fixed the singular storage data problem but now the numbers do not vary (in the screnshot). Do you know anything about this?

Since your latest reply is a completely different question from the one I understood from your first post, I’ll start again.

Does your experiment work locally?

Please could you show any Python code related to “Level”?

If you have any manually edited JavaScript code, please explain why.

Yeah sorry about.

Yes the experiment works locally and on Python, the problem is just that levels is not stored properly.

I have manually edit the JS but I am not sure why this is exactly relevant. The edits were definitely more minor than major.

Code in python:

“def setupLogging(filename):
“””
Setup a log file and tell it what level to log at.

Parameters
==========
filename : str or pathlib.Path
    Filename to save log file and data files as, doesn't need an extension.

Returns
==========
psychopy.logging.LogFile
    Text stream to receive inputs from the logging system.
"""
# set how much information should be printed to the console / app
if PILOTING:
    logging.console.setLevel(
        prefs.piloting['pilotConsoleLoggingLevel']
    )
else:
    logging.console.setLevel('warning')
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log')
if PILOTING:
    logFile.setLevel(
        prefs.piloting['pilotLoggingLevel']
    )
else:
    logFile.setLevel(
        logging.getLevel('info')
    )

return logFile"

"# set up handler to look after randomisation of trials etc
conditions = data.importConditions(‘adaptive_loop_quest_debugging.xlsx’)
trials = data.MultiStairHandler(stairType=‘QUEST’, name=‘trials’,
nTrials=1.0,
conditions=conditions,
method=‘random’,
originPath=-1)
thisExp.addLoop(trials) # add the loop to the experiment
# initialise values for first condition
level = trials._nextIntensity # initialise some vals
condition = trials.currentStaircase.condition

for **level**, condition in trials:
    currentLoop = trials
    thisExp.timestampOnFlip(win, 'thisRow.t', format=globalClock.format)
    # abbreviate parameter names if possible (e.g. rgb=condition.rgb)
    for paramName in condition:
        globals()[paramName] = condition[paramName]
    
    # --- Prepare to start Routine "DiscriminationTrial" ---
    # create an object to store info about Routine DiscriminationTrial
    DiscriminationTrial = data.Routine(
        name='DiscriminationTrial',
        components=[Shape1, Shape2, key_resp_2],
    )
    DiscriminationTrial.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    # Run 'Begin Routine' code from SetupTrial
    feature = discrimination_parameters[feature_index]  
    feature_center = [feature[0],feature[1]] # XX later number these
    feature_vector = [feature[2],feature[3]]
    #coord0 = feature_center # If no difference
    trials.finished=True # Crash this phase XXdebugging
    coord1 = vector_plus(feature_center,scalar_product(**level**,feature_vector))
    coord2 = vector_minus(feature_center,scalar_product(**level**,feature_vector))
    if random() < .5:
        correct_answer = 'd' # different
        shape1 = shape_from_coordinates(coord1,feature_space,10)
        shape2 = shape_from_coordinates(coord2,feature_space,10)
    else:
        correct_answer = 's' # same
        shape1 = shape_from_coordinates(feature_center,feature_space,10)
        shape2 = shape_from_coordinates(feature_center,feature_space,10)"

“def endExperiment(thisExp, win=None):
“””
End this experiment, performing final shut down operations.

This function does NOT close the window or end the Python process - use `quit` for this.

Parameters
==========
thisExp : psychopy.data.ExperimentHandler
    Handler object for this experiment, contains the data to save and information about 
    where to save it to.
win : psychopy.visual.Window
    Window for this experiment.
"""
if win is not None:
    # remove autodraw from all current components
    win.clearAutoDraw()
    # Flip one final time so any remaining win.callOnFlip() 
    # and win.timeOnFlip() tasks get executed
    win.flip()
# return console logger level to WARNING
logging.console.setLevel(logging.WARNING)
# mark experiment handler as finished
thisExp.status = FINISHED
logging.flush()"

I’m afraid that I don’t know much about Quest stair handlers but if the code you have posted is in your code components I would strongly suggest that you rely more on Builder components rather than trying to replicate their functions in code.

You won’t be able to save a custom log file online.

Why is your staircase loop in code? Your parameter level appears to be part of that loop.

Why do you have End Experiment code?

Not trynna ghost you or anything, but I have sort of solved the issue, and I do not think Psychop/Pavlovia handles quest in the way in which I would like it to. But, I have gotten around to my issues with it. Appreciate you being swift with your responses.