Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
cceb4bf
1
Parent(s):
8541b66
Refactor VORP scoring and roster assignment in Streamlit app to include halfPPR and custom match dictionaries, enhancing accuracy in player evaluations and simplifying the function signatures for better clarity.
Browse files- src/streamlit_app.py +13 -18
src/streamlit_app.py
CHANGED
@@ -383,31 +383,26 @@ def assign_vorp_scoring(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict,
|
|
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 |
orig_rank_dict = dict(zip(vorp_frame['Name'], vorp_frame['pos_designation']))
|
|
|
|
|
386 |
|
387 |
-
return pos_des_dict, orig_rank_dict
|
388 |
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
elif league_settings['TYPE'] == 'PPR':
|
393 |
-
rv_type = 'ppr'
|
394 |
-
elif league_settings['TYPE'] == 'Standard':
|
395 |
-
rv_type = 'standard'
|
396 |
-
elif league_settings['TYPE'] == 'Superflex':
|
397 |
-
rv_type = 'halfPpr'
|
398 |
-
elif league_settings['TYPE'] == 'TE Premium':
|
399 |
-
rv_type = 'halfPpr'
|
400 |
|
401 |
vorp_frame = pd.DataFrame()
|
402 |
for positions in ['QB', 'RB', 'WR', 'TE']:
|
403 |
pos_frame = frame[frame['Pos'] == positions]
|
404 |
pos_frame = pos_frame[pos_frame['Rank'] != 0]
|
405 |
pos_frame = pos_frame.sort_values(by='Rank', ascending=True).reset_index(drop=True)
|
|
|
|
|
406 |
|
407 |
pos_frame['halfPpr_rv'] = halfPpr_rv[positions]
|
408 |
pos_frame['custom_rv'] = custom_rv[positions]
|
409 |
-
pos_frame['halfPpr_VORP'] = pos_frame[
|
410 |
-
pos_frame['custom_VORP'] = pos_frame[
|
411 |
|
412 |
vorp_frame = pd.concat([vorp_frame, pos_frame]).reset_index(drop=True)
|
413 |
|
@@ -445,11 +440,11 @@ def main():
|
|
445 |
custom_roster_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
|
446 |
|
447 |
# Calculate VORP and rankings
|
448 |
-
pos_des_dict, orig_rank_dict = assign_vorp_scoring(position_df, halfPpr_rv, custom_scoring_rv, user_league_settings, user_pos_vorp_limiters)
|
449 |
-
final_df = assign_vorp_roster(position_df, halfPpr_rv, custom_roster_rv, user_league_settings, user_pos_vorp_limiters)
|
450 |
final_df = final_df.drop(columns=['SR_ID'], axis=1)
|
451 |
-
final_df['
|
452 |
-
final_df['
|
453 |
|
454 |
# Display results
|
455 |
st.header("Player Rankings")
|
|
|
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 |
orig_rank_dict = dict(zip(vorp_frame['Name'], vorp_frame['pos_designation']))
|
386 |
+
half_ppr_match_dict = dict(zip(vorp_frame['pos_designation'], vorp_frame['halfPpr']))
|
387 |
+
custom_match_dict = dict(zip(vorp_frame['pos_designation'], vorp_frame[rv_type]))
|
388 |
|
|
|
389 |
|
390 |
+
return pos_des_dict, orig_rank_dict, half_ppr_match_dict, custom_match_dict
|
391 |
+
|
392 |
+
def assign_vorp_roster(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, pos_vorp_limiters: dict, half_ppr_match_dict: dict, custom_match_dict: dict) -> pd.DataFrame:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
|
394 |
vorp_frame = pd.DataFrame()
|
395 |
for positions in ['QB', 'RB', 'WR', 'TE']:
|
396 |
pos_frame = frame[frame['Pos'] == positions]
|
397 |
pos_frame = pos_frame[pos_frame['Rank'] != 0]
|
398 |
pos_frame = pos_frame.sort_values(by='Rank', ascending=True).reset_index(drop=True)
|
399 |
+
halfPpr_rv_var = pos_frame['Rank'].map(half_ppr_match_dict)
|
400 |
+
custom_rv_var = pos_frame['Rank'].map(custom_match_dict)
|
401 |
|
402 |
pos_frame['halfPpr_rv'] = halfPpr_rv[positions]
|
403 |
pos_frame['custom_rv'] = custom_rv[positions]
|
404 |
+
pos_frame['halfPpr_VORP'] = pos_frame[halfPpr_rv_var] - halfPpr_rv[positions]
|
405 |
+
pos_frame['custom_VORP'] = pos_frame[custom_rv_var] - custom_rv[positions]
|
406 |
|
407 |
vorp_frame = pd.concat([vorp_frame, pos_frame]).reset_index(drop=True)
|
408 |
|
|
|
440 |
custom_roster_rv = create_custom_rv(position_df, custom_pos_reqs, user_league_settings)
|
441 |
|
442 |
# Calculate VORP and rankings
|
443 |
+
pos_des_dict, orig_rank_dict, half_ppr_match_dict, custom_match_dict = assign_vorp_scoring(position_df, halfPpr_rv, custom_scoring_rv, user_league_settings, user_pos_vorp_limiters)
|
444 |
+
final_df = assign_vorp_roster(position_df, halfPpr_rv, custom_roster_rv, user_league_settings, user_pos_vorp_limiters, half_ppr_match_dict, custom_match_dict)
|
445 |
final_df = final_df.drop(columns=['SR_ID'], axis=1)
|
446 |
+
final_df['Name_Lookup'] = final_df['Name'].map(orig_rank_dict)
|
447 |
+
final_df['Scoring_Lookup'] = final_df['pos_designation'].map(pos_des_dict)
|
448 |
|
449 |
# Display results
|
450 |
st.header("Player Rankings")
|