def show_players(user_input, players_in, label, team=None, show_details=False):
    players_in = sorted(players_in, key=lambda player: player.player_name)
    print("[ANSWER of " + label + " --> " + str(user_input) + "]")

    show_details = len(players_in) < 10 or show_details
    for i, player_in in enumerate(players_in):
        player_out = get_player_str(player_in, show_details, team)
        GuiUtil.print_indent_answer(i + 1, player_out, True)
示例#2
0
def search_by_name():
    user_input = input("Insert country name: ")
    countries = Country.read_by_name(user_input, like=True)

    if len(countries) == 0:
        GuiUtil.print_att("No country found", user_input)
    else:
        GuiUtil.show_list_answer([c.name for c in countries], print_index=True)
示例#3
0
def search_by_date():
    date = GuiUtil.input_date_or_day_passed()
    matches = Match.read_by_match_date(date)
    matches = sorted(matches, key=lambda match: match.date)

    if len(matches) == 0:
        GuiUtil.print_att("No match found in date", date)
    else:
        for i, match in enumerate(matches):
            match_out = get_printable_match(match)
            GuiUtil.print_indent_answer(i + 1, match_out, True)
def show_current_predictor():
    global ml_alg_method
    global ml_alg_framework
    global ml_train_input_id
    global ml_train_input_representation
    global ml_train_stages_to_train
    GuiUtil.print_info("Machine Learning Framework", ml_alg_framework)
    GuiUtil.print_info("Machine Learning Algorithm", ml_alg_method)
    GuiUtil.print_info("Machine Learning Input", ml_train_input_id)
    GuiUtil.print_info("Machine Learning Input representation", ml_train_input_representation)
    GuiUtil.print_info("Machine Learning Training Size", ml_train_stages_to_train)
示例#5
0
def search_by_name():
    user_input = input("Insert league name: ")
    leagues = League.read_by_name(user_input, like=True)

    if len(leagues) == 0:
        GuiUtil.print_att("No Leagues found", user_input)
    else:
        GuiUtil.show_list_answer(
            [get_league_str(league) for league in leagues],
            print_index=True,
            label="League by name",
            label_value=user_input)
def search_by_name():
    user_input = input("Insert team name: ")
    teams = Team.read_by_name(user_input, like=True)

    if len(teams) == 0:
        GuiUtil.print_att("No teams found", user_input)
    else:
        teams = sorted(teams, key=lambda team: team.team_long_name)
        teams_to_print = [
            t.team_long_name + ": http://sofifa.com/team/" +
            str(t.team_fifa_api_id) for t in teams
        ]
        GuiUtil.show_list_answer(teams_to_print, print_index=True)
def find_new_matches():
    print("Type the last day to be crawled")
    starting_date = GuiUtil.input_date_or_day_passed()

    while True:
        try:
            user_input = input(
                "Insert number of days back to date (if 1 --> only the date) to be crawled: "
            )
            stop_when = int(user_input)
            break
        except ValueError:
            GuiUtil.print_err("Value error", user_input)

    go_back = stop_when != 0
    CrawlerMatches.start_crawling(go_back, stop_when, starting_date)
def search_by_team():
    user_input = input("Insert team name: ")
    GuiUtil.print_info("Looking for", user_input)

    teams_found = Team.read_by_name(user_input, like=False)
    if len(teams_found) == 0:
        GuiUtil.print_att("No team found with exact name", user_input)
        teams_found = Team.read_by_name(user_input, like=True)
        if len(teams_found) == 0:
            GuiUtil.print_att("No team found", user_input)
        elif len(teams_found) == 1:
            team = teams_found[0]
            show_players(user_input,
                         team.get_current_players(),
                         "Players of the team",
                         team=team,
                         show_details=True)

    elif len(teams_found) == 1:
        team = teams_found[0]
        show_players(user_input,
                     team.get_current_players(),
                     "Players of the team",
                     team=team,
                     show_details=True)
def predict_by_date():
    global ml_alg_method
    global ml_alg_framework
    global ml_train_input_id
    global ml_train_input_representation
    global ml_train_stages_to_train

    if check_setting_current_predictor() == -1:
        return
    date = GuiUtil.input_date_or_day_passed()
    matches = Match.read_by_match_date(date)
    matches = sorted(matches, key=lambda match: match.date)

    if len(matches) == 0:
        GuiUtil.print_att("No match found in date", date)
    else:
        GuiUtil.print_ans("Prediction by date", date)
        pi = 1
        for match in matches:
            if not match.is_finished():
                league = match.get_league()
                season = match.season
                stage = match.stage

                predictor = Predictor.get_predictor(ml_alg_framework,
                       ml_alg_method,
                       ml_train_input_id,
                       ml_train_input_representation,
                       ml_train_stages_to_train)
                prediction_by_league = predictor.predict(league, season, stage)

                try:
                    prediction, probability = prediction_by_league[match.id]
                    prediction_str = get_printable_prediction(match, prediction, probability)
                    GuiUtil.print_indent_answer(pi, prediction_str, True)
                    pi += 1

                except KeyError:
                    log.warning("Not possible to predict [" + str(match.id) + ": "
                                + match.get_home_team().team_long_name + "vs"
                                + match.get_away_team().team_long_name + "]")

        if pi == 1:
            GuiUtil.print_ans("Matches to predict", "NOT FOUND")
示例#10
0
def run():
    GuiUtil.print_head("Countries")
    menu = {1: "Name"}
    GuiUtil.print_menu("Country menu:", menu, add_go_back=True)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)

            if user_input == 1:
                GuiUtil.print_info("Searching by", "country")
                search_by_name()

            else:
                raise ValueError

            GuiUtil.print_line_separator()
            GuiUtil.print_menu("Country Menu:", menu, add_go_back=True)

        except ValueError:
            if user_input == 'gb':
                return
            print("Insert a valid input!!!")
示例#11
0
def print_bet_odds(date):
    GuiUtil.print_info("Bet odds of", date)
    matches = Match.read_by_match_date(date, order_by_date=True)
    pi = 1
    for match in matches:
        match_event_out = get_match_event_out(match)
        GuiUtil.print_indent_answer(pi, match_event_out, True)
        pi += 1

    if pi == 1:
        GuiUtil.print_att("No match found", date)
def search_by_name():
    user_input = input("Insert a name: ")
    GuiUtil.print_info("Looking for", user_input)
    players_found = Player.read_by_name(user_input)
    GuiUtil.print_info("Players found", len(players_found))
    if len(players_found) == 0:
        GuiUtil.print_info("Looking for player with similar name", user_input)
        players_found = Player.read_by_name(user_input, like=True)

    if len(players_found) == 1:
        show_players(players_found[0].player_name, players_found,
                     "Players by exact name")
    else:
        show_players(user_input, players_found, "Players by similar name")
示例#13
0
def search_by_league():
    user_input = input("Insert league name: ")
    GuiUtil.print_info("Looking for", user_input)
    leagues = League.read_by_name(user_input, like=True)

    if len(leagues) == 0:
        GuiUtil.print_att("No leagues found with name", user_input)
    elif len(leagues) == 1:
        league = leagues[0]
        matches = league.get_matches(season=util.get_current_season(),
                                     ordered=True)
        for i, match in enumerate(matches):
            match_out = get_printable_match(match)
            GuiUtil.print_indent_answer(i + 1, match_out, True)
def search_by_league():
    user_input = input("Insert league name: ")
    leagues = League.read_by_name(user_input, like=True)

    if len(leagues) == 0:
        GuiUtil.print_att("No leagues found", user_input)
    elif len(leagues) == 1:
        teams = sorted(leagues[0].get_teams(),
                       key=lambda team: team.team_long_name)
        teams_to_print = [
            t.team_long_name + ": http://sofifa.com/team/" +
            str(t.team_fifa_api_id) for t in teams
        ]
        GuiUtil.show_list_answer(teams_to_print, print_index=True)
    else:
        GuiUtil.print_att("Too many leagues found", user_input)
def search_by_country():
    user_input = input("Insert country name: ")
    countries = Country.read_by_name(user_input, like=True)

    if len(countries) == 0:
        GuiUtil.print_att("No country found", user_input)
    elif len(countries) == 1:
        country = countries[0]
        leagues = country.get_leagues()
        if len(leagues) == 0:
            GuiUtil.print_att("No leagues found in the country", country.name)
        else:
            teams = []
            for league in leagues:
                teams.extend(league.get_teams())
            if len(teams) == 0:
                GuiUtil.show_list_answer([], print_index=True)
            else:
                teams = sorted(teams, key=lambda team: team.team_long_name)
                teams_to_print = [
                    t.team_long_name + ": http://sofifa.com/team/" +
                    str(t.team_fifa_api_id) for t in teams
                ]
                GuiUtil.show_list_answer(teams_to_print, print_index=True)
def set_predictor():
    global ml_alg_method
    global ml_alg_framework
    global ml_train_input_id
    global ml_train_input_representation
    global ml_train_stages_to_train

    show_current_predictor()
    GuiUtil.print_info("Setting", "predictor")

    GuiUtil.show_list_answer(mla.get_frameworks(), label="List", label_value="Frameworks (String)")
    GuiUtil.show_list_answer(mla.get_methods(), label="List", label_value="Algorithms (String)")
    GuiUtil.print_ans("List", "Machine learning input (Id)")
    for input_id, input_desc in mli.get_input_ids().items():
        repr = mli.get_representations(input_id)
        GuiUtil.print_indent_answer(input_id, input_desc+"\nRepresentations: "+str(repr), True)

    GuiUtil.print_inst("list of parameter", "framework(str) algorithm(str) input(int) representation(int) training(int)")
    GuiUtil.print_inst("Use . for", "default")

    while True:
        user_input = input("\nType your representation: ")
        try:
            for i in range(5):
                value = user_input.split()[i]
                if value == '.':
                    continue
                elif i == 0:
                    ml_alg_framework = value
                elif i == 1:
                    ml_alg_method = value
                elif i == 2:
                    ml_train_input_id = int(value)
                elif i == 3:
                    ml_train_input_representation = int(value)
                elif i == 4:
                    ml_train_stages_to_train = int(value)
            break
        except IndexError:
            GuiUtil.print_att("Some input is missing", "5 parameter are needed")
            GuiUtil.print_inst("list of parameter", "framework algorithm input representation training")
            GuiUtil.print_inst("Use . for", "default")
        except ValueError:
            GuiUtil.print_att("Some input should be int", "found string")
            GuiUtil.print_inst("list of parameter", "framework algorithm input representation training")
            GuiUtil.print_inst("Use . for", "default")
def run():
    GuiUtil.print_head("Predictions")
    menu = {1: "Set Current Predictor",
            2: "Show Current Predictor",
            3: "Check setting current predictor",
            4: "Predict matches by date" }
    GuiUtil.print_menu("Predictions menu:", menu, add_go_back=True)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)

            if user_input == 1:
                set_predictor()

            elif user_input == 2:
                GuiUtil.print_info("Show", "Current Predictor")
                show_current_predictor()

            elif user_input == 3:
                GuiUtil.print_info("Check Setting", "Current Predictor")
                if check_setting_current_predictor() == 0:
                    GuiUtil.print_ans("Predictor status", "READY")

            elif user_input == 4:
                GuiUtil.print_info("Predict matches by", "date")
                try:
                    predict_by_date()
                except Exception as e:
                    print(e)
                    GuiUtil.print_att("Error during prediction", "controlling your current predictor..")
                    if check_setting_current_predictor() == 0:
                        GuiUtil.print_att("Predictor OK", "contact administrator")

            else:
                raise ValueError

            GuiUtil.print_line_separator()
            GuiUtil.print_menu("Predictions Menu:", menu, add_go_back=True)

        except ValueError:
            if user_input == 'gb':
                return
            print("Insert a valid input!!!")
示例#18
0
def search_by_country():
    user_input = input("Insert country name: ")
    countries = Country.read_by_name(user_input, like=False)

    if len(countries) == 0:
        GuiUtil.print_att("No country found with correct name", user_input)
        GuiUtil.print_info("Searching for coutnry with similar name",
                           user_input)
        countries = Country.read_by_name(user_input, like=True)

    if len(countries) == 1:
        country = countries[0]
        leagues = country.get_leagues()
        if len(leagues) == 0:
            GuiUtil.print_att("No leagues found in the country", country.name)
        else:
            GuiUtil.show_list_answer(
                [get_league_str(league) for league in leagues],
                print_index=True,
                label="League by country",
                label_value=user_input)
    else:
        for country in countries:
            leagues = country.get_leagues()
            if len(leagues) == 0:
                GuiUtil.print_att("No leagues found in the country",
                                  country.name)
            else:
                GuiUtil.show_list_answer(
                    [get_league_str(league) for league in leagues],
                    print_index=True,
                    label="League by country",
                    label_value=country.name)
def check_setting_current_predictor():
    global ml_alg_framework
    global ml_alg_method
    global ml_train_input_id
    global ml_train_input_representation
    global ml_train_stages_to_train

    # check framework
    if ml_alg_framework not in mla.get_frameworks():
        GuiUtil.print_att("Framework NOT FOUND", ml_alg_framework)
        GuiUtil.show_list_answer(mla.get_frameworks(), label="List", label_value="Valid Frameworks")
        return -1

    # check algorithm
    methods_by_framework = mla.get_methods_by_framework(ml_alg_framework)
    if len(methods_by_framework) > 0 and ml_alg_method not in methods_by_framework:
        GuiUtil.print_att("Methods for framework NOT FOUND", ml_alg_method)
        GuiUtil.show_list_answer(methods_by_framework, label="List", label_value="Valid Methods for "+ml_alg_framework)
        return -1

    # ml input
    ml_inputs_by_framework = mla.get_inputs_by_framework(ml_alg_framework)
    if ml_train_input_id not in ml_inputs_by_framework:
        GuiUtil.print_att("Inputs for framework NOT FOUND", ml_train_input_id)
        GuiUtil.show_list_answer(ml_inputs_by_framework, label="List", label_value="Valid Inputs for " + ml_alg_framework)
        return -1

    # ml input representations
    ml_train_input_representations = mla.get_inputs_by_input(ml_train_input_id)
    if len(ml_train_input_representations) > 0 and ml_train_input_representation not in ml_train_input_representations:
        GuiUtil.print_att("Representation for Input NOT FOUND", ml_train_input_id)
        GuiUtil.show_list_answer(ml_train_input_representations, label="List",
                                 label_value="Valid Inputs for input " + ml_train_input_id)
        return -1

    return 0
示例#20
0
def run():
    GuiUtil.print_head("Bet odds")
    menu = {1: "All bet-odds of today", 2: "Bet-odds by date"}
    GuiUtil.print_menu("Bet odds menu:", menu, add_go_back=True)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)
            if user_input == 1:
                GuiUtil.print_info("Bet odds", "today")
                print_bet_odds(util.get_today_date(with_hours=False))

            elif user_input == 2:
                GuiUtil.print_info("Bet odds", "by date")
                print_bet_odds(GuiUtil.input_date_or_day_passed())

            else:
                raise ValueError

            GuiUtil.print_line_separator()
            GuiUtil.print_menu("Bet odds Menu:", menu, add_go_back=True)

        except ValueError:
            if user_input == 'gb':
                return
            print("Insert a valid input!!!")
def run():
    GuiUtil.print_head("Teams")
    menu = {1: "Country", 2: "Name", 3: "League"}
    GuiUtil.print_menu("Find teams by:", menu, add_go_back=True)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)

            if user_input == 1:
                GuiUtil.print_info("Searching by", "country")
                search_by_country()

            elif user_input == 2:
                GuiUtil.print_info("Searching by", "name")
                search_by_name()

            elif user_input == 3:
                GuiUtil.print_info("Searching by", "league")
                search_by_league()

            else:
                raise ValueError

            GuiUtil.print_line_separator()
            GuiUtil.print_menu("Find teams by:", menu, add_go_back=True)

        except ValueError:
            if user_input == 'gb':
                return
            print("Insert a valid input!!!")
示例#22
0
def run():
    GuiUtil.print_head("Matches")
    menu = {1: "Find by Team", 2: "Find by League", 3: "Find by Date"}
    GuiUtil.print_menu("Matches menu:", menu, add_go_back=True)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)
            if user_input == 1:
                GuiUtil.print_info("Searching by", "team")
                search_by_team()

            elif user_input == 2:
                GuiUtil.print_info("Searching by", "league")
                search_by_league()

            elif user_input == 3:
                GuiUtil.print_info("Searching by", "date")
                search_by_date()

            else:
                raise ValueError

            GuiUtil.print_line_separator()
            GuiUtil.print_menu("Matches Menu:", menu, add_go_back=True)

        except ValueError:
            if user_input == 'gb':
                return
            print("Insert a valid input!!!")
示例#23
0
def search_by_team():
    user_input = input("Insert team name: ")
    GuiUtil.print_info("Looking for", user_input)
    teams_found = Team.read_by_name(user_input)

    GuiUtil.print_info("Teams found", len(teams_found))
    if len(teams_found) == 0:
        GuiUtil.print_att("Looking for team with similar name", user_input)
        teams_found = Team.read_by_name(user_input, like=True)

    if len(teams_found) == 0:
        GuiUtil.print_att("Teams found", 0)
    elif len(teams_found) == 1:
        team = teams_found[0]
        matches = team.get_matches(season=util.get_current_season(),
                                   ordered=True)
        for i, match in enumerate(matches):
            match_out = get_printable_match(match)
            GuiUtil.print_indent_answer(i + 1, match_out, True)
    else:
        GuiUtil.print_att("Too many teams found", "Be more precise")
def run():
    GuiUtil.print_head("Crawling")
    menu = {
        1: "Find new matches",
        2: "Find new players",
        3: "Find new bet-odds"
    }
    GuiUtil.print_menu("Crawl menu:", menu, add_go_back=True)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)
            if user_input == 1:
                GuiUtil.print_info("Finding", "matches")
                find_new_matches()

            elif user_input == 2:
                GuiUtil.print_info("Finding", "players")
                find_new_players()

            elif user_input == 3:
                GuiUtil.print_info("Finding", "bet-odds")
                find_new_bet_odds()

            else:
                raise ValueError

            GuiUtil.print_line_separator()
            GuiUtil.print_menu("Crawl Menu:", menu, add_go_back=True)

        except ValueError:
            if user_input == 'gb':
                return
            print("Insert a valid input!!!")
def run():
    head = "ScorePrediction application"
    GuiUtil.print_head(head)
    menu = {
        1: "Players",
        2: "Matches",
        3: "Leagues",
        4: "Countries",
        5: "Teams",
        6: "Crawling",
        7: "Prediction",
        8: "Bet odds"
    }
    GuiUtil.print_menu("Browse the application to discover different data",
                       menu)

    while True:
        try:
            user_input = input("\nSelect an item: ")
            user_input = int(user_input)
            if user_input == 1:
                GuiUtil.print_info("Opening", "Players")
                PlayerGui.run()

            elif user_input == 2:
                GuiUtil.print_info("Opening", "Mathces")
                MatchGui.run()

            elif user_input == 3:
                GuiUtil.print_info("Opening", "Leagues")
                LeaguesGui.run()

            elif user_input == 4:
                GuiUtil.print_info("Opening", "Countries")
                CountryGui.run()

            elif user_input == 5:
                GuiUtil.print_info("Opening", "Teams")
                TeamGui.run()

            elif user_input == 6:
                GuiUtil.print_info("Opening", "Crawling")
                CrawlGui.run()

            elif user_input == 7:
                GuiUtil.print_info("Opening", "Predictions")
                PredictionGui.run()

            elif user_input == 8:
                GuiUtil.print_info("Opening", "Predictions")
                BetOddsGui.run()

            else:
                raise ValueError

            GuiUtil.print_head(head)
            GuiUtil.print_menu(
                "Browse the application to discover different data", menu)
        except ValueError:
            print("Insert a valid input!!!")