Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
f6e8cf1
1
Parent(s):
64bf25c
Refactor Pivot Finder UI for improved layout and functionality. Organized filters into expandable sections, enhanced data loading/resetting options, and streamlined player selection process. Added support for advanced projections and export functionality.
Browse files- src/streamlit_app.py +190 -185
src/streamlit_app.py
CHANGED
|
@@ -135,77 +135,165 @@ selected_tab = st.segmented_control(
|
|
| 135 |
)
|
| 136 |
|
| 137 |
if selected_tab == 'Pivot Finder':
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
player_var = player_var.reset_index()
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
flex_file =
|
| 209 |
flex_file['Floor_raw'] = flex_file['Median'] * .25
|
| 210 |
flex_file['Ceiling_raw'] = flex_file['Median'] * 1.75
|
| 211 |
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * .33), flex_file['Floor_raw'])
|
|
@@ -217,9 +305,9 @@ if selected_tab == 'Pivot Finder':
|
|
| 217 |
hold_file = flex_file.copy()
|
| 218 |
overall_file = flex_file.copy()
|
| 219 |
salary_file = flex_file.copy()
|
| 220 |
-
|
| 221 |
overall_players = overall_file[['Player']]
|
| 222 |
-
|
| 223 |
for x in range(0,total_sims):
|
| 224 |
salary_file[x] = salary_file['Salary']
|
| 225 |
|
|
@@ -273,121 +361,38 @@ if selected_tab == 'Pivot Finder':
|
|
| 273 |
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 274 |
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 275 |
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
|
|
|
| 276 |
|
| 277 |
-
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'LevX']]
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
overall_players = overall_file[['Player']]
|
| 309 |
-
|
| 310 |
-
for x in range(0,total_sims):
|
| 311 |
-
salary_file[x] = salary_file['Salary']
|
| 312 |
-
|
| 313 |
-
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 314 |
-
|
| 315 |
-
salary_file = salary_file.div(1000)
|
| 316 |
-
|
| 317 |
-
for x in range(0,total_sims):
|
| 318 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 319 |
-
|
| 320 |
-
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 321 |
-
|
| 322 |
-
players_only = hold_file[['Player']]
|
| 323 |
-
raw_lineups_file = players_only
|
| 324 |
-
|
| 325 |
-
for x in range(0,total_sims):
|
| 326 |
-
maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))}
|
| 327 |
-
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
| 328 |
-
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
| 329 |
-
|
| 330 |
-
players_only=players_only.drop(['Player'], axis=1)
|
| 331 |
-
|
| 332 |
-
salary_2x_check = (overall_file - (salary_file*2))
|
| 333 |
-
salary_3x_check = (overall_file - (salary_file*3))
|
| 334 |
-
salary_4x_check = (overall_file - (salary_file*4))
|
| 335 |
-
|
| 336 |
-
players_only['Average_Rank'] = players_only.mean(axis=1)
|
| 337 |
-
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
| 338 |
-
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
| 339 |
-
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
| 340 |
-
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
| 341 |
-
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
| 342 |
-
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
| 343 |
-
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
| 344 |
-
|
| 345 |
-
players_only['Player'] = hold_file[['Player']]
|
| 346 |
-
|
| 347 |
-
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
| 348 |
-
|
| 349 |
-
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
| 350 |
-
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
| 351 |
-
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
| 352 |
-
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
| 353 |
-
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
| 354 |
-
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
| 355 |
-
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
| 356 |
-
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
| 357 |
-
final_Proj['LevX'] = 0
|
| 358 |
-
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 359 |
-
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 360 |
-
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 361 |
-
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 362 |
-
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
| 363 |
-
final_Proj['Pivot_source'] = players
|
| 364 |
-
|
| 365 |
-
final_Proj = final_Proj[['Player', 'Pivot_source', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'LevX']]
|
| 366 |
-
|
| 367 |
-
final_Proj = final_Proj.sort_values(by='Top_finish', ascending=False)
|
| 368 |
-
final_proj_list.append(final_Proj)
|
| 369 |
-
st.write(f'finished run for {players}')
|
| 370 |
-
|
| 371 |
-
# Concatenate all the final_Proj dataframes
|
| 372 |
-
final_Proj_combined = pd.concat(final_proj_list)
|
| 373 |
-
final_Proj_combined = final_Proj_combined.sort_values(by='LevX', ascending=False)
|
| 374 |
-
final_Proj_combined = final_Proj_combined[final_Proj_combined['Player'] != final_Proj_combined['Pivot_source']]
|
| 375 |
-
st.session_state.final_Proj = final_Proj_combined.reset_index(drop=True) # Assign the combined dataframe back to final_Proj
|
| 376 |
-
|
| 377 |
-
placeholder.empty()
|
| 378 |
-
|
| 379 |
-
with displayholder.container():
|
| 380 |
-
if 'final_Proj' in st.session_state:
|
| 381 |
-
st.dataframe(st.session_state.final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
| 382 |
-
|
| 383 |
-
st.download_button(
|
| 384 |
-
label="Export Tables",
|
| 385 |
-
data=convert_df_to_csv(st.session_state.final_Proj),
|
| 386 |
-
file_name='NFL_pivot_export.csv',
|
| 387 |
-
mime='text/csv',
|
| 388 |
-
)
|
| 389 |
-
else:
|
| 390 |
-
st.write("Run some pivots my dude/dudette")
|
| 391 |
|
| 392 |
if selected_tab == 'User Upload':
|
| 393 |
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', and 'Own'.")
|
|
|
|
| 135 |
)
|
| 136 |
|
| 137 |
if selected_tab == 'Pivot Finder':
|
| 138 |
+
with st.expander("Infos and Filters"):
|
| 139 |
+
app_info_column, player_select_column, micro_filter_column, macro_filter_column = st.columns(4)
|
| 140 |
+
with app_info_column:
|
| 141 |
+
st.info(t_stamp)
|
| 142 |
+
if st.button("Load/Reset Data", key='reset1'):
|
| 143 |
+
st.cache_data.clear()
|
| 144 |
+
player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw = init_baselines()
|
| 145 |
+
opp_dict = dict(zip(dk_roo_raw.Team, dk_roo_raw.Opp))
|
| 146 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 147 |
+
data_var1 = st.radio("Which data are you loading?", ('Paydirt', 'User'), key='data_var1')
|
| 148 |
+
if site_var == 'Draftkings':
|
| 149 |
+
if data_var1 == 'User':
|
| 150 |
+
raw_baselines = st.session_state['proj_dataframe']
|
| 151 |
+
elif data_var1 != 'User':
|
| 152 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == 'Main Slate']
|
| 153 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
| 154 |
+
raw_baselines = raw_baselines.sort_values(by='Own', ascending=False)
|
| 155 |
+
elif site_var == 'Fanduel':
|
| 156 |
+
if data_var1 == 'User':
|
| 157 |
+
raw_baselines = st.session_state['proj_dataframe']
|
| 158 |
+
elif data_var1 != 'User':
|
| 159 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == 'Main Slate']
|
| 160 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
| 161 |
+
raw_baselines = raw_baselines.sort_values(by='Own', ascending=False)
|
| 162 |
+
with player_select_column:
|
| 163 |
+
check_seq = st.radio("Do you want to check a single player or the top 10 in ownership?", ('Single Player', 'Top X Owned'), key='check_seq')
|
| 164 |
+
if check_seq == 'Single Player':
|
| 165 |
+
player_check = st.selectbox('Select player to create comps', options = raw_baselines['Player'].unique(), key='dk_player')
|
| 166 |
+
elif check_seq == 'Top X Owned':
|
| 167 |
+
top_x_var = st.number_input('How many players would you like to check?', min_value = 1, max_value = 10, value = 5, step = 1)
|
| 168 |
+
with micro_filter_column:
|
| 169 |
+
Salary_var = st.number_input('Acceptable +/- Salary range', min_value = 0, max_value = 1000, value = 300, step = 100)
|
| 170 |
+
Median_var = st.number_input('Acceptable +/- Median range', min_value = 0, max_value = 10, value = 3, step = 1)
|
| 171 |
+
with macro_filter_column:
|
| 172 |
+
pos_var1 = st.radio("Compare to all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_var1')
|
| 173 |
+
if pos_var1 == 'Specific Positions':
|
| 174 |
+
pos_var_list = st.multiselect('Which positions would you like to include?', options = raw_baselines['Position'].unique(), key='pos_var_list')
|
| 175 |
+
elif pos_var1 == 'All Positions':
|
| 176 |
+
pos_var_list = raw_baselines.Position.values.tolist()
|
| 177 |
+
split_var1 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var1')
|
| 178 |
+
if split_var1 == 'Specific Games':
|
| 179 |
+
team_var1 = st.multiselect('Which teams would you like to include?', options = raw_baselines['Team'].unique(), key='team_var1')
|
| 180 |
+
elif split_var1 == 'Full Slate Run':
|
| 181 |
+
team_var1 = raw_baselines.Team.values.tolist()
|
| 182 |
|
| 183 |
+
placeholder = st.empty()
|
| 184 |
+
displayholder = st.empty()
|
| 185 |
+
|
| 186 |
+
if st.button('Simulate appropriate pivots'):
|
| 187 |
+
with placeholder:
|
| 188 |
+
if site_var == 'Draftkings':
|
| 189 |
+
working_roo = raw_baselines
|
| 190 |
+
working_roo.replace('', 0, inplace=True)
|
| 191 |
+
if site_var == 'Fanduel':
|
| 192 |
+
working_roo = raw_baselines
|
| 193 |
+
working_roo.replace('', 0, inplace=True)
|
| 194 |
+
|
| 195 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
| 196 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
| 197 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
| 198 |
+
pos_dict = dict(zip(working_roo.Player, working_roo.Position))
|
| 199 |
+
total_sims = 1000
|
| 200 |
+
|
| 201 |
+
if check_seq == 'Single Player':
|
| 202 |
+
player_var = working_roo.loc[working_roo['Player'] == player_check]
|
| 203 |
+
player_var = player_var.reset_index()
|
| 204 |
+
working_roo = working_roo[working_roo['Position'].isin(pos_var_list)]
|
| 205 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var1)]
|
| 206 |
+
working_roo = working_roo.loc[(working_roo['Salary'] >= player_var['Salary'][0] - Salary_var) & (working_roo['Salary'] <= player_var['Salary'][0] + Salary_var)]
|
| 207 |
+
working_roo = working_roo.loc[(working_roo['Median'] >= player_var['Median'][0] - Median_var) & (working_roo['Median'] <= player_var['Median'][0] + Median_var)]
|
| 208 |
+
|
| 209 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Median']]
|
| 210 |
+
flex_file['Floor_raw'] = flex_file['Median'] * .25
|
| 211 |
+
flex_file['Ceiling_raw'] = flex_file['Median'] * 1.75
|
| 212 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * .33), flex_file['Floor_raw'])
|
| 213 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'WR', (flex_file['Median'] * .15), flex_file['Floor_raw'])
|
| 214 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * 1.75), flex_file['Ceiling_raw'])
|
| 215 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'WR', (flex_file['Median'] * 1.85), flex_file['Ceiling_raw'])
|
| 216 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 217 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 218 |
+
hold_file = flex_file.copy()
|
| 219 |
+
overall_file = flex_file.copy()
|
| 220 |
+
salary_file = flex_file.copy()
|
| 221 |
+
|
| 222 |
+
overall_players = overall_file[['Player']]
|
| 223 |
+
|
| 224 |
+
for x in range(0,total_sims):
|
| 225 |
+
salary_file[x] = salary_file['Salary']
|
| 226 |
+
|
| 227 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 228 |
+
|
| 229 |
+
salary_file = salary_file.div(1000)
|
| 230 |
+
|
| 231 |
+
for x in range(0,total_sims):
|
| 232 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 233 |
+
|
| 234 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 235 |
+
|
| 236 |
+
players_only = hold_file[['Player']]
|
| 237 |
+
raw_lineups_file = players_only
|
| 238 |
+
|
| 239 |
+
for x in range(0,total_sims):
|
| 240 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))}
|
| 241 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
| 242 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
| 243 |
+
|
| 244 |
+
players_only=players_only.drop(['Player'], axis=1)
|
| 245 |
+
|
| 246 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
| 247 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
| 248 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
| 249 |
+
|
| 250 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
| 251 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
| 252 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
| 253 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
| 254 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
| 255 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
| 256 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
| 257 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
| 258 |
+
|
| 259 |
+
players_only['Player'] = hold_file[['Player']]
|
| 260 |
+
|
| 261 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
| 262 |
+
|
| 263 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
| 264 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
| 265 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
| 266 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
| 267 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
| 268 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
| 269 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
| 270 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
| 271 |
+
final_Proj['LevX'] = 0
|
| 272 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 273 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 274 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 275 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 276 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
| 277 |
+
|
| 278 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'LevX']]
|
| 279 |
+
final_Proj = final_Proj.set_index('Player')
|
| 280 |
+
st.session_state.final_Proj = final_Proj.sort_values(by='Top_finish', ascending=False)
|
| 281 |
+
|
| 282 |
+
elif check_seq == 'Top X Owned':
|
| 283 |
+
if pos_var1 == 'Specific Positions':
|
| 284 |
+
raw_baselines = raw_baselines[raw_baselines['Position'].isin(pos_var_list)]
|
| 285 |
+
player_check = raw_baselines['Player'].head(top_x_var).tolist()
|
| 286 |
+
final_proj_list = []
|
| 287 |
+
for players in player_check:
|
| 288 |
+
players_pos = pos_dict[players]
|
| 289 |
+
player_var = working_roo.loc[working_roo['Player'] == players]
|
| 290 |
player_var = player_var.reset_index()
|
| 291 |
+
working_roo_temp = working_roo[working_roo['Position'] == players_pos]
|
| 292 |
+
working_roo_temp = working_roo_temp[working_roo_temp['Team'].isin(team_var1)]
|
| 293 |
+
working_roo_temp = working_roo_temp.loc[(working_roo_temp['Salary'] >= player_var['Salary'][0] - Salary_var) & (working_roo_temp['Salary'] <= player_var['Salary'][0] + Salary_var)]
|
| 294 |
+
working_roo_temp = working_roo_temp.loc[(working_roo_temp['Median'] >= player_var['Median'][0] - Median_var) & (working_roo_temp['Median'] <= player_var['Median'][0] + Median_var)]
|
| 295 |
+
|
| 296 |
+
flex_file = working_roo_temp[['Player', 'Position', 'Salary', 'Median']]
|
| 297 |
flex_file['Floor_raw'] = flex_file['Median'] * .25
|
| 298 |
flex_file['Ceiling_raw'] = flex_file['Median'] * 1.75
|
| 299 |
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * .33), flex_file['Floor_raw'])
|
|
|
|
| 305 |
hold_file = flex_file.copy()
|
| 306 |
overall_file = flex_file.copy()
|
| 307 |
salary_file = flex_file.copy()
|
| 308 |
+
|
| 309 |
overall_players = overall_file[['Player']]
|
| 310 |
+
|
| 311 |
for x in range(0,total_sims):
|
| 312 |
salary_file[x] = salary_file['Salary']
|
| 313 |
|
|
|
|
| 361 |
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 362 |
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 363 |
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
| 364 |
+
final_Proj['Pivot_source'] = players
|
| 365 |
|
| 366 |
+
final_Proj = final_Proj[['Player', 'Pivot_source', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'LevX']]
|
| 367 |
+
|
| 368 |
+
final_Proj = final_Proj.sort_values(by='Top_finish', ascending=False)
|
| 369 |
+
final_proj_list.append(final_Proj)
|
| 370 |
+
st.write(f'finished run for {players}')
|
| 371 |
+
|
| 372 |
+
# Concatenate all the final_Proj dataframes
|
| 373 |
+
final_Proj_combined = pd.concat(final_proj_list)
|
| 374 |
+
final_Proj_combined = final_Proj_combined.sort_values(by='LevX', ascending=False)
|
| 375 |
+
final_Proj_combined = final_Proj_combined[final_Proj_combined['Player'] != final_Proj_combined['Pivot_source']]
|
| 376 |
+
st.session_state.final_Proj = final_Proj_combined.reset_index(drop=True) # Assign the combined dataframe back to final_Proj
|
| 377 |
+
|
| 378 |
+
placeholder.empty()
|
| 379 |
+
|
| 380 |
+
with displayholder.container():
|
| 381 |
+
if 'final_Proj' in st.session_state:
|
| 382 |
+
if view_var == 'Simple':
|
| 383 |
+
st.session_state['final_Proj'] = st.session_state['final_Proj'][['Player', 'Position', 'Team', 'Salary', 'Median', 'Own', 'LevX']]
|
| 384 |
+
st.dataframe(st.session_state['final_Proj'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
| 385 |
+
if view_var == 'Advanced':
|
| 386 |
+
st.dataframe(st.session_state['final_Proj'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
| 387 |
+
|
| 388 |
+
st.download_button(
|
| 389 |
+
label="Export Tables",
|
| 390 |
+
data=convert_df_to_csv(st.session_state.final_Proj),
|
| 391 |
+
file_name='NFL_pivot_export.csv',
|
| 392 |
+
mime='text/csv',
|
| 393 |
+
)
|
| 394 |
+
else:
|
| 395 |
+
st.write("Run some pivots my dude/dudette")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
if selected_tab == 'User Upload':
|
| 398 |
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', and 'Own'.")
|