Utils package

Module Contents

This section contains detailed documentation of the utils package, encompassing a variety of modules designed for many processes. This is a more general package with functions for calculating similarity scores, filtering, rebuilding structures and more.

utils.interactions module

utils.interactions.record_interaction(interaction_data, cur, conn)

Records a user interaction with a recommendation in the database.

Args:

  • interaction_data (dict): Dictionary containing interaction details including user ID, recommendation ID, and interaction type.

  • cur: Database cursor object for executing queries.

  • conn: Database connection object.

Returns:

  • Response: JSON response indicating if there was a match or not.

This function takes interaction data from a user and records it in the database, it also checks if this interaction is a match (mutual likes). It handles exceptions and returns a JSON response to indicate the status of the operation.

utils.interactions.record_report(report_data, user_id, cur, conn, match)

Records a user report in the database and handles match deletions if necessary.

Args:

  • report_data (dict): Data about the report, including reported user ID and reason.

  • user_id (int): ID of the user making the report.

  • cur: Database cursor for executing queries.

  • conn: Database connection object.

  • match (bool): Indicates if there is a match between the reporting and reported users.

Returns:

  • Response: JSON response indicating the result of the operation.

utils.interactions.remove_matches(removed_id, user_id, cur, conn)

Removes match records from the database involving the specified users.

Args:

  • removed_id (int): ID of the user whose matches are to be removed.

  • user_id (int): ID of the user initiating the removal.

  • cur: Database cursor for executing queries.

  • conn: Database connection object.

Returns:

  • Response: JSON response indicating the result of the operation.

utils.similarity_metrics module

utils.similarity_metrics.get_top_matches(cur, user_id, candidate_ids, data_type, n=5)

Retrieves the top ‘n’ matching candidates based on specific data types preferences or features (depending on which form of filtering we’re doing).

Args:

  • cur: Database cursor for executing SQL queries.

  • user_id (int): ID of the current user for whom matches are being found.

  • candidate_ids (list): List of potential candidate user IDs for matching.

  • data_type (str): Type of data to use for matching (e.g., ‘preference’, ‘feature’).

  • n (int, optional): Number of top matches to retrieve. Default is 5.

Returns: - list: List of top recommendation candidate IDs.

utils.update_data_structures module

utils.update_data_structures.update_preferences_web(conn, cur, user_id, interactions)

Updates user preferences in the database based on their recent interactions.

Args:

  • conn: Database connection object.

  • cur: Database cursor object for executing queries.

  • user_id (int): ID of the user whose preferences are being updated.

  • interactions (list of tuples): List of tuples containing interaction data (user_id, interaction_type).

Returns:

  • dict: Updated preferences dictionary after processing interactions.

This function first retrieves the features of all users interacted with and updates the preferences based on the type of interaction (like, dislike, superlike). Preferences with negative values are removed. Finally, it updates the user’s preferences in the database.

See Also

Note

For a complete overview of all modules, visit the modules overview page.