w4h_db_utils module

w4h_db_utils.create_tables(db_name: str, config_file='config.yaml')[source]

Create the W4H tables in the database with the given name based on the config file

Parameters:
  • db_name (str) – Name of the database to create the tables in

  • config_file (str, optional) – Path to the config file. Defaults to ‘config.yaml’.

w4h_db_utils.create_w4h_instance(db_name: str, config_file='config.yaml')[source]

Create a new W4H database instance with the given name and initialize the tables based on the config file

Parameters:
  • db_name (str) – Name of the database to create

  • config_file (str, optional) – Path to the config file. Defaults to ‘config.yaml’.

w4h_db_utils.get_existing_databases(config_file='config.yaml') list[source]

Get a list of all existing databases

Parameters:

config_file (str, optional) – Path to the config file. Defaults to ‘config.yaml’.

Returns:

List of all existing databases (strings)

Return type:

list

w4h_db_utils.populate_subject_table(df: DataFrame, db_name: str, config_path='config.yaml', user_tbl_name=None)[source]

Populate the W4H subject table in the given database with the data from the given dataframe based on the given subject table name in the config file.

Parameters:
  • df (pd.DataFrame) – Dataframe containing the subject data to be inserted into the database

  • db_name (str) – Name of the subject database to insert the data into

  • config_path (str, optional) – Path to the config file. Defaults to ‘config.yaml’.

w4h_db_utils.populate_tables(df: DataFrame, db_name: str, mappings: dict, config_path='config.yaml')[source]

Populate the W4H tables in the given database with the data from the given dataframe based on the mappings between the CSV columns and the database tables.

Parameters:
  • df (pd.DataFrame) – Dataframe containing the data to be inserted into the database

  • db_name (str) – Name of the database to insert the data into

  • mappings (dict) – Dictionary containing the mappings between the CSV columns and the database tables

  • config_path (str, optional) – Path to the config file. Defaults to ‘config.yaml’.