Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
53152e8
1
Parent(s):
9143c92
Removed custom ROO, adjusted some object names, added a TLL to data
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ gspreadcon = init_conn()
|
|
| 35 |
|
| 36 |
dk_player_url = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=172632260'
|
| 37 |
|
| 38 |
-
@st.cache_data
|
| 39 |
def load_overall_stats():
|
| 40 |
sh = gspreadcon.open_by_url(dk_player_url)
|
| 41 |
worksheet = sh.worksheet('DK_Build_Up')
|
|
@@ -83,8 +83,7 @@ def load_overall_stats():
|
|
| 83 |
raw_display = raw_display.apply(pd.to_numeric, errors='ignore')
|
| 84 |
roo_raw = raw_display.sort_values(by='Median', ascending=False)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
timestamp = worksheet.acell('A1').value
|
| 88 |
|
| 89 |
return dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp
|
| 90 |
|
|
@@ -94,25 +93,9 @@ def convert_df_to_csv(df):
|
|
| 94 |
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = load_overall_stats()
|
| 95 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 96 |
|
| 97 |
-
tab1, tab2, tab3 = st.tabs(['
|
| 98 |
|
| 99 |
with tab1:
|
| 100 |
-
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Minutes', 'Median', 'Own'.")
|
| 101 |
-
col1, col2 = st.columns([1, 5])
|
| 102 |
-
|
| 103 |
-
with col1:
|
| 104 |
-
proj_file = st.file_uploader("Upload Projections File", key = 'proj_uploader')
|
| 105 |
-
|
| 106 |
-
if proj_file is not None:
|
| 107 |
-
try:
|
| 108 |
-
proj_dataframe = pd.read_csv(proj_file)
|
| 109 |
-
except:
|
| 110 |
-
proj_dataframe = pd.read_excel(proj_file)
|
| 111 |
-
with col2:
|
| 112 |
-
if proj_file is not None:
|
| 113 |
-
st.dataframe(proj_dataframe.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 114 |
-
|
| 115 |
-
with tab2:
|
| 116 |
|
| 117 |
col1, col2 = st.columns([1, 9])
|
| 118 |
|
|
@@ -126,15 +109,15 @@ with tab2:
|
|
| 126 |
del st.session_state[key]
|
| 127 |
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 128 |
if site_var2 == 'Draftkings':
|
| 129 |
-
site_baselines = roo_raw[roo_raw['
|
| 130 |
elif site_var2 == 'Fanduel':
|
| 131 |
-
site_baselines = roo_raw[roo_raw['
|
| 132 |
slate_split = st.radio("Are you viewing the main slate or the secondary slate?", ('Main Slate', 'Secondary'), key='slate_split')
|
| 133 |
if slate_split == 'Main Slate':
|
| 134 |
-
raw_baselines = site_baselines[site_baselines['
|
| 135 |
elif slate_split == 'Secondary':
|
| 136 |
-
raw_baselines = site_baselines[site_baselines['
|
| 137 |
-
split_var2 = st.radio("Are you running the full slate or
|
| 138 |
if split_var2 == 'Specific Games':
|
| 139 |
team_var2 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var2')
|
| 140 |
elif split_var2 == 'Full Slate Run':
|
|
@@ -155,7 +138,7 @@ with tab2:
|
|
| 155 |
st.session_state.display_proj = st.session_state.display_proj
|
| 156 |
elif pos_var2 != 'All':
|
| 157 |
st.session_state.display_proj = st.session_state.display_proj[st.session_state.display_proj['Position'].str.contains(pos_var2)]
|
| 158 |
-
st.dataframe(st.session_state.display_proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 159 |
|
| 160 |
with display_dl_container_1:
|
| 161 |
display_dl_container = st.empty()
|
|
@@ -167,147 +150,18 @@ with tab2:
|
|
| 167 |
mime='text/csv',
|
| 168 |
)
|
| 169 |
|
| 170 |
-
with
|
| 171 |
-
|
| 172 |
-
col1, col2 = st.columns([1,
|
| 173 |
|
| 174 |
with col1:
|
| 175 |
-
st.
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
slate_var1 = st.radio("Which data are you loading?", ('Paydirt', 'User'), key='slate_var1')
|
| 183 |
-
site_var1 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var1')
|
| 184 |
-
slate_split2 = st.radio("Are you viewing the main slate or the secondary slate?", ('Main Slate', 'Secondary'), key='slate_split2')
|
| 185 |
-
if site_var1 == 'Draftkings':
|
| 186 |
-
if slate_var1 == 'User':
|
| 187 |
-
raw_baselines = proj_dataframe
|
| 188 |
-
elif slate_var1 != 'User':
|
| 189 |
-
if slate_split2 == 'Main Slate':
|
| 190 |
-
raw_baselines = dk_raw
|
| 191 |
-
elif slate_split2 == 'Secondary':
|
| 192 |
-
raw_baselines = dk_raw_sec
|
| 193 |
-
elif site_var1 == 'Fanduel':
|
| 194 |
-
if slate_var1 == 'User':
|
| 195 |
-
raw_baselines = proj_dataframe
|
| 196 |
-
elif slate_var1 != 'User':
|
| 197 |
-
if slate_split2 == 'Main Slate':
|
| 198 |
-
raw_baselines = fd_raw
|
| 199 |
-
elif slate_split2 == 'Secondary':
|
| 200 |
-
raw_baselines = fd_raw_sec
|
| 201 |
-
split_var1 = st.radio("Are you running the full slate or crtain games?", ('Full Slate Run', 'Specific Games'), key='split_var1')
|
| 202 |
-
if split_var1 == 'Specific Games':
|
| 203 |
-
team_var1 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var1')
|
| 204 |
-
elif split_var1 == 'Full Slate Run':
|
| 205 |
-
team_var1 = raw_baselines.Team.values.tolist()
|
| 206 |
-
pos_var1 = st.selectbox('View specific position?', options = ['All', 'PG', 'SG', 'SF', 'PF', 'C'])
|
| 207 |
-
|
| 208 |
with col2:
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
hold_container = st.empty()
|
| 212 |
-
if st.button('Create Range of Outcomes for Slate'):
|
| 213 |
-
with hold_container:
|
| 214 |
-
|
| 215 |
-
working_roo = raw_baselines
|
| 216 |
-
working_roo = working_roo[working_roo['Team'].isin(team_var1)]
|
| 217 |
-
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
| 218 |
-
min_dict = dict(zip(working_roo.Player, working_roo.Minutes))
|
| 219 |
-
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
| 220 |
-
total_sims = 1000
|
| 221 |
-
|
| 222 |
-
flex_file = working_roo[['Player', 'Position', 'Salary', 'Median', 'Minutes']]
|
| 223 |
-
flex_file.rename(columns={"Agg": "Median"}, inplace = True)
|
| 224 |
-
flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
|
| 225 |
-
flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
|
| 226 |
-
flex_file['STD'] = (flex_file['Median']/4)
|
| 227 |
-
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 228 |
-
hold_file = flex_file
|
| 229 |
-
overall_file = flex_file
|
| 230 |
-
salary_file = flex_file
|
| 231 |
-
|
| 232 |
-
overall_players = overall_file[['Player']]
|
| 233 |
-
|
| 234 |
-
for x in range(0,total_sims):
|
| 235 |
-
salary_file[x] = salary_file['Salary']
|
| 236 |
-
|
| 237 |
-
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 238 |
-
salary_file.astype('int').dtypes
|
| 239 |
-
|
| 240 |
-
salary_file = salary_file.div(1000)
|
| 241 |
-
|
| 242 |
-
for x in range(0,total_sims):
|
| 243 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 244 |
-
|
| 245 |
-
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 246 |
-
overall_file.astype('int').dtypes
|
| 247 |
-
|
| 248 |
-
players_only = hold_file[['Player']]
|
| 249 |
-
raw_lineups_file = players_only
|
| 250 |
-
|
| 251 |
-
for x in range(0,total_sims):
|
| 252 |
-
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
| 253 |
-
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
| 254 |
-
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
| 255 |
-
|
| 256 |
-
players_only=players_only.drop(['Player'], axis=1)
|
| 257 |
-
players_only.astype('int').dtypes
|
| 258 |
-
|
| 259 |
-
salary_2x_check = (overall_file - (salary_file*4))
|
| 260 |
-
salary_3x_check = (overall_file - (salary_file*5))
|
| 261 |
-
salary_4x_check = (overall_file - (salary_file*6))
|
| 262 |
-
gpp_check = (overall_file - ((salary_file*5)+10))
|
| 263 |
-
|
| 264 |
-
players_only['Average_Rank'] = players_only.mean(axis=1)
|
| 265 |
-
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
| 266 |
-
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
| 267 |
-
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
| 268 |
-
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
| 269 |
-
players_only['3x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
| 270 |
-
players_only['4x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
| 271 |
-
players_only['5x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
| 272 |
-
players_only['GPP%'] = salary_4x_check[gpp_check >= 1].count(axis=1)/float(total_sims)
|
| 273 |
-
|
| 274 |
-
players_only['Player'] = hold_file[['Player']]
|
| 275 |
-
|
| 276 |
-
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '3x%', '4x%', '5x%', 'GPP%']]
|
| 277 |
-
|
| 278 |
-
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
| 279 |
-
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '3x%', '4x%', '5x%', 'GPP%']]
|
| 280 |
-
|
| 281 |
-
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
| 282 |
-
final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
|
| 283 |
-
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
| 284 |
-
final_Proj['Own'] = final_Proj['Own'].astype('float')
|
| 285 |
-
final_Proj['LevX'] = ((final_Proj[['Top_finish', '4x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
|
| 286 |
-
final_Proj['ValX'] = ((final_Proj[['4x%', '5x%']].mean(axis=1))*100) + final_Proj['LevX']
|
| 287 |
-
|
| 288 |
-
final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '3x%', '4x%', '5x%', 'GPP%', 'Own', 'LevX', 'ValX']]
|
| 289 |
-
final_Proj = final_Proj.set_index('Player')
|
| 290 |
-
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
| 291 |
-
|
| 292 |
-
st.session_state.final_Proj = final_Proj
|
| 293 |
-
|
| 294 |
-
hold_container = st.empty()
|
| 295 |
-
|
| 296 |
-
with display_container:
|
| 297 |
-
display_container = st.empty()
|
| 298 |
-
if 'final_Proj' in st.session_state:
|
| 299 |
-
if pos_var1 == 'All':
|
| 300 |
-
st.session_state.final_Proj = st.session_state.final_Proj
|
| 301 |
-
elif pos_var1 != 'All':
|
| 302 |
-
st.session_state.final_Proj = st.session_state.final_Proj[st.session_state.final_Proj['Position'].str.contains(pos_var1)]
|
| 303 |
-
st.dataframe(st.session_state.final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 304 |
-
|
| 305 |
-
with display_dl_container:
|
| 306 |
-
display_dl_container = st.empty()
|
| 307 |
-
if 'final_Proj' in st.session_state:
|
| 308 |
-
st.download_button(
|
| 309 |
-
label="Export Tables",
|
| 310 |
-
data=convert_df_to_csv(st.session_state.final_Proj),
|
| 311 |
-
file_name='Custom_NBA_export.csv',
|
| 312 |
-
mime='text/csv',
|
| 313 |
-
)
|
|
|
|
| 35 |
|
| 36 |
dk_player_url = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=172632260'
|
| 37 |
|
| 38 |
+
@st.cache_data(ttl=300)
|
| 39 |
def load_overall_stats():
|
| 40 |
sh = gspreadcon.open_by_url(dk_player_url)
|
| 41 |
worksheet = sh.worksheet('DK_Build_Up')
|
|
|
|
| 83 |
raw_display = raw_display.apply(pd.to_numeric, errors='ignore')
|
| 84 |
roo_raw = raw_display.sort_values(by='Median', ascending=False)
|
| 85 |
|
| 86 |
+
timestamp = raw_display['timestamp'].values[0]
|
|
|
|
| 87 |
|
| 88 |
return dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp
|
| 89 |
|
|
|
|
| 93 |
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp = load_overall_stats()
|
| 94 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 95 |
|
| 96 |
+
tab1, tab2, tab3 = st.tabs(['Range of Outcomes', 'Uploads and Info'])
|
| 97 |
|
| 98 |
with tab1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
col1, col2 = st.columns([1, 9])
|
| 101 |
|
|
|
|
| 109 |
del st.session_state[key]
|
| 110 |
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 111 |
if site_var2 == 'Draftkings':
|
| 112 |
+
site_baselines = roo_raw[roo_raw['site'] == 'Draftkings']
|
| 113 |
elif site_var2 == 'Fanduel':
|
| 114 |
+
site_baselines = roo_raw[roo_raw['site'] == 'Fanduel']
|
| 115 |
slate_split = st.radio("Are you viewing the main slate or the secondary slate?", ('Main Slate', 'Secondary'), key='slate_split')
|
| 116 |
if slate_split == 'Main Slate':
|
| 117 |
+
raw_baselines = site_baselines[site_baselines['slate'] == 'Main Slate']
|
| 118 |
elif slate_split == 'Secondary':
|
| 119 |
+
raw_baselines = site_baselines[site_baselines['slate'] == 'Secondary']
|
| 120 |
+
split_var2 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var2')
|
| 121 |
if split_var2 == 'Specific Games':
|
| 122 |
team_var2 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var2')
|
| 123 |
elif split_var2 == 'Full Slate Run':
|
|
|
|
| 138 |
st.session_state.display_proj = st.session_state.display_proj
|
| 139 |
elif pos_var2 != 'All':
|
| 140 |
st.session_state.display_proj = st.session_state.display_proj[st.session_state.display_proj['Position'].str.contains(pos_var2)]
|
| 141 |
+
st.dataframe(st.session_state.display_proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
| 142 |
|
| 143 |
with display_dl_container_1:
|
| 144 |
display_dl_container = st.empty()
|
|
|
|
| 150 |
mime='text/csv',
|
| 151 |
)
|
| 152 |
|
| 153 |
+
with tab2:
|
| 154 |
+
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Minutes', 'Median', 'Own'.")
|
| 155 |
+
col1, col2 = st.columns([1, 5])
|
| 156 |
|
| 157 |
with col1:
|
| 158 |
+
proj_file = st.file_uploader("Upload Projections File", key = 'proj_uploader')
|
| 159 |
+
|
| 160 |
+
if proj_file is not None:
|
| 161 |
+
try:
|
| 162 |
+
proj_dataframe = pd.read_csv(proj_file)
|
| 163 |
+
except:
|
| 164 |
+
proj_dataframe = pd.read_excel(proj_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
with col2:
|
| 166 |
+
if proj_file is not None:
|
| 167 |
+
st.dataframe(proj_dataframe.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|