James McCool commited on
Commit
8d589f1
·
1 Parent(s): 632ebd1

added connections and tabs

Browse files
Files changed (1) hide show
  1. app.py +65 -47
app.py CHANGED
@@ -37,12 +37,10 @@ def init_conn():
37
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
38
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
39
  }
40
-
41
- NFL_Data = st.secrets['NFL_Data']
42
 
43
  uri = st.secrets['mongo_uri']
44
  client = MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
45
- dfs_db = client["NFL_Database"]
46
  props_db = client["Props_DB"]
47
 
48
  gc = gspread.service_account_from_dict(credentials)
@@ -57,44 +55,12 @@ american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead
57
 
58
  @st.cache_resource(ttl=600)
59
  def init_baselines():
60
- collection = dfs_db["Game_Betting_Model"]
61
  cursor = collection.find()
62
  raw_display = pd.DataFrame(list(cursor))
63
  game_model = raw_display[['Team', 'Opp', 'Win%', 'Vegas', 'Win% Diff', 'Win Line', 'Vegas Line', 'Line Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
64
-
65
- collection = dfs_db["Player_Stats"]
66
- cursor = collection.find()
67
- raw_display = pd.DataFrame(list(cursor))
68
- overall_stats = raw_display[['Player', 'Position', 'Team', 'Opp', 'rush_att', 'rec', 'dropbacks', 'rush_yards', 'rush_tds', 'rec_yards', 'rec_tds', 'pass_att', 'pass_yards', 'pass_tds', 'PPR', 'Half_PPR']]
69
-
70
- collection = dfs_db["Prop_Trends"]
71
- cursor = collection.find()
72
- raw_display = pd.DataFrame(list(cursor))
73
- prop_trends = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L3 Success', 'L6_Success', 'L10_success', 'L6 Avg', 'Projection',
74
- 'Proj Diff', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge']]
75
-
76
- collection = dfs_db["DK_NFL_ROO"]
77
- cursor = collection.find()
78
 
79
- raw_display = pd.DataFrame(list(cursor))
80
- raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%',
81
- 'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own', 'CPT_Own', 'LevX', 'version', 'slate', 'timestamp', 'player_id', 'site']]
82
- load_display = raw_display[raw_display['Position'] != 'K']
83
- timestamp = load_display['timestamp'][0]
84
-
85
- collection = dfs_db["Prop_Trends"]
86
- cursor = collection.find()
87
- raw_display = pd.DataFrame(list(cursor))
88
- prop_frame = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L3 Success', 'L6_Success', 'L10_success', 'L6 Avg', 'Projection',
89
- 'Proj Diff', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge']]
90
-
91
- collection = dfs_db['Pick6_Trends']
92
- cursor = collection.find()
93
- raw_display = pd.DataFrame(list(cursor))
94
- pick_frame = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L3 Success', 'L6_Success', 'L10_success', 'L6 Avg', 'Projection',
95
- 'Proj Diff', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge', 'last_name', 'P6_name', 'Full_name']]
96
-
97
- collection = props_db["NFL_Props"]
98
  cursor = collection.find()
99
 
100
  raw_display = pd.DataFrame(list(cursor))
@@ -104,22 +70,41 @@ def init_baselines():
104
  market_props['under_prop'] = market_props['Projection']
105
  market_props['under_line'] = market_props['under_pay'].apply(lambda x: (x - 1) * 100 if x >= 2.0 else -100 / (x - 1))
106
 
107
- return game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props
108
 
109
  def convert_df_to_csv(df):
110
  return df.to_csv().encode('utf-8')
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  with tab1:
113
- st.info(t_stamp)
114
  if st.button("Reset Data", key='reset1'):
115
  st.cache_data.clear()
116
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
117
- qb_stats = overall_stats[overall_stats['Position'] == 'QB']
118
- qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
119
- non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
120
- non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
121
- team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
122
- t_stamp = f"Last Update: " + str(timestamp) + f" CST"
123
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
124
  team_frame = game_model
125
  if line_var1 == 'Percentage':
@@ -137,7 +122,40 @@ with tab1:
137
  st.download_button(
138
  label="Export Team Model",
139
  data=convert_df_to_csv(team_frame),
140
- file_name='NFL_team_betting_export.csv',
141
  mime='text/csv',
142
  key='team_export',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  )
 
37
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
38
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
39
  }
 
 
40
 
41
  uri = st.secrets['mongo_uri']
42
  client = MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
43
+ dfs_db = client["NCAAF_Database"]
44
  props_db = client["Props_DB"]
45
 
46
  gc = gspread.service_account_from_dict(credentials)
 
55
 
56
  @st.cache_resource(ttl=600)
57
  def init_baselines():
58
+ collection = dfs_db["NCAAF_GameModel"]
59
  cursor = collection.find()
60
  raw_display = pd.DataFrame(list(cursor))
61
  game_model = raw_display[['Team', 'Opp', 'Win%', 'Vegas', 'Win% Diff', 'Win Line', 'Vegas Line', 'Line Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
+ collection = props_db["NCAAF_Props"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  cursor = collection.find()
65
 
66
  raw_display = pd.DataFrame(list(cursor))
 
70
  market_props['under_prop'] = market_props['Projection']
71
  market_props['under_line'] = market_props['under_pay'].apply(lambda x: (x - 1) * 100 if x >= 2.0 else -100 / (x - 1))
72
 
73
+ return game_model, market_props
74
 
75
  def convert_df_to_csv(df):
76
  return df.to_csv().encode('utf-8')
77
 
78
+ def calculate_no_vig(row):
79
+ def implied_probability(american_odds):
80
+ if american_odds < 0:
81
+ return (-american_odds) / ((-american_odds) + 100)
82
+ else:
83
+ return 100 / (american_odds + 100)
84
+
85
+ over_line = row['over_line']
86
+ under_line = row['under_line']
87
+ over_prop = row['over_prop']
88
+
89
+ over_prob = implied_probability(over_line)
90
+ under_prob = implied_probability(under_line)
91
+
92
+ total_prob = over_prob + under_prob
93
+ no_vig_prob = (over_prob / total_prob + 0.5) * over_prop
94
+
95
+ return no_vig_prob
96
+
97
+ prop_table_options = ['NCAAF_GAME_PLAYER_PASSING_YARDS', 'NCAAF_GAME_PLAYER_RUSHING_YARDS', 'NCAAF_GAME_PLAYER_PASSING_ATTEMPTS', 'NCAAF_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NCAAF_GAME_PLAYER_PASSING_COMPLETIONS', 'NCAAF_GAME_PLAYER_RUSHING_ATTEMPTS',
98
+ 'NCAAF_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NCAAF_GAME_PLAYER_RECEIVING_YARDS', 'NCAAF_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
99
+ prop_format = {'L3 Success': '{:.2%}', 'L6_Success': '{:.2%}', 'L10_success': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
100
+ 'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
101
+
102
+ tab1, tab2 = st.tabs(["Game Model", "Prop Market"])
103
+
104
  with tab1:
 
105
  if st.button("Reset Data", key='reset1'):
106
  st.cache_data.clear()
107
+ game_model, market_props = init_baselines()
 
 
 
 
 
 
108
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
109
  team_frame = game_model
110
  if line_var1 == 'Percentage':
 
122
  st.download_button(
123
  label="Export Team Model",
124
  data=convert_df_to_csv(team_frame),
125
+ file_name='NCAAF_team_betting_export.csv',
126
  mime='text/csv',
127
  key='team_export',
128
+ )
129
+
130
+ with tab2:
131
+ if st.button("Reset Data", key='reset4'):
132
+ st.cache_data.clear()
133
+ game_model, market_props = init_baselines()
134
+ market_type = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options, key = 'market_type_key')
135
+ disp_market = market_props.copy()
136
+ disp_market = disp_market[disp_market['PropType'] == market_type]
137
+ disp_market['No_Vig_Prop'] = disp_market.apply(calculate_no_vig, axis=1)
138
+ fanduel_frame = disp_market[disp_market['OddsType'] == 'FANDUEL']
139
+ fanduel_dict = dict(zip(fanduel_frame['Name'], fanduel_frame['No_Vig_Prop']))
140
+ draftkings_frame = disp_market[disp_market['OddsType'] == 'DRAFTKINGS']
141
+ draftkings_dict = dict(zip(draftkings_frame['Name'], draftkings_frame['No_Vig_Prop']))
142
+ mgm_frame = disp_market[disp_market['OddsType'] == 'MGM']
143
+ mgm_dict = dict(zip(mgm_frame['Name'], mgm_frame['No_Vig_Prop']))
144
+ bet365_frame = disp_market[disp_market['OddsType'] == 'BET_365']
145
+ bet365_dict = dict(zip(bet365_frame['Name'], bet365_frame['No_Vig_Prop']))
146
+
147
+ disp_market['FANDUEL'] = disp_market['Name'].map(fanduel_dict)
148
+ disp_market['DRAFTKINGS'] = disp_market['Name'].map(draftkings_dict)
149
+ disp_market['MGM'] = disp_market['Name'].map(mgm_dict)
150
+ disp_market['BET365'] = disp_market['Name'].map(bet365_dict)
151
+
152
+ disp_market = disp_market[['Name', 'Position','FANDUEL', 'DRAFTKINGS', 'MGM', 'BET365']]
153
+ disp_market = disp_market.drop_duplicates(subset=['Name'], keep='first', ignore_index=True)
154
+
155
+ st.dataframe(disp_market.style.background_gradient(axis=1, subset=['FANDUEL', 'DRAFTKINGS', 'MGM', 'BET365'], cmap='RdYlGn').format(prop_format, precision=2), height = 1000, use_container_width = True)
156
+ st.download_button(
157
+ label="Export Market Props",
158
+ data=convert_df_to_csv(disp_market),
159
+ file_name='NCAAF_market_props_export.csv',
160
+ mime='text/csv',
161
  )