James McCool commited on
Commit
2c53a1d
·
1 Parent(s): a7bb74a

Refactor app.py to implement tabbed navigation for Scoring Percentages, Player ROO, and Optimals sections, enhancing user experience and organization. Remove unnecessary session state keys for radio button selections, streamlining input handling.

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
 
4
  import pymongo
5
 
6
  st.set_page_config(layout="wide")
@@ -104,7 +105,6 @@ def init_FD_lineups():
104
 
105
  return FD_seed
106
 
107
- @st.cache_data
108
  def convert_df_to_csv(df):
109
  return df.to_csv().encode('utf-8')
110
 
@@ -116,20 +116,17 @@ def convert_df(array):
116
  roo_data, sd_roo_data, scoring_percentages = init_baselines()
117
  hold_display = roo_data
118
 
119
- st.write("Current session state keys:", list(st.session_state.keys()))
120
 
121
  with st.container():
122
- col1, col2, col3 = st.columns([3, 3, 3])
123
  with col1:
124
  view_var = st.selectbox("Select view", ["Simple", "Advanced"], key='view_var')
125
  with col2:
126
  site_var = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'), key='site_var')
127
- with col3:
128
- model_var = st.radio("What do you want to view?", ('Scoring Percentages', 'Player ROO', 'Optimals'), key='model_var')
129
 
130
- if model_var == 'Scoring Percentages':
131
  st.header("Scoring Percentages")
132
-
133
  with st.expander("Info and Filters"):
134
  col1, col2, col3 = st.columns([3, 3, 3])
135
  with col1:
@@ -142,9 +139,9 @@ if model_var == 'Scoring Percentages':
142
  for key in st.session_state.keys():
143
  del st.session_state[key]
144
  with col2:
145
- slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'All Games'), key='slate_var1')
146
  with col3:
147
- own_var1 = st.radio("How would you like to display team ownership?", ('Sum', 'Average'), key='own_var1')
148
  st.title("Scoring Percentages")
149
  if view_var == "Simple":
150
  scoring_percentages = scoring_percentages[['Names', 'Avg Score', '8+ runs', 'Win Percentage']]
@@ -152,9 +149,8 @@ if model_var == 'Scoring Percentages':
152
  elif view_var == "Advanced":
153
  st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
154
 
155
- if model_var == 'Player ROO':
156
  st.header("Player ROO")
157
-
158
  with st.expander("Info and Filters"):
159
  col1, col2, col3, col4 = st.columns([3, 3, 3, 3])
160
  with col1:
@@ -167,11 +163,11 @@ if model_var == 'Player ROO':
167
  for key in st.session_state.keys():
168
  del st.session_state[key]
169
  with col2:
170
- slate_type_var2 = st.radio("Which slate type are you loading?", ('Regular', 'Showdown'), key='slate_type_var2')
171
  with col3:
172
- slate_var2 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'), key='slate_var2')
173
  with col4:
174
- pos_var2 = st.radio("Which position group would you like to view?", ('All', 'Pitchers', 'Hitters'), key='pos_var2')
175
 
176
  if slate_type_var2 == 'Regular':
177
  player_roo_raw = roo_data.copy()
@@ -214,9 +210,8 @@ if model_var == 'Player ROO':
214
  elif view_var == "Advanced":
215
  st.dataframe(st.session_state['player_roo'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True, hide_index=True)
216
 
217
- if model_var == 'Optimals':
218
  st.header("Optimals")
219
-
220
  with st.expander("Info and Filters"):
221
  if st.button("Load/Reset Data", key='reset3'):
222
  st.cache_data.clear()
@@ -227,8 +222,8 @@ if model_var == 'Optimals':
227
  for key in st.session_state.keys():
228
  del st.session_state[key]
229
 
230
- slate_type_var3 = st.radio("Which slate type are you loading?", ('Regular', 'Showdown'), key='slate_type_var3')
231
- slate_var3 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'), key='slate_var3')
232
 
233
  if slate_type_var3 == 'Regular':
234
  if site_var == 'Draftkings':
 
1
  import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
+ import gspread
5
  import pymongo
6
 
7
  st.set_page_config(layout="wide")
 
105
 
106
  return FD_seed
107
 
 
108
  def convert_df_to_csv(df):
109
  return df.to_csv().encode('utf-8')
110
 
 
116
  roo_data, sd_roo_data, scoring_percentages = init_baselines()
117
  hold_display = roo_data
118
 
119
+ tab1, tab2, tab3 = st.tabs(["Scoring Percentages", "Player ROO", "Optimals"])
120
 
121
  with st.container():
122
+ col1, col2 = st.columns([3, 3])
123
  with col1:
124
  view_var = st.selectbox("Select view", ["Simple", "Advanced"], key='view_var')
125
  with col2:
126
  site_var = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'), key='site_var')
 
 
127
 
128
+ with tab1:
129
  st.header("Scoring Percentages")
 
130
  with st.expander("Info and Filters"):
131
  col1, col2, col3 = st.columns([3, 3, 3])
132
  with col1:
 
139
  for key in st.session_state.keys():
140
  del st.session_state[key]
141
  with col2:
142
+ slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'All Games'))
143
  with col3:
144
+ own_var1 = st.radio("How would you like to display team ownership?", ('Sum', 'Average'))
145
  st.title("Scoring Percentages")
146
  if view_var == "Simple":
147
  scoring_percentages = scoring_percentages[['Names', 'Avg Score', '8+ runs', 'Win Percentage']]
 
149
  elif view_var == "Advanced":
150
  st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
151
 
152
+ with tab2:
153
  st.header("Player ROO")
 
154
  with st.expander("Info and Filters"):
155
  col1, col2, col3, col4 = st.columns([3, 3, 3, 3])
156
  with col1:
 
163
  for key in st.session_state.keys():
164
  del st.session_state[key]
165
  with col2:
166
+ slate_type_var2 = st.radio("Which slate type are you loading?", ('Regular', 'Showdown'))
167
  with col3:
168
+ slate_var2 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'))
169
  with col4:
170
+ pos_var2 = st.radio("Which position group would you like to view?", ('All', 'Pitchers', 'Hitters'))
171
 
172
  if slate_type_var2 == 'Regular':
173
  player_roo_raw = roo_data.copy()
 
210
  elif view_var == "Advanced":
211
  st.dataframe(st.session_state['player_roo'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True, hide_index=True)
212
 
213
+ with tab3:
214
  st.header("Optimals")
 
215
  with st.expander("Info and Filters"):
216
  if st.button("Load/Reset Data", key='reset3'):
217
  st.cache_data.clear()
 
222
  for key in st.session_state.keys():
223
  del st.session_state[key]
224
 
225
+ slate_type_var3 = st.radio("Which slate type are you loading?", ('Regular', 'Showdown'))
226
+ slate_var3 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'))
227
 
228
  if slate_type_var3 == 'Regular':
229
  if site_var == 'Draftkings':