def determine_tourney_games_and_make_brackets(self): """ We don't have data saying which games were a part of the tournament, so we have to create it programmatically. Some assumptions: - all tournament games occur in March or April - the last game played by the winning team was the championship game - all round i games finish before any round i+1 games start Note we can't just take the last 63 games, because there are e.g., NIT tournament games mixed in. """ self.brackets = {} self.tournament_starts = {} for season in PAST_WINNERS: if season == "2011-2012": continue if season not in self.game_results_by_season: continue bracket = Bracket() dummy, tourney_year = season.split("-") games = [] for i, game in enumerate(self.game_results_by_season[season]): (date, home_id, away_id, home_score, away_score) = game year, month, day = date if not (month == 3 or month == 4): continue home_code = self.team_codes[home_id] away_code = self.team_codes[away_id] games.append((month * 100 + day, home_code, away_code, game)) surviving_teams = [PAST_WINNERS[season]] bracket.round[6] = surviving_teams for game in reversed(sorted(games)): num_surviving = len(surviving_teams) home_code, away_code = game[1], game[2] if home_code in surviving_teams: surviving_teams.append(away_code) elif away_code in surviving_teams: surviving_teams.append(home_code) else: continue r = 5 - int(np.floor(np.log2(num_surviving))) if r < 0: break bracket.round[r].append(game[3]) if season not in self.tournament_starts or \ game[0] < self.tournament_starts[season]: self.tournament_starts[season] = game[0] bracket.make_bracket_structure(team_codes=self.team_codes) self.brackets[season] = bracket
def determine_tourney_games_and_make_brackets(self): """ We don't have data saying which games were a part of the tournament, so we have to create it programmatically. Some assumptions: - all tournament games occur in March or April - the last game played by the winning team was the championship game - all round i games finish before any round i+1 games start Note we can't just take the last 63 games, because there are e.g., NIT tournament games mixed in. """ self.brackets = {} self.tournament_starts = {} for season in PAST_WINNERS: if season == "2011-2012": continue if season not in self.game_results_by_season: continue bracket = Bracket() dummy, tourney_year = season.split("-") games = [] for i, game in enumerate(self.game_results_by_season[season]): (date, home_id, away_id, home_score, away_score) = game year, month, day = date if not (month == 3 or month == 4): continue home_code = self.team_codes[home_id] away_code = self.team_codes[away_id] games.append((month*100+day, home_code, away_code, game)) surviving_teams = [PAST_WINNERS[season]] bracket.round[6] = surviving_teams for game in reversed(sorted(games)): num_surviving = len(surviving_teams) home_code, away_code = game[1], game[2] if home_code in surviving_teams: surviving_teams.append(away_code) elif away_code in surviving_teams: surviving_teams.append(home_code) else: continue r = 5 - int(np.floor(np.log2(num_surviving))) if r < 0: break bracket.round[r].append(game[3]) if season not in self.tournament_starts or \ game[0] < self.tournament_starts[season]: self.tournament_starts[season] = game[0] bracket.make_bracket_structure(team_codes=self.team_codes) self.brackets[season] = bracket