Page
****

class psynet.page.DebugResponsePage

   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.EndPageRedirect(failure_tags=None, **kwargs)

   Bases: "Elt"

   Base class for end pages that redirect to a named timeline branch.

   Parameters:
      **failure_tags** ("Optional"["List"]) -- Optional failure tags
      to append before redirecting.

class psynet.page.ExecuteFrontEndJS(js)

   Bases: "InfoPage"

   Execute JavaScript in a lifecycle-managed page module.

class psynet.page.InfoPage(content, time_estimate=None, label='info', **kwargs)

   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. Use "markupsafe.Markup" to
        display raw HTML.

      * **time_estimate** ("Optional"["float"]) -- Time estimated for
        the page.

      * **label** ("str") -- The page's label, for example to find the
        page in a bot test with "bot.current_page_label". Defaults to
        ""info"".

      * ****kwargs** -- Further arguments to pass to
        "psynet.modular_page.ModularPage".

   get_bot_response(experiment, bot)

      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, which
      is saved without passing through "format_answer". For more
      sophisticated treatment, the function can return a "BotResponse"
      object which contains other parameters such as "blobs" and
      "metadata". PsyNet's built-in answer controls return
      "BotResponse(raw_answer=...)" with what the browser would
      submit, so that bot answers pass through the same
      "format_answer" methods as browser answers.

class psynet.page.JsPsychPage(label, timeline, time_estimate, js_dependencies, css_links, js_vars=None, **kwargs)

   Bases: "Page"

   A page that embeds a jsPsych experiment. See "demos/jspsych" for
   example usage.

   label :
      Label for the page.

   timeline :
      URL of a JavaScript module exporting "buildTimeline(context)".
      This function receives "jsPsych", "vars", "page", "psynet", and
      "root", and returns the jsPsych timeline array. See
      "demos/jspsych" for an example.

   js_dependencies :
      A list of JavaScript libraries to load once per browser
      document. 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"]".

class psynet.page.RejectedConsentPage(failure_tags=None, **kwargs)

   Bases: "EndPageRedirect"

   Redirects the participant to the rejected consent branch.

class psynet.page.SuccessfulEndPage(failure_tags=None, **kwargs)

   Bases: "EndPageRedirect"

   Redirects the participant to the successful end branch.

class psynet.page.UnityPage(title, resources, contents, session_id, game_container_width='960px', game_container_height='600px', time_estimate=None, debug=False, **kwargs)

   Bases: "Page"

   This is the main page when conducting Unity experiments. Its
   attributes "contents" and "attributes" can be accessed through the
   JavaScript variable "psynet.page" inside the page template.

   In 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 updating
   "psynet.page" and triggering the JavaScript event "pageUpdated" in
   the "window" 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)

      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:

         1. "raw_answer": The raw answer returned from the
            participant's browser.

         2. "answer": The formatted answer.

         3. "metadata": The original metadata returned from the
            participant's browser.

         3. "experiment": An instantiation of
            "psynet.experiment.Experiment", corresponding to the
            current experiment.

         4. "participant": An instantiation of
            "psynet.participant.Participant", corresponding to the
            current participant.

      Returns:
         * *dict* -- A dictionary of metadata.

class psynet.page.UnsuccessfulEndPage(failure_tags=None, **kwargs)

   Bases: "EndPageRedirect"

   Redirects the participant to the unsuccessful end branch.

class psynet.page.VolumeCalibration(url=str(resources.files('psynet') / 'resources/audio/brown_noise.wav'), min_time=2.5, time_estimate=5.0, id_='volume_calibration')

   Bases: "Module"

   Module that loops a sound so the participant can set a comfortable
   volume.

class psynet.page.WaitPage(wait_time, content=None, **kwargs)

   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. Plain strings are shown as text; pass
        "markupsafe.Markup" or a "dominate" tag for HTML. Default:
        "Please wait, the experiment should continue shortly..."

      * ****kwargs** -- Further arguments to pass to
        "psynet.timeline.Page".

   get_bot_response(experiment, bot)

      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, which
      is saved without passing through "format_answer". For more
      sophisticated treatment, the function can return a "BotResponse"
      object which contains other parameters such as "blobs" and
      "metadata". PsyNet's built-in answer controls return
      "BotResponse(raw_answer=...)" with what the browser would
      submit, so that bot answers pass through the same
      "format_answer" methods as browser answers.

   metadata(**kwargs)

      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:

         1. "raw_answer": The raw answer returned from the
            participant's browser.

         2. "answer": The formatted answer.

         3. "metadata": The original metadata returned from the
            participant's browser.

         3. "experiment": An instantiation of
            "psynet.experiment.Experiment", corresponding to the
            current experiment.

         4. "participant": An instantiation of
            "psynet.participant.Participant", corresponding to the
            current participant.

      Returns:
         * *dict* -- A dictionary of metadata.

   property plain_text

      A plain text version of the page's content. This is used for
      testing purposes. Users are invited to override this method in
      subclasses.

psynet.page.wait_for_recording(recording, expected_wait=0, check_interval=2.0)

   Wait for a recording to deposit or become unavailable without
   failing the participant.

   "recording" is a "Recording" or a callable accepting "participant"
   and/or "experiment" that returns one. The callable is evaluated at
   each poll and should resolve the same recording. Check its
   "deposited" property afterwards and provide a fallback page when
   False; finishing this wait does not guarantee playable media.

   The wait budget is fixed on entry using the recording's upload and
   processing deadlines plus 20 seconds for polling. Legacy recordings
   without these deadlines have a 20-second limit. If processing
   stalls, the participant can still proceed after this limit. This
   helper does not alter recording deadlines, trial failure rules, or
   performance checks.

   "expected_wait" and "check_interval" are in seconds, as in
   "wait_while()".

psynet.page.wait_while(condition, expected_wait, check_interval=2.0, max_wait_time=20.0, wait_page=None, log_message=None, fail_on_timeout=True, fix_time_credit=None, waiting_message=None, on_timeout=None, waiting_screen=None)

   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) and "experiment" (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. This controls progress estimation
        and fixed time credit; actual visible waiting time is credited
        when "fix_time_credit" is false.

      * **check_interval** ("float") -- How often the browser should
        check the condition if no framework wake notification arrives,
        in seconds.

      * **max_wait_time** ("Union"["float", "Callable", "None"]) --
        The participant's maximum waiting time in seconds. Default:
        20.0. May be None for an unlimited wait, or a callable
        accepting "participant" and/or "experiment". A callable is
        evaluated once when waiting starts, as in "while_loop()";
        polling does not reset the limit.

      * **wait_page** -- The wait page that should be displayed to the
        participant; by default the current page is preserved with a
        lightweight waiting indicator. Pass "WaitPage" or another page
        factory to opt into page-based waiting.

      * **log_message** ("Optional"["str"]) -- Optional message to
        display in the log.

      * **fail_on_timeout** -- Whether the participant should be
        failed when "max_wait_time" is reached. Setting this to
        "False" allows them to proceed to the next page instead.

      * **fix_time_credit** ("Optional"["bool"]) -- Whether to award
        the fixed "expected_wait" rather than actual visible waiting
        time. Defaults to "False" for timeline holds and "True" for
        explicit page-based waiting.

      * **waiting_message** ("Union"["str", "Markup", "dom_tag",
        "Callable", "None"]) -- Message displayed by the timeline
        hold. Only used when "wait_page" is omitted. Plain strings are
        shown as text; pass "markupsafe.Markup" or a dominate tag for
        HTML. A module-level function of "participant" returning one
        of these shows each participant their own message, for example
        by role. There is no "{SECONDS}" countdown here, so a string
        containing it raises an error.

      * **on_timeout** ("Optional"["Callable"]) -- Optional function
        called with "participant=..." when "max_wait_time" is reached,
        before the participant is failed or moves on. It must not
        commit the database session.

      * **waiting_screen** -- What to show in place of the current
        page while the participant waits, as for "Barrier": text, a
        prompt, a "ModularPage" that nothing submits, or a module-
        level function returning one of these (or "None" to keep the
        current page). The function may take "participant", "trial"
        (their "current_trial", which stays their previous trial until
        the next one is cued) and "group_round" (that trial's
        "SyncGroupRound", or "None"). "waiting_message" still sets the
        waiting indicator shown on top. Only used when "wait_page" is
        omitted.

   Returns:
      * *list* -- A list of test elts suitable for inclusion in a
        PsyNet timeline.
