]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Change to explicit floats, add string representations of objects.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 25 Dec 2017 19:27:05 +0000 (14:27 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 25 Dec 2017 19:27:05 +0000 (14:27 -0500)
xonstat/glicko.py
xonstat/models/__init__.py
xonstat/models/player.py

index f9f9020d0869f63a13bac398ddfd0f1e77dff545..167304392ce280e1a48d92e60528dc5bf6ef8994 100644 (file)
@@ -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 ("<GlickoWIP({0.pg}, k={0.k_factors}, ping={0.ping_factors}, "
+                "opponents={0.opponents}, results={0.results})>".format(self))
+
 
 class GlickoProcessor(object):
     """
index 817cc372502767d542e099cc1268c7d9abe2a27b..a7d874124455d50e548b7dae36dd3fcf6ea728a7 100644 (file)
@@ -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)
index fece334272b71ee51a97fb7fe27ebe43662c4981..89c8cdb7dc1c63bf04ed91c4d5c24bef50c63976 100644 (file)
@@ -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 ("<PlayerGlicko({0.player_id}, {0.game_type_cd}, {0.category}, "
+                "{0.mu}, {0.phi}, {0.sigma})>".format(self))
+
 
 class PlayerGlickoBase(PlayerGlicko):
     """