James McCool
commited on
Commit
·
bd90e32
1
Parent(s):
d619fee
Refactor portfolio duplication prediction in predict_dupes.py: enhance the function to accommodate sport-specific logic for CS2, improving ownership calculations and ensuring accurate duplication metrics based on player ownership and salary. Update app.py to pass sport_var to predict_dupes for better context in calculations.
Browse files- app.py +25 -12
- global_func/predict_dupes.py +63 -22
app.py
CHANGED
|
@@ -724,17 +724,30 @@ with tab2:
|
|
| 724 |
|
| 725 |
if site_var == 'Draftkings':
|
| 726 |
if type_var == 'Classic':
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
elif type_var == 'Showdown':
|
| 739 |
if sport_var == 'NFL':
|
| 740 |
map_dict = {
|
|
@@ -831,7 +844,7 @@ with tab2:
|
|
| 831 |
submitted = st.form_submit_button("Trim")
|
| 832 |
if submitted:
|
| 833 |
st.write('initiated')
|
| 834 |
-
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var)
|
| 835 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Dupes'] <= max_dupes]
|
| 836 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] >= min_salary]
|
| 837 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] <= max_salary]
|
|
|
|
| 724 |
|
| 725 |
if site_var == 'Draftkings':
|
| 726 |
if type_var == 'Classic':
|
| 727 |
+
if sport_var == 'CS2':
|
| 728 |
+
map_dict = {
|
| 729 |
+
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
| 730 |
+
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
| 731 |
+
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
| 732 |
+
'proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'])),
|
| 733 |
+
'own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['ownership'])),
|
| 734 |
+
'own_percent_rank':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['ownership'].rank(pct=True))),
|
| 735 |
+
'cpt_salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'] * 1.5)),
|
| 736 |
+
'cpt_proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'] * 1.5)),
|
| 737 |
+
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
| 738 |
+
}
|
| 739 |
+
elif sport_var != 'CS2':
|
| 740 |
+
map_dict = {
|
| 741 |
+
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
| 742 |
+
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
| 743 |
+
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
| 744 |
+
'proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'])),
|
| 745 |
+
'own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['ownership'])),
|
| 746 |
+
'own_percent_rank':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['ownership'].rank(pct=True))),
|
| 747 |
+
'cpt_salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
| 748 |
+
'cpt_proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'] * 1.5)),
|
| 749 |
+
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
| 750 |
+
}
|
| 751 |
elif type_var == 'Showdown':
|
| 752 |
if sport_var == 'NFL':
|
| 753 |
map_dict = {
|
|
|
|
| 844 |
submitted = st.form_submit_button("Trim")
|
| 845 |
if submitted:
|
| 846 |
st.write('initiated')
|
| 847 |
+
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
| 848 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Dupes'] <= max_dupes]
|
| 849 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] >= min_salary]
|
| 850 |
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] <= max_salary]
|
global_func/predict_dupes.py
CHANGED
|
@@ -5,7 +5,7 @@ import time
|
|
| 5 |
from fuzzywuzzy import process
|
| 6 |
import math
|
| 7 |
|
| 8 |
-
def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, strength_var):
|
| 9 |
if strength_var == 'Weak':
|
| 10 |
dupes_multiplier = .75
|
| 11 |
percentile_multiplier = .90
|
|
@@ -126,27 +126,68 @@ def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, streng
|
|
| 126 |
np.round(portfolio['dupes_calc'], 0) - 1
|
| 127 |
)
|
| 128 |
if type_var == 'Classic':
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
portfolio['Dupes'] = np.round(portfolio['Dupes'], 0)
|
| 152 |
portfolio['own_ratio'] = np.where(
|
|
|
|
| 5 |
from fuzzywuzzy import process
|
| 6 |
import math
|
| 7 |
|
| 8 |
+
def predict_dupes(portfolio, maps_dict, site_var, type_var, Contest_Size, strength_var, sport_var):
|
| 9 |
if strength_var == 'Weak':
|
| 10 |
dupes_multiplier = .75
|
| 11 |
percentile_multiplier = .90
|
|
|
|
| 126 |
np.round(portfolio['dupes_calc'], 0) - 1
|
| 127 |
)
|
| 128 |
if type_var == 'Classic':
|
| 129 |
+
if sport_var == 'CS2':
|
| 130 |
+
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']
|
| 131 |
+
own_columns = ['CPT_Own', 'FLEX1_Own', 'FLEX2_Own', 'FLEX3_Own', 'FLEX4_Own', 'FLEX5_Own']
|
| 132 |
+
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']
|
| 133 |
+
flex_ownerships = pd.concat([
|
| 134 |
+
portfolio.iloc[:,1].map(maps_dict['own_map']),
|
| 135 |
+
portfolio.iloc[:,2].map(maps_dict['own_map']),
|
| 136 |
+
portfolio.iloc[:,3].map(maps_dict['own_map']),
|
| 137 |
+
portfolio.iloc[:,4].map(maps_dict['own_map'])
|
| 138 |
+
])
|
| 139 |
+
flex_rank = flex_ownerships.rank(pct=True)
|
| 140 |
+
|
| 141 |
+
# Assign ranks back to individual columns using the same rank scale
|
| 142 |
+
portfolio['CPT_Own_percent_rank'] = portfolio.iloc[:,0].map(maps_dict['cpt_own_map']).rank(pct=True)
|
| 143 |
+
portfolio['FLEX1_Own_percent_rank'] = portfolio.iloc[:,1].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 144 |
+
portfolio['FLEX2_Own_percent_rank'] = portfolio.iloc[:,2].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 145 |
+
portfolio['FLEX3_Own_percent_rank'] = portfolio.iloc[:,3].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 146 |
+
portfolio['FLEX4_Own_percent_rank'] = portfolio.iloc[:,4].map(maps_dict['own_map']).map(lambda x: flex_rank[flex_ownerships == x].iloc[0])
|
| 147 |
+
|
| 148 |
+
portfolio['CPT_Own'] = portfolio.iloc[:,0].map(maps_dict['cpt_own_map']) / 100
|
| 149 |
+
portfolio['FLEX1_Own'] = portfolio.iloc[:,1].map(maps_dict['own_map']) / 100
|
| 150 |
+
portfolio['FLEX2_Own'] = portfolio.iloc[:,2].map(maps_dict['own_map']) / 100
|
| 151 |
+
portfolio['FLEX3_Own'] = portfolio.iloc[:,3].map(maps_dict['own_map']) / 100
|
| 152 |
+
portfolio['FLEX4_Own'] = portfolio.iloc[:,4].map(maps_dict['own_map']) / 100
|
| 153 |
+
|
| 154 |
+
portfolio['own_product'] = (portfolio[own_columns].product(axis=1))
|
| 155 |
+
portfolio['own_average'] = (portfolio['Own'].max() * .33) / 100
|
| 156 |
+
portfolio['own_sum'] = portfolio[own_columns].sum(axis=1)
|
| 157 |
+
portfolio['avg_own_rank'] = portfolio[dup_count_columns].mean(axis=1)
|
| 158 |
+
|
| 159 |
+
# Calculate dupes formula
|
| 160 |
+
portfolio['dupes_calc'] = (portfolio['own_product'] * portfolio['avg_own_rank']) * Contest_Size + ((portfolio['salary'] - (50000 - portfolio['Own'])) / 100) - ((50000 - portfolio['salary']) / 100)
|
| 161 |
+
portfolio['dupes_calc'] = portfolio['dupes_calc'] * dupes_multiplier
|
| 162 |
+
|
| 163 |
+
# Round and handle negative values
|
| 164 |
+
portfolio['Dupes'] = np.where(
|
| 165 |
+
np.round(portfolio['dupes_calc'], 0) <= 0,
|
| 166 |
+
0,
|
| 167 |
+
np.round(portfolio['dupes_calc'], 0) - 1
|
| 168 |
+
)
|
| 169 |
+
elif sport_var != 'CS2':
|
| 170 |
+
num_players = len([col for col in portfolio.columns if col not in ['salary', 'median', 'Own']])
|
| 171 |
+
dup_count_columns = [f'player_{i}_percent_rank' for i in range(1, num_players + 1)]
|
| 172 |
+
own_columns = [f'player_{i}_own' for i in range(1, num_players + 1)]
|
| 173 |
+
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']
|
| 174 |
+
for i in range(1, num_players + 1):
|
| 175 |
+
portfolio[f'player_{i}_percent_rank'] = portfolio.iloc[:,i-1].map(maps_dict['own_percent_rank'])
|
| 176 |
+
portfolio[f'player_{i}_own'] = portfolio.iloc[:,i-1].map(maps_dict['own_map']) / 100
|
| 177 |
+
|
| 178 |
+
portfolio['own_product'] = (portfolio[own_columns].product(axis=1))
|
| 179 |
+
portfolio['own_average'] = (portfolio['Own'].max() * .33) / 100
|
| 180 |
+
portfolio['own_sum'] = portfolio[own_columns].sum(axis=1)
|
| 181 |
+
portfolio['avg_own_rank'] = portfolio[dup_count_columns].mean(axis=1)
|
| 182 |
+
|
| 183 |
+
portfolio['dupes_calc'] = (portfolio['own_product'] * portfolio['avg_own_rank']) * Contest_Size + ((portfolio['salary'] - (50000 - portfolio['Own'])) / 100) - ((50000 - portfolio['salary']) / 100)
|
| 184 |
+
portfolio['dupes_calc'] = portfolio['dupes_calc'] * dupes_multiplier
|
| 185 |
+
# Round and handle negative values
|
| 186 |
+
portfolio['Dupes'] = np.where(
|
| 187 |
+
np.round(portfolio['dupes_calc'], 0) <= 0,
|
| 188 |
+
0,
|
| 189 |
+
np.round(portfolio['dupes_calc'], 0) - 1
|
| 190 |
+
)
|
| 191 |
|
| 192 |
portfolio['Dupes'] = np.round(portfolio['Dupes'], 0)
|
| 193 |
portfolio['own_ratio'] = np.where(
|