diff --git a/install/database_schema.sql b/install/database_schema.sql index 899940b..0e2171e 100644 --- a/install/database_schema.sql +++ b/install/database_schema.sql @@ -342,6 +342,7 @@ CREATE TABLE user_statistics ( /** We track stats separately for each variant type */ variant_type SMALLINT NOT NULL, current_streak INTEGER, + maximum_streak INTEGER, games_played INTEGER, games_won INTEGER, games_lost INTEGER GENERATED ALWAYS AS (games_played - games_won) STORED, diff --git a/src/stats.py b/src/stats.py index 56206c5..f40c4c9 100644 --- a/src/stats.py +++ b/src/stats.py @@ -123,15 +123,15 @@ 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, total_crits_lots)" + " (user_id, variant_type, total_game_moves, games_played, games_won, current_streak, maximum_streak, total_bdr, total_crits_lots)" " (" - " SELECT id, %s, 0, 0, 0, 0, 0, 0 FROM users" + " SELECT id, %s, 0, 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_crits_lots)" + " (total_game_moves, games_played, games_won, current_streak, maximum_streak, total_bdr, total_crits_lots)" " =" - " (EXCLUDED.total_game_moves, EXCLUDED.games_played, EXCLUDED.games_won, EXCLUDED.current_streak, EXCLUDED.total_bdr, EXCLUDED.total_crits_lots)", + " (EXCLUDED.total_game_moves, EXCLUDED.games_played, EXCLUDED.games_won, EXCLUDED.current_streak, EXCLUDED.maximum_streak, EXCLUDED.total_bdr, EXCLUDED.total_crits_lots)", (rating_type,) ) @@ -180,7 +180,7 @@ def update_user_statistics(): # row ranging over all games, where we grouped by user id and rating type (Clue Starved/Non-CS currently) # Finally, we just wrap the computed data into an insert statement to directly store it in the statistics table cur.execute( - "INSERT INTO user_statistics (user_id, variant_type, current_streak)" + "INSERT INTO user_statistics (user_id, variant_type, maximum_streak)" " (" " SELECT" " user_id," @@ -224,7 +224,7 @@ def update_user_statistics(): " GROUP BY user_id, clue_starved" " )" "ON CONFLICT (user_id, variant_type) DO UPDATE " - "SET current_streak = EXCLUDED.current_streak", + "SET maximum_streak = EXCLUDED.maximum_streak", (utils.get_rating_type(True), utils.get_rating_type(False)) ) conn_manager.get_connection().commit()