Recovering recorded data during trial - within the task

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): v2021.2.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

I want to record the number of correct button presses during the trial, and present total number correct during the feedback routine.

The “trial” routine is surrounded by two loops.
The first, inside loop, to choose image to present.
The second, outside loop, to choose subsets of the image list to shuffle, i.e., shuffle 0:3, 3:6, 6:9, 9:12…so on.

image

What did you try to make it work?:
This is my code in my “feedback” routine, to print in my feedback routine:

countCorr2 = int(trials_shuffler.trial.data[‘key_resp.corr’].sum())
$feedback_text = ‘You got str(countCorr2) correct.’

I reset countCorr2=0 at the beginning of every block, in the “Begin Experiment” tab.

What specifically went wrong when you tried that?:

Here is my error:

countCorr2 = int(trials_shuffler.trial.data[‘color_change_resp.corr’].sum())
AttributeError: ‘TrialHandler’ object has no attribute ‘trial’

To note, I have also tried:
countCorr2 = int(trial.data[‘key_resp.corr’].sum())
→ The experiment runs, but the incorrect number of correct button presses is recorded. I know this, when I compare the actual key_resp.corr column in the excel sheet output.

countCorr2 = int(trials_shuffler.data[‘key_resp.corr’].sum())
→ I get the error: KeyError: ‘color_change_resp.corr’

The feedback code works, if I remove the outer loop that shuffles a subset of trials.

Please advise, thank you so much.

Hello,

what is the difference between countCorr2 and the number of correct responses in the result-file? Did I understand you correctly that the reset countCorr2 in the Begin Experiment tab only? You need to reset it after each feedback. I’d put the reset in the End routine tab of the feedback.

Best wishes Jens

Thank you for your response!
countCorr2 is the number of responses in the result-file.
In the result-file, I get an output with column labeled “key_resp.corr” with 1’s or 0’s for each trial. Then, I sum the entire column.
This is where I got it from:
https://psychopy.org/recipes/builderFeedback.html

Sorry I did not mention, I also reset it at the “End Routine” of the “feedback” tab.

Here is my entire experiment (simplified, of course):

In the “Begin Experiment” tab, I initialize countCorr2 = 0.

I have 3 blocks. [block loop]
In each block, I have 12 trials; I shuffle subset of 3 trials at a time [trials_shuffler loop]

And then in each trial, I present 1 image at a time, 12 total, in the random order dictated by trials_shuffler. [trial loop]
Here, I count the number of button presses to the correct image.

In [feedback_2], I give feedback on total number correct in the block, and re-set the “countCorr2” counter.

My problem is that the countCorr2 printed in the feedback routine is always less than what it should be.

Additionally, I have instead tried:

if color_change_resp.corr:
countCorr3 += 1

in the “End routine” of the trial_routine. This overcounts countCorr3.

I cannot figure out what is going on. Something about the [trials_shuffler] loop interferes with the correct trial counter. So, I had thought I was printing the feedback incorrectly when there are two loops around the routine ([trial] and [trials_shuffler]). Would you agree, and if so, how should I format the countCorr2?

Thank you so much for any advice.

Thank you so much for making a toy-experiment. It’s similar, but my task also has a “shuffling a subset of trials per block” component.

The excel sheet looks like this:

image

Basically, I have this [trials_shuffler] loop that shuffles subsets of images presented.

I would send you my toy example but right now, it requires images. I’ll try and figure out how to replace images with polygons, and get back to you if it would be clarifying.

Thank you so much again for your time and help!

Hello,

I needed to adapt my program a little bit. My last example had the feedback at the wrong part in the flow. See adapted version.

ReportCorrect.psyexp (15.6 KB)
UseRows.xlsx (17.6 KB)
ReportCorr.xlsx (17.7 KB)

Well, it should not matter whether you use a subset or the whole list. See the new toy-example.

Best wishes Jens

1 Like

Thank you so much!! It’s finally working.

I switched to dynamically counting the number correct, per routine, as you did in your toy example.

if key_resp.corr:
countCor += 1

This worked better than calling the excel file output and taking the sum of correct answers across an entire block. Now the feedback is consistently displaying the correct response.

Many thanks! :slight_smile: