From d8ef86dcfea8c60bea31c67f2a0d9410b3609f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 24 Nov 2023 17:28:40 +0100 Subject: [PATCH] some cleanup --- install/database_schema.sql | 18 ------------------ src/stats.py | 9 ++++++++- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/install/database_schema.sql b/install/database_schema.sql index 0e2171e..72a72db 100644 --- a/install/database_schema.sql +++ b/install/database_schema.sql @@ -298,13 +298,6 @@ CREATE TABLE user_ratings ( user_id INTEGER NOT NULL, type SMALLINT NOT NULL, - /** - * Do we want to store this here as well? Would be nice to be displayed in some elo page imo. - * Note: We don't need to store the result (i guess), since we can easily retrieve that info by looking up the game using the league_id - * TODO: Since I'm not even sure on the rating model yet (I could imagine something slightly different than a team rating), - * I'll leave this here as potentially null for now and don't implement it. - */ - team_rating REAL, change REAL NOT NULL, value_after REAL NOT NULL, @@ -357,14 +350,3 @@ CREATE TABLE user_statistics ( average_game_moves REAL GENERATED ALWAYS AS (CASE WHEN games_played != 0 THEN CAST(total_game_moves AS REAL) / games_played ELSE NULL END) STORED, PRIMARY KEY (user_id, variant_type) ); - -/** -* TODO: I'm really unsure right now how to store user-related statistics, stuff like -* - Current streak -* - Average bdrs/moves/whatever -* - Cumulative stuff like 'number of wins/losses', 'number of strikeouts' etc. -* Computationally it would just be fine to re-evaluate them whenever needed, since it's only looking stuff up in the database + some linear time calculation. -* On the other hand, it would be sort of nice to have them here as well. -* In the latter case, I'd probably suggest having just one row for each user that we automatically update whenever we process a game of that user, -* together with an indication on how recent that entry is (so that on query, we always know if it's up to date). -*/ diff --git a/src/stats.py b/src/stats.py index dfa80d8..ad8907c 100644 --- a/src/stats.py +++ b/src/stats.py @@ -1,6 +1,8 @@ import enum from typing import List, Tuple, Set +import psycopg2.extras + from hanabi import hanab_game import utils from database import conn_manager @@ -24,7 +26,7 @@ class GameAnalysisResult: bdrs: List[Tuple[hanab_game.DeckCard, int]], lost_crits: List[hanab_game.DeckCard] ): - self.outcome = GameOutcome + self.outcomes = outcomes self.bdrs = bdrs self.lost_crits = lost_crits @@ -85,6 +87,11 @@ def analyze_game_and_store_stats(game_id: int): "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)) ) + psycopg2.extras.execute_values( + cur, + "INSERT INTO game_outcomes (game_id, outcome) VALUES %s", + ((game_id, outcome.value) for outcome in analysis.outcomes) + ) conn_manager.get_connection().commit()