Multichem commited on
Commit
ecb89c6
·
1 Parent(s): a586f3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -43
app.py CHANGED
@@ -49,6 +49,8 @@ gcservice_account = init_conn()
49
  NBAGetGameData = 'https://docs.google.com/spreadsheets/d/1tRQrF_I5rS7Q0g9vE8NrENDZ2P3_DvtbBZzKEakwOI0/edit#gid=1373653837'
50
  NBABettingModel = 'https://docs.google.com/spreadsheets/d/1WBnvOHQi_zVTGF63efejK5ho02AY00HiYrMHnMJXY1E/edit#gid=1157978351'
51
 
 
 
52
  percentages_format = {'Playoff Odds': '{:.2%}', 'Division Odds': '{:.2%}', 'Top 4 Seed Odds': '{:.2%}', '1 Seed Odds': '{:.2%}', 'Win 1st Round': '{:.2%}',
53
  'Win 2nd Round': '{:.2%}', 'Win Conference': '{:.2%}', 'Win Title': '{:.2%}', '1': '{:.2%}', '2': '{:.2%}', '3': '{:.2%}',
54
  '4': '{:.2%}', '5': '{:.2%}', '6': '{:.2%}', '7': '{:.2%}', '8': '{:.2%}', '9': '{:.2%}', '10': '{:.2%}', '11': '{:.2%}',
@@ -67,6 +69,7 @@ def init_baselines():
67
  cols_to_check = ['Win %', 'Injury and Rotation Adjusted Win %']
68
  raw_display.loc[:, cols_to_check] = raw_display.loc[:, cols_to_check].replace({'%': ''}, regex=True).astype(float) / 100
69
  raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
 
70
  game_model = raw_display[raw_display['Injury and Rotation Adjusted Win %'] != ""]
71
  game_model['Team Date'] = game_model['Team'] + " " + game_model['Date']
72
 
@@ -81,57 +84,79 @@ def init_baselines():
81
  raw_display.loc[:, cols_to_check] = raw_display.loc[:, cols_to_check].replace({'%': ''}, regex=True).astype(float) / 100
82
  raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
83
  season_model = raw_display[raw_display['Team'] != ""]
 
 
 
84
 
85
- return game_model, season_model
86
 
87
  def convert_df_to_csv(df):
88
  return df.to_csv().encode('utf-8')
89
 
90
- game_model, season_model = init_baselines()
91
 
92
  tab1, tab2 = st.tabs(["Game Betting Model", "Season and Futures"])
93
 
94
  with tab1:
95
- if st.button("Reset Data", key='reset1'):
96
- st.cache_data.clear()
97
- game_model, season_model = init_baselines()
98
- split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
99
- if split_var1 == 'Specific Teams':
100
- team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = game_model['Team'].unique(), key='team_var1')
101
- elif split_var1 == 'All':
102
- team_var1 = game_model.Team.values.tolist()
103
- date_split_var1 = st.radio("Would you like to view all Dates or specific ones?", ('All', 'Specific Dates'), key='date_split_var1')
104
- if date_split_var1 == 'Specific Teams':
105
- date_var1 = st.multiselect('Which Dates would you like to include in the tables?', options = game_model['Date'].unique(), key='date_var1')
106
- elif date_split_var1 == 'All':
107
- date_var1 = game_model.Date.values.tolist()
108
- game_display = game_model[game_model['Team'].isin(team_var1)]
109
- game_display = game_display[game_display['Date'].isin(date_var1)]
110
- game_display = game_display.set_index('Team Date')
111
- st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
112
- st.download_button(
113
- label="Export Game Model",
114
- data=convert_df_to_csv(game_model),
115
- file_name='AmericanNumbers_Game_Model_export.csv',
116
- mime='text/csv',
117
- )
 
 
 
118
 
119
  with tab2:
120
- if st.button("Reset Data", key='reset2'):
121
- st.cache_data.clear()
122
- game_model, season_model = init_baselines()
123
- split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
124
- if split_var2 == 'Specific Teams':
125
- team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = season_model['Team'].unique(), key='team_var2')
126
- elif split_var2 == 'All':
127
- team_var2 = season_model.Team.values.tolist()
128
- season_model = season_model[season_model['Team'].isin(team_var2)]
129
- season_display = season_model.set_index('Team')
130
- season_display = season_display.sort_values(by=['Win Projection Now'], ascending=False)
131
- st.dataframe(season_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), use_container_width = True)
132
- st.download_button(
133
- label="Export Futures Model",
134
- data=convert_df_to_csv(season_model),
135
- file_name='AmericanNumbers_Season_Futures.csv',
136
- mime='text/csv',
137
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  NBAGetGameData = 'https://docs.google.com/spreadsheets/d/1tRQrF_I5rS7Q0g9vE8NrENDZ2P3_DvtbBZzKEakwOI0/edit#gid=1373653837'
50
  NBABettingModel = 'https://docs.google.com/spreadsheets/d/1WBnvOHQi_zVTGF63efejK5ho02AY00HiYrMHnMJXY1E/edit#gid=1157978351'
51
 
52
+ game_format = {'Win %', 'Injury and Rotation Adjusted Win %'}
53
+
54
  percentages_format = {'Playoff Odds': '{:.2%}', 'Division Odds': '{:.2%}', 'Top 4 Seed Odds': '{:.2%}', '1 Seed Odds': '{:.2%}', 'Win 1st Round': '{:.2%}',
55
  'Win 2nd Round': '{:.2%}', 'Win Conference': '{:.2%}', 'Win Title': '{:.2%}', '1': '{:.2%}', '2': '{:.2%}', '3': '{:.2%}',
56
  '4': '{:.2%}', '5': '{:.2%}', '6': '{:.2%}', '7': '{:.2%}', '8': '{:.2%}', '9': '{:.2%}', '10': '{:.2%}', '11': '{:.2%}',
 
69
  cols_to_check = ['Win %', 'Injury and Rotation Adjusted Win %']
70
  raw_display.loc[:, cols_to_check] = raw_display.loc[:, cols_to_check].replace({'%': ''}, regex=True).astype(float) / 100
71
  raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
72
+ raw_display = raw_display.drop(columns=['Day of season', 'Team', 'Opp', 'Date Num', 'DR Team', 'In Minutes File'])
73
  game_model = raw_display[raw_display['Injury and Rotation Adjusted Win %'] != ""]
74
  game_model['Team Date'] = game_model['Team'] + " " + game_model['Date']
75
 
 
84
  raw_display.loc[:, cols_to_check] = raw_display.loc[:, cols_to_check].replace({'%': ''}, regex=True).astype(float) / 100
85
  raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
86
  season_model = raw_display[raw_display['Team'] != ""]
87
+ title_sims = season_model[['Team', 'Conference', 'Division', 'Power Rank', 'Team PointMarginPerGame', 'SeasonSimLookup', 'Win Projection Now',
88
+ 'Playoff Odds', 'Division Odds', 'Top 4 Seed Odds', '1 Seed Odds', 'Win 1st Round', 'Win 2nd Round', 'Win Conference', 'Win Title']]
89
+ seed_probs = season_model[['Team', 'Conference', 'Division', 'Avg Seed', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']]
90
 
91
+ return game_model, season_model, seed_probs, title_sims
92
 
93
  def convert_df_to_csv(df):
94
  return df.to_csv().encode('utf-8')
95
 
96
+ game_model, season_model, seed_probs, title_sims = init_baselines()
97
 
98
  tab1, tab2 = st.tabs(["Game Betting Model", "Season and Futures"])
99
 
100
  with tab1:
101
+ col1, col2 = st.columns([1, 9])
102
+ with col1:
103
+ if st.button("Reset Data", key='reset1'):
104
+ st.cache_data.clear()
105
+ game_model, season_model, seed_probs, title_sims = init_baselines()
106
+ split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
107
+ if split_var1 == 'Specific Teams':
108
+ team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = game_model['Team'].unique(), key='team_var1')
109
+ elif split_var1 == 'All':
110
+ team_var1 = game_model.Team.values.tolist()
111
+ date_split_var1 = st.radio("Would you like to view all Dates or specific ones?", ('All', 'Specific Dates'), key='date_split_var1')
112
+ if date_split_var1 == 'Specific Teams':
113
+ date_var1 = st.multiselect('Which Dates would you like to include in the tables?', options = game_model['Date'].unique(), key='date_var1')
114
+ elif date_split_var1 == 'All':
115
+ date_var1 = game_model.Date.values.tolist()
116
+ with col2:
117
+ game_display = game_model[game_model['Team'].isin(team_var1)]
118
+ game_display = game_display[game_display['Date'].isin(date_var1)]
119
+ game_display = game_display.set_index('Team Date')
120
+ st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
121
+ st.download_button(
122
+ label="Export Game Model",
123
+ data=convert_df_to_csv(game_model),
124
+ file_name='AmericanNumbers_Game_Model_export.csv',
125
+ mime='text/csv',
126
+ )
127
 
128
  with tab2:
129
+ col1, col2 = st.columns([1, 9])
130
+ with col1:
131
+ if st.button("Reset Data", key='reset2'):
132
+ st.cache_data.clear()
133
+ game_model, season_model, seed_probs, title_sims = init_baselines()
134
+ view_var2 = st.radio("Would you like to view title odds and win projections or seeding probabilities?", ('Win Odds', 'Seed Probabilities'), key='view_var2')
135
+ split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
136
+ if split_var2 == 'Specific Teams':
137
+ team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = season_model['Team'].unique(), key='team_var2')
138
+ elif split_var2 == 'All':
139
+ team_var2 = season_model.Team.values.tolist()
140
+ with col2:
141
+ if view_var2 == 'Win Odds':
142
+ title_sims = title_sims[title_sims['Team'].isin(team_var2)]
143
+ season_display = title_sims.set_index('Team')
144
+ season_display = season_display.sort_values(by=['Win Projection Now'], ascending=False)
145
+ st.dataframe(season_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), use_container_width = True)
146
+ st.download_button(
147
+ label="Export Futures Model",
148
+ data=convert_df_to_csv(title_sims),
149
+ file_name='AmericanNumbers_Season_Futures.csv',
150
+ mime='text/csv',
151
+ )
152
+ elif view_var2 == 'Seed Probabilities':
153
+ seed_probs = seed_probs[seed_probs['Team'].isin(team_var2)]
154
+ season_display = seed_probs.set_index('Team')
155
+ season_display = season_display.sort_values(by=['Win Projection Now'], ascending=False)
156
+ st.dataframe(season_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), use_container_width = True)
157
+ st.download_button(
158
+ label="Export Futures Model",
159
+ data=convert_df_to_csv(seed_probs),
160
+ file_name='AmericanNumbers_Season_Futures.csv',
161
+ mime='text/csv',
162
+ )