URL of experiment:
Description of the problem:
I was able to follow the instruction of this post to display a participant’s reaction time at the end of the task. In addition, I would like to display their accuracy as well, but I’m not sure how to retrieve the information for the accuracy calculation.
Here is the Python code for displaying accuracy and reaction time:
RTmean = trials.data['TrialResp.rt'].mean()
acc = trials.data['TrialResp.corr'].sum()
## calculate percent of accuracy
totalNumberTrial = trials.nTotal
pacc = (acc/totalNumberTrial)*100
msg = "You got %0.2f %% correct. \nYour response time is %.2f seconds." %(pacc, RTmean)
Here is the PsychoJS version, but it only displays the reaction time:
// Get JS array of trial objects (i.e., a list of python dicts with response data)
dat = psychoJS.experiment._trialsData
// Filter data to get correct trials
corr = dat.filter((trial) => trial['TrialResp.corr'] === 1)
// Get RTs only as an array
rts = corr.map((trial) => trial['TrialResp.rt'])
// Reduce RTs to a single number : the mean
RTmean = rts.reduce((a, b) => (a + b), 0) / rts.length
const msg = `Your response time is ${RTmean.toFixed(2)} seconds.`;
My teammate has tried this code, but it gave the error “totalTrials not found.”
totalTrials = dat.length;
correctTrials = corr.length;
ACCmean = (correctTrials / totalTrials) * 100;
Could anyone please suggest how to include the accuracy calculation? Thank you so much for your help.