Page¶
- 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.