+
+
+class PlayerGlicko(object):
+ """
+ A player's skill for a particular game type, as determined by the Glicko2 algorithm.
+ """
+ def __init__(self, player_id, game_type_cd, category="general", mu=MU, phi=PHI, sigma=SIGMA):
+ self.player_id = player_id
+ self.game_type_cd = game_type_cd
+ self.category = category
+ self.mu = float(mu)
+ self.phi = phi
+ self.sigma = sigma
+
+ def to_glicko2(self):
+ """ Convert a rating to the Glicko2 scale. """
+ return PlayerGlicko(
+ player_id=self.player_id,
+ game_type_cd=self.game_type_cd,
+ category=self.category,
+ mu=(float(self.mu) - MU)/GLICKO2_SCALE,
+ phi=self.phi/GLICKO2_SCALE,
+ sigma=self.sigma
+ )
+
+ def from_glicko2(self):
+ """ Convert a rating to the original Glicko scale. """
+ return PlayerGlicko(
+ player_id=self.player_id,
+ game_type_cd=self.game_type_cd,
+ category=self.category,
+ mu=self.mu * GLICKO2_SCALE + MU,
+ phi=self.phi * GLICKO2_SCALE,
+ 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):
+ """
+ A clone of the above PlayerGlicko class, but created separately in order to avoid
+ dealing with primary and non-primary SQLAlchemy mappers.
+ """
+ pass
\ No newline at end of file