forked from Hanabi/hanabi-league
Update database schemea: add stats
This commit is contained in:
parent
4e0b624c3f
commit
9a8318bc6d
2 changed files with 44 additions and 8 deletions
|
@ -272,7 +272,7 @@ CREATE TABLE variant_ratings (
|
|||
|
||||
DROP TABLE IF EXISTS user_base_ratings CASCADE;
|
||||
CREATE TABLE user_base_ratings (
|
||||
user_id SMALLINT,
|
||||
user_id INTEGER,
|
||||
/**
|
||||
* Since a user has different ratings now, this should represent which of the ratings we mean.
|
||||
* For now, I suggest 0 = NoVar, 1 = ClueStarved.
|
||||
|
@ -295,7 +295,7 @@ CREATE TABLE user_ratings (
|
|||
*/
|
||||
league_id INTEGER REFERENCES games (league_id),
|
||||
|
||||
user_id SMALLINT NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
type SMALLINT NOT NULL,
|
||||
|
||||
/**
|
||||
|
@ -316,13 +316,38 @@ CREATE TABLE user_ratings (
|
|||
/* TABLES RELATED TO STATISTICS */
|
||||
|
||||
/** This is a rough outline, not really happy with it right now. */
|
||||
DROP TABLE IF EXISTS statistics CASCADE;
|
||||
CREATE TABLE statistics (
|
||||
game_id INTEGER PRIMARY KEY,
|
||||
DROP TABLE IF EXISTS game_statistics CASCADE;
|
||||
CREATE TABLE game_statistics (
|
||||
game_id INTEGER PRIMARY KEY REFERENCES games (id),
|
||||
/** I'd say all of the following can just be null in case we have not evaluated them yet. */
|
||||
bdr SMALLINT,
|
||||
moves SMALLINT,
|
||||
strikeout BOOLEAN
|
||||
bottom_deck_risk SMALLINT,
|
||||
num_crits_lost SMALLINT
|
||||
);
|
||||
|
||||
/**
|
||||
* Need a new table here, since a single game might have several outcomes:
|
||||
* Think of losing a crit and striking out, for example
|
||||
*/
|
||||
DROP TABLE IF EXISTS game_outcomes CASCADE;
|
||||
CREATE TABLE game_outcomes (
|
||||
game_id INTEGER REFERENCES games (id),
|
||||
/** This stores the game outcome, corresponding to the values of the statistics.GameOutcome enum */
|
||||
outcome SMALLINT
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS user_statistics;
|
||||
CREATE TABLE user_statistics (
|
||||
user_id INTEGER NOT NULL REFERENCES users (id),
|
||||
/** We track stats separately for each variant type */
|
||||
variant_type SMALLINT NOT NULL,
|
||||
current_streak INTEGER NOT NULL,
|
||||
games_played INTEGER NOT NULL,
|
||||
games_won INTEGER NOT NULL,
|
||||
total_bdr INTEGER NOT NULL,
|
||||
/** Number of critical cards that were either discarded or misplayed */
|
||||
total_crits_lots INTEGER NOT NULL,
|
||||
total_game_moves INTEGER NOT NULL,
|
||||
PRIMARY KEY (user_id, variant_type)
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,8 @@ from typing import List, Tuple
|
|||
|
||||
from hanabi import hanab_game
|
||||
|
||||
from database import conn_manager
|
||||
|
||||
|
||||
class GameOutcome(enum.Enum):
|
||||
win = 0
|
||||
|
@ -59,3 +61,12 @@ def analyze_game(instance: hanab_game.HanabiInstance, actions: List[hanab_game.A
|
|||
outcomes.append(GameOutcome.win)
|
||||
|
||||
return GameAnalysisResult(outcomes, bdrs)
|
||||
|
||||
|
||||
def update_user_statistics(user_ids: List[int]):
|
||||
"""
|
||||
Update the cumulative user statistics for this user, assuming that the corresponding game statistics have
|
||||
been computed already.
|
||||
@param user_ids:
|
||||
@return:
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue