forked from Hanabi/hanabi-league
Fix display of games on webpage: Do not show passive variant rating
changes
This commit is contained in:
parent
4b760e5f84
commit
ef48441483
3 changed files with 13 additions and 7 deletions
|
@ -269,6 +269,11 @@ CREATE TABLE variant_ratings (
|
||||||
|
|
||||||
change REAL NOT NULL,
|
change REAL NOT NULL,
|
||||||
value_after REAL NOT NULL,
|
value_after REAL NOT NULL,
|
||||||
|
/**
|
||||||
|
* Since multiple variants change rating for a single game, we mark the primary variant that changed here.
|
||||||
|
* This enables us to know what rows to display on statistic pages
|
||||||
|
*/
|
||||||
|
primary_change BOOLEAN NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (league_id, variant_id, num_players)
|
PRIMARY KEY (league_id, variant_id, num_players)
|
||||||
);
|
);
|
||||||
|
|
|
@ -197,9 +197,9 @@ def process_rating_of_next_game() -> bool:
|
||||||
user_changes, variant_change = compute_rating_changes(user_ratings, games_played, variant_rating, score == 5 * num_suits)
|
user_changes, variant_change = compute_rating_changes(user_ratings, games_played, variant_rating, score == 5 * num_suits)
|
||||||
|
|
||||||
# Update database for the played variant
|
# Update database for the played variant
|
||||||
cur.execute("INSERT INTO variant_ratings (league_id, variant_id, num_players, change, value_after) "
|
cur.execute("INSERT INTO variant_ratings (league_id, variant_id, num_players, change, value_after, primary_change) "
|
||||||
"VALUES (%s, %s, %s, %s, %s)",
|
"VALUES (%s, %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, True)
|
||||||
)
|
)
|
||||||
# Note: We do not commit here, only after players have been processed as well
|
# Note: We do not commit here, only after players have been processed as well
|
||||||
|
|
||||||
|
@ -232,12 +232,12 @@ def process_rating_of_next_game() -> bool:
|
||||||
other_variant_change = -variant_change / len(variants_of_same_rating_type)
|
other_variant_change = -variant_change / len(variants_of_same_rating_type)
|
||||||
other_variant_vals = []
|
other_variant_vals = []
|
||||||
for (other_variant_id, other_num_players, current_rating) in variants_of_same_rating_type:
|
for (other_variant_id, other_num_players, current_rating) in variants_of_same_rating_type:
|
||||||
other_variant_vals.append((league_id, other_variant_id, other_num_players, other_variant_change, current_rating + other_variant_change))
|
other_variant_vals.append((league_id, other_variant_id, other_num_players, other_variant_change, current_rating + other_variant_change, False))
|
||||||
|
|
||||||
# This updates the variants now
|
# This updates the variants now
|
||||||
psycopg2.extras.execute_values(
|
psycopg2.extras.execute_values(
|
||||||
cur,
|
cur,
|
||||||
"INSERT INTO variant_ratings (league_id, variant_id, num_players, change, value_after) "
|
"INSERT INTO variant_ratings (league_id, variant_id, num_players, change, value_after, primary_change) "
|
||||||
"VALUES %s",
|
"VALUES %s",
|
||||||
other_variant_vals
|
other_variant_vals
|
||||||
)
|
)
|
||||||
|
|
|
@ -182,12 +182,13 @@ def get_games():
|
||||||
"LEFT OUTER JOIN variants"
|
"LEFT OUTER JOIN variants"
|
||||||
" ON variants.id = game_data.variant_id "
|
" ON variants.id = game_data.variant_id "
|
||||||
"LEFT OUTER JOIN variant_ratings"
|
"LEFT OUTER JOIN variant_ratings"
|
||||||
" ON variant_ratings.league_id = game_data.league_id "
|
" ON variant_ratings.league_id = game_data.league_id AND variant_ratings.primary_change = true "
|
||||||
"GROUP BY ("
|
"GROUP BY ("
|
||||||
" game_data.game_id, game_data.num_players, users, user_ids, game_data.variant_id, variants.name, seed, score, num_turns,"
|
" game_data.game_id, game_data.num_players, users, user_ids, game_data.variant_id, variants.name, seed, score, num_turns,"
|
||||||
" game_data.league_id, num_bottom_deck_risks, num_crits_lost, change, value_after"
|
" game_data.league_id, num_bottom_deck_risks, num_crits_lost, change, value_after"
|
||||||
" ) "
|
" ) "
|
||||||
"ORDER BY league_id DESC"
|
"ORDER BY league_id DESC",
|
||||||
|
(True,)
|
||||||
)
|
)
|
||||||
res = []
|
res = []
|
||||||
for row in cur.fetchall():
|
for row in cur.fetchall():
|
||||||
|
|
Loading…
Reference in a new issue