Spaces:
Running
Running
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import re | |
| from database import db | |
| st.set_page_config(layout="wide") | |
| wrong_acro = ['WSH', 'AZ'] | |
| right_acro = ['WAS', 'ARI'] | |
| game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}', | |
| 'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'} | |
| team_roo_format = {'Top Score%': '{:.2%}','0 Runs': '{:.2%}', '1 Run': '{:.2%}', '2 Runs': '{:.2%}', '3 Runs': '{:.2%}', '4 Runs': '{:.2%}', | |
| '5 Runs': '{:.2%}','6 Runs': '{:.2%}', '7 Runs': '{:.2%}', '8 Runs': '{:.2%}', '9 Runs': '{:.2%}', '10 Runs': '{:.2%}'} | |
| player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}', | |
| '4x%': '{:.2%}','GPP%': '{:.2%}'} | |
| st.markdown(""" | |
| <style> | |
| /* Tab styling */ | |
| .stElementContainer [data-baseweb="button-group"] { | |
| gap: 2.000rem; | |
| padding: 4px; | |
| } | |
| .stElementContainer [kind="segmented_control"] { | |
| height: 2.000rem; | |
| white-space: pre-wrap; | |
| background-color: #DAA520; | |
| color: white; | |
| border-radius: 20px; | |
| gap: 1px; | |
| padding: 10px 20px; | |
| font-weight: bold; | |
| transition: all 0.3s ease; | |
| } | |
| .stElementContainer [kind="segmented_controlActive"] { | |
| height: 3.000rem; | |
| background-color: #DAA520; | |
| border: 3px solid #FFD700; | |
| border-radius: 10px; | |
| color: black; | |
| } | |
| .stElementContainer [kind="segmented_control"]:hover { | |
| background-color: #FFD700; | |
| cursor: pointer; | |
| } | |
| div[data-baseweb="select"] > div { | |
| background-color: #DAA520; | |
| color: white; | |
| } | |
| </style>""", unsafe_allow_html=True) | |
| def init_baselines(): | |
| collection = db["Player_Baselines"] | |
| cursor = collection.find() | |
| raw_display = pd.DataFrame(list(cursor)) | |
| raw_display = raw_display[['name', 'Team', 'Opp', 'Position', 'Salary', 'team_plays', 'team_pass', 'team_rush', 'team_tds', 'team_pass_tds', 'team_rush_tds', 'dropbacks', 'pass_yards', 'pass_tds', | |
| 'rush_att', 'rush_yards', 'rush_tds', 'targets', 'rec', 'rec_yards', 'rec_tds', 'PPR', 'Half_PPR', 'Own']] | |
| player_stats = raw_display[raw_display['Position'] != 'K'] | |
| collection = db["DK_NFL_ROO"] | |
| cursor = collection.find() | |
| raw_display = pd.DataFrame(list(cursor)) | |
| raw_display = raw_display.rename(columns={'player_ID': 'player_id'}) | |
| raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', | |
| 'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own', 'CPT_Own', 'LevX', 'version', 'slate', 'timestamp', 'player_id', 'site']] | |
| load_display = raw_display[raw_display['Position'] != 'K'] | |
| dk_roo_raw = load_display.dropna(subset=['Median']) | |
| collection = db["FD_NFL_ROO"] | |
| cursor = collection.find() | |
| raw_display = pd.DataFrame(list(cursor)) | |
| raw_display = raw_display.rename(columns={'player_ID': 'player_id'}) | |
| raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', | |
| 'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own', 'CPT_Own', 'LevX', 'version', 'slate', 'timestamp', 'player_id', 'site']] | |
| load_display = raw_display[raw_display['Position'] != 'K'] | |
| fd_roo_raw = load_display.dropna(subset=['Median']) | |
| return player_stats, dk_roo_raw, fd_roo_raw | |
| def convert_df_to_csv(df): | |
| return df.to_csv().encode('utf-8') | |
| player_stats, dk_roo_raw, fd_roo_raw = init_baselines() | |
| opp_dict = dict(zip(dk_roo_raw.Team, dk_roo_raw.Opp)) | |
| t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST" | |
| app_load_reset_column, app_view_site_column = st.columns([1, 9]) | |
| with app_load_reset_column: | |
| if st.button("Load/Reset Data", key='reset_data_button'): | |
| st.cache_data.clear() | |
| player_stats, dk_roo_raw, fd_roo_raw = init_baselines() | |
| for key in st.session_state.keys(): | |
| del st.session_state[key] | |
| with app_view_site_column: | |
| with st.container(): | |
| app_view_column, app_site_column = st.columns([3, 3]) | |
| with app_view_column: | |
| view_var = st.selectbox("Select view", ["Simple", "Advanced"], key='view_selectbox') | |
| with app_site_column: | |
| site_var = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'), key='site_selectbox') | |
| selected_tab = st.segmented_control( | |
| "Select Tab", | |
| options=["Pivot Finder", "User Upload"], | |
| selection_mode='single', | |
| default='Pivot Finder', | |
| width='stretch', | |
| label_visibility='collapsed', | |
| key='tab_selector' | |
| ) | |
| if selected_tab == 'Pivot Finder': | |
| with st.expander("Infos and Filters"): | |
| st.info("Welcome to the Pivot Finder! Select a player or a set of players and run the algorithm to find the best spots to pivot for maximum relative value.") | |
| app_info_column, player_select_column, micro_filter_column, macro_filter_column = st.columns(4) | |
| with app_info_column: | |
| st.info(t_stamp) | |
| if st.button("Load/Reset Data", key='reset1'): | |
| st.cache_data.clear() | |
| player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw = init_baselines() | |
| opp_dict = dict(zip(dk_roo_raw.Team, dk_roo_raw.Opp)) | |
| t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST" | |
| data_var1 = st.radio("Which data are you loading?", ('Paydirt', 'User'), key='data_var1') | |
| if site_var == 'Draftkings': | |
| if data_var1 == 'User': | |
| raw_baselines = st.session_state['proj_dataframe'] | |
| elif data_var1 != 'User': | |
| raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == 'Main Slate'] | |
| raw_baselines = raw_baselines[raw_baselines['version'] == 'overall'] | |
| raw_baselines = raw_baselines.sort_values(by='Own', ascending=False) | |
| elif site_var == 'Fanduel': | |
| if data_var1 == 'User': | |
| raw_baselines = st.session_state['proj_dataframe'] | |
| elif data_var1 != 'User': | |
| raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == 'Main Slate'] | |
| raw_baselines = raw_baselines[raw_baselines['version'] == 'overall'] | |
| raw_baselines = raw_baselines.sort_values(by='Own', ascending=False) | |
| with player_select_column: | |
| 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') | |
| if check_seq == 'Single Player': | |
| player_check = st.selectbox('Select player to create comps', options = raw_baselines['Player'].unique(), key='dk_player') | |
| elif check_seq == 'Top X Owned': | |
| top_x_var = st.number_input('How many players would you like to check?', min_value = 1, max_value = 10, value = 5, step = 1) | |
| with micro_filter_column: | |
| Salary_var = st.number_input('Acceptable +/- Salary range', min_value = 0, max_value = 1000, value = 300, step = 100) | |
| Median_var = st.number_input('Acceptable +/- Median range', min_value = 0, max_value = 10, value = 3, step = 1) | |
| with macro_filter_column: | |
| pos_var1 = st.radio("Compare to all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_var1') | |
| if pos_var1 == 'Specific Positions': | |
| pos_var_list = st.multiselect('Which positions would you like to include?', options = raw_baselines['Position'].unique(), key='pos_var_list') | |
| elif pos_var1 == 'All Positions': | |
| pos_var_list = raw_baselines.Position.values.tolist() | |
| split_var1 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var1') | |
| if split_var1 == 'Specific Games': | |
| team_var1 = st.multiselect('Which teams would you like to include?', options = raw_baselines['Team'].unique(), key='team_var1') | |
| elif split_var1 == 'Full Slate Run': | |
| team_var1 = raw_baselines.Team.values.tolist() | |
| placeholder = st.empty() | |
| displayholder = st.empty() | |
| if st.button('Simulate appropriate pivots'): | |
| with placeholder: | |
| if site_var == 'Draftkings': | |
| working_roo = raw_baselines | |
| working_roo.replace('', 0, inplace=True) | |
| if site_var == 'Fanduel': | |
| working_roo = raw_baselines | |
| working_roo.replace('', 0, inplace=True) | |
| own_dict = dict(zip(working_roo.Player, working_roo.Own)) | |
| team_dict = dict(zip(working_roo.Player, working_roo.Team)) | |
| opp_dict = dict(zip(working_roo.Player, working_roo.Opp)) | |
| pos_dict = dict(zip(working_roo.Player, working_roo.Position)) | |
| total_sims = 1000 | |
| if check_seq == 'Single Player': | |
| player_var = working_roo.loc[working_roo['Player'] == player_check] | |
| player_var = player_var.reset_index() | |
| working_roo = working_roo[working_roo['Position'].isin(pos_var_list)] | |
| working_roo = working_roo[working_roo['Team'].isin(team_var1)] | |
| working_roo = working_roo.loc[(working_roo['Salary'] >= player_var['Salary'][0] - Salary_var) & (working_roo['Salary'] <= player_var['Salary'][0] + Salary_var)] | |
| working_roo = working_roo.loc[(working_roo['Median'] >= player_var['Median'][0] - Median_var) & (working_roo['Median'] <= player_var['Median'][0] + Median_var)] | |
| flex_file = working_roo[['Player', 'Position', 'Salary', 'Median']] | |
| flex_file['Floor_raw'] = flex_file['Median'] * .25 | |
| flex_file['Ceiling_raw'] = flex_file['Median'] * 1.75 | |
| flex_file['Floor'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * .33), flex_file['Floor_raw']) | |
| flex_file['Floor'] = np.where(flex_file['Position'] == 'WR', (flex_file['Median'] * .15), flex_file['Floor_raw']) | |
| flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * 1.75), flex_file['Ceiling_raw']) | |
| flex_file['Ceiling'] = np.where(flex_file['Position'] == 'WR', (flex_file['Median'] * 1.85), flex_file['Ceiling_raw']) | |
| flex_file['STD'] = flex_file['Median'] / 4 | |
| flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']] | |
| hold_file = flex_file.copy() | |
| overall_file = flex_file.copy() | |
| salary_file = flex_file.copy() | |
| overall_players = overall_file[['Player']] | |
| for x in range(0,total_sims): | |
| salary_file[x] = salary_file['Salary'] | |
| salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1) | |
| salary_file = salary_file.div(1000) | |
| for x in range(0,total_sims): | |
| overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD']) | |
| overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1) | |
| players_only = hold_file[['Player']] | |
| raw_lineups_file = players_only | |
| for x in range(0,total_sims): | |
| maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))} | |
| raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])]) | |
| players_only[x] = raw_lineups_file[x].rank(ascending=False) | |
| players_only=players_only.drop(['Player'], axis=1) | |
| salary_2x_check = (overall_file - (salary_file*2)) | |
| salary_3x_check = (overall_file - (salary_file*3)) | |
| salary_4x_check = (overall_file - (salary_file*4)) | |
| players_only['Average_Rank'] = players_only.mean(axis=1) | |
| players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims | |
| players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims | |
| players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims | |
| players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims) | |
| players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims) | |
| players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims) | |
| players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims) | |
| players_only['Player'] = hold_file[['Player']] | |
| final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']] | |
| final_Proj = pd.merge(hold_file, final_outcomes, on="Player") | |
| final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']] | |
| final_Proj['Own'] = final_Proj['Player'].map(own_dict) | |
| final_Proj['Team'] = final_Proj['Player'].map(team_dict) | |
| final_Proj['Opp'] = final_Proj['Player'].map(opp_dict) | |
| 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']] | |
| final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True) | |
| final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True) | |
| final_Proj['LevX'] = 0 | |
| 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']) | |
| 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']) | |
| 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']) | |
| 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']) | |
| final_Proj['CPT_Own'] = final_Proj['Own'] / 4 | |
| 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']] | |
| final_Proj = final_Proj.set_index('Player') | |
| st.session_state.final_Proj = final_Proj.sort_values(by='Top_finish', ascending=False) | |
| elif check_seq == 'Top X Owned': | |
| if pos_var1 == 'Specific Positions': | |
| raw_baselines = raw_baselines[raw_baselines['Position'].isin(pos_var_list)] | |
| player_check = raw_baselines['Player'].head(top_x_var).tolist() | |
| final_proj_list = [] | |
| for players in player_check: | |
| players_pos = pos_dict[players] | |
| player_var = working_roo.loc[working_roo['Player'] == players] | |
| player_var = player_var.reset_index() | |
| working_roo_temp = working_roo[working_roo['Position'] == players_pos] | |
| working_roo_temp = working_roo_temp[working_roo_temp['Team'].isin(team_var1)] | |
| 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)] | |
| 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)] | |
| flex_file = working_roo_temp[['Player', 'Position', 'Salary', 'Median']] | |
| flex_file['Floor_raw'] = flex_file['Median'] * .25 | |
| flex_file['Ceiling_raw'] = flex_file['Median'] * 1.75 | |
| flex_file['Floor'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * .33), flex_file['Floor_raw']) | |
| flex_file['Floor'] = np.where(flex_file['Position'] == 'WR', (flex_file['Median'] * .15), flex_file['Floor_raw']) | |
| flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * 1.75), flex_file['Ceiling_raw']) | |
| flex_file['Ceiling'] = np.where(flex_file['Position'] == 'WR', (flex_file['Median'] * 1.85), flex_file['Ceiling_raw']) | |
| flex_file['STD'] = flex_file['Median'] / 4 | |
| flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']] | |
| hold_file = flex_file.copy() | |
| overall_file = flex_file.copy() | |
| salary_file = flex_file.copy() | |
| overall_players = overall_file[['Player']] | |
| for x in range(0,total_sims): | |
| salary_file[x] = salary_file['Salary'] | |
| salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1) | |
| salary_file = salary_file.div(1000) | |
| for x in range(0,total_sims): | |
| overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD']) | |
| overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1) | |
| players_only = hold_file[['Player']] | |
| raw_lineups_file = players_only | |
| for x in range(0,total_sims): | |
| maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))} | |
| raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])]) | |
| players_only[x] = raw_lineups_file[x].rank(ascending=False) | |
| players_only=players_only.drop(['Player'], axis=1) | |
| salary_2x_check = (overall_file - (salary_file*2)) | |
| salary_3x_check = (overall_file - (salary_file*3)) | |
| salary_4x_check = (overall_file - (salary_file*4)) | |
| players_only['Average_Rank'] = players_only.mean(axis=1) | |
| players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims | |
| players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims | |
| players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims | |
| players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims) | |
| players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims) | |
| players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims) | |
| players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims) | |
| players_only['Player'] = hold_file[['Player']] | |
| final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']] | |
| final_Proj = pd.merge(hold_file, final_outcomes, on="Player") | |
| final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']] | |
| final_Proj['Own'] = final_Proj['Player'].map(own_dict) | |
| final_Proj['Team'] = final_Proj['Player'].map(team_dict) | |
| final_Proj['Opp'] = final_Proj['Player'].map(opp_dict) | |
| 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']] | |
| final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True) | |
| final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True) | |
| final_Proj['LevX'] = 0 | |
| 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']) | |
| 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']) | |
| 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']) | |
| 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']) | |
| final_Proj['CPT_Own'] = final_Proj['Own'] / 4 | |
| final_Proj['Pivot_source'] = players | |
| 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']] | |
| final_Proj = final_Proj.sort_values(by='Top_finish', ascending=False) | |
| final_proj_list.append(final_Proj) | |
| st.write(f'finished run for {players}') | |
| # Concatenate all the final_Proj dataframes | |
| final_Proj_combined = pd.concat(final_proj_list) | |
| final_Proj_combined = final_Proj_combined.sort_values(by='LevX', ascending=False) | |
| final_Proj_combined = final_Proj_combined[final_Proj_combined['Player'] != final_Proj_combined['Pivot_source']] | |
| st.session_state.final_Proj = final_Proj_combined.reset_index(drop=True) # Assign the combined dataframe back to final_Proj | |
| placeholder.empty() | |
| with displayholder.container(): | |
| if 'final_Proj' in st.session_state: | |
| if view_var == 'Simple': | |
| display_table = st.session_state['final_Proj'][['Position', 'Team', 'Salary', 'Median', 'Own', 'LevX']] | |
| st.dataframe(display_table.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True) | |
| if view_var == 'Advanced': | |
| display_table = st.session_state['final_Proj'] | |
| st.dataframe(display_table.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True) | |
| st.download_button( | |
| label="Export Tables", | |
| data=convert_df_to_csv(st.session_state.final_Proj), | |
| file_name='NFL_pivot_export.csv', | |
| mime='text/csv', | |
| ) | |
| else: | |
| st.write("Run some pivots my dude/dudette") | |
| if selected_tab == 'User Upload': | |
| 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'.") | |
| col1, col2 = st.columns([1, 5]) | |
| with col1: | |
| proj_file = st.file_uploader("Upload Projections File", key = 'proj_uploader') | |
| if proj_file is not None: | |
| try: | |
| st.session_state['proj_dataframe'] = pd.read_csv(proj_file) | |
| except: | |
| st.session_state['proj_dataframe'] = pd.read_excel(proj_file) | |
| with col2: | |
| if proj_file is not None: | |
| st.dataframe(st.session_state['proj_dataframe'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True) |