James McCool
commited on
Commit
·
209a946
1
Parent(s):
7e6e154
Enhance payout calculation logic in app.py
Browse files- Updated the get_payout_for_position function to handle ties by splitting the payout among tied positions, improving accuracy in payout calculations.
- Adjusted the application of the function in the dataframe to include the count of tied entries, ensuring correct payout values are computed for each finish position.
app.py
CHANGED
|
@@ -106,16 +106,38 @@ def export_contest_file(db, sport, type, contest_date, contest_id, contest_data)
|
|
| 106 |
|
| 107 |
return return_message
|
| 108 |
|
| 109 |
-
def get_payout_for_position(finish_pos, payout_df):
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
else:
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
def color_roi(val):
|
| 121 |
"""Color ROI values: green if > 100%, red if < 100%"""
|
|
@@ -424,7 +446,7 @@ if selected_tab == 'Data Load':
|
|
| 424 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 425 |
try:
|
| 426 |
working_df['payout'] = working_df['finish'].apply(
|
| 427 |
-
lambda x: get_payout_for_position(x, st.session_state['payout_info'])
|
| 428 |
)
|
| 429 |
except:
|
| 430 |
pass
|
|
@@ -505,7 +527,7 @@ if selected_tab == 'Data Load':
|
|
| 505 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 506 |
try:
|
| 507 |
working_df['payout'] = working_df['finish'].apply(
|
| 508 |
-
lambda x: get_payout_for_position(x, st.session_state['payout_info'])
|
| 509 |
)
|
| 510 |
except:
|
| 511 |
pass
|
|
|
|
| 106 |
|
| 107 |
return return_message
|
| 108 |
|
| 109 |
+
def get_payout_for_position(finish_pos, payout_df, dupes_count=1):
|
| 110 |
+
"""
|
| 111 |
+
Calculate payout for a position, handling ties by splitting the combined payout.
|
| 112 |
+
|
| 113 |
+
Args:
|
| 114 |
+
finish_pos: The finish position (0-indexed)
|
| 115 |
+
payout_df: DataFrame with payout structure
|
| 116 |
+
dupes_count: Number of entries that are tied (from the 'dupes' column)
|
| 117 |
+
"""
|
| 118 |
+
if dupes_count == 1:
|
| 119 |
+
# Single position, no tie
|
| 120 |
+
matching_row = payout_df[
|
| 121 |
+
(payout_df['minPosition'] <= finish_pos + 1) &
|
| 122 |
+
(payout_df['maxPosition'] >= finish_pos + 1)
|
| 123 |
+
]
|
| 124 |
+
if not matching_row.empty:
|
| 125 |
+
return matching_row.iloc[0]['value']
|
| 126 |
+
else:
|
| 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']
|
| 138 |
+
|
| 139 |
+
# Return the split payout
|
| 140 |
+
return total_payout / dupes_count
|
| 141 |
|
| 142 |
def color_roi(val):
|
| 143 |
"""Color ROI values: green if > 100%, red if < 100%"""
|
|
|
|
| 446 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 447 |
try:
|
| 448 |
working_df['payout'] = working_df['finish'].apply(
|
| 449 |
+
lambda x: get_payout_for_position(x, st.session_state['payout_info'], working_df['dupes'])
|
| 450 |
)
|
| 451 |
except:
|
| 452 |
pass
|
|
|
|
| 527 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 528 |
try:
|
| 529 |
working_df['payout'] = working_df['finish'].apply(
|
| 530 |
+
lambda x: get_payout_for_position(x, st.session_state['payout_info'], working_df['dupes'])
|
| 531 |
)
|
| 532 |
except:
|
| 533 |
pass
|