Database package¶
Module Contents¶
This section contains detailed documentation of the database package, encompassing a variety of modules designed for interacting with the database through, select, insert and delete statements.
database.apply_filters module¶
- database.apply_filters.apply_filters(cur, filters, user_id, filter_uni, filter_prof)¶
Applies the given filters to fetch users from the database, excluding users already interacted with by the current user.
Args:
cur: Database cursor for executing SQL queries.
filters (dict): A dictionary containing filter criteria.
user_id (int): The ID of the current user to exclude their interactions.
filter_uni (bool): Indicates if university filter should be applied.
filter_prof (bool): Indicates if profession filter should be applied.
Returns:
tuple: A tuple containing two lists - all_users (all filtered users which will be used for collab filtering) and non_interacted_users (users not yet interacted with).
- database.apply_filters.create_filter_query(filters, user_id, filter_uni, filter_prof)¶
Constructs an SQL query to filter users based on specified criteria and excludes users who have already interacted with the current user.
Args:
filters (dict): A dictionary containing the user’s filter preferences.
user_id (int): The ID of the current user, used to exclude their previous interactions.
filter_uni (bool): Flag to determine if university filter should be applied.
filter_prof (bool): Flag to determine if profession filter should be applied.
Returns:
str: An SQL query string for fetching filtered user data.
database.db_connection_web module¶
- database.db_connection_web.account_deletion(user_id, conn, cur)¶
Deletes a user’s account and all associated data from the database.
Args:
user_id (int): The ID of the user whose account is to be deleted.
conn: Database connection object.
cur: Database cursor for executing queries.
Returns:
bool: True if the deletion was successful, False otherwise.
- database.db_connection_web.check_user_exists(cur, firebase_uid)¶
Checks if a user exists in the database based on Firebase UID.
Args:
cur: Database cursor for executing queries.
firebase_uid (str): Firebase UID of the user.
Returns:
int/None: The user ID if the user exists, None otherwise.
- database.db_connection_web.get_matches(cur, user_id)¶
Retrieves matches for a specific user from the database.
Args:
cur: Database cursor for executing queries.
user_id (int): The ID of the user for whom matches are being fetched.
Returns:
list: A list of dictionaries, each containing detailed information about a match. All infromation included is required to populate a match card on the front end.
- database.db_connection_web.get_user_data(cur, user_id)¶
Fetches and formats a specific user’s data from the database, this is used for the edit page in order to pre populate the form fields.
Args:
cur: Database cursor for executing queries.
user_id (int): The ID of the user whose data is to be fetched.
Returns:
dict: A dictionary containing detailed information of the user.
- database.db_connection_web.get_user_isochrone_data(cur, user_id)¶
Retrieves the isochrone data along with latitude and longitude for a given user from the database.
This function executes a SQL query to fetch the isochrone data, which represents the geographic area accessible within a certain time frame from the user’s location. It also retrieves the user’s latitude and longitude coordinates.
Args:
cur: The database cursor used to execute the query.
user_id (int): The ID of the user for whom to retrieve the isochrone data.
Returns:
tuple: A tuple containing the isochrone data as a JSON object (or other format depending on the database), and the latitude and longitude coordinates of the user as floats.
- database.db_connection_web.update_user_dicts(cur, user_id, data, data_type)¶
Updates a single user’s features or preferences in the database.
Args: - cur: Database cursor object for executing queries. - user_id: ID of the user to update. - data: Dictionary containing features or preferences. - data_type: Type of data to update (‘features’ or ‘preferences’).
Returns: - None
database.user_creation module¶
- database.user_creation.add_user(firebase_uid, conn)¶
Adds a new user to the database from a web form submission.
Args:
firebase_uid (str): A string representing the users firebase_uid, this will be provided upon signing in.
conn: Database connection object.
Returns:
int: An integer representing the users ID in order to add to the session.
This function extracts user information from a submitted web form, including personal details, preferences, and filters. It then creates a new user record in the database and returns the new user’s id in order to add them to the session. This function also handles the standard formatting of profile pictures (300x300px) and fetching a users isochrone.
- database.user_creation.parse_filter_range(filter_range, base_value)¶
Parses a filter range string and calculates the minimum and maximum values based on a base value.
Args:
filter_range (str): A string representing the range filter, e.g., “+/- 100”.
base_value (int): The base value to calculate the range from.
Returns:
tuple: A tuple containing the minimum and maximum values of the range.
- database.user_creation.update_user_data(conn)¶
Updates an existing user’s data in the database.
Args:
conn: Database connection object.
Returns:
int: The ID of the user whose data was updated.
This function extracts updated user information from a submitted web form and updates the user record in the database. It handles updates to personal details, preferences, and filters, and returns the user’s ID. This function also handles the standard formatting of profile pictures (300x300px), fetching of a new isochrone and it updates the recommendations database by calculating recommendations for the user based on their updated information.
See Also¶
Note
For a complete overview of all modules, visit the modules overview page.