-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Background
Currently, forms that present a stimulus via the jsPsych mechanism do so by loading an entire timeline, typically, but not necessarily, consisting of a single trial. After the trial executes and the timeline (experiment) ends, the form is sent back to the server and the response is written to the response table.
Issue
Sometimes it is necessary to present multiple trials within a timeline, with each trial sending an array of responses back to the server so that those can be written to the database. In return, the frontend client expects the parameters for a new trial. The timeline ends when no more parameters are received from the server. The regular handling via views.serve_form() will not work in this case, so a different solution needs to be found.
Proposed solution
- A new type of form handler should be created, perhaps form_jspsych_multitrial
- views.serve_form() should be called, per usual, at the end of a jsPsych timeline/experiment, but should circumvent writing of responses when handling a post from a form_jspsych_multitrial handled form. Any responses will have been written by the endpoint called in the per-trial callback function during the running of the timeline.
- The per-trial endpoint should be an experiment-specific module that is exposed in the urls.py file for the experiment.
- jsPsych has built-in functionality for per-trial callback functions that get called when a trial in a timeline completes.
- The desired callback function probably needs to be attached in the original specification of the timeline.
- The callback function should consist of a synchronous, i.e. blocking, call to the server, sending all data for that trial to the server which handles writing of it to the Response table.
- The callback function should implement a success() function that injects the returned (non-empty) trial dictionary into the timeline