Multichem commited on
Commit
eae0f4b
1 Parent(s): 02ea0a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -11
app.py CHANGED
@@ -59,8 +59,15 @@ def init_baselines():
59
  raw_display = pd.DataFrame(worksheet.get_all_records())
60
  raw_display.replace('', np.nan, inplace=True)
61
  raw_display.rename(columns={"Name": "Player"}, inplace = True)
62
- raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', '3P', 'Points', 'Rebounds', 'Assists', 'Steals', 'Blocks', 'Turnovers', 'Fantasy']]
63
- player_stats = raw_display[raw_display['Minutes'] > 0]
 
 
 
 
 
 
 
64
 
65
  player_stats['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
66
  ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
@@ -85,21 +92,22 @@ def init_baselines():
85
  pick_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
86
  ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
87
  'Trey Murphy III', 'Cam Thomas'], inplace=True)
88
- return game_model, player_stats, prop_frame, pick_frame, timestamp
 
89
 
90
  def convert_df_to_csv(df):
91
  return df.to_csv().encode('utf-8')
92
 
93
- game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
94
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
95
 
96
- tab1, tab2, tab3, tab4, tab5 = st.tabs(["Game Betting Model", "Player Projections", "Prop Trend Table", "Player Prop Simulations", "Stat Specific Simulations"])
97
 
98
  with tab1:
99
  st.info(t_stamp)
100
  if st.button("Reset Data", key='reset1'):
101
  st.cache_data.clear()
102
- game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
103
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
104
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
105
  team_frame = game_model
@@ -124,7 +132,7 @@ with tab2:
124
  st.info(t_stamp)
125
  if st.button("Reset Data", key='reset2'):
126
  st.cache_data.clear()
127
- game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
128
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
129
  split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
130
  if split_var1 == 'Specific Teams':
@@ -146,7 +154,7 @@ with tab3:
146
  st.info(t_stamp)
147
  if st.button("Reset Data", key='reset3'):
148
  st.cache_data.clear()
149
- game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
150
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
151
  split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
152
  if split_var5 == 'Specific Teams':
@@ -170,7 +178,7 @@ with tab4:
170
  st.info(t_stamp)
171
  if st.button("Reset Data", key='reset4'):
172
  st.cache_data.clear()
173
- game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
174
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
175
  col1, col2 = st.columns([1, 5])
176
 
@@ -315,7 +323,7 @@ with tab5:
315
  st.info('The Over and Under percentages are a composite 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.')
316
  if st.button("Reset Data/Load Data", key='reset5'):
317
  st.cache_data.clear()
318
- game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
319
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
320
  col1, col2 = st.columns([1, 5])
321
 
@@ -618,4 +626,24 @@ with tab5:
618
  file_name='Nba_prop_proj.csv',
619
  mime='text/csv',
620
  key='prop_proj',
621
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  raw_display = pd.DataFrame(worksheet.get_all_records())
60
  raw_display.replace('', np.nan, inplace=True)
61
  raw_display.rename(columns={"Name": "Player"}, inplace = True)
62
+
63
+ raw_baselines = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', 'FGM', 'FGA', 'FG2M', 'FG2A', 'Threes', 'FG3A', 'FTM', 'FTA', 'TRB', 'AST', 'STL', 'BLK', 'TOV']]
64
+ raw_baselines = raw_baselines[raw_baselines['Minutes'] > 0]
65
+ raw_baselines['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
66
+ ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
67
+ 'Trey Murphy III', 'Cam Thomas'], inplace=True)
68
+
69
+ player_stats = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', '3P', 'Points', 'Rebounds', 'Assists', 'Steals', 'Blocks', 'Turnovers', 'Fantasy']]
70
+ player_stats = player_stats[player_stats['Minutes'] > 0]
71
 
72
  player_stats['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
73
  ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
 
92
  pick_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
93
  ['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
94
  'Trey Murphy III', 'Cam Thomas'], inplace=True)
95
+
96
+ return game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp
97
 
98
  def convert_df_to_csv(df):
99
  return df.to_csv().encode('utf-8')
100
 
101
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
102
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
103
 
104
+ tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Game Betting Model", "Player Projections", "Prop Trend Table", "Player Prop Simulations", "Stat Specific Simulations", "Testing"])
105
 
106
  with tab1:
107
  st.info(t_stamp)
108
  if st.button("Reset Data", key='reset1'):
109
  st.cache_data.clear()
110
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
111
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
112
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
113
  team_frame = game_model
 
132
  st.info(t_stamp)
133
  if st.button("Reset Data", key='reset2'):
134
  st.cache_data.clear()
135
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
136
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
137
  split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
138
  if split_var1 == 'Specific Teams':
 
154
  st.info(t_stamp)
155
  if st.button("Reset Data", key='reset3'):
156
  st.cache_data.clear()
157
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
158
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
159
  split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
160
  if split_var5 == 'Specific Teams':
 
178
  st.info(t_stamp)
179
  if st.button("Reset Data", key='reset4'):
180
  st.cache_data.clear()
181
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
182
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
183
  col1, col2 = st.columns([1, 5])
184
 
 
323
  st.info('The Over and Under percentages are a composite 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.')
324
  if st.button("Reset Data/Load Data", key='reset5'):
325
  st.cache_data.clear()
326
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
327
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
328
  col1, col2 = st.columns([1, 5])
329
 
 
626
  file_name='Nba_prop_proj.csv',
627
  mime='text/csv',
628
  key='prop_proj',
629
+ )
630
+ with tab6:
631
+ st.info(t_stamp)
632
+ if st.button("Reset Data", key='reset6'):
633
+ st.cache_data.clear()
634
+ game_model, raw_baselines, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
635
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
636
+ split_var6 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var6')
637
+ if split_var6 == 'Specific Teams':
638
+ team_var6 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var6')
639
+ elif split_var6 == 'All':
640
+ team_var6 = player_stats.Team.values.tolist()
641
+ raw_baselines_disp = raw_baselines[raw_baselines['Team'].isin(team_var6)]\
642
+ raw_stats_disp = raw_stats_disp.sort_values(by='Minutes', ascending=False)
643
+ st.data_editor(raw_stats_disp.format(precision=2), use_container_width = True)
644
+ st.download_button(
645
+ label="Export Customizable Model",
646
+ data=convert_df_to_csv(player_stats),
647
+ file_name='NBA_stats_export.csv',
648
+ mime='text/csv',
649
+ )