Skip to content

Replace magic numbers with constants #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions glicko2/glicko2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,32 @@

import math

GLICKO_SCALE_FACTOR = 400 / math.log(10)
BASE_RATING = 1500

class Player:
# Class attribute
# The system constant, which constrains
# the change in volatility over time.
_tau = 0.5

def getRating(self):
return (self.__rating * 173.7178) + 1500
return (self.__rating * GLICKO_SCALE_FACTOR) + BASE_RATING

def setRating(self, rating):
self.__rating = (rating - 1500) / 173.7178
self.__rating = (rating - BASE_RATING) / GLICKO_SCALE_FACTOR

rating = property(getRating, setRating)

def getRd(self):
return self.__rd * 173.7178
return self.__rd * GLICKO_SCALE_FACTOR

def setRd(self, rd):
self.__rd = rd / 173.7178
self.__rd = rd / GLICKO_SCALE_FACTOR

rd = property(getRd, setRd)

def __init__(self, rating = 1500, rd = 350, vol = 0.06):
def __init__(self, rating = BASE_RATING, rd = 350, vol = 0.06):
# For testing purposes, preload the values
# assigned to an unrated player.
self.setRating(rating)
Expand All @@ -70,7 +73,7 @@ def update_player(self, rating_list, RD_list, outcome_list):

"""
# Convert the rating and rating deviation values for internal use.
rating_list = [(x - 1500) / 173.7178 for x in rating_list]
rating_list = [(x - BASE_RATING) / GLICKO_SCALE_FACTOR for x in rating_list]
RD_list = [x / 173.7178 for x in RD_list]

v = self._v(rating_list, RD_list)
Expand Down