James McCool commited on
Commit
c7bda3f
·
1 Parent(s): c9a8444

Enhance VORP calculations in Streamlit app by introducing adjusted rankings and position locks for players, improving accuracy in player evaluations and rankings across positions.

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +27 -8
src/streamlit_app.py CHANGED
@@ -363,13 +363,27 @@ def assign_vorp(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_s
363
  vorp_frame = pd.DataFrame()
364
  for positions in ['QB', 'RB', 'WR', 'TE']:
365
  pos_frame = frame[frame['Pos'] == positions]
366
- pos_frame = pos_frame[pos_frame['Rank'] != 0].reset_index(drop=True)
367
- pos_frame = pos_frame.sort_values(by='Rank', ascending=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
 
369
  pos_frame['halfPpr_rv'] = halfPpr_rv[positions]
370
  pos_frame['custom_rv'] = custom_rv[positions]
371
- pos_frame['halfPpr_VORP'] = pos_frame['halfPpr'] - halfPpr_rv[positions]
372
- pos_frame['custom_VORP'] = pos_frame[rv_type] - custom_rv[positions]
373
 
374
  vorp_frame = pd.concat([vorp_frame, pos_frame]).reset_index(drop=True)
375
 
@@ -378,11 +392,13 @@ def assign_vorp(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_s
378
  vorp_frame['vorp_diff'] = np.where(vorp_frame['halfPpr_VORP'] == vorp_frame['custom_VORP'], 0, vorp_frame['halfPpr_vorp_rank'] - vorp_frame['custom_vorp_rank'])
379
  for positions in ['QB', 'RB', 'WR', 'TE']:
380
  vorp_frame.loc[vorp_frame['Pos'] == positions, 'Rank_Adjust'] = (vorp_frame['Rank'] - (vorp_frame['vorp_diff'] * pos_vorp_limiters[positions])).astype(float)
 
 
381
  vorp_frame['custom_rank'] = vorp_frame['Rank_Adjust'].rank(method='first', ascending=True)
 
 
382
 
383
- print(vorp_frame.sort_values(by='custom_vorp_rank', ascending=True).head(50))
384
-
385
- return vorp_frame.sort_values(by='custom_rank', ascending=True)
386
 
387
  def main():
388
  st.title("Fantasy Football VORP Calculator")
@@ -406,7 +422,10 @@ def main():
406
  custom_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
407
 
408
  # Calculate VORP and rankings
409
- final_df = assign_vorp(position_df, halfPpr_rv, custom_rv, user_league_settings, user_pos_vorp_limiters)
 
 
 
410
 
411
  # Display results
412
  st.header("Player Rankings")
 
363
  vorp_frame = pd.DataFrame()
364
  for positions in ['QB', 'RB', 'WR', 'TE']:
365
  pos_frame = frame[frame['Pos'] == positions]
366
+ pos_frame = pos_frame[pos_frame['Rank'] != 0]
367
+ pos_frame = pos_frame.sort_values(by='Rank', ascending=True).reset_index(drop=True)
368
+ pos_frame['custom_rank_raw'] = pos_frame[rv_type].rank(method='first', ascending=False)
369
+ pos_frame['custom_calc'] = ((pos_frame['custom_rank_raw'] + pos_frame['Rank']) / 2).astype(int)
370
+ pos_frame['custom_proj_rank'] = pos_frame['custom_calc'].rank(method='first', ascending=True).astype(int)
371
+
372
+ pos_frame['max_halfPpr'] = pos_frame['halfPpr'].max()
373
+ pos_frame['halfPpr_range'] = (pos_frame['max_halfPpr']) / len(pos_frame)
374
+ pos_frame['adj_halfPpr'] = pos_frame['halfPpr_range'] * (len(pos_frame) - (pos_frame.index))
375
+
376
+ pos_frame['max_custom'] = pos_frame[rv_type].max()
377
+ pos_frame['custom_range'] = (pos_frame['max_custom']) / len(pos_frame)
378
+ pos_frame['adj_custom'] = pos_frame['custom_range'] * (len(pos_frame) - (pos_frame['custom_proj_rank'] - 1))
379
+ pos_frame['pos_lock'] = (pos_frame['Pos'].astype(str) + pos_frame['custom_proj_rank'].astype(str))
380
+
381
+ print(pos_frame[['Name', 'Rank', 'custom_proj_rank', 'halfPpr', rv_type, 'adj_halfPpr', 'adj_custom', 'pos_lock']].head(20))
382
 
383
  pos_frame['halfPpr_rv'] = halfPpr_rv[positions]
384
  pos_frame['custom_rv'] = custom_rv[positions]
385
+ pos_frame['halfPpr_VORP'] = pos_frame['adj_halfPpr'] - halfPpr_rv[positions]
386
+ pos_frame['custom_VORP'] = pos_frame['adj_custom'] - custom_rv[positions]
387
 
388
  vorp_frame = pd.concat([vorp_frame, pos_frame]).reset_index(drop=True)
389
 
 
392
  vorp_frame['vorp_diff'] = np.where(vorp_frame['halfPpr_VORP'] == vorp_frame['custom_VORP'], 0, vorp_frame['halfPpr_vorp_rank'] - vorp_frame['custom_vorp_rank'])
393
  for positions in ['QB', 'RB', 'WR', 'TE']:
394
  vorp_frame.loc[vorp_frame['Pos'] == positions, 'Rank_Adjust'] = (vorp_frame['Rank'] - (vorp_frame['vorp_diff'] * pos_vorp_limiters[positions])).astype(float)
395
+ pos_lock_dict = dict(zip(vorp_frame['pos_lock'], vorp_frame['Name']))
396
+ name_lock_dict = dict(zip(vorp_frame['Name'], vorp_frame['pos_lock']))
397
  vorp_frame['custom_rank'] = vorp_frame['Rank_Adjust'].rank(method='first', ascending=True)
398
+ vorp_frame['pos_rank'] = vorp_frame.groupby('Pos')['custom_rank'].rank(method='first', ascending=True).astype(int)
399
+ vorp_frame['pos_designation'] = vorp_frame['Pos'] + vorp_frame['pos_rank'].astype(str)
400
 
401
+ return vorp_frame.sort_values(by='custom_rank', ascending=True), pos_lock_dict, name_lock_dict
 
 
402
 
403
  def main():
404
  st.title("Fantasy Football VORP Calculator")
 
422
  custom_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
423
 
424
  # Calculate VORP and rankings
425
+ final_df, pos_lock_dict, name_lock_dict = assign_vorp(position_df, halfPpr_rv, custom_rv, user_league_settings, user_pos_vorp_limiters)
426
+ final_df = final_df.drop(columns=['SR_ID'], axis=1)
427
+ final_df['pos_lock_lu'] = final_df['Name'].map(name_lock_dict)
428
+ final_df['pos_lock_name'] = final_df['pos_designation'].map(pos_lock_dict)
429
 
430
  # Display results
431
  st.header("Player Rankings")