From f830a11ec26c1a05daf05f599bdf89d847c082d1 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sun, 30 Apr 2017 08:20:42 -0400 Subject: [PATCH] Use categories in submissions. --- xonstat/elo.py | 15 ++++++++++----- xonstat/views/submission.py | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xonstat/elo.py b/xonstat/elo.py index 60e7505..2e2ba76 100644 --- a/xonstat/elo.py +++ b/xonstat/elo.py @@ -99,11 +99,14 @@ class EloProcessor: """EloProcessor is a container for holding all of the intermediary AND final values used to calculate Elo deltas for all players in a given game.""" - def __init__(self, session, game, pgstats): + def __init__(self, session, game, pgstats, category): # game which we are processing self.game = game + # which type of Elo category we are processing + self.category = category + # work-in-progress values, indexed by player self.wip = {} @@ -138,14 +141,16 @@ class EloProcessor: # Fetch current Elo values for all players. For players that don't yet # have an Elo record, we'll give them a default one. - for e in session.query(PlayerElo).\ - filter(PlayerElo.player_id.in_(self.wip.keys())).\ - filter(PlayerElo.game_type_cd==game.game_type_cd).all(): + for e in session.query(PlayerElo)\ + .filter(PlayerElo.player_id.in_(self.wip.keys()))\ + .filter(PlayerElo.game_type_cd==game.game_type_cd)\ + .filter(PlayerElo.category==self.category)\ + .all(): self.wip[e.player_id].elo = e for pid in self.wip.keys(): if self.wip[pid].elo is None: - self.wip[pid].elo = PlayerElo(pid, game.game_type_cd, ELOPARMS.initial) + self.wip[pid].elo = PlayerElo(pid, game.game_type_cd, ELOPARMS.initial, category) # determine k reduction self.wip[pid].k = KREDUCTION.eval(self.wip[pid].elo.games, self.wip[pid].alivetime, diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index 28026ad..3f45a7f 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -1126,7 +1126,11 @@ def submit_stats(request): create_team_stat(session, game, events) if server.elo_ind and gametype_elo_eligible(submission.game_type_cd): - ep = EloProcessor(session, game, pgstats) + category = elo_submission_category(submission) + if not server.categories or category not in server.categories: + category = "general" + + ep = EloProcessor(session, game, pgstats, category) ep.save(session) elos = ep.wip else: -- 2.39.2