def test_conferences_integration(self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return(YEAR) conferences = Conferences() assert conferences.team_conference == self.team_conference assert conferences.conferences == self.conferences_result
def test_invalid_default_year_reverts_to_previous_year( self, *args, **kwargs): flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return(2019) conferences = Conferences() assert conferences.team_conference == self.team_conference assert conferences.conferences == self.conferences_result
def make_predictions(prediction_stats, games_list, match_info, predictor): prediction_list = [] conferences = Conferences().team_conference prediction_data = pd.concat(prediction_stats) prediction_data = differential_vector(prediction_data) prediction_data['points_difference'] = prediction_data['home_points'] - \ prediction_data['away_points'] prediction_data = predictor.simplify(prediction_data) predictions = predictor.predict(prediction_data, int) for sim in range(len(games_list) / NUM_SIMS): total_points = {} num_wins = {} for i in range(NUM_SIMS): x = sim * NUM_SIMS + i winner_idx = list(predictions[x]).index(max(predictions[x])) loser_idx = list(predictions[x]).index(min(predictions[x])) # In the case of a tie, give precedence to the home team. if winner_idx == loser_idx: winner_idx = 0 winner = games_list[x].home.abbreviation loser_idx = 1 loser = games_list[x].away.abbreviation elif winner_idx == 0: winner = games_list[x].home.abbreviation loser = games_list[x].away.abbreviation else: winner = games_list[x].away.abbreviation loser = games_list[x].home.abbreviation home = games_list[x].home.abbreviation away = games_list[x].away.abbreviation winner_points = predictions[x][winner_idx] loser_points = predictions[x][loser_idx] try: total_points[winner] += winner_points except KeyError: total_points[winner] = winner_points try: total_points[loser] += loser_points except KeyError: total_points[loser] = loser_points try: num_wins[winner] += 1 except KeyError: num_wins[winner] = 1 winner, loser = get_winner(num_wins, home, away) winner_prob, loser_prob = get_probability(num_wins, winner, loser) winner_points, loser_points = get_points(total_points, winner, loser) display_prediction(games_list[sim*NUM_SIMS].title, winner) p = create_prediction_data(match_info[sim*NUM_SIMS], conferences, winner, loser, winner_prob, loser_prob, winner_points, loser_points) prediction_list.append(p) return prediction_list
def start_monte_carlo_simulations(predictor, rankings, teams, mongo_url, num_sims=NUM_SIMS, skip_save_to_mongodb=False): results_dict = {} points_dict = {} for abbreviation, details in Conferences().conferences.items(): results, points = simulate_conference(predictor, details, rankings, teams, num_sims) results_dict[abbreviation] = { 'results': results, 'name': details['name'] } points_dict[abbreviation] = {'points': points, 'name': details['name']} simulation = save_simulation(num_sims, results_dict, points_dict, 'simulations/simulation.json', teams) if not skip_save_to_mongodb: save_to_mongodb(mongo_url, simulation, MONTE_CARLO_SIMULATION)
def test_conferences_integration_bad_url(self, *args, **kwargs): with pytest.raises(ValueError): conferences = Conferences('BAD')
def test_conferences_integration(self, *args, **kwargs): team_conference = { 'kansas': 'big-12', 'texas-tech': 'big-12', 'west-virginia': 'big-12', 'kansas-state': 'big-12', 'texas-christian': 'big-12', 'oklahoma-state': 'big-12', 'oklahoma': 'big-12', 'baylor': 'big-12', 'texas': 'big-12', 'iowa-state': 'big-12', 'xavier': 'big-east', 'villanova': 'big-east', 'seton-hall': 'big-east', 'creighton': 'big-east', 'providence': 'big-east', 'butler': 'big-east', 'marquette': 'big-east', 'georgetown': 'big-east', 'st-johns-ny': 'big-east', 'depaul': 'big-east' } conferences_result = { 'big-12': { 'name': 'Big 12 Conference', 'teams': { 'kansas': 'Kansas', 'texas-tech': 'Texas Tech', 'west-virginia': 'West Virginia', 'kansas-state': 'Kansas State', 'texas-christian': 'Texas Christian', 'oklahoma-state': 'Oklahoma State', 'oklahoma': 'Oklahoma', 'baylor': 'Baylor', 'texas': 'Texas', 'iowa-state': 'Iowa State' } }, 'big-east': { 'name': 'Big East Conference', 'teams': { 'xavier': 'Xavier', 'villanova': 'Villanova', 'seton-hall': 'Seton Hall', 'creighton': 'Creighton', 'providence': 'Providence', 'butler': 'Butler', 'marquette': 'Marquette', 'georgetown': 'Georgetown', 'st-johns-ny': "St. John's (NY)", 'depaul': 'DePaul' } } } flexmock(utils) \ .should_receive('_find_year_for_season') \ .and_return(YEAR) conferences = Conferences() assert conferences.team_conference == team_conference assert conferences.conferences == conferences_result
def test_conferences_string_representation(self, *args, **kwargs): conferences = Conferences() assert conferences.__repr__() == 'NCAAB Conferences'
import sys, os sys.path.append(os.path.dirname(os.path.dirname(sys.path[0]))) from sportsreference.ncaab.conferences import Conferences from sportsreference.ncaab.rankings import Rankings from sportsreference.ncaab.teams import Teams for team in Teams(): print(team.name) for player in team.roster.players: print(player.name) for game in team.schedule: print(game.dataframe) print(game.dataframe_extended) conferences = Conferences() print(conferences.conferences) print(conferences.team_conference) rankings = Rankings() print(rankings.current) print(rankings.current_extended) print(rankings.complete)