stats: add number of lost crits

This commit is contained in:
Maximilian Keßler 2023-11-24 12:22:53 +01:00
parent ddd751f0f3
commit 18607699c9
Signed by: max
GPG Key ID: BCC5A619923C0BA5

View File

@ -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) " "INSERT INTO game_statistics (game_id, num_bottom_deck_risks, num_crits_lost) "
"VALUES (%s, %s, %s) " "VALUES (%s, %s, %s) "
"ON CONFLICT (game_id) DO UPDATE " "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)) (game_id, len(analysis.bdrs), len(analysis.lost_crits))
) )
conn_manager.get_connection().commit() 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. # so the zero value never shows up in the database if it was nonzero before.
cur.execute( cur.execute(
"INSERT INTO user_statistics" "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 " "ON CONFLICT (user_id, variant_type) DO UPDATE "
"SET" "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,) (rating_type,)
) )
cur.execute( 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" " SELECT"
" users.id," " users.id,"
@ -143,7 +143,8 @@ def update_user_statistics():
" SUM(games.num_turns)," " SUM(games.num_turns),"
" COUNT(*)," " COUNT(*),"
" COUNT(*) FILTER ( WHERE variants.num_suits * 5 = games.score )," " 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" "FROM users"
" INNER JOIN game_participants " " INNER JOIN game_participants "
" ON game_participants.user_id = users.id " " ON game_participants.user_id = users.id "
@ -157,9 +158,9 @@ def update_user_statistics():
" ) " " ) "
"ON CONFLICT (user_id, variant_type) DO UPDATE " "ON CONFLICT (user_id, variant_type) DO UPDATE "
"SET" "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)) (utils.get_rating_type(True), utils.get_rating_type(False))
) )
cur.execute( cur.execute(