James McCool
commited on
Commit
·
b53e467
1
Parent(s):
17b7fee
Refactor predict_dupes function to enhance League of Legends (LOL) support, adding specific calculations for ownership percentages and ranks, while maintaining existing logic for CS2. This improves accuracy in player predictions and ensures consistent handling of duplicate calculations across both sports.
Browse files- global_func/predict_dupes.py +50 -1
global_func/predict_dupes.py
CHANGED
|
@@ -435,7 +435,7 @@ def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, streng
|
|
| 435 |
np.round(portfolio['dupes_calc'], 0) - 1
|
| 436 |
)
|
| 437 |
elif type_var == 'Classic':
|
| 438 |
-
if sport_var == 'CS2'
|
| 439 |
dup_count_columns = ['CPT_Own_percent_rank', 'FLEX1_Own_percent_rank', 'FLEX2_Own_percent_rank', 'FLEX3_Own_percent_rank', 'FLEX4_Own_percent_rank', 'FLEX5_Own_percent_rank']
|
| 440 |
own_columns = ['CPT_Own', 'FLEX1_Own', 'FLEX2_Own', 'FLEX3_Own', 'FLEX4_Own', 'FLEX5_Own']
|
| 441 |
calc_columns = ['own_product', 'own_average', 'own_sum', 'avg_own_rank', 'dupes_calc', 'low_own_count', 'Ref_Proj', 'Max_Proj', 'Min_Proj', 'Avg_Ref', 'own_ratio']
|
|
@@ -475,6 +475,55 @@ def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, streng
|
|
| 475 |
portfolio['dupes_calc'] = (portfolio['own_product'] * portfolio['avg_own_rank']) * Contest_Size + ((portfolio['salary'] - (50000 - portfolio['Own'])) / 100) - ((50000 - portfolio['salary']) / 100)
|
| 476 |
portfolio['dupes_calc'] = portfolio['dupes_calc'] * dupes_multiplier
|
| 477 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
# Round and handle negative values
|
| 479 |
portfolio['Dupes'] = np.where(
|
| 480 |
np.round(portfolio['dupes_calc'], 0) <= 0,
|
|
|
|
| 435 |
np.round(portfolio['dupes_calc'], 0) - 1
|
| 436 |
)
|
| 437 |
elif type_var == 'Classic':
|
| 438 |
+
if sport_var == 'CS2':
|
| 439 |
dup_count_columns = ['CPT_Own_percent_rank', 'FLEX1_Own_percent_rank', 'FLEX2_Own_percent_rank', 'FLEX3_Own_percent_rank', 'FLEX4_Own_percent_rank', 'FLEX5_Own_percent_rank']
|
| 440 |
own_columns = ['CPT_Own', 'FLEX1_Own', 'FLEX2_Own', 'FLEX3_Own', 'FLEX4_Own', 'FLEX5_Own']
|
| 441 |
calc_columns = ['own_product', 'own_average', 'own_sum', 'avg_own_rank', 'dupes_calc', 'low_own_count', 'Ref_Proj', 'Max_Proj', 'Min_Proj', 'Avg_Ref', 'own_ratio']
|
|
|
|
| 475 |
portfolio['dupes_calc'] = (portfolio['own_product'] * portfolio['avg_own_rank']) * Contest_Size + ((portfolio['salary'] - (50000 - portfolio['Own'])) / 100) - ((50000 - portfolio['salary']) / 100)
|
| 476 |
portfolio['dupes_calc'] = portfolio['dupes_calc'] * dupes_multiplier
|
| 477 |
|
| 478 |
+
# Round and handle negative values
|
| 479 |
+
portfolio['Dupes'] = np.where(
|
| 480 |
+
np.round(portfolio['dupes_calc'], 0) <= 0,
|
| 481 |
+
0,
|
| 482 |
+
np.round(portfolio['dupes_calc'], 0) - 1
|
| 483 |
+
)
|
| 484 |
+
if sport_var == 'LOL':
|
| 485 |
+
dup_count_columns = ['CPT_Own_percent_rank', 'TOP_Own_percent_rank', 'JNG_Own_percent_rank', 'MID_Own_percent_rank', 'ADC_Own_percent_rank', 'SUP_Own_percent_rank', 'Team_Own_percent_rank']
|
| 486 |
+
own_columns = ['CPT_Own', 'TOP_Own', 'JNG_Own', 'MID_Own', 'ADC_Own', 'SUP_Own', 'Team_Own']
|
| 487 |
+
calc_columns = ['own_product', 'own_average', 'own_sum', 'avg_own_rank', 'dupes_calc', 'low_own_count', 'Ref_Proj', 'Max_Proj', 'Min_Proj', 'Avg_Ref', 'own_ratio']
|
| 488 |
+
# Get the original player columns (first 6 columns excluding salary, median, Own)
|
| 489 |
+
player_columns = [col for col in portfolio.columns[:6] if col not in ['salary', 'median', 'Own']]
|
| 490 |
+
|
| 491 |
+
flex_ownerships = pd.concat([
|
| 492 |
+
portfolio.iloc[:,1].map(maps_dict['own_map']),
|
| 493 |
+
portfolio.iloc[:,2].map(maps_dict['own_map']),
|
| 494 |
+
portfolio.iloc[:,3].map(maps_dict['own_map']),
|
| 495 |
+
portfolio.iloc[:,4].map(maps_dict['own_map']),
|
| 496 |
+
portfolio.iloc[:,5].map(maps_dict['own_map']),
|
| 497 |
+
portfolio.iloc[:,6].map(maps_dict['own_map'])
|
| 498 |
+
])
|
| 499 |
+
flex_rank = flex_ownerships.rank(pct=True)
|
| 500 |
+
|
| 501 |
+
# Assign ranks back to individual columns using the same rank scale
|
| 502 |
+
portfolio['CPT_Own_percent_rank'] = portfolio.iloc[:,0].map(maps_dict['cpt_own_map']).rank(pct=True)
|
| 503 |
+
portfolio['TOP_Own_percent_rank'] = portfolio.iloc[:,1].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 504 |
+
portfolio['JNG_Own_percent_rank'] = portfolio.iloc[:,2].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 505 |
+
portfolio['MID_Own_percent_rank'] = portfolio.iloc[:,3].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 506 |
+
portfolio['ADC_Own_percent_rank'] = portfolio.iloc[:,4].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 507 |
+
portfolio['SUP_Own_percent_rank'] = portfolio.iloc[:,5].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 508 |
+
portfolio['Team_Own_percent_rank'] = portfolio.iloc[:,6].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 509 |
+
|
| 510 |
+
portfolio['CPT_Own'] = portfolio.iloc[:,0].map(maps_dict['cpt_own_map']).astype('float32') / 100
|
| 511 |
+
portfolio['TOP_Own'] = portfolio.iloc[:,1].map(maps_dict['own_map']).astype('float32') / 100
|
| 512 |
+
portfolio['JNG_Own'] = portfolio.iloc[:,2].map(maps_dict['own_map']).astype('float32') / 100
|
| 513 |
+
portfolio['MID_Own'] = portfolio.iloc[:,3].map(maps_dict['own_map']).astype('float32') / 100
|
| 514 |
+
portfolio['ADC_Own'] = portfolio.iloc[:,4].map(maps_dict['own_map']).astype('float32') / 100
|
| 515 |
+
portfolio['SUP_Own'] = portfolio.iloc[:,5].map(maps_dict['own_map']).astype('float32') / 100
|
| 516 |
+
portfolio['Team_Own'] = portfolio.iloc[:,6].map(maps_dict['own_map']).astype('float32') / 100
|
| 517 |
+
|
| 518 |
+
portfolio['own_product'] = (portfolio[own_columns].product(axis=1))
|
| 519 |
+
portfolio['own_average'] = (portfolio['Own'].max() * .33) / 100
|
| 520 |
+
portfolio['own_sum'] = portfolio[own_columns].sum(axis=1)
|
| 521 |
+
portfolio['avg_own_rank'] = portfolio[dup_count_columns].mean(axis=1)
|
| 522 |
+
|
| 523 |
+
# Calculate dupes formula
|
| 524 |
+
portfolio['dupes_calc'] = (portfolio['own_product'] * portfolio['avg_own_rank']) * Contest_Size + ((portfolio['salary'] - (50000 - portfolio['Own'])) / 100) - ((50000 - portfolio['salary']) / 100)
|
| 525 |
+
portfolio['dupes_calc'] = portfolio['dupes_calc'] * dupes_multiplier
|
| 526 |
+
|
| 527 |
# Round and handle negative values
|
| 528 |
portfolio['Dupes'] = np.where(
|
| 529 |
np.round(portfolio['dupes_calc'], 0) <= 0,
|