started implementing bracket generation
This commit is contained in:
parent
cda703bfae
commit
22150033ca
8
games.py
8
games.py
|
@ -108,6 +108,14 @@ class team(object):
|
|||
else:
|
||||
return (None, None, None)
|
||||
|
||||
def average_stars(self):
|
||||
total_stars = 0
|
||||
for _player in self.lineup:
|
||||
total_stars += _player.stlats["batting_stars"]
|
||||
for _player in self.rotation:
|
||||
total_stars += _player.stlats["pitching_stars"]
|
||||
return total_stars/(len(self.lineup) + len(self.rotation))
|
||||
|
||||
def swap_player(self, name):
|
||||
this_player, index, roster = self.find_player(name)
|
||||
if this_player is not None and len(roster) > 1:
|
||||
|
|
33
leagues.py
33
leagues.py
|
@ -1,4 +1,5 @@
|
|||
import time, asyncio, jsonpickle
|
||||
import time, asyncio, jsonpickle, random, math
|
||||
from games import team, game
|
||||
import database as db
|
||||
|
||||
|
||||
|
@ -15,5 +16,33 @@ class league(object):
|
|||
|
||||
class division(object):
|
||||
def __init__(self):
|
||||
self.teams = {} #key: team name, value: {wins; losses; run diff}
|
||||
self.teams = {} #key: team object, value: {wins; losses; run diff}
|
||||
|
||||
class tournament(object):
|
||||
def __init__(self, team_dic):
|
||||
self.teams = {} #same format as division, wins/losses will be used for seeding later
|
||||
self.bracket = {}
|
||||
self.bracket_layers = 0
|
||||
|
||||
def build_bracket(self, random = False, by_wins = False):
|
||||
teams_list = self.teams.keys().copy()
|
||||
|
||||
if random:
|
||||
def sorter(team_in_list):
|
||||
return random.random()
|
||||
|
||||
elif by_wins:
|
||||
def sorter(team_in_list):
|
||||
return self.teams[team_in_list][0] #sorts by wins
|
||||
|
||||
if not random and not by_wins: #sort by average stars
|
||||
def sorter(team_in_list):
|
||||
return team_in_list.average_stars()
|
||||
|
||||
teams_list.sort(key=sorter, reverse=True)
|
||||
|
||||
self.bracket_layers = int(math.ceil(math.log(len(teams_list), 2)))
|
||||
empty_slots = int(math.pow(2, bracket_layers) - len(teams_list))
|
||||
|
||||
for i in range(0, empty_slots):
|
||||
teams_list.append(None)
|
||||
|
|
Loading…
Reference in New Issue
Block a user