Reputation: 13
I want to show participants a feedback page containing e.g. how many taps were detected during the trial they just completed. Here is what I'm trying to do:
class PracticeTrialMaker(StaticTrialMaker):
give_end_feedback_passed = True
performance_check_type = "performance"
performance_check_threshold = 0
end_performance_check_waits = True
def get_end_feedback_passed_page(self, score):
how_many_taps = "NA" if score is None else f"{(score):.0f}"
return InfoPage(
Markup(
f"You tapped <strong>{how_many_taps}% times;</strong>."
),
time_estimate=5,
)
def performance_check(self, experiment, participant, participant_trials):
# for now, just count number of taps detected
n_taps_detected = participant_trials.analysis['num_resp_raw_all']
failed = participant_trials.failed
return {"score": n_taps_detected, "passed": not failed}
But I don't know how to find / pass into performance_check the analysis results... they are not contained in participant_trials or participant or experiment, unless I am completely missing something.
How can I show analysis-based feedback to a participant?
Upvotes: 1
Views: 29
Reputation: 96
The method get_end_feedback_passed_page
provides feedback at the end of aStaticTrialMaker
based on the overall performance of all trials within that trial maker. More precisely, it only shows the feedback if the participant has successfully met the performance threshold.
For your case, I would use the method show_feedback
within a StaticTrial
. This allows you to provide feedback after each individual trial. You can then access the output of the analysis (the dictionary returned in the method analyze_recording
) by calling the analysis output stored in the trial - i.e., self.details["analysis"]
. Here is an example in context:
class MyExperimentalTrial(StaticTrial):
__mapper_args__ = {"polymorphic_identity": "custom_trial"}
wait_for_feedback = True
def gives_feedback(self, experiment, participant):
return True
def show_feedback(self, experiment, participant):
output_analysis = self.details["analysis"]
if output_analysis["num_taps"] > 20:
return InfoPage(
Markup(
f"""
<h3>Excellent!</h3>
<hr>
We detected {output_analysis["num_taps"]} taps.
"""
),
time_estimate=5
)
else:
return InfoPage(
Markup(
f"""
<h3>VERY BAD...</h3>
"""
),
time_estimate=5
)
Note that you should use it in combination with gives_feedback
and also specify in the definition of the corresponding trialmaker check_performance_every_trial=False
Upvotes: 1