diff options
author | emkael <emkael@tlen.pl> | 2014-10-07 11:04:42 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2014-10-07 11:04:42 +0200 |
commit | 3d39c79d532800a8bdb7e410a1d441dfbc31cb01 (patch) | |
tree | 03786ce7354dd2eb9c6f398be6a608662142caef | |
parent | 6298e63ddb46d01d9e272f8830186d1d7482751a (diff) | |
parent | 11e3b2851216a3fa24efd52e094d83c608766444 (diff) |
Merge branch 'master'
Conflicts:
elo.py
-rwxr-xr-x | elo.py | 21 | ||||
-rw-r--r-- | f1elo/elo.py | 9 |
2 files changed, 14 insertions, 16 deletions
@@ -73,18 +73,21 @@ if date is None: date = datetime.date.today() date += one_day -print 'Rankings for %s' % date - one_year = dateutil.relativedelta.relativedelta(years=1) - rankings = session.query(Ranking).filter(Ranking.rank_date > (date - one_year)).filter(Ranking.rank_date <= date).all() -drivers = {} -for ranking in rankings: - if not drivers.has_key(ranking.driver): - drivers[ranking.driver] = ranking.driver.get_ranking(date) +if len(rankings): + print 'Rankings for %s' % date + + drivers = {} + for ranking in rankings: + if not drivers.has_key(ranking.driver): + drivers[ranking.driver] = ranking.driver.get_ranking(date) + -for rank in sorted(drivers.values(), key=lambda rank: rank.ranking, reverse=True): - print rank + for rank in sorted(drivers.values(), key=lambda rank: rank.ranking, reverse=True): + print rank +else: + print 'No rankings for %s' % date session.commit() diff --git a/f1elo/elo.py b/f1elo/elo.py index cb35e6c..99c1fd7 100644 --- a/f1elo/elo.py +++ b/f1elo/elo.py @@ -32,11 +32,6 @@ class Elo: entries_to_compare.append(e) for c in combinations(entries_to_compare, 2): score = self.get_score(rankings[c[0]] - rankings[c[1]], self.get_outcome(c), self.get_importance(race, [rankings[c[0]], rankings[c[1]]])) - #print c[0], '@', rankings[c[0]] - #print 'against' - #print c[1], '@', rankings[c[1]] - #print 'score: ', score - #print new_rankings[c[0]] += score new_rankings[c[1]] -= score return new_rankings @@ -49,7 +44,7 @@ class Elo: if min_rank <= 2400: return base_importance * 0.75 return base_importance / 2 - + def get_outcome(self, entries): if entries[0].result_group < entries[1].result_group: @@ -57,6 +52,6 @@ class Elo: elif entries[0].result_group > entries[1].result_group: return 0 return 0.5 - + def get_score(self, difference, outcome, importance): return importance * (outcome - 1 / (1 + (10 ** (-difference / self.config['disparity'])))) |