From 94d698ad14dc778fb80d3c123ee4e1899e38b909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 24 Nov 2023 13:12:41 +0100 Subject: [PATCH] Compute current streaks for statistics --- src/constants.py | 3 +++ src/stats.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/constants.py b/src/constants.py index 657103b..544f400 100644 --- a/src/constants.py +++ b/src/constants.py @@ -40,3 +40,6 @@ FORBIDDEN_GAME_OPTIONS = [ , "allOrNothing" , "detrimentalCharacters" ] + +# Cache time in secodn +USER_HISTORY_CACHE_TIME = 5 diff --git a/src/stats.py b/src/stats.py index f40c4c9..2531742 100644 --- a/src/stats.py +++ b/src/stats.py @@ -180,12 +180,14 @@ 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, maximum_streak)" + "INSERT INTO user_statistics (user_id, variant_type, maximum_streak, current_streak)" " (" " SELECT" " user_id," " CASE WHEN clue_starved THEN %s ELSE %s END," - " MAX(streak_length) AS max_streak_length FROM" + " MAX(streak_length) AS max_streak_length," + " (array_agg(streak_length ORDER BY league_id DESC))[1]" + " FROM" " (" " SELECT" " *," @@ -224,7 +226,7 @@ def update_user_statistics(): " GROUP BY user_id, clue_starved" " )" "ON CONFLICT (user_id, variant_type) DO UPDATE " - "SET maximum_streak = EXCLUDED.maximum_streak", + "SET (maximum_streak, current_streak) = (EXCLUDED.maximum_streak, EXCLUDED.current_streak)", (utils.get_rating_type(True), utils.get_rating_type(False)) ) conn_manager.get_connection().commit()