Created
January 19, 2016 00:09
-
-
Save mrshoe/6d5abc5e7ae2306a966e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LEAGUE_SIZE = 12 | |
class Team: | |
def __init__(self, number): | |
self.number = number | |
self.wins = [] | |
self.losses = [] | |
self.winning_pct = 0.0 | |
self.opps_500plus = 0 | |
self.wins_500plus = 0 | |
self.avg_opp_winpct = 0.0 | |
@property | |
def games_played(self): | |
return len(self.wins) + len(self.losses) | |
@property | |
def win_count(self): | |
return len(self.wins) | |
@property | |
def loss_count(self): | |
return len(self.losses) | |
def __repr__(self): | |
return 'Beta%02d\t%d-%d\t%0.2f\t%d\t%d\t%0.2f' % (self.number, self.win_count, self.loss_count, self.winning_pct, self.wins_500plus, self.opps_500plus, self.avg_opp_winpct) | |
def __cmp__(self, other): | |
return self.number.__cmp__(other.number) | |
def game(team1, team2): | |
winner, loser = (team1, team2) if team1 < team2 else (team2, team1) | |
winner.wins.append(loser) | |
loser.losses.append(winner) | |
league = [Team(x+1) for x in xrange(LEAGUE_SIZE)] | |
league_games = league[:] | |
while league_games: | |
team = league_games.pop() | |
for t in league_games: | |
game(team, t) | |
for t in league: | |
t.winning_pct = float(t.win_count) / t.games_played | |
for t in league: | |
t.opps_500plus = len([w for w in (t.wins+t.losses) if w.win_count >= w.loss_count]) | |
t.wins_500plus = len([w for w in t.wins if w.win_count >= w.loss_count]) | |
for t in league: | |
opp_winpct = [x.winning_pct for x in (t.wins + t.losses)] | |
t.avg_opp_winpct = sum(opp_winpct) / len(opp_winpct) | |
for t in sorted(league, key=lambda x: -1*x.winning_pct): | |
print t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment