James McCool commited on
Commit
31e306d
·
1 Parent(s): ccdf83a

Refactor payout calculation logic in app.py

Browse files

- Updated the payout calculation to group by actual fantasy points instead of tied positions, improving efficiency and accuracy in payout distribution.
- Simplified the logic for handling single and multiple tied entries, ensuring consistent application of payouts across grouped entries.

Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -449,19 +449,26 @@ if selected_tab == 'Data Load':
449
  working_df['finish'] = working_df['index']
450
  working_df = working_df.drop(['sorted', 'index'], axis=1)
451
  try:
452
- # Calculate payouts efficiently by processing each unique tie group once
453
  working_df['payout'] = 0 # Initialize payout column
454
 
455
- # Group by dupes and finish position to process each tie group
456
- for (dupes, finish), group in working_df.groupby(['dupes', 'finish']):
457
- if dupes == 1:
 
 
 
 
 
458
  # Single entry - no tie
459
- payout = get_payout_for_position(finish, st.session_state['payout_info'], 1)
460
- working_df.loc[group.index, 'payout'] = payout
461
  else:
462
- # Multiple entries tied - calculate split payout once and apply to all
463
- split_payout = get_payout_for_position(finish, st.session_state['payout_info'], dupes)
464
- working_df.loc[group.index, 'payout'] = split_payout
 
 
 
465
  except:
466
  pass
467
 
@@ -540,19 +547,26 @@ if selected_tab == 'Data Load':
540
  working_df['finish'] = working_df['index']
541
  working_df = working_df.drop(['sorted', 'index'], axis=1)
542
  try:
543
- # Calculate payouts efficiently by processing each unique tie group once
544
  working_df['payout'] = 0 # Initialize payout column
545
 
546
- # Group by dupes and finish position to process each tie group
547
- for (dupes, finish), group in working_df.groupby(['dupes', 'finish']):
548
- if dupes == 1:
 
 
 
 
 
549
  # Single entry - no tie
550
- payout = get_payout_for_position(finish, st.session_state['payout_info'], 1)
551
- working_df.loc[group.index, 'payout'] = payout
552
  else:
553
- # Multiple entries tied - calculate split payout once and apply to all
554
- split_payout = get_payout_for_position(finish, st.session_state['payout_info'], dupes)
555
- working_df.loc[group.index, 'payout'] = split_payout
 
 
 
556
  except:
557
  pass
558
 
 
449
  working_df['finish'] = working_df['index']
450
  working_df = working_df.drop(['sorted', 'index'], axis=1)
451
  try:
452
+ # Calculate payouts efficiently by processing each unique fantasy points group
453
  working_df['payout'] = 0 # Initialize payout column
454
 
455
+ # Group by actual_fpts since tied entries will have the same fantasy points
456
+ for fpts, group in working_df.groupby('actual_fpts'):
457
+ # Get the first row's finish position and dupes count
458
+ first_row = group.iloc[0]
459
+ finish_pos = first_row['finish']
460
+ dupes_count = first_row['dupes']
461
+
462
+ if dupes_count == 1:
463
  # Single entry - no tie
464
+ payout = get_payout_for_position(finish_pos, st.session_state['payout_info'], 1)
 
465
  else:
466
+ # Multiple entries tied - calculate split payout once
467
+ split_payout = get_payout_for_position(finish_pos, st.session_state['payout_info'], dupes_count)
468
+ payout = split_payout
469
+
470
+ # Apply the same payout to all rows in this group
471
+ working_df.loc[group.index, 'payout'] = payout
472
  except:
473
  pass
474
 
 
547
  working_df['finish'] = working_df['index']
548
  working_df = working_df.drop(['sorted', 'index'], axis=1)
549
  try:
550
+ # Calculate payouts efficiently by processing each unique fantasy points group
551
  working_df['payout'] = 0 # Initialize payout column
552
 
553
+ # Group by actual_fpts since tied entries will have the same fantasy points
554
+ for fpts, group in working_df.groupby('actual_fpts'):
555
+ # Get the first row's finish position and dupes count
556
+ first_row = group.iloc[0]
557
+ finish_pos = first_row['finish']
558
+ dupes_count = first_row['dupes']
559
+
560
+ if dupes_count == 1:
561
  # Single entry - no tie
562
+ payout = get_payout_for_position(finish_pos, st.session_state['payout_info'], 1)
 
563
  else:
564
+ # Multiple entries tied - calculate split payout once
565
+ split_payout = get_payout_for_position(finish_pos, st.session_state['payout_info'], dupes_count)
566
+ payout = split_payout
567
+
568
+ # Apply the same payout to all rows in this group
569
+ working_df.loc[group.index, 'payout'] = payout
570
  except:
571
  pass
572