Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -203,137 +203,141 @@ with tab1:
|
|
203 |
gc.collect()
|
204 |
|
205 |
with tab2:
|
206 |
-
|
207 |
-
with col1:
|
208 |
hold_container = st.empty()
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
raw_lineups_file
|
275 |
-
|
276 |
-
|
277 |
-
|
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 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
|
|
|
|
319 |
|
320 |
-
|
|
|
321 |
proj_container = st.empty()
|
322 |
display_container = st.empty()
|
323 |
display_dl_container = st.empty()
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
st.
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
st.
|
333 |
-
|
334 |
-
|
335 |
-
with
|
336 |
-
|
337 |
-
|
338 |
-
st.
|
|
|
|
|
339 |
|
|
|
203 |
gc.collect()
|
204 |
|
205 |
with tab2:
|
206 |
+
with st.container():
|
|
|
207 |
hold_container = st.empty()
|
208 |
+
col1, col2, col3 = st.columns([3, 3, 3])
|
209 |
+
with col1:
|
210 |
+
if st.button("Load/Reset Data", key='reset1'):
|
211 |
+
for key in st.session_state.keys():
|
212 |
+
del st.session_state[key]
|
213 |
+
display_portfolio = hold_portfolio
|
214 |
+
st.session_state.display_portfolio = display_portfolio
|
215 |
+
st.session_state.player_freq = pd.DataFrame(np.column_stack(np.unique(st.session_state.display_portfolio.iloc[:,0:9].values, return_counts=True)),
|
216 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
217 |
+
st.session_state.player_freq['Freq'] = st.session_state.player_freq['Freq'].astype(int)
|
218 |
+
with col2:
|
219 |
+
if st.button("Trim Lineups", key='trim1'):
|
220 |
+
max_proj = 10000
|
221 |
+
max_own = display_portfolio['Ownership'].iloc[0]
|
222 |
+
x = 0
|
223 |
+
for index, row in display_portfolio.iterrows():
|
224 |
+
if row['Ownership'] > max_own:
|
225 |
+
display_portfolio.drop(index, inplace=True)
|
226 |
+
elif row['Ownership'] <= max_own:
|
227 |
+
max_own = row['Ownership']
|
228 |
+
st.session_state.display_portfolio = display_portfolio
|
229 |
+
with col3:
|
230 |
+
player_check = st.selectbox('Select player to create comps', options = proj_dataframe['Player'].unique(), key='dk_player')
|
231 |
+
if st.button('Simulate appropriate pivots'):
|
232 |
+
with hold_container:
|
233 |
+
|
234 |
+
working_roo = proj_dataframe
|
235 |
+
working_roo.rename(columns={"Minutes Proj": "Minutes_Proj"}, inplace = True)
|
236 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
237 |
+
min_dict = dict(zip(working_roo.Player, working_roo.Minutes_Proj))
|
238 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
239 |
+
total_sims = 1000
|
240 |
+
|
241 |
+
player_var = working_roo.loc[working_roo['Player'] == player_check]
|
242 |
+
player_var = player_var.reset_index()
|
243 |
+
|
244 |
+
working_roo = working_roo.loc[(working_roo['Salary'] >= player_var['Salary'][0] - 300) & (working_roo['Salary'] <= player_var['Salary'][0] + 300)]
|
245 |
+
working_roo = working_roo.loc[(working_roo['Median'] >= player_var['Median'][0] - 3) & (working_roo['Median'] <= player_var['Median'][0] + 3)]
|
246 |
+
|
247 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Median', 'Minutes_Proj']]
|
248 |
+
flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes_Proj'] * .25)
|
249 |
+
flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes_Proj'] * .25)
|
250 |
+
flex_file['STD'] = (flex_file['Median']/4)
|
251 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
252 |
+
hold_file = flex_file
|
253 |
+
overall_file = flex_file
|
254 |
+
salary_file = flex_file
|
255 |
+
|
256 |
+
overall_players = overall_file[['Player']]
|
257 |
+
|
258 |
+
for x in range(0,total_sims):
|
259 |
+
salary_file[x] = salary_file['Salary']
|
260 |
+
|
261 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
262 |
+
salary_file.astype('int').dtypes
|
263 |
+
|
264 |
+
salary_file = salary_file.div(1000)
|
265 |
+
|
266 |
+
for x in range(0,total_sims):
|
267 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
268 |
+
|
269 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
270 |
+
overall_file.astype('int').dtypes
|
271 |
+
|
272 |
+
players_only = hold_file[['Player']]
|
273 |
+
raw_lineups_file = players_only
|
274 |
+
|
275 |
+
for x in range(0,total_sims):
|
276 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
277 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
278 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
279 |
+
|
280 |
+
players_only=players_only.drop(['Player'], axis=1)
|
281 |
+
players_only.astype('int').dtypes
|
282 |
+
|
283 |
+
salary_2x_check = (overall_file - (salary_file*4))
|
284 |
+
salary_3x_check = (overall_file - (salary_file*5))
|
285 |
+
salary_4x_check = (overall_file - (salary_file*6))
|
286 |
+
gpp_check = (overall_file - ((salary_file*5)+10))
|
287 |
+
|
288 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
289 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
290 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
291 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
292 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
293 |
+
players_only['3x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
294 |
+
players_only['4x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
295 |
+
players_only['5x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
296 |
+
players_only['GPP%'] = salary_4x_check[gpp_check >= 1].count(axis=1)/float(total_sims)
|
297 |
+
|
298 |
+
players_only['Player'] = hold_file[['Player']]
|
299 |
+
|
300 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '3x%', '4x%', '5x%', 'GPP%']]
|
301 |
+
|
302 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
303 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '3x%', '4x%', '5x%', 'GPP%']]
|
304 |
+
|
305 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
306 |
+
final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
|
307 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
308 |
+
final_Proj['Own'] = final_Proj['Own'].astype('float')
|
309 |
+
final_Proj['Projection Rank'] = final_Proj.Top_finish.rank(pct = True)
|
310 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
311 |
+
final_Proj['LevX'] = (final_Proj['Projection Rank'] - final_Proj['Own Rank']) * 100
|
312 |
+
final_Proj['ValX'] = ((final_Proj[['4x%', '5x%']].mean(axis=1))*100) + final_Proj['LevX']
|
313 |
+
final_Proj['ValX'] = np.where(final_Proj['ValX'] > 100, 100, final_Proj['ValX'])
|
314 |
+
final_Proj['ValX'] = np.where(final_Proj['ValX'] < 0, 0, final_Proj['ValX'])
|
315 |
+
|
316 |
+
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']]
|
317 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
318 |
+
final_Proj['Player_swap'] = player_check
|
319 |
+
st.session_state.final_Proj = final_Proj
|
320 |
|
321 |
+
hold_container = st.empty()
|
322 |
+
with st.container():
|
323 |
proj_container = st.empty()
|
324 |
display_container = st.empty()
|
325 |
display_dl_container = st.empty()
|
326 |
+
col1, col2 = st.columns([7, 3])
|
327 |
+
with col1:
|
328 |
+
with proj_container:
|
329 |
+
proj_container = st.empty()
|
330 |
+
if 'display_portfolio' in st.session_state:
|
331 |
+
st.dataframe(st.session_state.display_portfolio.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
332 |
+
|
333 |
+
with display_container:
|
334 |
+
display_container = st.empty()
|
335 |
+
if 'final_Proj' in st.session_state:
|
336 |
+
st.dataframe(st.session_state.final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
337 |
+
with col2:
|
338 |
+
freq_container = st.empty()
|
339 |
+
with freq_container:
|
340 |
+
freq_container = st.empty()
|
341 |
+
if 'player_freq' in st.session_state:
|
342 |
+
st.dataframe(st.session_state.player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
343 |
|