Spaces:
Sleeping
Sleeping
James McCool commited on
Commit ·
4e0ef71
1
Parent(s): edd8d5b
Refactor VORP scoring logic in Streamlit app to include league type conditions and enhance player ranking calculations, improving accuracy and output structure for halfPPR and custom scoring formats.
Browse files- src/streamlit_app.py +45 -6
src/streamlit_app.py
CHANGED
|
@@ -348,7 +348,44 @@ def create_custom_rv(frame: pd.DataFrame, pos_reqs: dict, league_settings: dict)
|
|
| 348 |
|
| 349 |
return rv_dict
|
| 350 |
|
| 351 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
if league_settings['TYPE'] == 'Half PPR':
|
| 353 |
rv_type = 'halfPpr'
|
| 354 |
elif league_settings['TYPE'] == 'PPR':
|
|
@@ -425,13 +462,15 @@ def main():
|
|
| 425 |
|
| 426 |
# Calculate replacement values
|
| 427 |
halfPpr_rv = create_halfPpr_rv(position_df, base_pos_reqs)
|
| 428 |
-
|
|
|
|
| 429 |
|
| 430 |
# Calculate VORP and rankings
|
| 431 |
-
|
| 432 |
-
final_df =
|
|
|
|
| 433 |
final_df['orig_rank'] = final_df['Name'].map(name_lock_dict)
|
| 434 |
-
final_df['pos_lock_name'] = final_df['pos_designation'].map(
|
| 435 |
|
| 436 |
# Display results
|
| 437 |
st.header("Player Rankings")
|
|
@@ -440,7 +479,7 @@ def main():
|
|
| 440 |
# Position breakdown
|
| 441 |
st.header("Position Breakdown")
|
| 442 |
for pos in ['QB', 'RB', 'WR', 'TE']:
|
| 443 |
-
pos_df = final_df[final_df['Pos'] == pos].head(
|
| 444 |
st.subheader(f"Top {pos}s")
|
| 445 |
st.dataframe(pos_df, use_container_width=True)
|
| 446 |
|
|
|
|
| 348 |
|
| 349 |
return rv_dict
|
| 350 |
|
| 351 |
+
def assign_vorp_scoring(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_settings: dict, pos_vorp_limiters: dict) -> pd.DataFrame:
|
| 352 |
+
if league_settings['TYPE'] == 'Half PPR':
|
| 353 |
+
rv_type = 'halfPpr'
|
| 354 |
+
elif league_settings['TYPE'] == 'PPR':
|
| 355 |
+
rv_type = 'ppr'
|
| 356 |
+
elif league_settings['TYPE'] == 'Standard':
|
| 357 |
+
rv_type = 'standard'
|
| 358 |
+
elif league_settings['TYPE'] == 'Superflex':
|
| 359 |
+
rv_type = 'halfPpr'
|
| 360 |
+
elif league_settings['TYPE'] == 'TE Premium':
|
| 361 |
+
rv_type = 'halfPpr'
|
| 362 |
+
|
| 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 |
+
|
| 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 |
+
|
| 376 |
+
vorp_frame['halfPpr_vorp_rank'] = vorp_frame['halfPpr_VORP'].rank(method='max', ascending=False)
|
| 377 |
+
vorp_frame['custom_vorp_rank'] = vorp_frame['custom_VORP'].rank(method='max', ascending=False)
|
| 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).astype(int)
|
| 382 |
+
vorp_frame['pos_rank'] = vorp_frame.groupby('Pos')['custom_rank'].rank(method='first', ascending=True).astype(int)
|
| 383 |
+
vorp_frame['pos_designation'] = vorp_frame['Pos'] + vorp_frame['pos_rank'].astype(str)
|
| 384 |
+
pos_des_dict = dict(zip(vorp_frame['pos_designation'], vorp_frame['Name']))
|
| 385 |
+
|
| 386 |
+
return pos_des_dict
|
| 387 |
+
|
| 388 |
+
def assign_vorp_roster(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_settings: dict, pos_vorp_limiters: dict) -> pd.DataFrame:
|
| 389 |
if league_settings['TYPE'] == 'Half PPR':
|
| 390 |
rv_type = 'halfPpr'
|
| 391 |
elif league_settings['TYPE'] == 'PPR':
|
|
|
|
| 462 |
|
| 463 |
# Calculate replacement values
|
| 464 |
halfPpr_rv = create_halfPpr_rv(position_df, base_pos_reqs)
|
| 465 |
+
custom_scoring_rv = create_custom_rv(position_df, base_pos_reqs, user_league_settings)
|
| 466 |
+
custom_roster_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
|
| 467 |
|
| 468 |
# Calculate VORP and rankings
|
| 469 |
+
pos_des_dict = assign_vorp_scoring(position_df, halfPpr_rv, custom_scoring_rv, user_league_settings, user_pos_vorp_limiters)
|
| 470 |
+
final_df = assign_vorp_roster(position_df, halfPpr_rv, custom_roster_rv, user_league_settings, user_pos_vorp_limiters)
|
| 471 |
+
final_df, pos_lock_dict, name_lock_dict = final_df.drop(columns=['SR_ID'], axis=1)
|
| 472 |
final_df['orig_rank'] = final_df['Name'].map(name_lock_dict)
|
| 473 |
+
final_df['pos_lock_name'] = final_df['pos_designation'].map(pos_des_dict)
|
| 474 |
|
| 475 |
# Display results
|
| 476 |
st.header("Player Rankings")
|
|
|
|
| 479 |
# Position breakdown
|
| 480 |
st.header("Position Breakdown")
|
| 481 |
for pos in ['QB', 'RB', 'WR', 'TE']:
|
| 482 |
+
pos_df = final_df[final_df['Pos'] == pos].head(50)
|
| 483 |
st.subheader(f"Top {pos}s")
|
| 484 |
st.dataframe(pos_df, use_container_width=True)
|
| 485 |
|