James McCool commited on
Commit
ccdf83a
·
1 Parent(s): 7ee8722

Refactor payout calculation for tied positions in app.py

Browse files

- Updated the get_payout_for_position function to correctly handle 1-indexed positions when calculating payouts for ties, ensuring accurate payout distribution.
- Adjusted the range in the payout calculation loop to reflect the new indexing, improving the clarity and correctness of the payout logic.

Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -127,11 +127,15 @@ def get_payout_for_position(finish_pos, payout_df, dupes_count):
127
  return 0
128
  else:
129
  # Handle tie - sum payouts for the range of positions and divide by number of ties
 
 
 
 
130
  total_payout = 0
131
- for pos in range(finish_pos, finish_pos + dupes_count):
132
  matching_row = payout_df[
133
- (payout_df['minPosition'] <= pos + 1) &
134
- (payout_df['maxPosition'] >= pos + 1)
135
  ]
136
  if not matching_row.empty:
137
  total_payout += matching_row.iloc[0]['value']
 
127
  return 0
128
  else:
129
  # Handle tie - sum payouts for the range of positions and divide by number of ties
130
+ # Convert to 1-indexed positions for payout lookup
131
+ start_pos = finish_pos + 1 # 1-indexed start position
132
+ end_pos = finish_pos + dupes_count # 1-indexed end position
133
+
134
  total_payout = 0
135
+ for pos in range(start_pos, end_pos + 1):
136
  matching_row = payout_df[
137
+ (payout_df['minPosition'] <= pos) &
138
+ (payout_df['maxPosition'] >= pos)
139
  ]
140
  if not matching_row.empty:
141
  total_payout += matching_row.iloc[0]['value']