def update_ratings(self, color): points = {self.color: 1.0, self.opponent.color: 0.0}.get(color, 0.5) mine = utils.loads(self.factory.db[self.name]) others = utils.loads(self.factory.db[self.opponent.name]) mine['rating'], others['rating'] = utils.elo(mine['rating'], others['rating'], points) self.factory.db[self.name] = utils.dumps(mine) self.factory.db[self.opponent.name] = utils.dumps(others)
def test_elo(): rating = 1613 for opponent, result in [(1609, 0.0), (1477, 0.5), (1388, 1.0), (1586, 1.0), (1720, 0.0)]: rating = utils.elo(rating, opponent, result)[0] assert round(rating) == 1603