Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ gc = gspread.service_account_from_dict(credentials)
|
|
| 26 |
st.set_page_config(layout="wide")
|
| 27 |
|
| 28 |
american_format = {'OwnAvg': '{:.2%}'}
|
| 29 |
-
|
| 30 |
|
| 31 |
@st.cache_resource(ttl = 600)
|
| 32 |
def init_baselines():
|
|
@@ -119,17 +119,48 @@ def init_baselines():
|
|
| 119 |
|
| 120 |
flex_frame = flex_frame.sort_values(by='GPP Rank', ascending=False)
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
@st.cache_resource()
|
| 125 |
def convert_df_to_csv(df):
|
| 126 |
return df.to_csv().encode('utf-8')
|
| 127 |
|
| 128 |
-
qb_frame, rb_frame, wr_frame, flex_frame = init_baselines()
|
| 129 |
|
| 130 |
-
tab1, tab2, tab3, tab4 = st.tabs(['QB data', 'RB data', 'WR data', 'Flex data'])
|
| 131 |
|
| 132 |
with tab1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
with st.container():
|
| 134 |
st.dataframe(qb_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 135 |
st.download_button(
|
|
@@ -138,7 +169,7 @@ with tab1:
|
|
| 138 |
file_name='NCAAF_QB_model_export.csv',
|
| 139 |
mime='text/csv',
|
| 140 |
)
|
| 141 |
-
with
|
| 142 |
with st.container():
|
| 143 |
st.dataframe(rb_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 144 |
st.download_button(
|
|
@@ -147,7 +178,7 @@ with tab2:
|
|
| 147 |
file_name='NCAAF_RB_model_export.csv',
|
| 148 |
mime='text/csv',
|
| 149 |
)
|
| 150 |
-
with
|
| 151 |
with st.container():
|
| 152 |
st.dataframe(wr_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 153 |
st.download_button(
|
|
@@ -156,7 +187,7 @@ with tab3:
|
|
| 156 |
file_name='NCAAF_WR_model_export.csv',
|
| 157 |
mime='text/csv',
|
| 158 |
)
|
| 159 |
-
with
|
| 160 |
with st.container():
|
| 161 |
st.dataframe(flex_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 162 |
st.download_button(
|
|
|
|
| 26 |
st.set_page_config(layout="wide")
|
| 27 |
|
| 28 |
american_format = {'OwnAvg': '{:.2%}'}
|
| 29 |
+
stacks_format = {'Total Own': '{:.2%}'}
|
| 30 |
|
| 31 |
@st.cache_resource(ttl = 600)
|
| 32 |
def init_baselines():
|
|
|
|
| 119 |
|
| 120 |
flex_frame = flex_frame.sort_values(by='GPP Rank', ascending=False)
|
| 121 |
|
| 122 |
+
worksheet = sh.worksheet('Stacks')
|
| 123 |
+
all_values = worksheet.get_all_values()
|
| 124 |
+
cell_vals = [row[0:30] for row in all_values[1:500]]
|
| 125 |
+
frame_hold = pd.DataFrame(cell_vals, columns=['Team', 'Opp', 'd1', 'd2', 'Game Stack', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10', 'd11', 'd12', 'd13', 'd14', 'Team Stack',
|
| 126 |
+
'15', '16', '17', '18', '19', '20', '21', 'Total Stack Cost', 'Total Own', 'Total Points', 'Points/$'])
|
| 127 |
+
frame_hold['Total Points'] = frame_hold['Total Points'].astype(float)
|
| 128 |
+
frame_hold['Total Own'] = frame_hold['Total Own'].str.replace('%', '').astype(float)/100
|
| 129 |
+
stack_frame = frame_hold[['Team', 'Opp', 'Game Stack', 'Team Stack', 'Total Stack Cost', 'Total Own', 'Total Points', 'Points/$']]
|
| 130 |
+
string_cols = ['Team', 'Opp']
|
| 131 |
+
stack_frame = stack_frame.drop_duplicates(subset='Team')
|
| 132 |
+
stack_frame = stack_frame.set_index('Team')
|
| 133 |
+
|
| 134 |
+
for col in stack_frame.columns:
|
| 135 |
+
if col not in string_cols:
|
| 136 |
+
try:
|
| 137 |
+
stack_frame[col] = pd.to_numeric(stack_frame[col], errors='coerce')
|
| 138 |
+
except ValueError:
|
| 139 |
+
pass # Ignore columns that cannot be converted
|
| 140 |
+
|
| 141 |
+
stack_frame = stack_frame.sort_values(by='Team Stack', ascending=False)
|
| 142 |
+
|
| 143 |
+
return qb_frame, rb_frame, wr_frame, flex_frame, stack_frame
|
| 144 |
|
| 145 |
@st.cache_resource()
|
| 146 |
def convert_df_to_csv(df):
|
| 147 |
return df.to_csv().encode('utf-8')
|
| 148 |
|
| 149 |
+
qb_frame, rb_frame, wr_frame, flex_frame, stack_frame = init_baselines()
|
| 150 |
|
| 151 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(['Stacks data', 'QB data', 'RB data', 'WR data', 'Flex data'])
|
| 152 |
|
| 153 |
with tab1:
|
| 154 |
+
with st.container():
|
| 155 |
+
st.dataframe(stack_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(stacks_format, precision=2), height = 1000, use_container_width = True)
|
| 156 |
+
st.download_button(
|
| 157 |
+
label="Export Tables",
|
| 158 |
+
data=convert_df_to_csv(stack_frame),
|
| 159 |
+
file_name='NCAAF_Stacks_model_export.csv',
|
| 160 |
+
mime='text/csv',
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
with tab2:
|
| 164 |
with st.container():
|
| 165 |
st.dataframe(qb_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 166 |
st.download_button(
|
|
|
|
| 169 |
file_name='NCAAF_QB_model_export.csv',
|
| 170 |
mime='text/csv',
|
| 171 |
)
|
| 172 |
+
with tab3:
|
| 173 |
with st.container():
|
| 174 |
st.dataframe(rb_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 175 |
st.download_button(
|
|
|
|
| 178 |
file_name='NCAAF_RB_model_export.csv',
|
| 179 |
mime='text/csv',
|
| 180 |
)
|
| 181 |
+
with tab4:
|
| 182 |
with st.container():
|
| 183 |
st.dataframe(wr_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 184 |
st.download_button(
|
|
|
|
| 187 |
file_name='NCAAF_WR_model_export.csv',
|
| 188 |
mime='text/csv',
|
| 189 |
)
|
| 190 |
+
with tab5:
|
| 191 |
with st.container():
|
| 192 |
st.dataframe(flex_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), height = 1000, use_container_width = True)
|
| 193 |
st.download_button(
|