Multichem commited on
Commit
2718b31
·
1 Parent(s): 38ab091

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -48
app.py CHANGED
@@ -30,49 +30,31 @@ american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead
30
  master_hold = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=694077504'
31
 
32
  @st.cache_data
33
- def game_betting_model():
34
  sh = gc.open_by_url(master_hold)
35
  worksheet = sh.worksheet('Game_Betting')
36
  raw_display = pd.DataFrame(worksheet.get_all_records())
37
  raw_display.replace('#DIV/0!', np.nan, inplace=True)
38
- raw_display = raw_display.dropna()
39
-
40
- return raw_display
41
-
42
- @st.cache_data
43
- def player_stat_table():
44
- sh = gc.open_by_url(master_hold)
45
  worksheet = sh.worksheet('Prop_Table')
46
  raw_display = pd.DataFrame(worksheet.get_all_records())
47
  raw_display.replace('', np.nan, inplace=True)
48
- raw_display = raw_display.dropna()
49
-
50
- return raw_display
51
-
52
- @st.cache_data
53
- def timestamp_table():
54
- sh = gc.open_by_url(master_hold)
55
  worksheet = sh.worksheet('DK_ROO')
56
- raw_display = worksheet.acell('U2').value
57
-
58
- return raw_display
59
-
60
- @st.cache_data
61
- def player_prop_table():
62
- sh = gc.open_by_url(master_hold)
63
  worksheet = sh.worksheet('prop_frame')
64
  raw_display = pd.DataFrame(worksheet.get_all_records())
65
  raw_display.replace('', np.nan, inplace=True)
66
- raw_display = raw_display.dropna()
67
 
68
- return raw_display
69
 
70
- game_model = game_betting_model()
71
- overall_stats = player_stat_table()
72
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
73
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
74
- timestamp = timestamp_table()
75
- prop_frame = player_prop_table()
76
  team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
77
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
78
 
@@ -89,12 +71,11 @@ with tab1:
89
  st.info(t_stamp)
90
  if st.button("Reset Data", key='reset1'):
91
  st.cache_data.clear()
92
- game_model = game_betting_model()
93
- overall_stats = player_stat_table()
94
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
95
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
96
- prop_frame = player_prop_table()
97
- t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
98
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
99
  team_frame = game_model
100
  if line_var1 == 'Percentage':
@@ -118,12 +99,11 @@ with tab2:
118
  st.info(t_stamp)
119
  if st.button("Reset Data", key='reset2'):
120
  st.cache_data.clear()
121
- game_model = game_betting_model()
122
- overall_stats = player_stat_table()
123
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
124
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
125
- prop_frame = player_prop_table()
126
- t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
127
  split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
128
  if split_var1 == 'Specific Teams':
129
  team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = qb_stats['Team'].unique(), key='team_var1')
@@ -145,12 +125,11 @@ with tab3:
145
  st.info(t_stamp)
146
  if st.button("Reset Data", key='reset3'):
147
  st.cache_data.clear()
148
- game_model = game_betting_model()
149
- overall_stats = player_stat_table()
150
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
151
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
152
- prop_frame = player_prop_table()
153
- t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
154
  split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
155
  if split_var2 == 'Specific Teams':
156
  team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = non_qb_stats['Team'].unique(), key='team_var2')
@@ -172,12 +151,11 @@ with tab4:
172
  st.info(t_stamp)
173
  if st.button("Reset Data", key='reset4'):
174
  st.cache_data.clear()
175
- game_model = game_betting_model()
176
- overall_stats = player_stat_table()
177
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
178
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
179
- prop_frame = player_prop_table()
180
- t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
181
  col1, col2 = st.columns([1, 5])
182
 
183
  with col2:
@@ -320,12 +298,11 @@ with tab5:
320
  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.')
321
  if st.button("Reset Data/Load Data", key='reset5'):
322
  st.cache_data.clear()
323
- game_model = game_betting_model()
324
- overall_stats = player_stat_table()
325
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
326
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
327
- prop_frame = player_prop_table()
328
- t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
329
  col1, col2 = st.columns([1, 5])
330
 
331
  with col2:
 
30
  master_hold = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=694077504'
31
 
32
  @st.cache_data
33
+ def init_baselines():
34
  sh = gc.open_by_url(master_hold)
35
  worksheet = sh.worksheet('Game_Betting')
36
  raw_display = pd.DataFrame(worksheet.get_all_records())
37
  raw_display.replace('#DIV/0!', np.nan, inplace=True)
38
+ game_model = raw_display.dropna()
39
+
 
 
 
 
 
40
  worksheet = sh.worksheet('Prop_Table')
41
  raw_display = pd.DataFrame(worksheet.get_all_records())
42
  raw_display.replace('', np.nan, inplace=True)
43
+ overall_stats = raw_display.dropna()
44
+
 
 
 
 
 
45
  worksheet = sh.worksheet('DK_ROO')
46
+ timestamp = worksheet.acell('U2').value
47
+
 
 
 
 
 
48
  worksheet = sh.worksheet('prop_frame')
49
  raw_display = pd.DataFrame(worksheet.get_all_records())
50
  raw_display.replace('', np.nan, inplace=True)
51
+ prop_frame = raw_display.dropna()
52
 
53
+ return game_model, overall_stats, timestamp, prop_frame
54
 
55
+ game_model, overall_stats, timestamp, prop_frame = init_baselines()
 
56
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
57
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
 
 
58
  team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
59
  t_stamp = f"Last Update: " + str(timestamp) + f" CST"
60
 
 
71
  st.info(t_stamp)
72
  if st.button("Reset Data", key='reset1'):
73
  st.cache_data.clear()
74
+ game_model, overall_stats, timestamp, prop_frame = init_baselines()
 
75
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
76
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
77
+ team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
78
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
79
  line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
80
  team_frame = game_model
81
  if line_var1 == 'Percentage':
 
99
  st.info(t_stamp)
100
  if st.button("Reset Data", key='reset2'):
101
  st.cache_data.clear()
102
+ game_model, overall_stats, timestamp, prop_frame = init_baselines()
 
103
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
104
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
105
+ team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
106
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
107
  split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
108
  if split_var1 == 'Specific Teams':
109
  team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = qb_stats['Team'].unique(), key='team_var1')
 
125
  st.info(t_stamp)
126
  if st.button("Reset Data", key='reset3'):
127
  st.cache_data.clear()
128
+ game_model, overall_stats, timestamp, prop_frame = init_baselines()
 
129
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
130
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
131
+ team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
132
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
133
  split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
134
  if split_var2 == 'Specific Teams':
135
  team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = non_qb_stats['Team'].unique(), key='team_var2')
 
151
  st.info(t_stamp)
152
  if st.button("Reset Data", key='reset4'):
153
  st.cache_data.clear()
154
+ game_model, overall_stats, timestamp, prop_frame = init_baselines()
 
155
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
156
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
157
+ team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
158
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
159
  col1, col2 = st.columns([1, 5])
160
 
161
  with col2:
 
298
  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.')
299
  if st.button("Reset Data/Load Data", key='reset5'):
300
  st.cache_data.clear()
301
+ game_model, overall_stats, timestamp, prop_frame = init_baselines()
 
302
  qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
303
  non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
304
+ team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
305
+ t_stamp = f"Last Update: " + str(timestamp) + f" CST"
306
  col1, col2 = st.columns([1, 5])
307
 
308
  with col2: