James McCool commited on
Commit
a0bee85
·
1 Parent(s): 4dcd40c

added market table kind of

Browse files
Files changed (1) hide show
  1. app.py +49 -16
app.py CHANGED
@@ -5,6 +5,7 @@ import pandas as pd
5
  import gspread
6
  import plotly.express as px
7
  import scipy.stats as stats
 
8
  st.set_page_config(layout="wide")
9
 
10
  @st.cache_resource
@@ -39,12 +40,16 @@ def init_conn():
39
 
40
  NFL_Data = st.secrets['NFL_Data']
41
 
 
 
 
 
42
  gc = gspread.service_account_from_dict(credentials)
43
  gc2 = gspread.service_account_from_dict(credentials2)
44
 
45
- return gc, gc2, NFL_Data
46
 
47
- gcservice_account, gcservice_account2, NFL_Data = init_conn()
48
 
49
  game_format = {'Win%': '{:.2%}', 'Vegas': '{:.2%}', 'Win% Diff': '{:.2%}'}
50
  american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead Percentage': '{:.2%}'}
@@ -88,9 +93,15 @@ def init_baselines():
88
  raw_display.replace('', np.nan, inplace=True)
89
  pick_frame = raw_display.dropna(subset='Player')
90
 
91
- return game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame
 
 
 
 
 
 
92
 
93
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
94
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
95
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
96
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
@@ -107,7 +118,7 @@ all_sim_vars = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS'
107
  pick6_sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Completions', 'Rushing Yards', 'Receptions', 'Receiving Yards']
108
  sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
109
 
110
- tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Game Betting Model", "QB Projections", "RB/WR/TE Projections", "Player Prop Trends", "Player Prop Simulations", "Stat Specific Simulations"])
111
 
112
  def convert_df_to_csv(df):
113
  return df.to_csv().encode('utf-8')
@@ -116,7 +127,7 @@ with tab1:
116
  st.info(t_stamp)
117
  if st.button("Reset Data", key='reset1'):
118
  st.cache_data.clear()
119
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
120
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
121
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
122
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
@@ -149,7 +160,7 @@ with tab2:
149
  st.info(t_stamp)
150
  if st.button("Reset Data", key='reset2'):
151
  st.cache_data.clear()
152
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
153
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
154
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
155
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
@@ -177,7 +188,7 @@ with tab3:
177
  st.info(t_stamp)
178
  if st.button("Reset Data", key='reset3'):
179
  st.cache_data.clear()
180
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
181
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
182
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
183
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
@@ -200,12 +211,34 @@ with tab3:
200
  mime='text/csv',
201
  key='NFL_nonqb_stats_export',
202
  )
203
-
204
  with tab4:
205
  st.info(t_stamp)
206
  if st.button("Reset Data", key='reset4'):
207
  st.cache_data.clear()
208
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
210
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
211
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
@@ -232,11 +265,11 @@ with tab4:
232
  mime='text/csv',
233
  )
234
 
235
- with tab5:
236
  st.info(t_stamp)
237
- if st.button("Reset Data", key='reset5'):
238
  st.cache_data.clear()
239
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
240
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
241
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
242
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
@@ -382,12 +415,12 @@ with tab5:
382
  plot_hold_container = st.empty()
383
  st.plotly_chart(fig, use_container_width=True)
384
 
385
- with tab6:
386
  st.info(t_stamp)
387
  st.info('The Over and Under percentages are a compositve percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
388
- if st.button("Reset Data/Load Data", key='reset6'):
389
  st.cache_data.clear()
390
- game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame = init_baselines()
391
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
392
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
393
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
5
  import gspread
6
  import plotly.express as px
7
  import scipy.stats as stats
8
+ from pymongo import MongoClient
9
  st.set_page_config(layout="wide")
10
 
11
  @st.cache_resource
 
40
 
41
  NFL_Data = st.secrets['NFL_Data']
42
 
43
+ uri = st.secrets['mongo_uri']
44
+ client = MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
45
+ db = client["Props_DB"]
46
+
47
  gc = gspread.service_account_from_dict(credentials)
48
  gc2 = gspread.service_account_from_dict(credentials2)
49
 
50
+ return gc, gc2, NFL_Data, db
51
 
52
+ gcservice_account, gcservice_account2, NFL_Data, db = init_conn()
53
 
54
  game_format = {'Win%': '{:.2%}', 'Vegas': '{:.2%}', 'Win% Diff': '{:.2%}'}
55
  american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead Percentage': '{:.2%}'}
 
93
  raw_display.replace('', np.nan, inplace=True)
94
  pick_frame = raw_display.dropna(subset='Player')
95
 
96
+ collection = db["NFL_Props"]
97
+ cursor = collection.find()
98
+
99
+ raw_display = pd.DataFrame(list(cursor))
100
+ market_props = raw_display[['Name', 'Position', 'Projection', 'PropType', 'OddsType']]
101
+
102
+ return game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props
103
 
104
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
105
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
106
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
107
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
118
  pick6_sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Completions', 'Rushing Yards', 'Receptions', 'Receiving Yards']
119
  sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
120
 
121
+ tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["Game Betting Model", "QB Projections", "RB/WR/TE Projections", 'Market Table', "Player Prop Trends", "Player Prop Simulations", "Stat Specific Simulations"])
122
 
123
  def convert_df_to_csv(df):
124
  return df.to_csv().encode('utf-8')
 
127
  st.info(t_stamp)
128
  if st.button("Reset Data", key='reset1'):
129
  st.cache_data.clear()
130
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
131
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
132
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
133
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
160
  st.info(t_stamp)
161
  if st.button("Reset Data", key='reset2'):
162
  st.cache_data.clear()
163
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
164
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
165
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
166
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
188
  st.info(t_stamp)
189
  if st.button("Reset Data", key='reset3'):
190
  st.cache_data.clear()
191
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
192
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
193
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
194
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
211
  mime='text/csv',
212
  key='NFL_nonqb_stats_export',
213
  )
214
+
215
  with tab4:
216
  st.info(t_stamp)
217
  if st.button("Reset Data", key='reset4'):
218
  st.cache_data.clear()
219
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
220
+ qb_stats = overall_stats[overall_stats['Position'] == 'QB']
221
+ qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
222
+ non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
223
+ non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
224
+ team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
225
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
226
+ market_type = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options, key = 'market_type_key')
227
+ disp_market = market_props.copy()
228
+ disp_market = disp_market[disp_market['PropType'].isin(market_type)]
229
+ st.dataframe(disp_market.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(prop_format, precision=2), height = 1000, use_container_width = True)
230
+ st.download_button(
231
+ label="Export Market Props",
232
+ data=convert_df_to_csv(disp_market),
233
+ file_name='NFL_market_props_export.csv',
234
+ mime='text/csv',
235
+ )
236
+
237
+ with tab5:
238
+ st.info(t_stamp)
239
+ if st.button("Reset Data", key='reset5'):
240
+ st.cache_data.clear()
241
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
242
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
243
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
244
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
265
  mime='text/csv',
266
  )
267
 
268
+ with tab6:
269
  st.info(t_stamp)
270
+ if st.button("Reset Data", key='reset6'):
271
  st.cache_data.clear()
272
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
273
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
274
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
275
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
 
415
  plot_hold_container = st.empty()
416
  st.plotly_chart(fig, use_container_width=True)
417
 
418
+ with tab7:
419
  st.info(t_stamp)
420
  st.info('The Over and Under percentages are a compositve percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
421
+ if st.button("Reset Data/Load Data", key='reset7'):
422
  st.cache_data.clear()
423
+ game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
424
  qb_stats = overall_stats[overall_stats['Position'] == 'QB']
425
  qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
426
  non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']