forked from Hanabi/hanabi-league
Compute current streaks for statistics
This commit is contained in:
parent
9ba98a1f47
commit
94d698ad14
2 changed files with 8 additions and 3 deletions
|
@ -40,3 +40,6 @@ FORBIDDEN_GAME_OPTIONS = [
|
|||
, "allOrNothing"
|
||||
, "detrimentalCharacters"
|
||||
]
|
||||
|
||||
# Cache time in secodn
|
||||
USER_HISTORY_CACHE_TIME = 5
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue