Timeline¶
CodeBlock¶
- class psynet.timeline.CodeBlock(function)[source]¶
A timeline component that executes some back-end logic without showing anything to the participant.
- Parameters:
function – A function with up to two arguments named
participant
andexperiment
, that is executed once the participant reaches the corresponding part of the timeline.
Conditional statements¶
- psynet.timeline.conditional(label, condition, logic_if_true, logic_if_false=None, fix_time_credit=False, bound_progress=True, log_chosen_branch=True, time_estimate=None)[source]¶
Executes a series of elts if and only if a certain condition is satisfied.
- Parameters:
label (
str
) – Internal label to assign to the construct.condition (
Callable
) – A function with up to two arguments namedparticipant
andexperiment
, that is executed once the participant reaches the corresponding part of the timeline, returning a Boolean.logic_if_true – An elt (or list of elts) to display if
condition
returnsTrue
.logic_if_false – An optional elt (or list of elts) to display if
condition
returnsFalse
.fix_time_credit (
bool
) – Whether participants should receive the same time credit irrespective of the branch taken. Defaults toFalse
; if set toTrue
, all participants receive the same credit, corresponding to the branch with the maximum time credit.bound_progress (
bool
) – Whether the progress estimate should be ‘bound’ such that, whatever happens, when the participant exits the conditional construct, the progress estimate will be the same as if the participant had taken the branch with the maximum time credit. Defaults toTrue
.log_chosen_branch (
bool
) – Whether to keep a log of which participants took each branch; defaults toTrue
.time_estimate (
float
) – An optional time estimate to use for the conditional construct. If not provided, the time estimate will be estimated by computing time estimates for the two branches and taking the maximum.
- Returns:
list – A list of elts that can be embedded in a timeline using
psynet.timeline.join()
.
Page¶
- class psynet.timeline.Page(*, time_estimate=None, template_path=None, template_str=None, template_arg=None, label='untitled', js_vars=None, js_links=None, media=None, scripts=None, css=None, css_links=None, contents=None, session_id=None, save_answer=True, events=None, progress_display=None, start_trial_automatically=True, show_termination_button=None, aggressive_termination_on_no_focus=False, bot_response=<class 'psynet.utils.NoArgumentProvided'>, validate=None)[source]¶
The base class for pages, customised by passing values to the
__init__
function and by overriding the following methods:- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.template_path (
Optional
[str
]) – Path to the jinja2 template to use for the page.template_str (
Optional
[str
]) – Alternative way of specifying the jinja2 template as a string.template_arg (
Optional
[Dict
]) – Dictionary of arguments to pass to the jinja2 template.label (
str
) – Internal label to give the page, used for example in results saving.js_vars (
Optional
[Dict
]) – Dictionary of arguments to instantiate as global Javascript variables.js_links (
Optional
[List
]) – Optional list of paths to JavaScript scripts to include in the page.media (
psynet.timeline.MediaSpec
) – Optional specification of media assets to preload (see the documentation forpsynet.timeline.MediaSpec
).scripts (
Optional
[List
]) – Optional list of scripts to include in the page. Each script should be represented as a string, which will be passed verbatim to the page’s HTML.css (
Optional
[List
]) –Optional list of CSS specification to include in the page. Each specification should be represented as a string, which will be passed verbatim to the page’s HTML. A valid CSS specification might look like this:
.modal-content { background-color: #4989C8; margin: auto; padding: 20px; border: 1px solid #888; width: 80%; } .close { color: #aaaaaa; float: right; font-size: 28px; font-weight: bold; }
css_links (
Optional
[List
]) – Optional list of links to CSS stylesheets to include in the page.contents (
Optional
[Dict
]) – Optional dictionary to store some experiment specific data. For example, in an experiment about melodies, the contents property might look something like this: {”melody”: [1, 5, 2]}.save_answer (
bool
) – IfTrue
(default), then the answer generated by the page is saved toparticipant.answer
, and a link to the correspondingResponse
object is saved inparticipant.last_response_id
. IfFalse
, these slots are left unchanged. If a string, then the answer is not only saved toparticipant.answer
andparticipant.last_response_id
, but it is additionally saved as a participant variable named by that string.events (
Optional
[Dict
]) – An optional dictionary of event specifications for the page. This determines the timing of various Javascript events that happen on the page. Each key of this dictionary corresponds to a particular event. Each value should then correspond to an object of classEvent
. TheEvent
object specifies how the event is triggered by other events. For example, if I want to define an event that occurs 3 seconds after the trial starts, I would writeevents={"myEvent": Event(is_triggered_by="trialStart", delay=3.0)}
. Useful standard events to know aretrialStart
(start of the trial),promptStart
(start of the prompt),promptEnd
(end of the prompt),recordStart
(beginning of a recording),recordEnd
(end of a recording),responseEnable
(enables the response options), andsubmitEnable
(enables the user to submit their response). These events and their triggers are set to sensible defaults, but the user is welcome to modify them for greater customization. See also theupdate_events
methods ofPrompt
andControl
, which provide alternative ways to customize event sequences for modular pages.progress_display (
Optional
[ProgressDisplay
]) – OptionalProgressDisplay
object.show_termination_button (
bool
) – IfTrue
, a button is displayed allowing the participant to terminate the experiment, Defaults torecruiter.show_termination_button
which can beFalse
for all recruiters except for the Lucid recruiter where it should beTrue
.start_trial_automatically (
bool
) – IfTrue
(default), the trial starts automatically, e.g. by the playing of a queued audio file. Otherwise the trial will wait for the trialPrepare event to be triggered (e.g. by clicking a ‘Play’ button, or by calling psynet.trial.registerEvent(“trialPrepare”) in JS).bot_response – Optional function to call when this page is consumed by a bot. This will override any
bot_response
function specified in the class’sbot_response
method.validate (
Optional
[callable
]) –Optional validation function to use for the participant’s response. Alternatively, the validation function can be set by overriding this class’s
validate
method. If no validation function is found, no validation is performed. Seevalidate()
for information about how to write this function.Validation functions provided via the present route may contain various optional arguments. Most typically the function will be of the form
lambda answer: ...` or ``lambda answer, participant: ...
, but it is also possible to include the argumentsraw_answer
,response
,page
, andexperiment
. Note thatraw_answer
is the answer before applyingformat_answer
, andanswer
is the answer after applyingformat_answer
.Validation functions should return
None
if the validation passes, or if it fails a string corresponding to a message to pass to the participant.For example, a validation function testing that the answer contains exactly 3 characters might look like this:
lambda answer: "Answer must contain exactly 3 characters!" if len(answer) != 3 else None
.
- contents¶
A dictionary containing experiment specific data.
- Type:
dict
- session_id¶
If session_id is not None, then it must be a string. If two consecutive pages occur with the same session_id, then when it’s time to move to the second page, the browser will not navigate to a new page, but will instead update the Javascript variable psynet.page with metadata for the new page, and will trigger an event called pageUpdated. This event can be listened for with Javascript code like window.addEventListener(”pageUpdated”, …).
- Type:
str
- dynamically_update_progress_bar_and_reward¶
If
True
, then the page will regularly poll for updates to the progress bar and the reward. IfFalse
(default), the progress bar and reward are updated only on page refresh or on transition to the next page.- Type:
bool
- attributes(participant)[source]¶
Returns a dictionary containing the session_id, the page type, and the page_uuid .
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- metadata(**kwargs)[source]¶
Compiles metadata about the page or its response from the participant. This metadata will be merged with the default metadata object returned from the browser, with any duplicate terms overwritten.
- Parameters:
**kwargs –
Keyword arguments, including:
raw_answer
: The raw answer returned from the participant’s browser.answer
: The formatted answer.metadata
: The original metadata returned from the participant’s browser.
experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
dict – A dictionary of metadata.
- pre_render()[source]¶
This method is called immediately prior to rendering the page for the participant. It will be called again each time the participant refreshes the page.
- validate(response, **kwargs)[source]¶
Takes the
psynet.timeline.Response
object created by the page and runs a validation check to determine whether the participant may continue to the next page.- Parameters:
response – An instance of
psynet.timeline.Response
. Typically theanswer
attribute of this object is most useful for validation.**kwargs –
Keyword arguments, including:
experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.answer
: The formatted answer returned by the participant.raw_answer
: The unformatted answer returned by the participant.page
: The page to which the participant is responding.
- Returns:
None
or an object of classpsynet.timeline.FailedValidation
– On the case of failed validation, an instantiation ofpsynet.timeline.FailedValidation
containing a message to pass to the participant.
- class psynet.page.DebugResponsePage[source]¶
Bases:
PageMaker
Implements a debugging page for responses. Displays a page to the user with information about the last response received from the participant.
- class psynet.page.InfoPage(content, time_estimate=None, **kwargs)[source]¶
Bases:
ModularPage
This page displays some content to the user alongside a button with which to advance to the next page.
- Parameters:
content (
Union
[str
,Markup
,dom_tag
]) – The content to display to the user. Usemarkupsafe.Markup
to display raw HTML.time_estimate (
Optional
[float
]) – Time estimated for the page.**kwargs – Further arguments to pass to
psynet.modular_page.ModularPage
.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.page.JsPsychPage(label, timeline, time_estimate, js_links, css_links, js_vars=None, **kwargs)[source]¶
Bases:
Page
A page that embeds a jsPsych experiment. See
demos/jspsych
for example usage.- label :
Label for the page.
- timeline :
A path to an HTML file that defines the jsPsych experiment’s timeline. The timeline should be saved as an object called
timeline
. Seedemos/jspsych
for an example.- js_links :
A list of links to JavaScript files to include in the page. Typically this would include a link to the required jsPsych version as well as links to the required plug-ins. It is recommended to include these files in the
static
directory and refer to them using relative paths; alternatively it is possible to link to these files via a CDN.- css_links :
A list of links to CSS stylesheets to include. Typically this would include the standard jsPsych stylesheet.
- js_vars :
An optional dictionary of variables to pass to the front-end. These can then be accessed in the timeline template, writing for example
psynet.var["my_variable"]
.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- class psynet.page.UnityPage(title, resources, contents, session_id, game_container_width='960px', game_container_height='600px', time_estimate=None, debug=False, **kwargs)[source]¶
Bases:
Page
This is the main page when conducting Unity experiments. Its attributes
contents
andattributes
can be accessed through the JavaScript variablepsynet.page
inside the page template.Ín order to conclude this page call the
psynet.nextPage
function which has following parameters:rawAnswer
: The main answer that the page returns.metadata
: Additional information that might be useful for debugging or other exploration, e.g. time taken on the page.blobs
: Use this for large binaries, e.g. audio recordings.
Once the
psynet.nextPage
function is called, PsyNet will navigate to a new page if the new page has a different session_id compared to the current page, otherwise it will update the page while preserving the ongoing Unity session, specifically updatingpsynet.page
and triggering the JavaScript eventpageUpdated
in thewindow
object.- Parameters:
title (
str
) – The title of the experiment to be rendered in the HTML title-tag of the page.game_container_width (
str
) – The width of the game container, e.g. ‘960px’.game_container_height (
str
) – The height of the game container, e.g. ‘600px’.resources (
str
) –The path to the directory containing the Unity files residing inside the “static” directory. The path should start with “/static” and should comply with following basic structure:
static/ ├── css/ └── scripts/
css: Contains stylesheets scripts: Contains JavaScript files
contents (
dict
) – A dictionary containing experiment specific data.time_estimate (
Optional
[float
]) – Time estimated for the page (seconds).session_id (
str
) – If session_id is not None, then it must be a string. If two consecutive pages occur with the same session_id, then when it’s time to move to the second page, the browser will not navigate to a new page, but will instead update the JavaScript variable psynet.page with metadata for the new page, and will trigger an event called pageUpdated. This event can be listened for with JavaScript code like window.addEventListener(”pageUpdated”, …).debug (
bool
) – Specifies if we are in debug mode and use unity-debug-page.html as template instead of the standard unity-page.html.**kwargs – Further arguments to pass to
psynet.timeline.Page
.
- metadata(**kwargs)[source]¶
Compiles metadata about the page or its response from the participant. This metadata will be merged with the default metadata object returned from the browser, with any duplicate terms overwritten.
- Parameters:
**kwargs –
Keyword arguments, including:
raw_answer
: The raw answer returned from the participant’s browser.answer
: The formatted answer.metadata
: The original metadata returned from the participant’s browser.
experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
dict – A dictionary of metadata.
- class psynet.page.WaitPage(wait_time, content=None, **kwargs)[source]¶
Bases:
Page
This page makes the user wait for a specified amount of time before automatically continuing to the next page.
- Parameters:
wait_time (
float
) – Time that the user should wait.content – Message to display to the participant while they wait. Default: “Please wait, the experiment should continue shortly…”
**kwargs – Further arguments to pass to
psynet.timeline.Page
.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- metadata(**kwargs)[source]¶
Compiles metadata about the page or its response from the participant. This metadata will be merged with the default metadata object returned from the browser, with any duplicate terms overwritten.
- Parameters:
**kwargs –
Keyword arguments, including:
raw_answer
: The raw answer returned from the participant’s browser.answer
: The formatted answer.metadata
: The original metadata returned from the participant’s browser.
experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
dict – A dictionary of metadata.
- psynet.page.wait_while(condition, expected_wait, check_interval=2.0, max_wait_time=20.0, wait_page=<class 'psynet.page.WaitPage'>, log_message=None, fail_on_timeout=True)[source]¶
Displays the participant a waiting page while a given condition remains satisfied.
- Parameters:
condition – The condition to be checked; the participant will keep waiting while this condition returns True. This argument should be a function receiving the following arguments:
participant
(corresponding to the current participant) andexperiment
(corresponding to the current experiments). If one of this arguments is not needed, it can be omitted from the argument list.expected_wait (
float
) – How long the participant is likely to wait, in seconds.check_interval (
float
) – How often should the browser check the condition, in seconds.max_wait_time (
float
) – The participant’s maximum waiting time in seconds. Default: 20.0.wait_page – The wait page that should be displayed to the participant; defaults to
WaitPage
.log_message (
Optional
[str
]) – Optional message to display in the log.fail_on_timeout – Whether the participants should be failed when the
max_loop_time
is reached. Setting this toFalse
will not return theUnsuccessfulEndPage
when maximum time has elapsed but allow them to proceed to the next page.
- Returns:
list – A list of test elts suitable for inclusion in a PsyNet timeline.
Consent pages¶
- class psynet.consent.AudiovisualConsent(time_estimate=30)[source]¶
Bases:
Module
The audiovisual consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class AudiovisualConsentPage(time_estimate=30)[source]¶
-
This page displays the audiovisual consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.CAPRecruiterAudiovisualConsent(time_estimate=30)[source]¶
Bases:
Module
The CAP-Recruiter audiovisual recordings consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class CAPRecruiterAudiovisualConsentPage(time_estimate=30)[source]¶
-
This page displays the CAP-Recruiter audiovisual consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.CAPRecruiterStandardConsent(time_estimate=30)[source]¶
Bases:
Module
The CAP-Recruiter standard consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class CAPRecruiterStandardConsentPage(time_estimate=30)[source]¶
-
This page displays the CAP-Recruiter standard consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.Consent[source]¶
Bases:
Elt
Inherit from this class to mark a timeline element as being part of a consent form. PsyNet requires you have at least one such element in your timeline, to make sure you don’t forget to include a consent form. See
CAPRecruiterAudiovisualConsentPage
for an example. If you’re sure you want to omit the consent form, include aNoConsent
element in your timeline.
- class psynet.consent.DatabaseConsent(time_estimate=30)[source]¶
Bases:
Module
The database consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class DatabaseConsentPage(time_estimate=30)[source]¶
-
This page displays the database consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.LucidConsent(time_estimate=30)[source]¶
Bases:
Module
The Lucid consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class LucidConsentPage(time_estimate=30)[source]¶
-
This page displays the Lucid consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.MainConsent(time_estimate=30)[source]¶
Bases:
Module
The main consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class MainConsentPage(time_estimate=30)[source]¶
-
This page displays the main consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.NoConsent[source]¶
Bases:
Consent
,NullElt
If you want to have no consent form in your timeline, use this element as an empty placeholder.
- class psynet.consent.OpenScienceConsent(time_estimate=30)[source]¶
Bases:
Module
The open science consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class OpenScienceConsentPage(time_estimate=30)[source]¶
-
This page displays the open science consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.PrincetonCAPRecruiterConsent(time_estimate=30)[source]¶
Bases:
Module
The Princeton University consent form to be used in conjunction with CAP-Recruiter.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class PrincetonCAPRecruiterConsentPage(time_estimate=30)[source]¶
-
This page displays the Princeton University consent page to be used in conjunction with CAP-Recruiter.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.PrincetonConsent(time_estimate=30)[source]¶
Bases:
Module
The Princeton University consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class PrincetonConsentPage(time_estimate=30)[source]¶
-
This page displays the Princeton University consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
- class psynet.consent.VoluntaryWithNoCompensationConsent(time_estimate=30)[source]¶
Bases:
Module
The voluntary participation with no compensation consent form.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- class VoluntaryWithNoCompensationConsentPage(time_estimate=30)[source]¶
-
This page displays the voluntary participation with no compensation consent page.
- Parameters:
time_estimate (
Optional
[float
]) – Time estimated for the page.
- format_answer(raw_answer, **kwargs)[source]¶
Formats the raw answer object returned from the participant’s browser.
- Parameters:
raw_answer – The raw answer object returned from the participant’s browser.
**kwargs –
Keyword arguments, including:
blobs
: A dictionary of any blobs that were returned from the participant’s browser.metadata
: The metadata returned from the participant’s browser.experiment
: An instantiation ofpsynet.experiment.Experiment
, corresponding to the current experiment.participant
: An instantiation ofpsynet.participant.Participant
, corresponding to the current participant.
- Returns:
Object – The formatted answer, suitable for serialisation to JSON and storage in the database.
- get_bot_response(experiment, bot)[source]¶
This function is used when a bot simulates a participant responding to a given page. In the simplest form, the function just returns the value of the answer that the bot returns. For more sophisticated treatment, the function can return a
BotResponse
object which contains other parameters such asblobs
andmetadata
.
PageMaker¶
- class psynet.timeline.PageMaker(function, time_estimate=None, accumulate_answers=False, label='page_maker')[source]¶
A page maker is defined by a function that is executed when the participant requests the relevant page.
- Parameters:
function (
Callable
[...
,Union
[Elt
,List
[Elt
],EltCollection
]]) – A function that may take up to two arguments, namedexperiment
andparticipant
. These arguments correspond to instantiations of the class objectspsynet.experiment.Experiment
andpsynet.participant.Participant
respectively. The function should return either a single test element (e.g.psynet.timeline.Page
,psynet.timeline.PageMaker
,psynet.timeline.CodeBlock
) or a list of such elements. Note thatpsynet.timeline.PageMaker
objects can be nested arbitrarily deeply. Note also that, if the page maker returns multiple pages, then the function will be recomputed each time the participant progresses to the next page. This functionality can be used to make the latter pages depend on the earlier pages in the page maker.time_estimate (
Optional
[float
]) – Time estimated to complete the segment. This time estimate is used for predicting the overall length of the experiment and hence generating the progress bar. The actual time credit given to the participant is determined bytime_estimate
parameters provided to the pages generated byfunction
. However, there is an exception provided for back-compatibility: iffunction
generates a list containing solelypsynet.timeline.Page
orpsynet.timeline.PageMaker
objects, and if those objects are all missingtime_estimate
values, then thesetime_estimate
values will be imputed by dividing the parentpsynet.timeline.PageMaker
’stime_estimate
by the number of produced elements.
PreDeployRoutine¶
- class psynet.timeline.PreDeployRoutine(label, function, args=None)[source]¶
Bases:
NullElt
A timeline component that allows for the definition of tasks to be performed before deployment. It is possible to make database changes as part of these routines and these will be propagated to the deployed experiment.
- Parameters:
label – A label describing the pre-deployment task.
function – The name of a function to be executed.
args – The arguments for the function to be executed.
Response¶
- class psynet.timeline.Response(*args, **kwargs)[source]¶
Bases:
_Response
A database-backed object that stores the participant’s response to a
Page
. By default, one such object is created each time the participant tries to advance to a new page.- answer¶
The participant’s answer, after formatting.
- page_type¶
The type of page administered.
- Type:
str
- successful_validation¶
Whether the response validation was successful, allowing the participant to advance to the next page.
- Type:
bool
- client_ip_address¶
The participant’s IP address as reported by Flask.
- Type:
str
- creation_time¶
the time at which the Network was created.
- details¶
a generic column for storing structured JSON data
- failed¶
boolean indicating whether the Network has failed which prompts Dallinger to ignore it unless specified otherwise. Objects are usually failed to indicate something has gone wrong.
- failed_reason¶
an optional reason the object was failed. If the object is failed as part of a cascading failure triggered from another object, the chain of objects will be captured in this field.
- id¶
a unique number for every entry. 1, 2, 3 and so on…
- property metadata¶
A dictionary of metadata associated with the Response object. Stored in the
details
field in the database.
- property1¶
a generic column that can be used to store experiment-specific details in String form.
- property2¶
a generic column that can be used to store experiment-specific details in String form.
- property3¶
a generic column that can be used to store experiment-specific details in String form.
- property4¶
a generic column that can be used to store experiment-specific details in String form.
- property5¶
a generic column that can be used to store experiment-specific details in String form.
- time_of_death¶
the time at which failing occurred
- type¶
- vars¶
Switch statements¶
- psynet.timeline.switch(label, function, branches, fix_time_credit=False, bound_progress=True, log_chosen_branch=True, time_estimate=None)[source]¶
Selects a series of elts to display to the participant according to a certain condition.
- Parameters:
label (
str
) – Internal label to assign to the construct.function (
Callable
) – A function with up to two arguments namedparticipant
andexperiment
, that is executed once the participant reaches the corresponding part of the timeline, returning a key value with which to indexbranches
.branches (
dict
) – A dictionary indexed by the outputs offunction
; each value should correspond to an elt (or list of elts) that can be selected byfunction
.fix_time_credit (
bool
) – Whether participants should receive the same time credit irrespective of the branch taken. Defaults toFalse
; if set toTrue
, all participants receive the same credit, corresponding to the branch with the maximum time credit.bound_progress (
bool
) – Whether the progress estimate should be ‘bound’ such that, whatever happens, when the participant exits the conditional construct, the progress estimate will be the same as if the participant had taken the branch with the maximum time credit. Defaults toTrue
.log_chosen_branch (
bool
) – Whether to keep a log of which participants took each branch; defaults toTrue
.time_estimate (
float
) – An optional time estimate to use for the switch construct. If not provided, the time estimate will be estimated by computing time estimates for all branches and taking the maximum.
- Returns:
list – A list of elts that can be embedded in a timeline using
psynet.timeline.join()
.
While loops¶
- psynet.timeline.while_loop(label, condition, logic, expected_repetitions, max_loop_time=None, fix_time_credit=True, fail_on_timeout=True)[source]¶
Loops a series of elts while a given criterion is satisfied. The criterion function is evaluated once at the beginning of each loop.
- Parameters:
label (
str
) – Internal label to assign to the construct.condition (
Callable
) – A function with up to two arguments namedparticipant
andexperiment
, that is executed once the participant reaches the corresponding part of the timeline, returning a Boolean.logic – An elt (or list of elts) to display while
condition
returnsTrue
.expected_repetitions (
int
) – The number of times the loop is expected to be seen by a given participant. This doesn’t have to be completely accurate, but it is used for estimating the length of the total experiment.max_loop_time (
float
) – The maximum time in seconds for staying in the loop. Once exceeded, the participant is is presented theUnsuccessfulEndPage
. Default: None.fix_time_credit – Whether participants should receive the same time credit irrespective of whether
condition
returnsTrue
or not; defaults toTrue
, so that all participants receive the same credit.fail_on_timeout – Whether the participants should be failed when the
max_loop_time
is reached. Setting this toFalse
will not return theUnsuccessfulEndPage
when maximum time has elapsed but allow them to proceed to the next page.
- Returns:
list – A list of elts that can be embedded in a timeline using
psynet.timeline.join()
.