aepsych.database¶
Submodules¶
aepsych.database.db module¶
- class aepsych.database.db.Database(db_path=None)[source]¶
Bases:
object
Initialize the database object.
- Parameters:
db_path (str, optional) – The path to the database. Defaults to None.
- get_engine()[source]¶
Get the engine for the database.
- Returns:
The sessionmaker object for the database.
- Return type:
sessionmaker
- is_update_required()[source]¶
Check if an update is required on the database.
- Returns:
True if an update is required, False otherwise.
- Return type:
bool
- perform_updates()[source]¶
Perform updates on known tables. SQLAlchemy doesn’t do alters so they’re done the old fashioned way.
- Return type:
None
- execute_sql_query(query, vals)[source]¶
Execute an arbitrary query written in sql.
- Parameters:
query (str) – The query to execute.
vals (Dict[str, str]) – The values to use in the query.
- Returns:
The results of the query.
- Return type:
List[Any]
- get_master_records()[source]¶
Grab the list of master records.
- Returns:
The list of master records.
- Return type:
List[tables.DBMasterTable]
- get_master_record(experiment_id)[source]¶
Grab the list of master record for a specific experiment (master) id.
- Parameters:
experiment_id (int) – The experiment id.
- Returns:
The master record or None if it doesn’t exist.
- Return type:
tables.DBMasterTable or None
- get_replay_for(master_id)[source]¶
Get the replay records for a specific master row.
- Parameters:
master_id (int) – The master id.
- Returns:
The replay records or None if they don’t exist.
- Return type:
List[tables.DbReplayTable] or None
- get_strats_for(master_id=0)[source]¶
Get the strat records for a specific master row.
- Parameters:
master_id (int) – The master id. Defaults to 0.
- Returns:
The strat records or None if they don’t exist.
- Return type:
List[Any] or None
- get_strat_for(master_id, strat_id=- 1)[source]¶
Get a specific strat record for a specific master row.
- Parameters:
master_id (int) – The master id.
strat_id (int) – The strat id. Defaults to -1.
- Returns:
The strat record.
- Return type:
Any
- get_config_for(master_id)[source]¶
Get the strat records for a specific master row.
- Parameters:
master_id (int) – The master id.
- Returns:
The config records.
- Return type:
Any
- get_raw_for(master_id)[source]¶
Get the raw data for a specific master row.
- Parameters:
master_id (int) – The master id.
- Returns:
The raw data or None if it doesn’t exist.
- Return type:
List[tables.DbRawTable] or None
- get_all_params_for(master_id)[source]¶
Get the parameters for all the iterations of a specific experiment.
- Parameters:
master_id (int) – The master id.
- Returns:
The parameters or None if they don’t exist.
- Return type:
List[tables.DbRawTable] or None
- get_param_for(master_id, iteration_id)[source]¶
Get the parameters for a specific iteration of a specific experiment.
- Parameters:
master_id (int) – The master id.
iteration_id (int) – The iteration id.
- Returns:
The parameters or None if they don’t exist.
- Return type:
List[tables.DbRawTable] or None
- get_all_outcomes_for(master_id)[source]¶
Get the outcomes for all the iterations of a specific experiment.
- Parameters:
master_id (int) – The master id.
- Returns:
The outcomes or None if they don’t exist.
- Return type:
List[tables.DbRawTable] or None
- get_outcome_for(master_id, iteration_id)[source]¶
Get the outcomes for a specific iteration of a specific experiment.
- Parameters:
master_id (int) – The master id.
iteration_id (int) – The iteration id.
- Returns:
The outcomes or None if they don’t exist.
- Return type:
List[tables.DbRawTable] or None
- record_setup(description, name, extra_metadata=None, id=None, request=None, participant_id=None)[source]¶
Record the setup of an experiment.
- Parameters:
description (str) – The description of the experiment.
name (str) – The name of the experiment.
extra_metadata (str, optional) – Extra metadata. Defaults to None.
id (str, optional) – The id of the experiment. Defaults to None.
request (Dict[str, Any]) – The request. Defaults to None.
participant_id (int, optional) – The participant id. Defaults to None.
- Returns:
The experiment id.
- Return type:
str
- record_message(master_table, type, request)[source]¶
Record a message in the database.
- Parameters:
master_table (tables.DBMasterTable) – The master table.
type (str) – The type of the message.
request (Dict[str, Any]) – The request.
- Return type:
None
- record_raw(master_table, model_data, timestamp=None)[source]¶
Record raw data in the database.
- Parameters:
master_table (tables.DBMasterTable) – The master table.
model_data (Any) – The model data.
timestamp (datetime.datetime, optional) – The timestamp. Defaults to None.
- Returns:
The raw entry.
- Return type:
- record_param(raw_table, param_name, param_value)[source]¶
Record a parameter in the database.
- Parameters:
raw_table (tables.DbRawTable) – The raw table.
param_name (str) – The parameter name.
param_value (str) – The parameter value.
- Return type:
None
- record_outcome(raw_table, outcome_name, outcome_value)[source]¶
Record an outcome in the database.
- Parameters:
raw_table (tables.DbRawTable) – The raw table.
outcome_name (str) – The outcome name.
outcome_value (float) – The outcome value.
- Return type:
None
- record_strat(master_table, strat)[source]¶
Record a strategy in the database.
- Parameters:
master_table (tables.DBMasterTable) – The master table.
strat (Strategy) – The strategy.
- Return type:
None
- record_config(master_table, config)[source]¶
Record a config in the database.
- Parameters:
master_table (tables.DBMasterTable) – The master table.
config (Config) – The config.
- Return type:
None
aepsych.database.tables module¶
- class aepsych.database.tables.Base(**kwargs)¶
Bases:
object
The base class of the class hierarchy.
When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- metadata = MetaData()¶
- registry = <sqlalchemy.orm.decl_api.registry object>¶
- class aepsych.database.tables.DBMasterTable(**kwargs)[source]¶
Bases:
Base
Master table to keep track of all experiments and unique keys associated with the experiment
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- unique_id¶
- experiment_name¶
- experiment_description¶
- experiment_id¶
- participant_id¶
- extra_metadata¶
- children_replay¶
- children_strat¶
- children_config¶
- children_raw¶
- classmethod from_sqlite(row)[source]¶
Create a DBMasterTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DBMasterTable object.
- Return type:
- class aepsych.database.tables.DbReplayTable(**kwargs)[source]¶
Bases:
Base
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- use_extra_info = False¶
- unique_id¶
- timestamp¶
- message_type¶
- message_contents¶
- extra_info¶
- master_table_id¶
- parent¶
- classmethod from_sqlite(row)[source]¶
Create a DbReplayTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DbReplayTable object.
- Return type:
- class aepsych.database.tables.DbStratTable(**kwargs)[source]¶
Bases:
Base
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- unique_id¶
- timestamp¶
- strat¶
- master_table_id¶
- parent¶
- classmethod from_sqlite(row)[source]¶
Create a DbStratTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DbStratTable object.
- Return type:
- class aepsych.database.tables.DbConfigTable(**kwargs)[source]¶
Bases:
Base
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- unique_id¶
- timestamp¶
- config¶
- master_table_id¶
- parent¶
- classmethod from_sqlite(row)[source]¶
Create a DbConfigTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DbConfigTable object.
- Return type:
- class aepsych.database.tables.DbRawTable(**kwargs)[source]¶
Bases:
Base
Fact table to store the raw data of each iteration of an experiment.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- unique_id¶
- timestamp¶
- model_data¶
- master_table_id¶
- parent¶
- children_param¶
- children_outcome¶
- classmethod from_sqlite(row)[source]¶
Create a DbRawTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DbRawTable object.
- Return type:
- class aepsych.database.tables.DbParamTable(**kwargs)[source]¶
Bases:
Base
Dimension table to store the parameters of each iteration of an experiment. Supports multiple parameters per iteration, and multiple stimuli per parameter.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- unique_id¶
- param_name¶
- param_value¶
- iteration_id¶
- parent¶
- classmethod from_sqlite(row)[source]¶
Create a DbParamTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DbParamTable object.
- Return type:
- class aepsych.database.tables.DbOutcomeTable(**kwargs)[source]¶
Bases:
Base
Dimension table to store the outcomes of each iteration of an experiment. Supports multiple outcomes per iteration.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- unique_id¶
- outcome_name¶
- outcome_value¶
- iteration_id¶
- parent¶
- classmethod from_sqlite(row)[source]¶
Create a DbOutcomeTable object from a row in the sqlite database.
- Parameters:
row (Dict[str, Any]) – A row from the sqlite database.
- Returns:
A DbOutcomeTable object.
- Return type: