diff options
author | emkael <emkael@tlen.pl> | 2014-11-07 23:23:40 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2014-11-07 23:23:40 +0100 |
commit | 5e8b376770277e6b4db3095bc1d1c6fb3f5b36a7 (patch) | |
tree | 671b68c9a229d932b844930872e0fa58c915826d | |
parent | efcf12f3e6bb437f5089215fd81b2c924961e4d2 (diff) |
* non-linear disparity adjustements
-rw-r--r-- | config/elo.json | 14 | ||||
-rw-r--r-- | f1elo/elo.py | 38 |
2 files changed, 28 insertions, 24 deletions
diff --git a/config/elo.json b/config/elo.json index 6b08ee8..9940909 100644 --- a/config/elo.json +++ b/config/elo.json @@ -1,11 +1,15 @@ { "initial_ranking": 2000.0, - "disparity": 600, + "disparity": { + "base_disparity": 400, + "adjust": 1, + "base_rating_change": 150 + }, "importance": { - "NC_Q": 1.6, - "NC_R": 16, - "C_Q": 3.2, - "C_R": 32 + "NC_Q": 1.6, + "NC_R": 16, + "C_Q": 3.2, + "C_R": 32 }, "importance_threshold": [ 2000, 1800 ] } diff --git a/f1elo/elo.py b/f1elo/elo.py index 8b3c806..b7ba393 100644 --- a/f1elo/elo.py +++ b/f1elo/elo.py @@ -24,27 +24,27 @@ class Elo: return sum([self.get_ranking(d, date) for d in entry.drivers]) / len(entry.drivers) def rank_race(self, race): - recent_date = race.date - dateutil.relativedelta.relativedelta(months=9) - recent_ratings = self.session.query( - func.min(Ranking.ranking).label('min'), - func.max(Ranking.ranking).label('max') - ).filter( - Ranking.rank_date >= recent_date - ).group_by( - Ranking._driver - ) - changes_query = self.session.query( - func.avg( - func.abs( - recent_ratings.subquery().columns.min - recent_ratings.subquery().columns.max + race_disparity = self.config['disparity']['base_disparity'] + if self.config['disparity']['adjust']: + recent_date = race.date - dateutil.relativedelta.relativedelta(months=3) + recent_ratings = self.session.query( + func.min(Ranking.ranking).label('min'), + func.max(Ranking.ranking).label('max') + ).filter( + Ranking.rank_date >= recent_date + ).group_by( + Ranking._driver + ) + changes_query = self.session.query( + func.avg( + recent_ratings.subquery().columns.max - recent_ratings.subquery().columns.min ) ) - ) - recent_rank_changes = changes_query.scalar() - race_disparity = self.config['disparity'] - if recent_rank_changes: - race_disparity -= recent_rank_changes - print(race_disparity, str(race.date)) + recent_rank_change = changes_query.scalar() + if not recent_rank_change: + recent_rank_change = 0 + recent_rank_change = min(self.config['disparity']['base_rating_change'], recent_rank_change) + race_disparity *= (2.5 + (self.config['disparity']['base_rating_change']/(recent_rank_change - 2.0 * self.config['disparity']['base_rating_change']))) * 0.5 entries = race.entries entries_to_compare = [] rankings = {} |