James McCool
commited on
Commit
·
7ee8722
1
Parent(s):
9e7f389
Refactor payout calculation logic in app.py
Browse files- Improved the payout calculation by grouping entries based on tied positions, allowing for more efficient processing and accurate distribution of payouts.
- Replaced the previous row-wise application of the payout function with a grouped approach, enhancing performance and clarity in handling multiple tied entries.
app.py
CHANGED
|
@@ -445,10 +445,19 @@ if selected_tab == 'Data Load':
|
|
| 445 |
working_df['finish'] = working_df['index']
|
| 446 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 447 |
try:
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
except:
|
| 453 |
pass
|
| 454 |
|
|
@@ -527,10 +536,19 @@ if selected_tab == 'Data Load':
|
|
| 527 |
working_df['finish'] = working_df['index']
|
| 528 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 529 |
try:
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
except:
|
| 535 |
pass
|
| 536 |
|
|
|
|
| 445 |
working_df['finish'] = working_df['index']
|
| 446 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 447 |
try:
|
| 448 |
+
# Calculate payouts efficiently by processing each unique tie group once
|
| 449 |
+
working_df['payout'] = 0 # Initialize payout column
|
| 450 |
+
|
| 451 |
+
# Group by dupes and finish position to process each tie group
|
| 452 |
+
for (dupes, finish), group in working_df.groupby(['dupes', 'finish']):
|
| 453 |
+
if dupes == 1:
|
| 454 |
+
# Single entry - no tie
|
| 455 |
+
payout = get_payout_for_position(finish, st.session_state['payout_info'], 1)
|
| 456 |
+
working_df.loc[group.index, 'payout'] = payout
|
| 457 |
+
else:
|
| 458 |
+
# Multiple entries tied - calculate split payout once and apply to all
|
| 459 |
+
split_payout = get_payout_for_position(finish, st.session_state['payout_info'], dupes)
|
| 460 |
+
working_df.loc[group.index, 'payout'] = split_payout
|
| 461 |
except:
|
| 462 |
pass
|
| 463 |
|
|
|
|
| 536 |
working_df['finish'] = working_df['index']
|
| 537 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 538 |
try:
|
| 539 |
+
# Calculate payouts efficiently by processing each unique tie group once
|
| 540 |
+
working_df['payout'] = 0 # Initialize payout column
|
| 541 |
+
|
| 542 |
+
# Group by dupes and finish position to process each tie group
|
| 543 |
+
for (dupes, finish), group in working_df.groupby(['dupes', 'finish']):
|
| 544 |
+
if dupes == 1:
|
| 545 |
+
# Single entry - no tie
|
| 546 |
+
payout = get_payout_for_position(finish, st.session_state['payout_info'], 1)
|
| 547 |
+
working_df.loc[group.index, 'payout'] = payout
|
| 548 |
+
else:
|
| 549 |
+
# Multiple entries tied - calculate split payout once and apply to all
|
| 550 |
+
split_payout = get_payout_for_position(finish, st.session_state['payout_info'], dupes)
|
| 551 |
+
working_df.loc[group.index, 'payout'] = split_payout
|
| 552 |
except:
|
| 553 |
pass
|
| 554 |
|