def sim_and_rank_seasons(lineup, num_rotations=2): ordered_seasons = [] # stores seasons in descending order by runs/game counter = 0 lineup_copy = lineup[:] while counter < num_rotations: # generate random rotation shuffle(lineup_copy) # test all 9 possible orders of given rotation for i in range(9): lineup_copy.append(lineup_copy.pop(0)) # place first batter at end s = Season(lineup=deepcopy(list(lineup_copy)), num_games=162) s.play_season() ordered_seasons.append(s) #print to terminal so people don't freak out waiting for simulations to end sys.stdout.write("\rSeasons Simulated: %d/%d" % (i+counter*9+1, num_rotations*9)) sys.stdout.flush() counter += 1 ordered_seasons.sort(key=lambda s: s.get_runs_per_game()) sys.stdout.write("\n") return ordered_seasons
def sim_and_rank_seasons(lineup, num_rotations=2): ordered_seasons = [] # stores seasons in descending order by runs/game counter = 0 lineup_copy = lineup[:] while counter < num_rotations: # generate random rotation shuffle(lineup_copy) # test all 9 possible orders of given rotation for i in range(9): lineup_copy.append(lineup_copy.pop(0)) # place first batter at end s = Season(lineup=deepcopy(list(lineup_copy)), num_games=162) s.play_season() ordered_seasons.append(s) #print to terminal so people don't freak out waiting for simulations to end sys.stdout.write("\rSeasons Simulated: %d/%d" % (i + counter * 9 + 1, num_rotations * 9)) sys.stdout.flush() counter += 1 ordered_seasons.sort(key=lambda s: s.get_runs_per_game()) sys.stdout.write("\n") return ordered_seasons
def rbi_sim_and_rank_seasons(lineup, trials_per_pos=2, name="David Oritz"): lineup_copy = lineup[:] this_player = None this_player_index = -1 ordered_seasons = [ [] for _ in range(9) ] # list of list of seasons. Index of list corresponds to player position # take player object of name out of lineup for i, p in enumerate(lineup_copy): if p.get_name() == name: if this_player is None: this_player = p this_player_index = i break else: # menas duplicate player names! print "Error: cannot use duplicate names in lineup!" sys.exit() if this_player is None and this_player_index == -1: print "Player name not in lineup!" sys.exit() lineup_copy.pop(this_player_index) # test player at 1-9 spots of lineup counter = 0 for lineup_pos in range(9): for i in range(trials_per_pos): shuffle(lineup_copy) # randomize lineup lineup_copy.insert( lineup_pos, this_player) # insert this player in appropriate spot s = Season(lineup=deepcopy(list(lineup_copy)), num_games=162) s.play_season() ordered_seasons[lineup_pos].append(s) for i, p in enumerate(lineup_copy): if p.get_name() == name: del lineup_copy[i] break #print to terminal so people don't freak out waiting for simulations to end sys.stdout.write("\rSeasons Simulated: %d/%d" % (counter + 1, trials_per_pos * 9)) sys.stdout.flush() counter += 1 sys.stdout.write("\n") return ordered_seasons
def rbi_sim_and_rank_seasons(lineup, trials_per_pos=2, name="David Oritz"): lineup_copy = lineup[:] this_player = None this_player_index = -1 ordered_seasons = [[] for _ in range(9)] # list of list of seasons. Index of list corresponds to player position # take player object of name out of lineup for i, p in enumerate(lineup_copy): if p.get_name() == name: if this_player is None: this_player = p this_player_index = i break else: # menas duplicate player names! print "Error: cannot use duplicate names in lineup!" sys.exit() if this_player is None and this_player_index == -1: print "Player name not in lineup!" sys.exit() lineup_copy.pop(this_player_index) # test player at 1-9 spots of lineup counter = 0 for lineup_pos in range(9): for i in range(trials_per_pos): shuffle(lineup_copy) # randomize lineup lineup_copy.insert(lineup_pos, this_player) # insert this player in appropriate spot s = Season(lineup=deepcopy(list(lineup_copy)), num_games=162) s.play_season() ordered_seasons[lineup_pos].append(s) for i, p in enumerate(lineup_copy): if p.get_name() == name: del lineup_copy[i] break #print to terminal so people don't freak out waiting for simulations to end sys.stdout.write("\rSeasons Simulated: %d/%d" % (counter+1, trials_per_pos*9)) sys.stdout.flush() counter += 1 sys.stdout.write("\n") return ordered_seasons
from season import Season s = Season("division.csv", "games.csv") s.play_season() s.league.standings(["Golden State Warriors", 'Los Angeles Lakers'], display=True) ##s.league.standings(s.league.get_conference('West') + s.league.get_conference('East'), display=True) #s.league.standings(s.league.get_division(s.league.teams['Houston Rockets'].division),display=True) #print(s.league.get_division('Southwest')) #print(s.league.is_division_leader('San Antonio Spurs')) ##s.league.global_standings() ##print(s.league.standings(s.league.get_conference('West') + s.league.get_conference('East'), display=True, option='West')) ##print(s.league.split_ties(s.league.standings(s.league.get_conference('West') + s.league.get_conference('East'), display=True, option='West'))) print( s.league.h2h_sort([('Golden State Warriors', 0.8170731708317073), ('San Antonio Spurs', 0.8170731707317073), ('Houston Rockets', 0.8170731707317073), ('LA Clippers', 0.8170731707317073), ('Utah Jazz', 0.6219512195121951), ('Oklahoma City Thunder', 0.573170731707317), ('Memphis Grizzlies', 0.524390243902439), ('Portland Trail Blazers', 0.5), ('Denver Nuggets', 0.4878048780487805), ('New Orleans Pelicans', 0.4146341463414634), ('Dallas Mavericks', 0.4024390243902439), ('Sacramento Kings', 0.3902439024390244), ('Minnesota Timberwolves', 0.3780487804878049), ('Los Angeles Lakers', 0.3170731707317073), ('Phoenix Suns', 0.2926829268292683)],