api.update_with_media(filepath, status=message) def write_to_google_sheet(row): # use creds to create a client to interact with the Google Drive API scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive'] credentials = ServiceAccountCredentials.from_json_keyfile_name('./client_secret.json', scope) client = gspread.authorize(credentials) sheet = client.open("2017-2018-PL-tips").sheet1 sheet.append_row(row) if __name__ == '__main__': data = read_player_data(season='2017-2018') cached_players = {} for gui, name in data.items(): if 'pereira' in name['name'] and name['general position'] == 'goalkeeper': gui_to_delete = gui del data[gui_to_delete] matches = get_lineups_from_flashscores() for match in matches: player_home_team = constants.FLASH_SCORES_TEAM_TO_PLAYER_RATINGS[match['home_team']] player_away_team = constants.FLASH_SCORES_TEAM_TO_PLAYER_RATINGS[match['away_team']]
len(midfield)) assert len( attack) <= 4, "No more than 4 attackers allowed, there is {}".format( len(attack)) defence = defence + [0] * (6 - len(defence)) midfield = midfield + [0] * (7 - len(midfield)) attack = attack + [0] * (4 - len(attack)) return goalkeeper + defence + midfield + attack if __name__ == '__main__': errors = [] data = read_player_data() match_data = read_match_data(league='SP1', season='2013-2014') football_data = read_all_football_data(league='SP1') match_data = assign_odds_to_match(match_data, football_data) feature_vectors = [] targets = [] errors = [] cached_players = {} for i, test_match in enumerate(reversed(match_data)):
def main(): bet_tracker = BetTracker() league = 'E0' match_data = read_match_data(season='2016-2017', league=league) match_data = assign_odds_to_match(match_data, read_all_football_data(league=league)) player_data = read_player_data(season='2016-2017') net = NeuralNet() bank = [100] all_odds = [] errors = [] cached_players = {} feature_vectors = [] for match in match_data: try: home_players_matched, cached_players = match_lineups_to_fifa_players(match['info']['home lineup names'], match['info']['home lineup raw names'], match['info']['home lineup numbers'], match['info'][ 'home lineup nationalities'], constants.LINEUP_TO_PLAYER_TEAM_MAPPINGS[ 'ALL'][ match['info']['home team']], match['info']['season'], player_data, cached_players) away_players_matched, cached_players = match_lineups_to_fifa_players(match['info']['away lineup names'], match['info']['away lineup raw names'], match['info']['away lineup numbers'], match['info'][ 'away lineup nationalities'], constants.LINEUP_TO_PLAYER_TEAM_MAPPINGS[ 'ALL'][ match['info']['away team']], match['info']['season'], player_data, cached_players) home_feature_vector = create_feature_vector_from_players(home_players_matched) away_feature_vector = create_feature_vector_from_players(away_players_matched) feature_vector = np.array(home_feature_vector + away_feature_vector).reshape(-1, 36) feature_vectors.append(normalise_features(feature_vector)) except Exception as exception: print(match['info']['date'], match['info']['home team'], match['info']['away team']) print(exception) errors.append(match['match number']) feature_vectors = np.vstack((x for x in feature_vectors)) probabilities = net.predict(feature_vectors, model_name='./models/' + league + '/deep') match_data = [match for match in match_data if match['match number'] not in errors] for match, probability in zip(match_data, probabilities): # print(match['info']['date'], match['info']['home team'], match['info']['away team']) pred_home_odds, pred_draw_odds, pred_away_odds = [1 / x for x in probability] home_odds, draw_odds, away_odds = match['info']['home odds'], match['info']['draw odds'], match['info'][ 'away odds'] all_odds.append((pred_home_odds, home_odds)) all_odds.append((pred_away_odds, away_odds)) if pred_home_odds < home_odds < 3.2 and 0.02 <= probability[0] - 1 / home_odds: stake = calculate_stake(home_odds, probability=1 / pred_home_odds, method='kelly', constant_profit=20) * bet_tracker.bankroll profit = stake * home_odds - stake bet = Bet(true_odds=home_odds, predicted_odds=pred_home_odds, stake=stake, profit=profit, match=match, type='home') bet_tracker.make_bet(bet) if match['info']['home goals'] > match['info']['away goals']: bet_tracker.bet_won() else: bet_tracker.bet_lost() bank.append(bet_tracker.bankroll) elif pred_away_odds < away_odds < 3.2 and 0.02 <= probability[2] - 1 / away_odds: stake = calculate_stake(away_odds, probability=1 / pred_away_odds, method='kelly', constant_profit=20) * bet_tracker.bankroll profit = stake * away_odds - stake bet = Bet(true_odds=away_odds, predicted_odds=pred_away_odds, stake=stake, profit=profit, match=match, type='away') bet_tracker.make_bet(bet) if match['info']['home goals'] < match['info']['away goals']: bet_tracker.bet_won() else: bet_tracker.bet_lost() bank.append(bet_tracker.bankroll) return bet_tracker, bank, all_odds