ExperimentSession#

class alfred3.experiment.ExperimentSession(session_id: str, config: Optional[alfred3.config.ExperimentConfig] = None, secrets: Optional[alfred3.config.ExperimentSecrets] = None, timeout: Optional[int] = None, **urlargs)[source]#

Bases: object

Coordinates all parts of an experiment session.

Parameters
  • session_id – Unique session identifier

  • config – Non-secret experiment configuration

  • secrets – Secret experiment configuration, such as database credentials

  • **urlargs – Keyword arguments from url parameters. Will be stored in the attribute urlargs for access in the experiment session.

Usually, there is no need to initialize an ExperimentSession manually. The Experiment object will take care of that for you.

You have access to this object in Page and Section hooks through their accessors Page.exp and Section.exp. It connects all parts of an experiment and allows you to access data from other pages and even other experiment sessions.

Note

Because the experiment session is newly created for every new subject, you can only access it in the class style of writing an alfred experiment by deriving new Page and/or Section classes and using their hooks to add elements.

See also

  • howto_exp explains how to go about writing an experiment.

  • howto_hooks explains how to use hooks.

  • Experiment is used to construct the experiment

Changed in version 2.0: Many changes, including new methods and properties for improved usability. Name changed from “Experiment” to “ExperimentSession”.

Methods

abort

Aborts the experiment session.

append

Appends Sections or Pages to the experiment's root section.

append_plugin_data_query

Appends a query dictionary to the internal list of plugin data queries.

backward

Moves the experiment backward one page.

decrypt

Decrypts input and returns the decrypted object as str.

encrypt

Encrypts the input and returns the encrypted string.

finish

Closes all previous pages and saves data.

forward

Moves the experiment forward one page.

get_page_data

Get the data dictionary of a specific page.

get_section_data

Get the data dictionary for all pages in a specific section.

jump

Jumps to a specific page in the experiment.

post_message

Post a message for one-time display after the next move.

read_csv_todict

Iterates over the rows in a .csv file, yielding dictionaries.

read_csv_tolist

Iterates over the rows in a .csv file, yielding lists.

read_yaml_todict

Imports a .yaml file to a dict.

send_mail

Sends an email message using credentials defined in secrets.conf.

start

Starts the experiment.

subpath

Returns the full path of an experiment subdirectory.

Attributes

abort_functions

A list of functions that will be called upon aborting an experiment session.

aborted

Indicates, whether the experiment was aborted.

adata

Shortcut for accessing the additional data dictionary.

additional_data

The additional data dictionary.

admin_mode

Indicates whether the experiment runs in admin mode.

alfred_version

The alfred3 version used for the current experiment.

all_exp_data

List of all experiment datasets.

all_members

Dictionary of all sections and pages in the experiment.

all_pages

Dictionary of all pages in the experiment.

all_sections

Dictionary of all sections in the experiment.

all_unlinked_data

List of all unlinked datasets.

author

Returns the experiment author.

client_data

Dictionary of information about the client, such as:

condition

Experiment condition.

config

The experiment configuration.

content

The experiment's main content section, which holds all sections and pages added to the experiment.

current_page

The currently active page of the experiment.

db

Database object of the main mongo saving agent.

db_main

Document collection of the main mongo saving agent.

db_misc

Document collection for miscellaneous data.

db_unlinked

Document collection of the unlinked mongo saving agent.

exp_id

Experiment id

final_page

The experiment's final page.

finish_functions

A list of functions that will be called upon finishing an experiment session.

finished

Indicates, whether the experiment has finished orderly.

log

Alfred's logging interface.

metadata

A dict of information about the experiment.

move_history

A list, containing the movement history for the current session.

path

Path to the experiment directory

plugins

A modified dictionary of experiment plugins.

progress_bar

The experiment's progress bar.

root_section

The experiment's root section, organizing all other sections, including content.

secrets

The secret experiment configuration.

session

Experiment session.

session_data

Full dataset of the current experimental session.

session_expired

Indicates whether the session has expired.

session_id

Unique session identifier

session_status

Session status for the current experiment.

session_timeout

The session's timeout (in seconds).

start_time

Start time in seconds since epoch.

start_timestamp

A human-readable string, indicating the start time.

test_mode

Indicates whether the experiment runs in test mode.

title

Experiment title

tmp

A modified dictionary of temporary data.

type

Type of the experiment

urlargs

A dictionary of key-value pairs that the experiment might have received as url parameters.

values

Dictionary of input elements and their current values.

version

Experiment version