uniform naming
This commit is contained in:
parent
9a8318bc6d
commit
4d6fedf768
3 changed files with 14 additions and 14 deletions
|
@ -249,9 +249,9 @@ DROP TABLE IF EXISTS variant_base_ratings CASCADE;
|
||||||
CREATE TABLE variant_base_ratings (
|
CREATE TABLE variant_base_ratings (
|
||||||
/* Note that a variant already includes the number of suits, so we do not have to add this here. */
|
/* Note that a variant already includes the number of suits, so we do not have to add this here. */
|
||||||
variant_id SMALLINT,
|
variant_id SMALLINT,
|
||||||
player_count SMALLINT NOT NULL,
|
num_players SMALLINT NOT NULL,
|
||||||
rating REAL 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),
|
league_id INTEGER PRIMARY KEY REFERENCES games (league_id),
|
||||||
|
|
||||||
variant_id SMALLINT NOT NULL,
|
variant_id SMALLINT NOT NULL,
|
||||||
player_count SMALLINT NOT NULL,
|
num_players SMALLINT NOT NULL,
|
||||||
change REAL NOT NULL,
|
change REAL NOT NULL,
|
||||||
value_after REAL NOT NULL,
|
value_after REAL NOT NULL,
|
||||||
|
|
||||||
|
|
|
@ -115,9 +115,9 @@ def initialize_variant_base_ratings():
|
||||||
|
|
||||||
psycopg2.extras.execute_values(
|
psycopg2.extras.execute_values(
|
||||||
cur,
|
cur,
|
||||||
"INSERT INTO variant_base_ratings (variant_id, player_count, rating)"
|
"INSERT INTO variant_base_ratings (variant_id, num_players, rating)"
|
||||||
"VALUES %s "
|
"VALUES %s "
|
||||||
"ON CONFLICT (variant_id, player_count) "
|
"ON CONFLICT (variant_id, num_players) "
|
||||||
"DO UPDATE SET rating = EXCLUDED.rating",
|
"DO UPDATE SET rating = EXCLUDED.rating",
|
||||||
ratings
|
ratings
|
||||||
)
|
)
|
||||||
|
|
|
@ -82,21 +82,21 @@ def get_current_user_ratings(user_ids: List[int], rating_type: int) -> Dict[int,
|
||||||
return ratings
|
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()
|
cur = conn_manager.get_new_cursor()
|
||||||
# Again, this query is tricky. For explanation, see the corresponding query for the user ratings
|
# Again, this query is tricky. For explanation, see the corresponding query for the user ratings
|
||||||
cur.execute("SELECT value_after FROM variant_ratings "
|
cur.execute("SELECT value_after FROM variant_ratings "
|
||||||
"INNER JOIN ("
|
"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 "
|
" FROM variant_ratings "
|
||||||
" GROUP BY (variant_id, player_count)"
|
" GROUP BY (variant_id, num_players)"
|
||||||
" ) AS latest_variant_ratings "
|
" ) AS latest_variant_ratings "
|
||||||
" ON"
|
" ON"
|
||||||
" variant_ratings.league_id = latest_variant_ratings.max_league_id "
|
" variant_ratings.league_id = latest_variant_ratings.max_league_id "
|
||||||
" AND variant_ratings.variant_id = latest_variant_ratings.variant_id "
|
" AND variant_ratings.variant_id = latest_variant_ratings.variant_id "
|
||||||
" AND variant_ratings.player_count = latest_variant_ratings.player_count "
|
" AND variant_ratings.num_players = latest_variant_ratings.num_players "
|
||||||
"WHERE variant_ratings.variant_id = %s AND variant_ratings.player_count = %s",
|
"WHERE variant_ratings.variant_id = %s AND variant_ratings.num_players = %s",
|
||||||
(variant_id, player_count)
|
(variant_id, num_players)
|
||||||
)
|
)
|
||||||
query_result = cur.fetchone()
|
query_result = cur.fetchone()
|
||||||
if query_result is not None:
|
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
|
# 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 "
|
cur.execute("SELECT rating FROM variant_base_ratings "
|
||||||
"WHERE variant_id = %s AND player_count = %s",
|
"WHERE variant_id = %s AND num_players = %s",
|
||||||
(variant_id, player_count)
|
(variant_id, num_players)
|
||||||
)
|
)
|
||||||
query_result = cur.fetchone()
|
query_result = cur.fetchone()
|
||||||
if query_result is None:
|
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)
|
user_changes, variant_change = rating_change(user_ratings, variant_rating, score == 5 * num_suits)
|
||||||
|
|
||||||
# Update database for variants
|
# 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)",
|
"VALUES (%s, %s, %s, %s, %s)",
|
||||||
(league_id, variant_id, num_players, variant_change, variant_rating + variant_change)
|
(league_id, variant_id, num_players, variant_change, variant_rating + variant_change)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue