psychopy.org | Reference | Downloads | Github

Accuracy feedback in pavlovia after multiple trials+block

Hi all,

I have an experiment on pavlovia. Generally,it works fine. I would like to implement two more features:

  1. I have a feedback screen every 24 trials as a break. This is done with the JS code below:
 breakTime = 24;
        if ((trials.thisTrialN === 0)) {
            continueRoutine = false;
            msg_3="Well Done."
        }
        if (((trials.thisTrialN% breakTime) > 0)) {
            continueRoutine = false;
            msg_3="Well Done."
        }

What I want to do is to show the accuracy of those 24 trials, e.g. accuracy from 0-24, then from 24-48 and so on so forth.

  1. Every 96 trials (this is the end of the entire block) I have also a feedback screen using this JS code:
breakTime = 95;
    if ((trials.thisN === 0)) {
        continueRoutine = false;
        msg_4="Well Done."
    }
    if (((trials.thisN% breakTime) > 0)) {
        continueRoutine = false;
        msg_4="Well Done."
    }

What I want to do is to show the accuracy of those 96 trials (1 block), e.g. accuracy from 0-96 (block 1), then from 96-182 (block 2) and so on so forth.

I managed to do that in python for both using this code (example code for the block feedback):

if Learning_loop.thisN not in [95,191, 287,383]:
    continueRoutine=False
    acc=Learning_loop.data["Accuracy"].sum()
    msg_4="You found %i stars. Well Done" %(acc)

Any idea on how to approach this in JS to work online? @jonathan.kominsky do you have any ideas on that?

I honestly don’t know how accessible the trialHandler data are in PsychoJS. Someone else might (@dvbridges, @jon), but going completely on intuition you could try psychoJS.experiment.data or currentLoop.data and see if those get you what you need.

Failing that you could also create a custom variable that tracks accuracy in parallel for the sole purpose of reporting it like this.

That’s exactly what I would do (even in Python where I wrote the handler!). It’s often just easier to see and increment your own variables

1 Like

Thanks @jonathan.kominsky && @jon . I actually made my own variables and solved it straight away. This way was a lot easier than messing around with JS handler.

1 Like

I managed to make my own custom variables and increment them in order to track accuracy BUT the issue I have now is the above:
image
In the Learning_feedback routine, Begin Experiment Tab, I have this JS code component:

msg_2 = "";
Acc_blocks=0;
Acc_trials=0;
my_trial=0;

In the Learning_feedback routine, Begin Routine Tab, I have this JS code component:

if (mouse_2.clicked_name.includes("Star", "Learning_scenes")) {
        msg_2 = "Got it!";
        Learning_loop.addData("Accuracy", "1");
        Acc_blocks=Acc_blocks+1;
        Acc_trials=Acc_trials+1;
    } else if (mouse_2.clicked_name.includes("Learning_scenes")){
            msg_2 = "Nope.";
            Learning_loop.addData("Accuracy", "0");
    } else {
            msg_2 = "Time's up";
            Learning_loop.addData("Accuracy", "-");
        }

my_trial=my_trial+1;
console.log(mouse_2.clicked_name);
console.log(my_trial);

Then on the Trial_Break routine, Each Frame Tab, I have this JS code component:

if (my_trial !== 24 && my_trial !== 48 && my_trial !== 72) {
    continueRoutine = false;
    msg_3="You completed 24 trials! You found " + Acc_trials + " out of 24 targets";
}

The problem is that even if I find all the targets in 24 trials (which means 24 targets), it says that I got only 23. For some reason, it omits the performance on the last trial. I inserted a “fake” routine in between (called gap) to console.log(Acc.trials) and it shows the right accuracy but when it moves to the next routine which is the Trial_Break and has to display the Accuracy it shows the wrong number. What is missing here???

Try logging Acc_trials each time it updates, and see if it even disagrees there. I don’t know why it would mysteriously decrement between the update and the break trial.

I logged it each time it updates (in the same Tab) and it shows the right number but then when called on the trial break routine it omits the last one. I even tried different ways of incrementing (++x, ++x, x+=1,x=x+1) but this didn’t solve the problem. Literally, I don’t know what else to try. @dvbridges any guess? Believe it’s something related to how JS evaluates and stores variables but I have limited knowledge.

Oh, I think I know what’s happening. Right now, you are setting the content of msg_3 inside the same condition that determines whether the break trial is displayed or not, and in particular, only when it is not. That is, the last time in the first 24 trials that msg_3 is updated is on trial 23, because on trial 24, that condition is false, which is necessary for the trial to be displayed! Try this on the each frame tab:

msg_3="You completed 24 trials! You found " + Acc_trials + " out of 24 targets";
if (my_trial !== 24 && my_trial !== 48 && my_trial !== 72) {
    continueRoutine = false;
} 

now msg_3 should update on every trial, including 24.

@jonathan.kominsky that was a smart guess but unfortunately it didn’t work. again it omits the last one despite the fact (see on the right side) the numbers are there (from top to bottom: trial number, acc for trials, acc for blocks):

One more thought: Try putting the “msg_3” line in the “begin routine” code instead of the “each frame” code.

Fundamentally, it’s clear Acc_trials is being set correctly, which means that for some reason, the line of code that sets msg_3 is not being updated before it displays on the break trial. The conditional thing would definitely have done that, but it may be that updating text after the text has already been displayed isn’t working as intended either.

This was my last guess and it worked. Wooohoo! Thanks a lot @jonathan.kominsky!!