James McCool commited on
Commit
5186ef3
·
1 Parent(s): fa3c2fa

Adding Bet Sheet

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +53 -9
src/streamlit_app.py CHANGED
@@ -17,6 +17,7 @@ from database import db, prop_db
17
  game_format = {'Paydirt Win%': '{:.2%}', 'Vegas Win%': '{:.2%}'}
18
  prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
19
  'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
 
20
  sim_format = {'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}', 'Imp Over': '{:.2%}', 'Imp Under': '{:.2%}', 'Over%': '{:.2%}', 'Under%': '{:.2%}', 'Edge': '{:.2%}'}
21
  prop_table_options = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
22
  all_sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
@@ -140,6 +141,33 @@ def init_baselines():
140
  pick_frame = raw_display.drop_duplicates(subset=['Player', 'prop_type'], keep='first')
141
  pick_frame = pick_frame.reset_index(drop=True)
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  prop_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
144
  ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
145
  'Trey Murphy III', 'Cam Thomas'], inplace=True)
@@ -157,7 +185,7 @@ def init_baselines():
157
  market_props['under_prop'] = market_props['Projection']
158
  market_props['under_line'] = market_props['under_pay'].apply(lambda x: (x - 1) * 100 if x >= 2.0 else -100 / (x - 1))
159
 
160
- return game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp
161
 
162
  def calculate_no_vig(row):
163
  def implied_probability(american_odds):
@@ -181,25 +209,41 @@ def calculate_no_vig(row):
181
  def convert_df_to_csv(df):
182
  return df.to_csv().encode('utf-8')
183
 
184
- game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp = init_baselines()
185
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
186
 
187
  selected_tab = st.segmented_control(
188
  "Select Tab",
189
- options=["Game Betting Model", 'Prop Market', "Player Projections", "Prop Trend Table", "Player Prop Simulations", "Stat Specific Simulations"],
190
  selection_mode='single',
191
- default='Game Betting Model',
192
  width='stretch',
193
  label_visibility='collapsed',
194
  key='tab_selector'
195
  )
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  if selected_tab == 'Game Betting Model':
198
  with st.expander("Info and Filters"):
199
  st.info(t_stamp)
200
  if st.button("Reset Data", key='reset1'):
201
  st.cache_data.clear()
202
- game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp = init_baselines()
203
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
204
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
205
  team_frame = game_model
@@ -225,7 +269,7 @@ if selected_tab == 'Prop Market':
225
  st.info(t_stamp)
226
  if st.button("Reset Data", key='reset2'):
227
  st.cache_data.clear()
228
- game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp = init_baselines()
229
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
230
  market_type = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options, key = 'market_type_key')
231
  disp_market = market_props.copy()
@@ -261,7 +305,7 @@ if selected_tab == 'Player Projections':
261
  st.info(t_stamp)
262
  if st.button("Reset Data", key='reset3'):
263
  st.cache_data.clear()
264
- game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp = init_baselines()
265
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
266
  split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
267
  if split_var1 == 'Specific Teams':
@@ -284,7 +328,7 @@ if selected_tab == 'Prop Trend Table':
284
  st.info(t_stamp)
285
  if st.button("Reset Data", key='reset4'):
286
  st.cache_data.clear()
287
- game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp = init_baselines()
288
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
289
  split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
290
  if split_var5 == 'Specific Teams':
@@ -313,7 +357,7 @@ if selected_tab == 'Player Prop Simulations':
313
  st.info(t_stamp)
314
  if st.button("Reset Data", key='reset5'):
315
  st.cache_data.clear()
316
- game_model, raw_baselines, player_stats, prop_frame, pick_frame, market_props, timestamp = init_baselines()
317
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
318
  col1, col2 = st.columns([1, 5])
319
 
 
17
  game_format = {'Paydirt Win%': '{:.2%}', 'Vegas Win%': '{:.2%}'}
18
  prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
19
  'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
20
+ bet_format = {'Edge': '{:.2%}'}
21
  sim_format = {'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}', 'Imp Over': '{:.2%}', 'Imp Under': '{:.2%}', 'Over%': '{:.2%}', 'Under%': '{:.2%}', 'Edge': '{:.2%}'}
22
  prop_table_options = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
23
  all_sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS']
 
141
  pick_frame = raw_display.drop_duplicates(subset=['Player', 'prop_type'], keep='first')
142
  pick_frame = pick_frame.reset_index(drop=True)
143
 
144
+ prop_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
145
+ ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
146
+ 'Trey Murphy III', 'Cam Thomas'], inplace=True)
147
+ pick_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
148
+ ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
149
+ 'Trey Murphy III', 'Cam Thomas'], inplace=True)
150
+
151
+ collection = db["Bet_Sheet"]
152
+ cursor = collection.find()
153
+
154
+ raw_display = pd.DataFrame(list(cursor))
155
+ raw_display.replace('', np.nan, inplace=True)
156
+ raw_display = raw_display[['Name', 'OddsType', 'PropType', 'No Vig', 'Team', 'Projection', 'Edge']]
157
+ raw_display = raw_display.rename(columns={"Name": "Player", "OddsType": "book", "PropType": "prop_type"})
158
+ bet_sheet = raw_display.dropna(subset='Player')
159
+ bet_sheet = bet_sheet.reset_index(drop=True)
160
+ bet_sheet = bet_sheet.drop_duplicates(subset=['Player', 'prop_type'], keep='first')
161
+
162
+ collection = db["Pick6_Trends"]
163
+ cursor = collection.find()
164
+
165
+ raw_display = pd.DataFrame(list(cursor))
166
+ raw_display = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L5 Success', 'L10_Success', 'L20_success', 'L10 Avg', 'Projection',
167
+ 'Proj Diff', 'Matchup Boost', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge']]
168
+ pick_frame = raw_display.drop_duplicates(subset=['Player', 'prop_type'], keep='first')
169
+ pick_frame = pick_frame.reset_index(drop=True)
170
+
171
  prop_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
172
  ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
173
  'Trey Murphy III', 'Cam Thomas'], inplace=True)
 
185
  market_props['under_prop'] = market_props['Projection']
186
  market_props['under_line'] = market_props['under_pay'].apply(lambda x: (x - 1) * 100 if x >= 2.0 else -100 / (x - 1))
187
 
188
+ return game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp
189
 
190
  def calculate_no_vig(row):
191
  def implied_probability(american_odds):
 
209
  def convert_df_to_csv(df):
210
  return df.to_csv().encode('utf-8')
211
 
212
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
213
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
214
 
215
  selected_tab = st.segmented_control(
216
  "Select Tab",
217
+ options=["Bet Sheet", "Game Betting Model", 'Prop Market', "Player Projections", "Prop Trend Table", "Player Prop Simulations", "Stat Specific Simulations"],
218
  selection_mode='single',
219
+ default='Bet Sheet',
220
  width='stretch',
221
  label_visibility='collapsed',
222
  key='tab_selector'
223
  )
224
 
225
+ if selected_tab == 'Bet Sheet':
226
+ with st.expander("Info and Filters"):
227
+ st.info(t_stamp)
228
+ if st.button("Reset Data", key='reset1'):
229
+ st.cache_data.clear()
230
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
231
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
232
+ st.dataframe(bet_sheet.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(bet_format, precision=2), use_container_width = True)
233
+ st.download_button(
234
+ label="Export Bet Sheet",
235
+ data=convert_df_to_csv(bet_sheet),
236
+ file_name='NBA_bet_sheet_export.csv',
237
+ mime='text/csv',
238
+ key='bet_sheet_export',
239
+ )
240
+
241
  if selected_tab == 'Game Betting Model':
242
  with st.expander("Info and Filters"):
243
  st.info(t_stamp)
244
  if st.button("Reset Data", key='reset1'):
245
  st.cache_data.clear()
246
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
247
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
248
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
249
  team_frame = game_model
 
269
  st.info(t_stamp)
270
  if st.button("Reset Data", key='reset2'):
271
  st.cache_data.clear()
272
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
273
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
274
  market_type = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options, key = 'market_type_key')
275
  disp_market = market_props.copy()
 
305
  st.info(t_stamp)
306
  if st.button("Reset Data", key='reset3'):
307
  st.cache_data.clear()
308
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
309
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
310
  split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
311
  if split_var1 == 'Specific Teams':
 
328
  st.info(t_stamp)
329
  if st.button("Reset Data", key='reset4'):
330
  st.cache_data.clear()
331
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
332
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
333
  split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
334
  if split_var5 == 'Specific Teams':
 
357
  st.info(t_stamp)
358
  if st.button("Reset Data", key='reset5'):
359
  st.cache_data.clear()
360
+ game_model, raw_baselines, player_stats, prop_frame, bet_sheet, pick_frame, market_props, timestamp = init_baselines()
361
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
362
  col1, col2 = st.columns([1, 5])
363