From 4d6fedf7685d11ea52eed31235a5c1eef91226e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 23 Nov 2023 18:34:25 +0100 Subject: [PATCH] uniform naming --- install/database_schema.sql | 6 +++--- src/database.py | 4 ++-- src/ratings.py | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/install/database_schema.sql b/install/database_schema.sql index 00fdaf8..297df32 100644 --- a/install/database_schema.sql +++ b/install/database_schema.sql @@ -249,9 +249,9 @@ DROP TABLE IF EXISTS variant_base_ratings CASCADE; CREATE TABLE variant_base_ratings ( /* Note that a variant already includes the number of suits, so we do not have to add this here. */ variant_id SMALLINT, - player_count SMALLINT NOT NULL, + num_players SMALLINT NOT NULL, rating REAL NOT NULL, - PRIMARY KEY (variant_id, player_count) + PRIMARY KEY (variant_id, num_players) ); /** @@ -263,7 +263,7 @@ CREATE TABLE variant_ratings ( league_id INTEGER PRIMARY KEY REFERENCES games (league_id), variant_id SMALLINT NOT NULL, - player_count SMALLINT NOT NULL, + num_players SMALLINT NOT NULL, change REAL NOT NULL, value_after REAL NOT NULL, diff --git a/src/database.py b/src/database.py index 1b6a1a8..40408d4 100644 --- a/src/database.py +++ b/src/database.py @@ -115,9 +115,9 @@ def initialize_variant_base_ratings(): psycopg2.extras.execute_values( cur, - "INSERT INTO variant_base_ratings (variant_id, player_count, rating)" + "INSERT INTO variant_base_ratings (variant_id, num_players, rating)" "VALUES %s " - "ON CONFLICT (variant_id, player_count) " + "ON CONFLICT (variant_id, num_players) " "DO UPDATE SET rating = EXCLUDED.rating", ratings ) diff --git a/src/ratings.py b/src/ratings.py index 6ff7521..25d7580 100644 --- a/src/ratings.py +++ b/src/ratings.py @@ -82,21 +82,21 @@ def get_current_user_ratings(user_ids: List[int], rating_type: int) -> Dict[int, return ratings -def get_current_variant_rating(variant_id: int, player_count: int) -> float: +def get_current_variant_rating(variant_id: int, num_players: int) -> float: cur = conn_manager.get_new_cursor() # Again, this query is tricky. For explanation, see the corresponding query for the user ratings cur.execute("SELECT value_after FROM variant_ratings " "INNER JOIN (" - " SELECT variant_id, player_count, MAX(league_id) AS max_league_id" + " SELECT variant_id, num_players, MAX(league_id) AS max_league_id" " FROM variant_ratings " - " GROUP BY (variant_id, player_count)" + " GROUP BY (variant_id, num_players)" " ) AS latest_variant_ratings " " ON" " variant_ratings.league_id = latest_variant_ratings.max_league_id " " AND variant_ratings.variant_id = latest_variant_ratings.variant_id " - " AND variant_ratings.player_count = latest_variant_ratings.player_count " - "WHERE variant_ratings.variant_id = %s AND variant_ratings.player_count = %s", - (variant_id, player_count) + " AND variant_ratings.num_players = latest_variant_ratings.num_players " + "WHERE variant_ratings.variant_id = %s AND variant_ratings.num_players = %s", + (variant_id, num_players) ) query_result = cur.fetchone() if query_result is not None: @@ -105,8 +105,8 @@ def get_current_variant_rating(variant_id: int, player_count: int) -> float: # Reaching this point of code execution just means this is the first game for this variant rating cur.execute("SELECT rating FROM variant_base_ratings " - "WHERE variant_id = %s AND player_count = %s", - (variant_id, player_count) + "WHERE variant_id = %s AND num_players = %s", + (variant_id, num_players) ) query_result = cur.fetchone() if query_result is None: @@ -162,7 +162,7 @@ def process_rating_of_next_game(): user_changes, variant_change = rating_change(user_ratings, variant_rating, score == 5 * num_suits) # Update database for variants - cur.execute("INSERT INTO variant_ratings (league_id, variant_id, player_count, change, value_after) " + cur.execute("INSERT INTO variant_ratings (league_id, variant_id, num_players, change, value_after) " "VALUES (%s, %s, %s, %s, %s)", (league_id, variant_id, num_players, variant_change, variant_rating + variant_change) )