From 57b24ea2be2032bc46fc248d0ffc29f0258e664c Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Mon, 25 Dec 2017 14:27:05 -0500 Subject: [PATCH 1/1] Change to explicit floats, add string representations of objects. --- xonstat/glicko.py | 6 +++++- xonstat/models/__init__.py | 8 +++++++- xonstat/models/player.py | 14 +++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/xonstat/glicko.py b/xonstat/glicko.py index f9f9020..1673043 100644 --- a/xonstat/glicko.py +++ b/xonstat/glicko.py @@ -136,7 +136,7 @@ def rate(player, opponents, results): return new_rating -class KReduction: +class KReduction(object): """ Scale the points gained or lost for players based on time played in the given game. """ @@ -194,6 +194,10 @@ class GlickoWIP(object): # the list of results for those games in the ranking period self.results = [] + def __repr__(self): + return ("".format(self)) + class GlickoProcessor(object): """ diff --git a/xonstat/models/__init__.py b/xonstat/models/__init__.py index 817cc37..a7d8741 100644 --- a/xonstat/models/__init__.py +++ b/xonstat/models/__init__.py @@ -2,7 +2,7 @@ Model initialization and mapping. """ -from sqlalchemy import MetaData +from sqlalchemy import MetaData, Numeric from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker, mapper @@ -62,6 +62,12 @@ def initialize_db(engine=None): player_glickos_base_table = metadata.tables['player_glickos_base'] player_glickos_current_table = metadata.tables['player_glickos_current'] + # explicit floats instead of decimals in certain tables + for table in [player_glickos_base_table, player_glickos_current_table]: + for column in table.columns.values(): + if isinstance(column.type, Numeric): + column.type.asdecimal = False + # Map the tables and the objects together mapper(PlayerAchievement, achievements_table) mapper(Achievement, cd_achievement_table) diff --git a/xonstat/models/player.py b/xonstat/models/player.py index fece334..89c8cdb 100644 --- a/xonstat/models/player.py +++ b/xonstat/models/player.py @@ -10,10 +10,10 @@ from xonstat.util import strip_colors, pretty_date, qfont_decode # Glicko Constants # the default initial rating value -MU = 1500 +MU = 1500.0 # the default ratings deviation value -PHI = 350 +PHI = 350.0 # the default volatility value SIGMA = 0.06 @@ -231,7 +231,7 @@ class PlayerGlicko(object): self.player_id = player_id self.game_type_cd = game_type_cd self.category = category - self.mu = mu + self.mu = float(mu) self.phi = phi self.sigma = sigma @@ -241,8 +241,8 @@ class PlayerGlicko(object): player_id=self.player_id, game_type_cd=self.game_type_cd, category=self.category, - mu=(self.mu - MU) / GLICKO2_SCALE, - phi=self.phi / GLICKO2_SCALE, + mu=(float(self.mu) - MU)/GLICKO2_SCALE, + phi=self.phi/GLICKO2_SCALE, sigma=self.sigma ) @@ -257,6 +257,10 @@ class PlayerGlicko(object): sigma=self.sigma ) + def __repr__(self): + return ("".format(self)) + class PlayerGlickoBase(PlayerGlicko): """ -- 2.39.2