def football_menu(league_data, fixtures, predictions): data_source = "Soccer Stats" football_options = [ ["(1) Select a league", "1", choose_leagues], # The selectLeague function from football.py ["(2) Generate predictions on currently loaded fixtures", "2"], [ "(3) Single game analysis from fixture list*", "3", single_game_analysis ], ["(4) Manual single game analysis", "4", fb.manual_game_analysis], ["(5) Reports", "5", reports], ["(6) Import data from JSON file", "6"], ["(7) Clear currently loaded league data", "7"], ["(8) Clear currently stored prediction data", "8"], ["(9) Change data source (CLEARS ALL DATA)", "9"], ["(Q) Quit", "q", leave] ] # ["(M) Previous menu", "m", leave] - removed as prev menu currently bypassed selected_leagues = [] exit_menu = False available_options = [] selection = "" # Gather a list of availableOption numbers for input recognition for option in football_options: available_options.append(option[1]) while not exit_menu: if league_data == {}: football_options[0][0] = "(1) Select a league" else: football_options[0][0] = "(1) Select another league" selected_leagues = [] # If there are leagues selected in LeagueData, add them to the selectedLeagues # list and display the list. if league_data != {}: for league in league_data: selected_leagues.append(league) print("\n Selected league(s):\n") for league in selected_leagues: print(league) print() else: print( "\nNo league currently selected. Please start by selecting a league.\n" ) print("Currently selected data source: " + data_source + "\n") # Display the available options for option in football_options: print(option[0]) # Display any additional information print("\nItems marked with a * are not available in this version.") # Keep asking for a selection while the selection provided is not in the availableOptions list. while selection not in available_options: selection = input().lower() # If the selection is in the list, run it's function passing # the leagueData dictionary by default. for option in football_options: """if selection == "m": exit_menu = True break continue """ #Commented out as previous menu bypassed. if selection == "q": quit() if selection == "1": # Select league choose_leagues(league_data, fixtures, data_source) selection = "" continue if selection == "2": # Run analysis on currently loaded fixtures predictions = fb.upcoming_fixture_predictions( fixtures, predictions, league_data) selection = "" continue if selection == "4": # Manual single game analysis exit_manual_analysis_menu = False while not exit_manual_analysis_menu: selection = "" another_game = "" # Manual_predictions holds an error message if something goes wrong. manual_predictions = fb.manual_game_analysis( league_data, predictions) while another_game.lower() != "y" and another_game.lower( ) != "n": # If something went wrong, don't ask to run another game analysis. print(manual_predictions) if manual_predictions == "No leagues loaded": exit_manual_analysis_menu = True break else: print("\nAnalyse another game? (Y/N)") another_game = input() if another_game.lower() == "n": exit_manual_analysis_menu = True break if another_game.lower() == "y": break if selection == "5": # Reports reports(league_data, fixtures, predictions) selection = "" continue if selection == "6": # Import data from JSON file new_data = cf.import_json_file() if new_data == None: # If load fails del new_data else: league_data = new_data.copy() del new_data selection = "" continue if selection == "7": # Clear currently loaded league data. league_data = {} fixtures = [] selection = "" continue if selection == "8": # Clear currently loaded predictions data. predictions.clear() selection = "" continue if selection == "9": # Switch data source. if data_source == "Soccer Stats": data_source = "Bet Study" else: data_source = "Soccer Stats" league_data = {} fixtures = [] predictions.clear() selection = "" continue # General action for other menu items if selection == option[1]: option[2](league_data) selection = "" continue
def football_menu(football_data): """ The main football menu. Takes all football_data. """ data_source, next_data_source = "Soccer Stats", "Bet Study" selected_leagues = [] exit_menu = False available_options = [] selection = "" while not exit_menu: football_options = [ ["(1) Select a league", "1", fb.select_league], # The selectLeague function from football.py ["(2) Generate predictions on currently loaded fixtures", "2"], [ "(3) Single game visual analysis from fixture list", "3", select_fixture ], ["(4) Single game benchmark result analysis", "4", benchmark], ["(5) Manual single game analysis", "5", fb.manual_game_analysis], ["(6) Reports", "6", reports], ["(7) Import data from JSON file", "7"], ["(8) Clear current prediction data", "8"], ["(9) Clear all data", "9"], [ "(10) Change data source to " + next_data_source + " (CLEARS ALL DATA)", "10" ], ["(Q) Quit", "q", leave] ] # ["(M) Previous menu", "m", leave] - removed as prev menu currently bypassed. # Gather a list of availableOption numbers for input recognition for option in football_options: available_options.append(option[1]) if football_data["league_data"] == {}: football_options[0][0] = "(1) Select a league" else: football_options[0][0] = "(1) Select another league" selected_leagues = [] # If there are leagues selected in LeagueData, add them to the selectedLeagues # list and display the list. if football_data["league_data"] != {}: for league in football_data["league_data"]: selected_leagues.append(league) print("\n Selected league(s):\n") for league in selected_leagues: print(league) print() else: print( "\nNo league currently selected. Please start by selecting a league.\n" ) print("Currently selected data source: " + data_source + "\n") # For clarity of switching data source if data_source == "Soccer Stats": next_data_source = "Bet Study" else: next_data_source = "Soccer Stats" # Display the available options for option in football_options: print(option[0]) # Display any additional information #print("\nItems marked with a * are not available in this version.") # Keep asking for a selection while the selection provided is not in the availableOptions list. while selection not in available_options: selection = input().lower() # If the selection is in the list, run it's function passing # the leagueData dictionary by default. for option in football_options: """if selection == "m": exit_menu = True break continue """ #Commented out as previous menu bypassed. if selection == "q": quit() if selection == "1": # Select league fb.select_league(football_data["league_data"], football_data["fixtures"], football_data["results"], data_source) # Set fixtures in range football_data["fixtures_in_range"] = filter_fixtures_by_range( football_data["fixtures"], football_data["future_range"]) # Set results in range football_data["results_in_range"] = fb.get_results_in_range( football_data["results"], football_data["past_range"]) selection = "" continue if selection == "2": # Run analysis on currently loaded fixtures if football_data["fixtures"] == []: print( "\nNo fixtures currently loaded. Select a league first." ) selection = "" continue choice = "" while choice not in ["1", "2"]: print("\nSelect a method of prediciton:") print("\n1) Classic home goals vs away goals") print("2) Benchmark games home goals vs away goals") choice = input() if choice == "1": football_data[ "predictions"] = p.upcoming_fixture_predictions( football_data["fixtures"], football_data["predictions"], football_data["league_data"]) football_data[ "predictions_in_range"] = fb.get_predictions_in_range( football_data["predictions"], football_data["future_range"]) print( "\nPredictions have been processed and can be viewed via the \"Reports\" menu.\nPress enter to continue." ) input() selection = "" continue if choice == "2": p.upcoming_fixture_predictions_benchmarks(football_data) football_data[ "predictions_in_range"] = fb.get_predictions_in_range( football_data["predictions"], football_data["future_range"]) print( "\nPredictions have been processed and can be viewed via the \"Reports\" menu.\nPress enter to continue." ) input() selection = "" continue if selection == "3": # Visually compare selected fixture # Get fixtures in range #football_data["fixtures_in_range"] = filter_fixtures_by_range(football_data["fixtures"], football_data["future_range"]) # If no fixtures yet, return to menu. if football_data["league_data"] == {}: print( "No league data loaded. Select a league to download first." ) print("\nPress enter to return to the previous menu.") input() selection = "" continue # Select fixture. fixture_to_view = select_fixture( football_data["fixtures_in_range"]) # Perform visual comparison v.visual_comparison(fixture_to_view, football_data["league_data"]) # Return to menu selection = "" continue if selection == "4": # Benchmark results analysis if football_data["league_data"] == {}: print( "No league data loaded. Select a league to download first." ) print("\nPress enter to return to the previous menu.") input() selection = "" continue exit_option = False while exit_option == False: # Select fixture. fixture_to_view = select_fixture( football_data["fixtures_in_range"]) benchmark(fixture_to_view, football_data) while True: print( "\nWould you like to benchmark analyse another game? (Y/N)\n" ) answer = input() if answer.lower() == "y": break elif answer.lower() == "n": exit_option = True break selection = "" continue if selection == "5": # Manual single game analysis exit_manual_analysis_menu = False while not exit_manual_analysis_menu: selection = "" another_game = "" # Manual_predictions holds an error message if something goes wrong in the prediction process. manual_predictions = p.manual_game_analysis( football_data["league_data"], football_data["predictions"]) # Add new predictions to the fixtures in range. football_data[ "predictions_in_range"] = fb.get_predictions_in_range( football_data["predictions"], football_data["future_range"]) while another_game.lower() != "y" and another_game.lower( ) != "n": # If something went wrong, don't ask to run another game analysis. if manual_predictions == "No leagues loaded": exit_manual_analysis_menu = True break else: print("\nAnalyse another game? (Y/N)") another_game = input() if another_game.lower() == "n": exit_manual_analysis_menu = True break if another_game.lower() == "y": break if selection == "6": # Reports reports(football_data) selection = "" continue if selection == "7": # Import data from JSON file new_data = cf.import_json_file() if new_data == None: # If load fails del new_data else: football_data["league_data"] = new_data.copy() del new_data selection = "" continue if selection == "8": # Clear currently loaded predictions data. football_data["predictions"] = [] football_data["predictions_in_range"] = [] football_data["filtered_predictions"] = [] football_data["applied_filters"] = [] selection = "" continue if selection == "9": # Clear currently loaded data. football_data["league_data"] = {} football_data["fixtures"] = [] football_data["results"] = [] football_data["predictions"] = [] football_data["predictions_in_range"] = [] football_data["filtered_predictions"] = [] football_data["applied_filters"] = [] selection = "" continue if selection == "10": # Switch data source. data_source, next_data_source = next_data_source, data_source # Clear all data football_data["league_data"] = {} football_data["fixtures"] = [] football_data["predictions"] = [] football_data["predictions_in_range"] = [] football_data["filtered_predictions"] = [] football_data["applied_filters"] = [] football_data["results"] = [] selection = "" continue # General action for other menu items if selection == option[1]: option[2](football_data["league_data"]) selection = "" continue
gather_data = inform_and_scrape(selection, league_data, fixtures) else: print("No leagues added.") # If gather_data is blank (user entered 0 without selecting leagues or scraping failed) just exit. # Otherwise, confirm data has been downloaded before exiting. if not gather_data: return league_data, fixtures else: print("\nLeague data has been downloaded. Press enter to continue.") input() return league_data, fixtures # The availableLeagues dictionary: "League name": "League link from betstudy.com" # Created from the leagues.json file. available_leagues = cf.import_json_file("leagues", False) def inform_and_scrape(selection, league_data, fixtures): """ Takes in the key value of a selected league. Advised that downloading of that league is taking place. Passes the league key to the get_league_data function for scraping. """ # Debug code: display the URL that will be used to obtain the league data # print("This will use the following url: " + availableLeagues[selection][1] + "\n") league_data_and_fixtures = get_league_data(selection, league_data, fixtures) if league_data_and_fixtures == "Scrape error": return else:
def select_league(league_data, fixtures, data_source): """Takes in the leagueData dictionary. Prompts the user to select a league. Returns the key value of the selected league. """ # Create the appropriate availableLeagues dictionary: "League name": "League link from data source" if data_source == "Bet Study": # Imported from the bet-study-leagues.json file. available_leagues = cf.import_json_file("bet-study-leagues", False) else: # Imported from the soccer-stats-leagues.json file. available_leagues = cf.import_json_file("soccer-stats-leagues", False) while True: available_options = [] new_leagues = { } # Used for input validation and tidy display of available leagues. option = "" # Number entered by user gather_data = "" # Will store gathered data if user chooses a league. # Create the available_options list of availble option numbers for input validation later on. option_number = 0 for league in available_leagues: option_number += 1 new_leagues[str(option_number) + " " + league] = [ str(option_number), league ] # Add option numbers to a new leagues dictionary for display. available_options.append( str(option_number) ) # Add the option number string to the list of selectable options. # Display the new leagues keys with the newly added option numbers. cf.custom_pretty_print(new_leagues, 3) # Add extra options to available options. extra_options = ["0", "all"] for extra_option in extra_options: available_options.append(extra_option) # Create a list to store the selected leagues. selected_leagues = [] # Print instructions outside of the loop to avoid repetition. print("\nSelected data source: " + data_source) print( "\nEnter leagues to add (one at a time). Enter all to select all leagues. Enter 0 when done." ) # True loop to add multiple leagues while True: while option not in available_options: option = input().lower() # If all entered, add all leagues to the list of selections and commence scrape. if option == "all": for league in available_leagues: selected_leagues.append(league) option = "0" else: # Check which league belongs to the selected option and add it to the selection list. for league in new_leagues: if option == new_leagues[league][0]: selected_leagues.append(new_leagues[league][1]) # Debug code: Display selected_leagues list. # print("Selected leagues: " + selected_leagues) # If user enters 0, exit the loop. if option == "0": del new_leagues # Remove the copy of the leagues dictionary. break # Reset the input to blank ready for the next selection. option = "" # If there are leagues in the selected_leagues list, scrape them. if selected_leagues: selected_leagues = cf.remove_duplicates(selected_leagues) print("\nDownloading the requested data, please wait...") gather_data = inform_and_scrape(selected_leagues, league_data, fixtures, available_leagues, data_source) else: print("No leagues added.") # If gather_data is blank (user entered 0 without selecting leagues or scraping failed) just exit. # Otherwise, confirm data has been downloaded before exiting. if gather_data == "Success": print( "\nLeague data has been downloaded. Press enter to continue.") input() return else: return
def football_menu(league_data, fixtures, predictions): football_options = [ ["(1) Select a league", "1", choose_leagues], # The selectLeague function from football.py ["(2) Generate predictions on currently loaded fixtures", "2"], [ "(3) Single game analysis from fixture list*", "3", single_game_analysis ], ["(4) Manual single game analysis", "4", fb.manual_game_analysis], ["(5) Reports", "5", reports], ["(6) Import data from JSON file", "6"], ["(7) Clear currently loaded league data", "7"], ["(8) Clear currently stored prediction data", "8"], ["(M) Previous menu", "m", leave] ] selected_leagues = [] exit_menu = False available_options = [] selection = "" # Gather a list of availableOption numbers for input recognition for option in football_options: available_options.append(option[1]) while not exit_menu: if league_data == {}: football_options[0][0] = "(1) Select a league" else: football_options[0][0] = "(1) Select another league" selected_leagues = [] # If there are leagues selected in LeagueData, add them to the selectedLeagues # list and display the list. if league_data != {}: for league in league_data: selected_leagues.append(league) print("\n Selected league(s):\n") for league in selected_leagues: print(league) print() else: print( "\nNo league currently selected. Please start by selecting a league.\n" ) # Display the available options for option in football_options: print(option[0]) # Display any additional information print("\nItems marked with a * are not available in this version.") # Keep asking for a selection while the selection provided is not in the availableOptions list. while selection not in available_options: selection = input().lower() # If the selection is in the list, run it's function passing # the leagueData dictionary by default. for option in football_options: if selection == "m": exit_menu = True break continue if selection == "1": # Select league choose_leagues(league_data, fixtures) selection = "" continue if selection == "2": # Run analysis on currently loaded fixtures predictions = fb.upcoming_fixture_predictions( fixtures, predictions, league_data) selection = "" continue if selection == "4": # Manual single game analysis exit_manual_analysis_menu = False while not exit_manual_analysis_menu: selection = "" another_game = "" fb.manual_game_analysis(league_data, predictions) while another_game.lower() != "y" and another_game.lower( ) != "n": print("\nAnalyse another game? (Y/N)") another_game = input() if another_game.lower() == "n": exit_manual_analysis_menu = True break if another_game.lower() == "y": break if selection == "5": # Reports reports(league_data, fixtures, predictions) selection = "" continue if selection == "6": # Import data from JSON file league_data = cf.import_json_file() selection = "" continue if selection == "7": # Clear currently loaded league data. league_data = {} fixtures = [] selection = "" continue if selection == "8": # Clear currently loaded predictions data. predictions.clear() selection = "" continue # General action for other menu items if selection == option[1]: option[2](league_data) selection = "" continue