Exemple #1
0
def topPlayers():
    data = CSV_reader('goalscorers.csv')
    teams = [
        'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV',
        'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL'
    ]
    top_inv = []
    top_player = []
    team_goals = []
    for team in teams:
        inv = 0
        goals = 0
        for row in data:
            if row[1] == team:
                old_inv = inv
                goals += int(row[2])
                inv = max(inv, int(row[2]) + int(row[3]))
                if not inv - old_inv == 0:
                    player = row[0]
        top_inv.append(inv)
        top_player.append(player)
        team_goals.append(goals)
    pct_inv = []
    for i in range(20):
        pct_inv.append(round(top_inv[i] / team_goals[i], 3))
    data = []
    for i in range(20):
        x = [top_player[i], teams[i], top_inv[i], team_goals[i], pct_inv[i]]
        data.append(x)
    return data
def list_assisters():
    data = CSV_reader('goalscorers.csv')
    data.sort(key=lambda x: int(x[3]), reverse=True)
    top = []
    for i in range(15):
        top.append([data[i][0], data[i][2], data[i][3]])
    print(tabulate(top, ['Name', 'G', 'A'], tablefmt='orgtbl'))
def list_assisters_2():
    data = CSV_reader('goalscorers.csv')
    data.sort(key=lambda x: int(x[3]), reverse=True)
    top = []
    for i in range(25):
        top.append([data[i][0].split(' ')[len(data[i][0].split(' ')) - 1], data[i][2], data[i][3]])
    return top
async def update_Form(league, form):
    games_no = int(CSV_reader('code_settings.csv')[0][0])
    async with aiohttp.ClientSession() as session:
        understat = Understat(session)
        teams_league = await understat.get_teams('epl', 2019)
        for j in range(20):
            xG = 0
            for i in range(len(teams_league[j]['history']) - games_no, len(teams_league[j]['history'])):
                xG += teams_league[j]['history'][i]['xG']
            form.addTeam(teams_league[j]['title'], xG, teams_league[j]['id'])
        print(Fore.RED + 'Updating player form data')
        time.sleep(0.5)
        for key, player in tqdm(league.players.items()):
            recent_matches = await understat.get_player_matches(player.player_id)
            recent_matches = recent_matches[:games_no]
            xG = 0
            xA = 0
            G = 0
            A = 0
            for i in range(games_no):
                if len(recent_matches) > games_no - 1:
                    xG += float(recent_matches[i]['xG'])
                    xA += float(recent_matches[i]['xA'])
                    G += float(recent_matches[i]['goals'])
                    A += float(recent_matches[i]['assists'])
            xGr = xG / form.teams[player.team].xG
            xAr = xA / form.teams[player.team].xG
            form.addPlayer(player.name, player.team, xGr, xG, xAr, xA, player.player_id)
        with open('recent_data.pkl', 'wb') as output:
            pickle.dump(form, output, pickle.HIGHEST_PROTOCOL)
Exemple #5
0
def roundPredictor_2(GW, cs):
    sheet = CSV_reader('FPL_Fixtures.csv')  # all good
    teams = [
        'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV',
        'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL'
    ]
    data = []
    for i in range(20):
        x = sheet[GW][i]
        if '&' in x:
            games = x.split('&')
            for x in games:
                if '(H)' in x:
                    data.append([teams[i], x.split(' ')[0]])
                elif '(A)' in x:
                    data.append([x.split(' ')[0], teams[i]])
        elif '(H)' in x and not inclusiveIndicator(teams[i], data):
            data.append([teams[i], x.split(' ')[0]])
        elif '(A)' in x and not inclusiveIndicator(teams[i], data):
            data.append([x.split(' ')[0], teams[i]])
    scorePredictions = []
    if cs:
        for i in range(len(data)):
            z = scorePredictor(data[i][0], data[i][1])
            y = [0, 0]
            y[0] = 100 * math.exp(-z[0])
            y[1] = 100 * math.exp(-z[1])
            z[1] = round(y[0], 1 - int(math.floor(math.log10(abs(y[0])))))
            z[0] = round(y[1], 1 - int(math.floor(math.log10(abs(y[1])))))
            scorePredictions.append(z)
    else:
        for i in range(len(data)):
            y = scorePredictor(data[i][0], data[i][1])
            scorePredictions.append(y)
    x = scorePredictions
    if cs:
        col1 = ''
        col2 = ''
        col3 = ''
        col4 = ''
        for i in range(len(x)):
            col1 += data[i][0] + '\n'
            col2 += colourNumbers_2(x[i][0]) + '\n'
            col3 += colourNumbers_2(x[i][1]) + '\n'
            col4 += data[i][1] + '\n'
        array = [col1, col2, col3, col4]
        return array
    else:
        col1 = ''
        col2 = ''
        col3 = ''
        col4 = ''
        for i in range(len(x)):
            col1 += data[i][0] + '\n'
            col2 += str(round(x[i][0], 2)) + '\n'
            col3 += str(round(x[i][1], 2)) + '\n'
            col4 += data[i][1] + '\n'
        array = [col1, col2, col3, col4]
        return array
Exemple #6
0
def rerecordAllFixtures():
    init = CSV_reader('initial_info.csv')
    with open('attack_difficulty.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(init[0])
        writer.writerow(init[1])
    with open('defence_difficulty.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(init[0])
        writer.writerow(init[1])
    with open('fixture_difficulty.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(init[0])
        writer.writerow(init[2])
    all_data = CSV_reader('all_fixtures.csv')
    for row in all_data:
        if not row[0] == 'HomeTeam':
            recordFixture(row[0] + ' (A)', row[1] + ' (H)', int(row[2]),
                          int(row[3]))
Exemple #7
0
def fixtureFinder(team_name, place):

    data = CSV_reader('all_fixtures.csv')
    games = []
    home_games = []
    away_games = []
    results = numpy.array([0, 0, 0, 0, 0, 0, 0, 0])
    results_home = numpy.array([0, 0, 0, 0, 0, 0, 0, 0])
    results_away = numpy.array([0, 0, 0, 0, 0, 0, 0, 0])
    for row in data:
        if place == 'H':
            if team_name == row[0]:
                games.append(row[0] + ' ' + row[2] + ' - ' + row[3] + ' ' +
                             row[1])
                y = numpy.array(resultRecorder(int(row[2]), int(row[3]), 'h'))
                results = results.__add__(y)
        elif place == 'A':
            if team_name == row[1]:
                games.append(row[0] + ' ' + row[2] + ' - ' + row[3] + ' ' +
                             row[1])
                y = numpy.array(resultRecorder(int(row[2]), int(row[3]), 'a'))
                results = results.__add__(y)
        else:
            if team_name == row[0]:
                home_games.append(row[0] + ' ' + row[2] + ' - ' + row[3] +
                                  ' ' + row[1])
                away_games.append('')
                y = numpy.array(resultRecorder(int(row[2]), int(row[3]), 'h'))
                results_home = results_home.__add__(y)
            elif team_name == row[1]:
                away_games.append(row[0] + ' ' + row[2] + ' - ' + row[3] +
                                  ' ' + row[1])
                home_games.append('')
                y = numpy.array(resultRecorder(int(row[2]), int(row[3]), 'a'))
                results_away = results_away.__add__(y)
    if place == 'H':
        return [games, list(results)]
    elif place == 'A':
        return [games, list(results)]
    else:
        return [home_games, away_games, results_home, results_away]
Exemple #8
0
def editPlan_2(choice, **kwargs):
    GW_no = kwargs.get('GW_no', None)
    player_in = kwargs.get('player_in', None)
    player_out = kwargs.get('player_out', None)
    plan = FPL_Plan()
    data = CSV_reader('plan.csv')
    for row in data:
        gameweek = GW(int(row[0]), row[1], row[2])
        plan.createGW(gameweek)
    if choice == 1:
        gameweek = GW(GW_no, player_in, player_out)
        found = False
        for stuff in plan.gameweeks:
            if stuff.number == GW_no:
                if player_in != '':
                    plan.addTransfer(GW_no, player_in, 'in')
                if player_out != '':
                    plan.addTransfer(GW_no, player_out, 'out')
                found = True
        if not found:
            plan.createGW(gameweek)
        # gameweek = plan.getGameweek(GW_no)
        # row = [gameweek.number, gameweek.trans_in, gameweek.trans_out]
    elif choice == 2:
        for gameweek in plan.gameweeks:
            if gameweek.number == GW_no:
                plan.removeTransfer(GW_no, player_in, 'in')
                plan.removeTransfer(GW_no, player_out, 'out')
    elif choice == 3:
        plan.removeGW(GW_no)
    with open('plan.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        rows = []
        for gameweek in plan.gameweeks:
            rows.append(
                [gameweek.number, gameweek.trans_in, gameweek.trans_out])
        for i in range(1, 39):
            for j in range(len(rows)):
                if rows[j][0] == i or rows[j][0] == str(i):
                    writer.writerow(rows[j])
def update_diff_lists_2(list_type):
    if list_type == 'OVR':
        data = CSV_reader('fixture_difficulty.csv')
    elif list_type == 'DEF':
        data = CSV_reader('defence_difficulty.csv')
    elif list_type == 'ATT':
        data = CSV_reader('attack_difficulty.csv')
    else:
        return None
    difficulties_home = []
    difficulties_away = []
    teams = [
        'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV',
        'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL'
    ]
    for i in range(40):
        if i % 2 == 0:
            difficulties_home.append(data[1][i])
        elif i % 2 == 1:
            difficulties_away.append(data[1][i])

    if list_type == 'OVR':
        with open('fixture_difficulty_table.csv', mode='w',
                  newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(difficulties_away)
            writer.writerow(difficulties_home)
        data = CSV_reader('fixture_difficulty.csv')
        teams = data[0][:40]
        ratings = data[1][:40]
        for i in range(40):
            for j in range(40):
                teams.append(teams[i] + '&' + teams[j])
                ratings.append(combsum(int(ratings[i]), int(ratings[j])))
        with open('fixture_difficulty.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(ratings)
    elif list_type == 'DEF':
        with open('defence_difficulty_table.csv', mode='w',
                  newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(difficulties_away)
            writer.writerow(difficulties_home)
        data = CSV_reader('defence_difficulty.csv')
        teams = data[0][:40]
        ratings = data[1][:40]
        for i in range(40):
            for j in range(40):
                teams.append(teams[i] + '&' + teams[j])
                ratings.append(combsum(int(ratings[i]), int(ratings[j])))
        with open('defence_difficulty.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(ratings)
    elif list_type == 'ATT':
        with open('attack_difficulty_table.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(difficulties_away)
            writer.writerow(difficulties_home)
        data = CSV_reader('attack_difficulty.csv')
        teams = data[0][:40]
        ratings = data[1][:40]
        for i in range(40):
            for j in range(40):
                teams.append(teams[i] + '&' + teams[j])
                ratings.append(combsum(int(ratings[i]), int(ratings[j])))
        with open('attack_difficulty.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(ratings)
    return [teams, difficulties_away, difficulties_home]
def update_diff_table():
    with open('FPL_fixtures.csv', 'r') as file:  # all good
        reader = csv.reader(file)
        initialise = True
        data = CSV_reader('fixture_difficulty.csv')
        fixtures = data[0]
        diffs = data[1]
        all_info = []
        for row in reader:
            if initialise:
                initialise = False
            else:
                row_info = []
                for i in row:
                    if i in fixtures:
                        row_info.append(diffs[fixtures.index(i)])
                    else:
                        row_info.append(1000)
                all_info.append(row_info)

    with open('FPL_Fixtures_numbered.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        teams = [
            'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI',
            'LIV', 'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT',
            'WHU', 'WOL'
        ]
        writer.writerow(teams)
        for row in all_info:
            writer.writerow(row)

    with open('FPL_fixtures.csv', 'r') as file:  # all good
        reader = csv.reader(file)
        initialise = True
        data = CSV_reader('defence_difficulty.csv')
        fixtures = data[0]
        diffs = data[1]
        all_info = []
        for row in reader:
            if initialise:
                initialise = False
            else:
                row_info = []
                for game in row:
                    if game == 'None':
                        pass
                    if game in fixtures:
                        row_info.append(diffs[fixtures.index(game)])
                    else:
                        row_info.append(1000)
                all_info.append(row_info)

    with open('FPL_Fixtures_numbered_def.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        teams = [
            'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI',
            'LIV', 'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT',
            'WHU', 'WOL'
        ]
        writer.writerow(teams)
        for row in all_info:
            writer.writerow(row)

    with open('FPL_fixtures.csv', 'r') as file:  # all good
        reader = csv.reader(file)
        initialise = True
        data = CSV_reader('attack_difficulty.csv')
        fixtures = data[0]
        diffs = data[1]
        all_info = []
        for row in reader:
            if initialise:
                initialise = False
            else:
                row_info = []
                for i in row:
                    if i in fixtures:
                        row_info.append(diffs[fixtures.index(i)])
                    else:
                        row_info.append(1000)
                all_info.append(row_info)

    with open('FPL_Fixtures_numbered_att.csv', mode='w', newline='') as file:
        writer = csv.writer(file)
        teams = [
            'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI',
            'LIV', 'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT',
            'WHU', 'WOL'
        ]
        writer.writerow(teams)
        for row in all_info:
            writer.writerow(row)
def update_diff_lists(list_type, disp):
    if list_type == 'OVR':
        data = CSV_reader('fixture_difficulty.csv')
    elif list_type == 'DEF':
        data = CSV_reader('defence_difficulty.csv')
    elif list_type == 'ATT':
        data = CSV_reader('attack_difficulty.csv')
    else:
        return None
    difficulties_home = []
    difficulties_away = []
    if list_type == 'DEF':
        divisor = 90
        shift = 3.5
    elif list_type == 'ATT':
        divisor = 120
        shift = 2.5
    elif list_type == 'OVR':
        divisor = 200
        shift = 0
    teams = [
        'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV',
        'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL'
    ]
    for i in range(40):
        if i % 2 == 0:
            difficulties_home.append(
                round(int(data[1][i]) / (divisor * 1.1) - shift, 2))
        elif i % 2 == 1:
            difficulties_away.append(
                round(int(data[1][i]) / (divisor * 1.1) - shift, 2))

    if list_type == 'OVR':
        with open('fixture_difficulty_table.csv', mode='w',
                  newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(difficulties_away)
            writer.writerow(difficulties_home)
        data = CSV_reader('fixture_difficulty.csv')
        teams = data[0][:40]
        ratings = data[1][:40]
        for i in range(40):
            for j in range(40):
                teams.append(teams[i] + '&' + teams[j])
                ratings.append(combsum(int(ratings[i]), int(ratings[j])))
        with open('fixture_difficulty.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(ratings)
    elif list_type == 'DEF':
        with open('defence_difficulty_table.csv', mode='w',
                  newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(difficulties_away)
            writer.writerow(difficulties_home)
        data = CSV_reader('defence_difficulty.csv')
        teams = data[0][:40]
        ratings = data[1][:40]
        for i in range(40):
            for j in range(40):
                teams.append(teams[i] + '&' + teams[j])
                ratings.append(combsum(int(ratings[i]), int(ratings[j])))
        with open('defence_difficulty.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(ratings)
    elif list_type == 'ATT':
        with open('attack_difficulty_table.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(difficulties_away)
            writer.writerow(difficulties_home)
        data = CSV_reader('attack_difficulty.csv')
        teams = data[0][:40]
        ratings = data[1][:40]
        for i in range(40):
            for j in range(40):
                teams.append(teams[i] + '&' + teams[j])
                ratings.append(combsum(int(ratings[i]), int(ratings[j])))
        with open('attack_difficulty.csv', mode='w', newline='') as file:
            writer = csv.writer(file)
            writer.writerow(teams)
            writer.writerow(ratings)
    if disp:
        return tabulate([*zip(*[teams, difficulties_away, difficulties_home])],
                        ['', 'Home', 'Away'],
                        tablefmt='orgtbl')
    else:
        return None
Exemple #12
0
def editPlan():
    plan = FPL_Plan()
    data = CSV_reader('plan.csv')
    for row in data:
        gameweek = GW(int(row[0]), row[1], row[2])
        plan.createGW(gameweek)

    choice = ''

    print(
        Fore.LIGHTCYAN_EX +
        'FPL_Plan Menu\n1. Add transfer\n2. Remove transfer\n3. View plan\n0. Exit FPL_Plan'
    )

    while choice != 0:

        choice = int(input('Enter FPL_Plan choice: '))
        if choice == 1:
            GW_no = int(
                input(
                    'In which gameweek would you like to make this transfer? ')
            )
            player_in = input('Which player would you like to transfer in? ')
            player_out = input('Which player would you like to transfer out? ')
            gameweek = GW(GW_no, player_in, player_out)
            found = False
            for stuff in plan.gameweeks:
                if stuff.number == GW_no:
                    if player_in != '':
                        plan.addTransfer(GW_no, player_in, 'in')
                    if player_out != '':
                        plan.addTransfer(GW_no, player_out, 'out')
                    found = True
            if not found:
                plan.createGW(gameweek)
            # gameweek = plan.getGameweek(GW_no)
            # row = [gameweek.number, gameweek.trans_in, gameweek.trans_out]
            with open('plan.csv', mode='w', newline='') as file:
                writer = csv.writer(file)
                rows = []
                for gameweek in plan.gameweeks:
                    rows.append([
                        gameweek.number, gameweek.trans_in, gameweek.trans_out
                    ])
                for i in range(1, 39):
                    for j in range(len(rows)):
                        if rows[j][0] == i or rows[j][0] == str(i):
                            writer.writerow(rows[j])

        elif choice == 2:
            GW_no = int(input('In which gameweek does this transfer occur? '))
            player_in = input('Which transfer in would you like to cancel? ')
            player_out = input('Which transfer out would you like to cancel? ')
            for gameweek in plan.gameweeks:
                if gameweek.number == GW_no:
                    plan.removeTransfer(GW_no, player_in, 'in')
                    plan.removeTransfer(GW_no, player_out, 'out')
            with open('plan.csv', mode='w', newline='') as file:
                writer = csv.writer(file)
                rows = []
                for gameweek in plan.gameweeks:
                    rows.append([
                        gameweek.number, gameweek.trans_in, gameweek.trans_out
                    ])
                for i in range(1, 39):
                    for j in range(len(rows)):
                        if rows[j][0] == i or rows[j][0] == str(i):
                            writer.writerow(rows[j])

        elif choice == 3:
            big_array = []
            for gameweek in plan.gameweeks:
                row = [
                    gameweek.number,
                    gameweek.trans_in.replace('&', ',\n'),
                    gameweek.trans_out.replace('&', ',\n')
                ]
                big_array.append(row)
            print(
                tabulate(sorted(big_array), ['GW', 'In', 'Out', 'Comments'],
                         tablefmt='orgtbl'))
Exemple #13
0
print(tabulate(menu, tablefmt='plain'))

menu_choice = ''

while menu_choice != 0:

    menu_choice = input('Enter main menu choice: ').upper()
    if menu_choice == 'S':
        print(
            Fore.LIGHTCYAN_EX +
            'Options Menu:\n1. Change Form sensitivity for xPoints\n2. Add / Remove players '
            'from nailed team selection\n3. Add / Remove players from bench fodder list'
        )
        menu_choice_2 = int(input('Enter sub-menu choice: '))
        if menu_choice_2 == 1:
            data = CSV_reader('code_settings.csv')
            new_form_value = input('Current form value is ' + data[0][0] +
                                   '. Change it to: ')
            x = [new_form_value, data[1], data[2]]
        elif menu_choice_2 == 2:
            data = CSV_reader('code_settings.csv')
            players = data[1][0]
            for i in range(1, len(data[1])):
                players = players + ', ' + data[1][i]
            menu_choice_3 = input('Current nailed players: ' + players +
                                  '. Add / Remove? (A / R) ').upper()
            if menu_choice_3 == 'A':
                y = data[1]
                name = input('Who? ')
                y.append(name)
                x = [data[0], y, data[2]]
Exemple #14
0
def roundPredictor(GW, mode, cs):
    sheet = CSV_reader('FPL_Fixtures.csv')  # all good
    teams = [
        'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV',
        'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL'
    ]
    data = []
    for i in range(20):
        x = sheet[GW][i]
        if '&' in x:
            games = x.split('&')
            for x in games:
                if '(H)' in x:
                    data.append([teams[i], x.split(' ')[0]])
                elif '(A)' in x:
                    data.append([x.split(' ')[0], teams[i]])
        elif '(H)' in x and not inclusiveIndicator(teams[i], data):
            data.append([teams[i], x.split(' ')[0]])
        elif '(A)' in x and not inclusiveIndicator(teams[i], data):
            data.append([x.split(' ')[0], teams[i]])
    end = True
    scorePredictions = []
    if cs:
        for i in range(len(data)):
            z = scorePredictor(data[i][0], data[i][1])
            y = [0, 0]
            y[0] = 100 * math.exp(-z[0])
            y[1] = 100 * math.exp(-z[1])
            z[1] = round(y[0], 1 - int(math.floor(math.log10(abs(y[0])))))
            z[0] = round(y[1], 1 - int(math.floor(math.log10(abs(y[1])))))
            scorePredictions.append(z)
    else:
        for i in range(len(data)):
            y = scorePredictor(data[i][0], data[i][1])
            scorePredictions.append(y)
    x = scorePredictions
    if mode == 'random':
        while end:
            cs = 0
            x = []
            for y in scorePredictions:
                x.append([
                    np.random.poisson(y[0], 1)[0],
                    np.random.poisson(y[1], 1)[0]
                ])
            for i in range(len(x)):
                if x[i][0] + x[i][1] == 0:
                    cs += 2
                elif x[i][0] * x[i][1] == 0:
                    cs += 1
            if cs < int(round(len(data) / 2) + 1):
                end = False
    array = []
    if cs:
        for i in range(len(x)):
            array.append([
                data[i][0],
                colourNumbers(x[i][0]),
                colourNumbers(x[i][1]), data[i][1]
            ])
        print(tabulate(array, tablefmt='grid'))
    else:
        for i in range(len(x)):
            array.append([
                data[i][0],
                colourNumbers(round(x[i][0], 2)),
                colourNumbers(round(x[i][1], 2)), data[i][1]
            ])
        print(tabulate(array, tablefmt='grid'))
Exemple #15
0
def captainSelector(GW):
    sheet = CSV_reader('FPL_Fixtures.csv')  # all good
    teams = [
        'ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV',
        'MCI', 'MUN', 'NEW', 'NOR', 'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL'
    ]
    fixtures = []
    for i in range(20):
        fixtures.append(sheet[GW][i])
    goals_scored = []
    for i in range(20):
        if '&' in fixtures[i]:
            matches = fixtures[i].split('&')
            x = 0
            if '(H)' in matches[0]:
                indiv_match = matches[0].replace(' (H)', '')
                x += round(scorePredictor(teams[i], indiv_match)[0], 2)
            elif '(A)' in matches[0]:
                indiv_match = matches[0].replace(' (A)', '')
                x += round(scorePredictor(indiv_match, teams[i])[1], 2)
            else:
                x += 0
            if '(H)' in matches[1]:
                indiv_match = matches[1].replace(' (H)', '')
                x += round(scorePredictor(teams[i], indiv_match)[0], 2)
            elif '(A)' in matches[1]:
                indiv_match = matches[1].replace(' (A)', '')
                x += round(scorePredictor(indiv_match, teams[i])[1], 2)
            else:
                x += 0
            goals_scored.append(x)
        elif '(H)' in fixtures[i]:
            indiv_match = fixtures[i].replace(' (H)', '')
            goals_scored.append(
                round(scorePredictor(teams[i], indiv_match)[0], 2))
        elif '(A)' in fixtures[i]:
            indiv_match = fixtures[i].replace(' (A)', '')
            goals_scored.append(
                round(scorePredictor(indiv_match, teams[i])[1], 2))
        else:
            goals_scored.append(0)

    data = topPlayers()
    xGA = []
    players = []
    for i in range(20):
        xGA.append(round(data[i][4] * goals_scored[i], 2))
        full_name = data[i][0].split(' ')
        name = full_name[len(full_name) - 1]
        players.append(name)

    def sortSecond(val):
        return val[1]

    array = []
    for i in range(20):
        array.append([players[i], xGA[i], fixtures[i]])
    array.sort(key=sortSecond, reverse=True)

    teams_sorted = []
    ratings_sorted = []
    fixtures = []
    for i in range(7):
        teams_sorted.append(array[i][0])
        ratings_sorted.append(array[i][1])
        fixtures.append(array[i][2])

    print(tabulate([teams_sorted, ratings_sorted, fixtures], tablefmt='rst'))
def pointsPredictor(GW, league, form):
    sheet = CSV_reader('FPL_Fixtures.csv')  # still to fix
    teams = ['ARS', 'AVL', 'BOU', 'BHA', 'BUR', 'CHE', 'CRY', 'EVE', 'LEI', 'LIV', 'MCI', 'MUN', 'NEW', 'NOR',
             'SHU', 'SOU', 'TOT', 'WAT', 'WHU', 'WOL']
    fixtures = []
    xGF = []
    xGA = []
    for i in range(20):
        fixtures.append(sheet[GW][i])
    for team in teams:
        opponent = fixtures[teams.index(team)]
        if '&' in opponent:
            x = opponent.split('&')
            yxGF = []
            yxGA = []
            for opponent in x:
                if '(H)' in opponent:
                    opponent = opponent.replace(' (H)', '')
                    score = scorePredictor(team, opponent)
                    yxGF.append(score[0])
                    yxGA.append(score[1])
                elif '(A)' in opponent:
                    opponent = opponent.replace(' (A)', '')
                    score = scorePredictor(opponent, team)
                    yxGF.append(score[1])
                    yxGA.append(score[0])
            xGF.append(yxGF)
            xGA.append(yxGA)
        elif '(H)' in opponent:
            opponent = opponent.replace(' (H)', '')
            score = scorePredictor(team, opponent)
            xGF.append(score[0])
            xGA.append(score[1])
        elif '(A)' in opponent:
            opponent = opponent.replace(' (A)', '')
            score = scorePredictor(opponent, team)
            xGF.append(score[1])
            xGA.append(score[0])
    names = []
    xPoints = []
    for key, player in form.players.items():
        names.append(player.name)
        if league.players[player.name].position == 'D':
            team_index = teams.index(teamAbbreviator(player.team))
            try:
                if isinstance(xGF[team_index], list):
                    xPoints.append(
                        round(xGF[team_index][0] * (6 * player.goal_ratio + 2.25 * player.assist_ratio) + 4 * math.exp(
                            - xGA[team_index][0]) - ConcededPointsLost(xGA[team_index][0]) + 2
                            + xGF[team_index][1] * (6 * player.goal_ratio + 2.25 * player.assist_ratio) + 4 * math.exp(
                            - xGA[team_index][1]) - ConcededPointsLost(xGA[team_index][1]) + 2, 2))
                else:
                    xPoints.append(
                        round(xGF[team_index] * (6 * player.goal_ratio + 2.25 * player.assist_ratio) + 4 * math.exp(
                            - xGA[team_index]) - ConcededPointsLost(xGA[team_index]) + 2, 2))
            except IndexError:
                xPoints.append(0)
        elif league.players[player.name].position == 'M':
            team_index = teams.index(teamAbbreviator(player.team))
            try:
                if isinstance(xGF[team_index], list):
                    xPoints.append(
                        round(xGF[team_index][0] * (5 * player.goal_ratio + 2.25 * player.assist_ratio) + math.exp(
                            - xGA[team_index][0]) + 2 +
                            xGF[team_index][1] * (5 * player.goal_ratio + 2.25 * player.assist_ratio) + math.exp(
                            - xGA[team_index][1]) + 2, 2))
                else:
                    xPoints.append(
                        round(xGF[team_index] * (5 * player.goal_ratio + 2.25 * player.assist_ratio) + math.exp(
                            - xGA[team_index]) + 2, 2))
            except IndexError:
                xPoints.append(0)
        elif league.players[player.name].position == 'A':
            team_index = teams.index(teamAbbreviator(player.team))
            try:
                if isinstance(xGF[team_index], list):
                    xPoints.append(
                        round(xGF[team_index][0] * (4 * player.goal_ratio + 2.25 * player.assist_ratio) + 2 +
                        xGF[team_index][1] * (4 * player.goal_ratio + 2.25 * player.assist_ratio) + 2, 2))
                else:
                    xPoints.append(
                        round(xGF[team_index] * (4 * player.goal_ratio + 2.25 * player.assist_ratio) + 2, 2))
            except IndexError:
                xPoints.append(0)
        else:
            team_index = teams.index(teamAbbreviator(player.team))
            try:
                if isinstance(xGF[team_index], list):
                    xPoints.append(
                        round(xGF[team_index][0] * (6 * player.goal_ratio + 2.25 * player.assist_ratio) + 4 * math.exp(
                            - xGA[team_index][0]) - ConcededPointsLost(xGA[team_index][0]) + 2 +
                            xGF[team_index][1] * (6 * player.goal_ratio + 2.25 * player.assist_ratio) + 4 * math.exp(
                            - xGA[team_index][1]) - ConcededPointsLost(xGA[team_index][1]) + 2, 2))
                else:
                    xPoints.append(
                        round(xGF[team_index] * (6 * player.goal_ratio + 2.25 * player.assist_ratio) + 4 * math.exp(
                            - xGA[team_index]) - ConcededPointsLost(xGA[team_index]) + 2, 2))
            except IndexError:
                xPoints.append(0)
    array = []
    for i in range(len(names)):
        array.append([names[i], xPoints[i]])
    return array
    def __init__(self):
        self.players = {}
        self.teams = {}

    def addPlayer(self, name, team, pos, G, xG, A, xA, id):
        self.players[name] = _Player(name, team, pos, G, xG, A, xA, id)

    def addTeam(self, team, xG, id):
        self.teams[team] = _Team(team, xG, id)


teams = ['Manchester City', 'Manchester United', 'Watford', 'Leicester', 'Crystal Palace', 'Bournemouth', 'Burnley',
         'Wolverhampton Wanderers', 'Brighton', 'Southampton', 'West Ham', 'Arsenal', 'Everton', 'Newcastle United',
         'Chelsea', 'Liverpool', 'Tottenham', 'Sheffield United', 'Aston Villa', 'Norwich']
data = CSV_reader('player_data.csv')
names = data[0]
positions = data[1]


def positionfunction(position):
    if position == 'D' or position == 'D S' or position == 'D M S' or position == 'D M':
        return 'D'
    elif position == 'M' or position == 'M S' or position == 'F M' or position == 'D F M S':
        return 'M'
    elif position == 'GK' or position == 'GK S':
        return 'G'
    elif position == 'F M S' or position == 'F S' or position == 'S' or position == 'F':
        return 'A'
    else:
        print(position)