Spaces:
Sleeping
Sleeping
Refactor VORP calculation in Streamlit app by removing position lock logic and adjusting output format, streamlining player ranking process and enhancing clarity in displayed results.
Browse files- src/streamlit_app.py +6 -12
src/streamlit_app.py
CHANGED
|
@@ -367,7 +367,7 @@ def assign_vorp(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_s
|
|
| 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)
|
| 371 |
|
| 372 |
pos_frame['max_halfPpr'] = pos_frame['halfPpr'].max()
|
| 373 |
pos_frame['halfPpr_range'] = (pos_frame['max_halfPpr']) / len(pos_frame)
|
|
@@ -376,9 +376,8 @@ def assign_vorp(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_s
|
|
| 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'
|
| 382 |
|
| 383 |
pos_frame['halfPpr_rv'] = halfPpr_rv[positions]
|
| 384 |
pos_frame['custom_rv'] = custom_rv[positions]
|
|
@@ -392,13 +391,11 @@ def assign_vorp(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_s
|
|
| 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 |
-
|
|
|
|
|
|
|
| 402 |
|
| 403 |
def main():
|
| 404 |
st.title("Fantasy Football VORP Calculator")
|
|
@@ -422,10 +419,7 @@ def main():
|
|
| 422 |
custom_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
|
| 423 |
|
| 424 |
# Calculate VORP and rankings
|
| 425 |
-
final_df
|
| 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")
|
|
|
|
| 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)
|
| 371 |
|
| 372 |
pos_frame['max_halfPpr'] = pos_frame['halfPpr'].max()
|
| 373 |
pos_frame['halfPpr_range'] = (pos_frame['max_halfPpr']) / len(pos_frame)
|
|
|
|
| 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 |
|
| 380 |
+
print(pos_frame[['Name', 'Rank', 'custom_proj_rank', 'halfPpr', rv_type, 'adj_halfPpr', 'adj_custom']].head(20))
|
| 381 |
|
| 382 |
pos_frame['halfPpr_rv'] = halfPpr_rv[positions]
|
| 383 |
pos_frame['custom_rv'] = custom_rv[positions]
|
|
|
|
| 391 |
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'])
|
| 392 |
for positions in ['QB', 'RB', 'WR', 'TE']:
|
| 393 |
vorp_frame.loc[vorp_frame['Pos'] == positions, 'Rank_Adjust'] = (vorp_frame['Rank'] - (vorp_frame['vorp_diff'] * pos_vorp_limiters[positions])).astype(float)
|
|
|
|
|
|
|
| 394 |
vorp_frame['custom_rank'] = vorp_frame['Rank_Adjust'].rank(method='first', ascending=True)
|
|
|
|
|
|
|
| 395 |
|
| 396 |
+
print(vorp_frame.sort_values(by='custom_vorp_rank', ascending=True).head(50))
|
| 397 |
+
|
| 398 |
+
return vorp_frame.sort_values(by='custom_rank', ascending=True)
|
| 399 |
|
| 400 |
def main():
|
| 401 |
st.title("Fantasy Football VORP Calculator")
|
|
|
|
| 419 |
custom_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
|
| 420 |
|
| 421 |
# Calculate VORP and rankings
|
| 422 |
+
final_df = assign_vorp(position_df, halfPpr_rv, custom_rv, user_league_settings, user_pos_vorp_limiters)
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
# Display results
|
| 425 |
st.header("Player Rankings")
|