diff --git a/src/stats.py b/src/stats.py index 4fda873..6f487f5 100644 --- a/src/stats.py +++ b/src/stats.py @@ -81,7 +81,7 @@ def analyze_game_and_store_stats(game_id: int): "INSERT INTO game_statistics (game_id, num_bottom_deck_risks, num_crits_lost) " "VALUES (%s, %s, %s) " "ON CONFLICT (game_id) DO UPDATE " - "SET (num_crits_lost, num_bottom_deck_risks) = (EXCLUDED.num_crits_lost, EXCLUDED.num_bottom_deck_risks)", + "SET (num_bottom_deck_risks, num_crits_lost) = (EXCLUDED.num_bottom_deck_risks, EXCLUDED.num_crits_lost)", (game_id, len(analysis.bdrs), len(analysis.lost_crits)) ) conn_manager.get_connection().commit() @@ -123,19 +123,19 @@ def update_user_statistics(): # so the zero value never shows up in the database if it was nonzero before. cur.execute( "INSERT INTO user_statistics" - " (user_id, variant_type, total_game_moves, games_played, games_won, current_streak, total_bdr)" + " (user_id, variant_type, total_game_moves, games_played, games_won, current_streak, total_bdr, total_crits_lots)" " (" - " SELECT id, %s, 0, 0, 0, 0, 0 FROM users" + " SELECT id, %s, 0, 0, 0, 0, 0, 0 FROM users" " )" "ON CONFLICT (user_id, variant_type) DO UPDATE " "SET" - " (total_game_moves, games_played, games_won, current_streak, total_bdr)" + " (total_game_moves, games_played, games_won, current_streak, total_bdr, total_crits_lots)" " =" - " (EXCLUDED.total_game_moves, EXCLUDED.games_played, EXCLUDED.games_won, EXCLUDED.current_streak, EXCLUDED.total_bdr)", + " (EXCLUDED.total_game_moves, EXCLUDED.games_played, EXCLUDED.games_won, EXCLUDED.current_streak, EXCLUDED.total_bdr, EXCLUDED.total_crits_lots)", (rating_type,) ) cur.execute( - "INSERT INTO user_statistics (user_id, variant_type, total_game_moves, games_played, games_won, total_bdr)" + "INSERT INTO user_statistics (user_id, variant_type, total_game_moves, games_played, games_won, total_bdr, total_crits_lots)" " (" " SELECT" " users.id," @@ -143,7 +143,8 @@ def update_user_statistics(): " SUM(games.num_turns)," " COUNT(*)," " COUNT(*) FILTER ( WHERE variants.num_suits * 5 = games.score )," - " SUM (game_statistics.num_bottom_deck_risks)" + " SUM (game_statistics.num_bottom_deck_risks)," + " SUM (game_statistics.num_crits_lost)" "FROM users" " INNER JOIN game_participants " " ON game_participants.user_id = users.id " @@ -157,9 +158,9 @@ def update_user_statistics(): " ) " "ON CONFLICT (user_id, variant_type) DO UPDATE " "SET" - " (total_game_moves, games_played, games_won, total_bdr)" + " (total_game_moves, games_played, games_won, total_bdr, total_crits_lots)" " =" - " (EXCLUDED.total_game_moves, EXCLUDED.games_played, EXCLUDED.games_won, EXCLUDED.total_bdr)", + " (EXCLUDED.total_game_moves, EXCLUDED.games_played, EXCLUDED.games_won, EXCLUDED.total_bdr, EXCLUDED.total_crits_lots)", (utils.get_rating_type(True), utils.get_rating_type(False)) ) cur.execute(