Spaces:
Running
Running
James McCool
commited on
Commit
·
3c0866b
1
Parent(s):
383a505
Add NFL support to ROO build functions and Streamlit display
Browse files- app.py +6 -2
- function_hold/MMA_functions.py +4 -8
- function_hold/NBA_functions.py +4 -8
- function_hold/NFL_functions.py +616 -0
- function_hold/NHL_functions.py +5 -3
app.py
CHANGED
@@ -20,9 +20,11 @@ from pandas import DataFrame
|
|
20 |
from function_hold.NBA_functions import DK_NBA_ROO_Build, FD_NBA_ROO_Build
|
21 |
from function_hold.MMA_functions import DK_MMA_ROO_Build, FD_MMA_ROO_Build
|
22 |
from function_hold.NHL_functions import DK_NHL_ROO_Build, FD_NHL_ROO_Build
|
|
|
23 |
|
24 |
nba_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '4x%': '{:.2%}', '5x%': '{:.2%}', '6x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
25 |
nhl_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '4x%': '{:.2%}', '5x%': '{:.2%}', '6x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
|
|
26 |
mma_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '100+%': '{:.2%}', '10x%': '{:.2%}', '11x%': '{:.2%}', '12x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
27 |
|
28 |
def load_file(upload):
|
@@ -53,7 +55,7 @@ with tab1:
|
|
53 |
if sport_var == "NBA":
|
54 |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
|
55 |
elif sport_var == "NFL":
|
56 |
-
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', '
|
57 |
elif sport_var == "MLB":
|
58 |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
|
59 |
elif sport_var == "MMA":
|
@@ -68,7 +70,7 @@ with tab1:
|
|
68 |
if sport_var == "NBA":
|
69 |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
|
70 |
elif sport_var == "NFL":
|
71 |
-
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', '
|
72 |
elif sport_var == "MLB":
|
73 |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
|
74 |
elif sport_var == "MMA":
|
@@ -139,6 +141,8 @@ with tab2:
|
|
139 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(nba_percentages_format, precision=2), height=1000, use_container_width = True)
|
140 |
elif sport_var == "NHL":
|
141 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(nhl_percentages_format, precision=2), height=1000, use_container_width = True)
|
|
|
|
|
142 |
elif sport_var == "MMA":
|
143 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(mma_percentages_format, precision=2), height=1000, use_container_width = True)
|
144 |
except:
|
|
|
20 |
from function_hold.NBA_functions import DK_NBA_ROO_Build, FD_NBA_ROO_Build
|
21 |
from function_hold.MMA_functions import DK_MMA_ROO_Build, FD_MMA_ROO_Build
|
22 |
from function_hold.NHL_functions import DK_NHL_ROO_Build, FD_NHL_ROO_Build
|
23 |
+
from function_hold.NFL_functions import DK_NFL_ROO_Build, FD_NFL_ROO_Build
|
24 |
|
25 |
nba_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '4x%': '{:.2%}', '5x%': '{:.2%}', '6x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
26 |
nhl_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '4x%': '{:.2%}', '5x%': '{:.2%}', '6x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
27 |
+
nfl_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '4x%': '{:.2%}', '5x%': '{:.2%}', '6x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
28 |
mma_percentages_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '100+%': '{:.2%}', '10x%': '{:.2%}', '11x%': '{:.2%}', '12x%': '{:.2%}', 'GPP%': '{:.2%}'}
|
29 |
|
30 |
def load_file(upload):
|
|
|
55 |
if sport_var == "NBA":
|
56 |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
|
57 |
elif sport_var == "NFL":
|
58 |
+
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Rush Yards', 'Receptions', 'Own'")
|
59 |
elif sport_var == "MLB":
|
60 |
st.info("upload a projections file that has Data oriented in the following format: 'Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'")
|
61 |
elif sport_var == "MMA":
|
|
|
70 |
if sport_var == "NBA":
|
71 |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
|
72 |
elif sport_var == "NFL":
|
73 |
+
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Rush Yards', 'Receptions', 'Own'])
|
74 |
elif sport_var == "MLB":
|
75 |
template_df = pd.DataFrame(columns=['Player', 'Team', 'Opp', 'Position', 'Salary', 'Median', 'Minutes', 'Own'])
|
76 |
elif sport_var == "MMA":
|
|
|
141 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(nba_percentages_format, precision=2), height=1000, use_container_width = True)
|
142 |
elif sport_var == "NHL":
|
143 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(nhl_percentages_format, precision=2), height=1000, use_container_width = True)
|
144 |
+
elif sport_var == "NFL":
|
145 |
+
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(nfl_percentages_format, precision=2), height=1000, use_container_width = True)
|
146 |
elif sport_var == "MMA":
|
147 |
st.dataframe(disp_file.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(mma_percentages_format, precision=2), height=1000, use_container_width = True)
|
148 |
except:
|
function_hold/MMA_functions.py
CHANGED
@@ -233,11 +233,9 @@ def DK_MMA_ROO_Build(projections_file, std_var, distribution_type):
|
|
233 |
final_Proj['Small_Own'] = final_Proj['Player'].map(small_own_dict)
|
234 |
final_Proj['Large_Own'] = final_Proj['Player'].map(large_own_dict)
|
235 |
final_Proj['Cash_Own'] = final_Proj['Player'].map(cash_own_dict)
|
236 |
-
final_Proj['CPT_Own'] = final_Proj['Own'] / 6
|
237 |
-
final_Proj['LevX'] = ((final_Proj[['Top_finish', '12x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
|
238 |
-
final_Proj['ValX'] = ((final_Proj[['10x%', '11x%']].mean(axis=1))*100) + final_Proj['LevX']
|
239 |
|
240 |
-
final_Proj = final_Proj[['Player', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '100+%', '10x%', '11x%', '12x%', 'GPP%',
|
|
|
241 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
242 |
|
243 |
return final_Proj.copy()
|
@@ -460,11 +458,9 @@ def FD_MMA_ROO_Build(projections_file, std_var, distribution_type):
|
|
460 |
final_Proj['Small_Own'] = final_Proj['Player'].map(small_own_dict)
|
461 |
final_Proj['Large_Own'] = final_Proj['Player'].map(large_own_dict)
|
462 |
final_Proj['Cash_Own'] = final_Proj['Player'].map(cash_own_dict)
|
463 |
-
final_Proj['CPT_Own'] = final_Proj['Own'] / 6
|
464 |
-
final_Proj['LevX'] = ((final_Proj[['Top_finish', '12x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
|
465 |
-
final_Proj['ValX'] = ((final_Proj[['10x%', '11x%']].mean(axis=1))*100) + final_Proj['LevX']
|
466 |
|
467 |
-
final_Proj = final_Proj[['Player', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '100+%', '10x%', '11x%', '12x%', 'GPP%',
|
|
|
468 |
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
469 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
470 |
|
|
|
233 |
final_Proj['Small_Own'] = final_Proj['Player'].map(small_own_dict)
|
234 |
final_Proj['Large_Own'] = final_Proj['Player'].map(large_own_dict)
|
235 |
final_Proj['Cash_Own'] = final_Proj['Player'].map(cash_own_dict)
|
|
|
|
|
|
|
236 |
|
237 |
+
final_Proj = final_Proj[['Player', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '100+%', '10x%', '11x%', '12x%', 'GPP%',
|
238 |
+
'Own', 'Small_Own', 'Large_Own', 'Cash_Own']]
|
239 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
240 |
|
241 |
return final_Proj.copy()
|
|
|
458 |
final_Proj['Small_Own'] = final_Proj['Player'].map(small_own_dict)
|
459 |
final_Proj['Large_Own'] = final_Proj['Player'].map(large_own_dict)
|
460 |
final_Proj['Cash_Own'] = final_Proj['Player'].map(cash_own_dict)
|
|
|
|
|
|
|
461 |
|
462 |
+
final_Proj = final_Proj[['Player', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '100+%', '10x%', '11x%', '12x%', 'GPP%',
|
463 |
+
'Own', 'Small_Own', 'Large_Own', 'Cash_Own']]
|
464 |
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
465 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
466 |
|
function_hold/NBA_functions.py
CHANGED
@@ -224,11 +224,9 @@ def DK_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribu
|
|
224 |
final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
|
225 |
final_Proj['Team'] = final_Proj['name_team'].map(team_dict)
|
226 |
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
227 |
-
final_Proj['CPT_Own'] = final_Proj['Own'] / 6
|
228 |
-
final_Proj['LevX'] = ((final_Proj[['Top_finish', '6x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
|
229 |
-
final_Proj['ValX'] = ((final_Proj[['5x%', '6x%']].mean(axis=1))*100) + final_Proj['LevX']
|
230 |
|
231 |
-
final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%',
|
|
|
232 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
233 |
|
234 |
return final_Proj.copy()
|
@@ -449,11 +447,9 @@ def FD_NBA_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribu
|
|
449 |
final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
|
450 |
final_Proj['Team'] = final_Proj['name_team'].map(team_dict)
|
451 |
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
452 |
-
final_Proj['CPT_Own'] = final_Proj['Own'] / 6
|
453 |
-
final_Proj['LevX'] = ((final_Proj[['Top_finish', '6x%', 'Top_5_finish']].mean(axis=1))*100) - final_Proj['Own']
|
454 |
-
final_Proj['ValX'] = ((final_Proj[['5x%', '6x%']].mean(axis=1))*100) + final_Proj['LevX']
|
455 |
|
456 |
-
final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%',
|
|
|
457 |
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
458 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
459 |
|
|
|
224 |
final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
|
225 |
final_Proj['Team'] = final_Proj['name_team'].map(team_dict)
|
226 |
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
|
|
|
|
|
|
227 |
|
228 |
+
final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%',
|
229 |
+
'Own', 'Small_Own', 'Large_Own', 'Cash_Own']]
|
230 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
231 |
|
232 |
return final_Proj.copy()
|
|
|
447 |
final_Proj['Minutes Proj'] = final_Proj['Player'].map(min_dict)
|
448 |
final_Proj['Team'] = final_Proj['name_team'].map(team_dict)
|
449 |
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
|
|
|
|
|
|
450 |
|
451 |
+
final_Proj = final_Proj[['Player', 'Minutes Proj', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '4x%', '5x%', '6x%', 'GPP%',
|
452 |
+
'Own', 'Small_Own', 'Large_Own', 'Cash_Own']]
|
453 |
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
454 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
455 |
|
function_hold/NFL_functions.py
ADDED
@@ -0,0 +1,616 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from numpy import nan as np_nan
|
2 |
+
from numpy import where as np_where
|
3 |
+
from numpy import random as np_random
|
4 |
+
from numpy import zeros as np_zeros
|
5 |
+
from numpy import array as np_array
|
6 |
+
from pandas import concat as pd_concat
|
7 |
+
from pandas import merge as pd_merge
|
8 |
+
from pandas import DataFrame
|
9 |
+
|
10 |
+
def DK_NFL_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribution_type):
|
11 |
+
total_sims = 1000
|
12 |
+
|
13 |
+
projects_raw = projections_file.copy()
|
14 |
+
projects_raw = projects_raw.replace("", np_nan)
|
15 |
+
dk_df = projects_raw.sort_values(by='Median', ascending=False)
|
16 |
+
|
17 |
+
basic_own_df = dk_df.copy()
|
18 |
+
basic_own_df['name_team'] = basic_own_df['Player'] + basic_own_df['Position']
|
19 |
+
|
20 |
+
def calculate_ownership(df, position):
|
21 |
+
# Filter the dataframe based on the position
|
22 |
+
frame = df[df['Position'].str.contains(position)]
|
23 |
+
|
24 |
+
# Calculate Small Field Own%
|
25 |
+
frame['Small Field Own%'] = np_where(
|
26 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
27 |
+
frame['Own'] * (5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
28 |
+
frame['Own']
|
29 |
+
)
|
30 |
+
frame['Small Field Own%'] = np_where(
|
31 |
+
frame['Small Field Own%'] > 75,
|
32 |
+
75,
|
33 |
+
frame['Small Field Own%']
|
34 |
+
)
|
35 |
+
|
36 |
+
# Calculate Large Field Own%
|
37 |
+
frame['Large Field Own%'] = np_where(
|
38 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
39 |
+
frame['Own'] * (2.5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
40 |
+
frame['Own']
|
41 |
+
)
|
42 |
+
frame['Large Field Own%'] = np_where(
|
43 |
+
frame['Large Field Own%'] > 75,
|
44 |
+
75,
|
45 |
+
frame['Large Field Own%']
|
46 |
+
)
|
47 |
+
|
48 |
+
# Calculate Cash Own%
|
49 |
+
frame['Cash Own%'] = np_where(
|
50 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
51 |
+
frame['Own'] * (6 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
52 |
+
frame['Own']
|
53 |
+
)
|
54 |
+
frame['Cash Own%'] = np_where(
|
55 |
+
frame['Cash Own%'] > 75,
|
56 |
+
75,
|
57 |
+
frame['Cash Own%']
|
58 |
+
)
|
59 |
+
|
60 |
+
return frame
|
61 |
+
|
62 |
+
def calculate_ownership_overall(df):
|
63 |
+
# Filter the dataframe based on the position
|
64 |
+
frame = df
|
65 |
+
|
66 |
+
# Calculate Small Field Own%
|
67 |
+
frame['Small Field Own%'] = np_where(
|
68 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
69 |
+
frame['Own'] * (5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
70 |
+
frame['Own']
|
71 |
+
)
|
72 |
+
frame['Small Field Own%'] = np_where(
|
73 |
+
frame['Small Field Own%'] > 75,
|
74 |
+
75,
|
75 |
+
frame['Small Field Own%']
|
76 |
+
)
|
77 |
+
|
78 |
+
# Calculate Large Field Own%
|
79 |
+
frame['Large Field Own%'] = np_where(
|
80 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
81 |
+
frame['Own'] * (2.5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
82 |
+
frame['Own']
|
83 |
+
)
|
84 |
+
frame['Large Field Own%'] = np_where(
|
85 |
+
frame['Large Field Own%'] > 75,
|
86 |
+
75,
|
87 |
+
frame['Large Field Own%']
|
88 |
+
)
|
89 |
+
|
90 |
+
# Calculate Cash Own%
|
91 |
+
frame['Cash Own%'] = np_where(
|
92 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
93 |
+
frame['Own'] * (6 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
94 |
+
frame['Own']
|
95 |
+
)
|
96 |
+
frame['Cash Own%'] = np_where(
|
97 |
+
frame['Cash Own%'] > 75,
|
98 |
+
75,
|
99 |
+
frame['Cash Own%']
|
100 |
+
)
|
101 |
+
|
102 |
+
return frame
|
103 |
+
|
104 |
+
# Apply the function to each dataframe
|
105 |
+
qb_frame = calculate_ownership(basic_own_df, 'QB')
|
106 |
+
rb_frame = calculate_ownership(basic_own_df, 'RB')
|
107 |
+
wr_frame = calculate_ownership(basic_own_df, 'WR')
|
108 |
+
te_frame = calculate_ownership(basic_own_df, 'TE')
|
109 |
+
dst_frame = calculate_ownership(basic_own_df, 'DST')
|
110 |
+
|
111 |
+
qb_reg_norm_var = 100 / qb_frame['Own'].sum()
|
112 |
+
qb_small_norm_var = 100 / qb_frame['Small Field Own%'].sum()
|
113 |
+
qb_large_norm_var = 100 / qb_frame['Large Field Own%'].sum()
|
114 |
+
qb_cash_norm_var = 100 / qb_frame['Cash Own%'].sum()
|
115 |
+
qb_frame['Own'] = qb_frame['Own'] * qb_reg_norm_var
|
116 |
+
qb_frame['Small Field Own%'] = qb_frame['Small Field Own%'] * qb_small_norm_var
|
117 |
+
qb_frame['Large Field Own%'] = qb_frame['Large Field Own%'] * qb_large_norm_var
|
118 |
+
qb_frame['Cash Own%'] = qb_frame['Cash Own%'] * qb_cash_norm_var
|
119 |
+
|
120 |
+
rb_reg_norm_var = 235 / rb_frame['Own'].sum()
|
121 |
+
rb_small_norm_var = 235 / rb_frame['Small Field Own%'].sum()
|
122 |
+
rb_large_norm_var = 235 / rb_frame['Large Field Own%'].sum()
|
123 |
+
rb_cash_norm_var = 235 / rb_frame['Cash Own%'].sum()
|
124 |
+
rb_frame['Own'] = rb_frame['Own'] * rb_reg_norm_var
|
125 |
+
rb_frame['Small Field Own%'] = rb_frame['Small Field Own%'] * rb_small_norm_var
|
126 |
+
rb_frame['Large Field Own%'] = rb_frame['Large Field Own%'] * rb_large_norm_var
|
127 |
+
rb_frame['Cash Own%'] = rb_frame['Cash Own%'] * rb_cash_norm_var
|
128 |
+
|
129 |
+
wr_reg_norm_var = 355 / wr_frame['Own'].sum()
|
130 |
+
wr_small_norm_var = 355 / wr_frame['Small Field Own%'].sum()
|
131 |
+
wr_large_norm_var = 355 / wr_frame['Large Field Own%'].sum()
|
132 |
+
wr_cash_norm_var = 355 / wr_frame['Cash Own%'].sum()
|
133 |
+
wr_frame['Own'] = wr_frame['Own'] * wr_reg_norm_var
|
134 |
+
wr_frame['Small Field Own%'] = wr_frame['Small Field Own%'] * wr_small_norm_var
|
135 |
+
wr_frame['Large Field Own%'] = wr_frame['Large Field Own%'] * wr_large_norm_var
|
136 |
+
wr_frame['Cash Own%'] = wr_frame['Cash Own%'] * wr_cash_norm_var
|
137 |
+
|
138 |
+
te_reg_norm_var = 110 / te_frame['Own'].sum()
|
139 |
+
te_small_norm_var = 110 / te_frame['Small Field Own%'].sum()
|
140 |
+
te_large_norm_var = 110 / te_frame['Large Field Own%'].sum()
|
141 |
+
te_cash_norm_var = 110 / te_frame['Cash Own%'].sum()
|
142 |
+
te_frame['Own'] = te_frame['Own'] * te_reg_norm_var
|
143 |
+
te_frame['Small Field Own%'] = te_frame['Small Field Own%'] * te_small_norm_var
|
144 |
+
te_frame['Large Field Own%'] = te_frame['Large Field Own%'] * te_large_norm_var
|
145 |
+
te_frame['Cash Own%'] = te_frame['Cash Own%'] * te_cash_norm_var
|
146 |
+
|
147 |
+
dst_reg_norm_var = 100 / dst_frame['Own'].sum()
|
148 |
+
dst_small_norm_var = 100 / dst_frame['Small Field Own%'].sum()
|
149 |
+
dst_large_norm_var = 100 / dst_frame['Large Field Own%'].sum()
|
150 |
+
dst_cash_norm_var = 100 / dst_frame['Cash Own%'].sum()
|
151 |
+
dst_frame['Own'] = dst_frame['Own'] * dst_reg_norm_var
|
152 |
+
dst_frame['Own'] = np_where(dst_frame['Own'] < 0, 1, dst_frame['Own'])
|
153 |
+
dst_frame['Small Field Own%'] = dst_frame['Small Field Own%'] * dst_small_norm_var
|
154 |
+
dst_frame['Small Field Own%'] = np_where(dst_frame['Small Field Own%'] < 0, 1, dst_frame['Small Field Own%'])
|
155 |
+
dst_frame['Large Field Own%'] = dst_frame['Large Field Own%'] * dst_large_norm_var
|
156 |
+
dst_frame['Large Field Own%'] = np_where(dst_frame['Large Field Own%'] < 0, 1, dst_frame['Large Field Own%'])
|
157 |
+
dst_frame['Cash Own%'] = dst_frame['Cash Own%'] * dst_cash_norm_var
|
158 |
+
dst_frame['Cash Own%'] = np_where(dst_frame['Cash Own%'] < 0, 1, dst_frame['Cash Own%'])
|
159 |
+
|
160 |
+
basic_own_df = pd_concat([qb_frame, rb_frame, wr_frame, te_frame, dst_frame])
|
161 |
+
|
162 |
+
basic_own_df = calculate_ownership_overall(basic_own_df)
|
163 |
+
|
164 |
+
own_norm_var_reg = 900 / basic_own_df['Own'].sum()
|
165 |
+
own_norm_var_small = 900 / basic_own_df['Small Field Own%'].sum()
|
166 |
+
own_norm_var_large = 900 / basic_own_df['Large Field Own%'].sum()
|
167 |
+
own_norm_var_cash = 900 / basic_own_df['Cash Own%'].sum()
|
168 |
+
basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
|
169 |
+
basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
|
170 |
+
basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
|
171 |
+
basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
|
172 |
+
|
173 |
+
basic_own_df['Own'] = np_where(basic_own_df['Own'] > 75, 75, basic_own_df['Own'])
|
174 |
+
|
175 |
+
# Apply the function to each dataframe
|
176 |
+
basic_own_df = calculate_ownership_overall(basic_own_df)
|
177 |
+
|
178 |
+
own_norm_var_reg = 900 / basic_own_df['Own'].sum()
|
179 |
+
own_norm_var_small = 900 / basic_own_df['Small Field Own%'].sum()
|
180 |
+
own_norm_var_large = 900 / basic_own_df['Large Field Own%'].sum()
|
181 |
+
own_norm_var_cash = 900 / basic_own_df['Cash Own%'].sum()
|
182 |
+
basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
|
183 |
+
basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
|
184 |
+
basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
|
185 |
+
basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
|
186 |
+
|
187 |
+
own_dict = dict(zip(basic_own_df.Player, basic_own_df.Own))
|
188 |
+
small_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Small Field Own%']))
|
189 |
+
large_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Large Field Own%']))
|
190 |
+
cash_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Cash Own%']))
|
191 |
+
team_dict = dict(zip(basic_own_df.Player, basic_own_df.Team))
|
192 |
+
opp_dict = dict(zip(basic_own_df.Player, basic_own_df.Opp))
|
193 |
+
|
194 |
+
flex_file = projections_file[['Player', 'Position', 'Salary', 'Median', 'Rush Yards', 'Receptions']]
|
195 |
+
flex_file['Floor'] = np_where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
196 |
+
flex_file['Ceiling_raw'] = np_where(flex_file['Position'] == 'QB',(flex_file['Median'] * 1.75) + (flex_file['Rush Yards']*.01), (flex_file['Median'] * 1.75) + flex_file['Receptions'])
|
197 |
+
flex_file['Ceiling'] = np_where(flex_file['Position'] == 'K', (flex_file['Median'] * 1.25), flex_file['Ceiling_raw'])
|
198 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
199 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
200 |
+
flex_file = flex_file.reset_index(drop=True)
|
201 |
+
hold_file = flex_file.copy()
|
202 |
+
overall_file = flex_file.copy()
|
203 |
+
salary_file = flex_file.copy()
|
204 |
+
|
205 |
+
try:
|
206 |
+
overall_floor_gpu = np_array(overall_file['Floor'])
|
207 |
+
overall_ceiling_gpu = np_array(overall_file['Ceiling'])
|
208 |
+
overall_median_gpu = np_array(overall_file['Median'])
|
209 |
+
overall_std_gpu = np_array(overall_file['STD'])
|
210 |
+
overall_salary_gpu = np_array(overall_file['Salary'])
|
211 |
+
|
212 |
+
data_shape = (len(overall_file['Player']), total_sims) # Example: 1000 rows
|
213 |
+
salary_array = np_zeros(data_shape)
|
214 |
+
sim_array = np_zeros(data_shape)
|
215 |
+
|
216 |
+
for x in range(0, total_sims):
|
217 |
+
result_gpu = overall_salary_gpu
|
218 |
+
salary_array[:, x] = result_gpu
|
219 |
+
cupy_array = salary_array
|
220 |
+
|
221 |
+
salary_file = salary_file.reset_index(drop=True)
|
222 |
+
salary_cupy = DataFrame(cupy_array, columns=list(range(0, total_sims)))
|
223 |
+
salary_check_file = pd_concat([salary_file, salary_cupy], axis=1)
|
224 |
+
except:
|
225 |
+
for x in range(0,total_sims):
|
226 |
+
salary_file[x] = salary_file['Salary']
|
227 |
+
salary_check_file = salary_file.copy()
|
228 |
+
|
229 |
+
salary_file=salary_check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
230 |
+
|
231 |
+
salary_file = salary_file.div(1000)
|
232 |
+
|
233 |
+
try:
|
234 |
+
for x in range(0, total_sims):
|
235 |
+
if distribution_type == 'normal':
|
236 |
+
# Normal distribution (existing logic)
|
237 |
+
result_gpu = np_random.normal(overall_median_gpu, overall_std_gpu)
|
238 |
+
elif distribution_type == 'poisson':
|
239 |
+
# Poisson distribution - using median as lambda
|
240 |
+
result_gpu = np_random.poisson(overall_median_gpu)
|
241 |
+
elif distribution_type == 'bimodal':
|
242 |
+
# Bimodal distribution - mixture of two normal distributions
|
243 |
+
# First peak centered at 80% of median, second at 120% of median
|
244 |
+
if np_random.random() < 0.5:
|
245 |
+
result_gpu = np_random.normal(overall_floor_gpu, overall_std_gpu)
|
246 |
+
else:
|
247 |
+
result_gpu = np_random.normal(overall_ceiling_gpu, overall_std_gpu)
|
248 |
+
else:
|
249 |
+
raise ValueError("Invalid distribution type. Must be 'normal', 'poisson', or 'bimodal'")
|
250 |
+
|
251 |
+
sim_array[:, x] = result_gpu
|
252 |
+
add_array = sim_array
|
253 |
+
|
254 |
+
overall_file = overall_file.reset_index(drop=True)
|
255 |
+
df2 = DataFrame(add_array, columns=list(range(0, total_sims)))
|
256 |
+
check_file = pd_concat([overall_file, df2], axis=1)
|
257 |
+
except:
|
258 |
+
for x in range(0,total_sims):
|
259 |
+
if distribution_type == 'normal':
|
260 |
+
overall_file[x] = np_random.normal(overall_file['Median'], overall_file['STD'])
|
261 |
+
elif distribution_type == 'poisson':
|
262 |
+
overall_file[x] = np_random.poisson(overall_file['Median'])
|
263 |
+
elif distribution_type == 'bimodal':
|
264 |
+
# Bimodal distribution fallback
|
265 |
+
if np_random.random() < 0.5:
|
266 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 0.8, overall_file['STD'])
|
267 |
+
else:
|
268 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 1.2, overall_file['STD'])
|
269 |
+
check_file = overall_file.copy()
|
270 |
+
|
271 |
+
overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
272 |
+
|
273 |
+
players_only = hold_file[['Player']]
|
274 |
+
raw_lineups_file = players_only
|
275 |
+
|
276 |
+
for x in range(0,total_sims):
|
277 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))}
|
278 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
279 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
280 |
+
|
281 |
+
players_only=players_only.drop(['Player'], axis=1)
|
282 |
+
|
283 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
284 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
285 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
286 |
+
|
287 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
288 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
289 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
290 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
291 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
292 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
293 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
294 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
295 |
+
|
296 |
+
players_only['Player'] = hold_file[['Player']]
|
297 |
+
|
298 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
299 |
+
|
300 |
+
final_Proj = pd_merge(hold_file, final_outcomes, on="Player")
|
301 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
302 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
303 |
+
final_Proj['Small_Field_Own'] = final_Proj['Player'].map(small_own_dict)
|
304 |
+
final_Proj['Large_Field_Own'] = final_Proj['Player'].map(large_own_dict)
|
305 |
+
final_Proj['Cash_Field_Own'] = final_Proj['Player'].map(cash_own_dict)
|
306 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
307 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
308 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%',
|
309 |
+
'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own']]
|
310 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
311 |
+
|
312 |
+
return final_Proj.copy()
|
313 |
+
|
314 |
+
def FD_NFL_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribution_type):
|
315 |
+
total_sims = 1000
|
316 |
+
|
317 |
+
projects_raw = projections_file.copy()
|
318 |
+
fd_df = projects_raw.sort_values(by='Median', ascending=False)
|
319 |
+
|
320 |
+
basic_own_df = fd_df.copy()
|
321 |
+
basic_own_df['name_team'] = basic_own_df['Player'] + basic_own_df['Position']
|
322 |
+
|
323 |
+
def calculate_ownership(df, position):
|
324 |
+
# Filter the dataframe based on the position
|
325 |
+
frame = df[df['Position'].str.contains(position)]
|
326 |
+
|
327 |
+
# Calculate Small Field Own%
|
328 |
+
frame['Small Field Own%'] = np_where(
|
329 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
330 |
+
frame['Own'] * (5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
331 |
+
frame['Own']
|
332 |
+
)
|
333 |
+
frame['Small Field Own%'] = np_where(
|
334 |
+
frame['Small Field Own%'] > 75,
|
335 |
+
75,
|
336 |
+
frame['Small Field Own%']
|
337 |
+
)
|
338 |
+
|
339 |
+
# Calculate Large Field Own%
|
340 |
+
frame['Large Field Own%'] = np_where(
|
341 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
342 |
+
frame['Own'] * (2.5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
343 |
+
frame['Own']
|
344 |
+
)
|
345 |
+
frame['Large Field Own%'] = np_where(
|
346 |
+
frame['Large Field Own%'] > 75,
|
347 |
+
75,
|
348 |
+
frame['Large Field Own%']
|
349 |
+
)
|
350 |
+
|
351 |
+
# Calculate Cash Own%
|
352 |
+
frame['Cash Own%'] = np_where(
|
353 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
354 |
+
frame['Own'] * (6 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
355 |
+
frame['Own']
|
356 |
+
)
|
357 |
+
frame['Cash Own%'] = np_where(
|
358 |
+
frame['Cash Own%'] > 75,
|
359 |
+
75,
|
360 |
+
frame['Cash Own%']
|
361 |
+
)
|
362 |
+
|
363 |
+
return frame
|
364 |
+
|
365 |
+
def calculate_ownership_overall(df):
|
366 |
+
# Filter the dataframe based on the position
|
367 |
+
frame = df
|
368 |
+
|
369 |
+
# Calculate Small Field Own%
|
370 |
+
frame['Small Field Own%'] = np_where(
|
371 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
372 |
+
frame['Own'] * (5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
373 |
+
frame['Own']
|
374 |
+
)
|
375 |
+
frame['Small Field Own%'] = np_where(
|
376 |
+
frame['Small Field Own%'] > 75,
|
377 |
+
75,
|
378 |
+
frame['Small Field Own%']
|
379 |
+
)
|
380 |
+
|
381 |
+
# Calculate Large Field Own%
|
382 |
+
frame['Large Field Own%'] = np_where(
|
383 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
384 |
+
frame['Own'] * (2.5 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
385 |
+
frame['Own']
|
386 |
+
)
|
387 |
+
frame['Large Field Own%'] = np_where(
|
388 |
+
frame['Large Field Own%'] > 75,
|
389 |
+
75,
|
390 |
+
frame['Large Field Own%']
|
391 |
+
)
|
392 |
+
|
393 |
+
# Calculate Cash Own%
|
394 |
+
frame['Cash Own%'] = np_where(
|
395 |
+
(frame['Own'] - frame['Own'].mean() >= 0),
|
396 |
+
frame['Own'] * (6 * (frame['Own'] - frame['Own'].mean()) / 100) + frame['Own'].mean(),
|
397 |
+
frame['Own']
|
398 |
+
)
|
399 |
+
frame['Cash Own%'] = np_where(
|
400 |
+
frame['Cash Own%'] > 75,
|
401 |
+
75,
|
402 |
+
frame['Cash Own%']
|
403 |
+
)
|
404 |
+
|
405 |
+
return frame
|
406 |
+
|
407 |
+
# Apply the function to each dataframe
|
408 |
+
qb_frame = calculate_ownership(basic_own_df, 'QB')
|
409 |
+
rb_frame = calculate_ownership(basic_own_df, 'RB')
|
410 |
+
wr_frame = calculate_ownership(basic_own_df, 'WR')
|
411 |
+
te_frame = calculate_ownership(basic_own_df, 'TE')
|
412 |
+
dst_frame = calculate_ownership(basic_own_df, 'D')
|
413 |
+
|
414 |
+
qb_reg_norm_var = 100 / qb_frame['Own'].sum()
|
415 |
+
qb_small_norm_var = 100 / qb_frame['Small Field Own%'].sum()
|
416 |
+
qb_large_norm_var = 100 / qb_frame['Large Field Own%'].sum()
|
417 |
+
qb_cash_norm_var = 100 / qb_frame['Cash Own%'].sum()
|
418 |
+
qb_frame['Own'] = qb_frame['Own'] * qb_reg_norm_var
|
419 |
+
qb_frame['Small Field Own%'] = qb_frame['Small Field Own%'] * qb_small_norm_var
|
420 |
+
qb_frame['Large Field Own%'] = qb_frame['Large Field Own%'] * qb_large_norm_var
|
421 |
+
qb_frame['Cash Own%'] = qb_frame['Cash Own%'] * qb_cash_norm_var
|
422 |
+
|
423 |
+
rb_reg_norm_var = 235 / rb_frame['Own'].sum()
|
424 |
+
rb_small_norm_var = 235 / rb_frame['Small Field Own%'].sum()
|
425 |
+
rb_large_norm_var = 235 / rb_frame['Large Field Own%'].sum()
|
426 |
+
rb_cash_norm_var = 235 / rb_frame['Cash Own%'].sum()
|
427 |
+
rb_frame['Own'] = rb_frame['Own'] * rb_reg_norm_var
|
428 |
+
rb_frame['Small Field Own%'] = rb_frame['Small Field Own%'] * rb_small_norm_var
|
429 |
+
rb_frame['Large Field Own%'] = rb_frame['Large Field Own%'] * rb_large_norm_var
|
430 |
+
rb_frame['Cash Own%'] = rb_frame['Cash Own%'] * rb_cash_norm_var
|
431 |
+
|
432 |
+
wr_reg_norm_var = 355 / wr_frame['Own'].sum()
|
433 |
+
wr_small_norm_var = 355 / wr_frame['Small Field Own%'].sum()
|
434 |
+
wr_large_norm_var = 355 / wr_frame['Large Field Own%'].sum()
|
435 |
+
wr_cash_norm_var = 355 / wr_frame['Cash Own%'].sum()
|
436 |
+
wr_frame['Own'] = wr_frame['Own'] * wr_reg_norm_var
|
437 |
+
wr_frame['Small Field Own%'] = wr_frame['Small Field Own%'] * wr_small_norm_var
|
438 |
+
wr_frame['Large Field Own%'] = wr_frame['Large Field Own%'] * wr_large_norm_var
|
439 |
+
wr_frame['Cash Own%'] = wr_frame['Cash Own%'] * wr_cash_norm_var
|
440 |
+
|
441 |
+
te_reg_norm_var = 110 / te_frame['Own'].sum()
|
442 |
+
te_small_norm_var = 110 / te_frame['Small Field Own%'].sum()
|
443 |
+
te_large_norm_var = 110 / te_frame['Large Field Own%'].sum()
|
444 |
+
te_cash_norm_var = 110 / te_frame['Cash Own%'].sum()
|
445 |
+
te_frame['Own'] = te_frame['Own'] * te_reg_norm_var
|
446 |
+
te_frame['Small Field Own%'] = te_frame['Small Field Own%'] * te_small_norm_var
|
447 |
+
te_frame['Large Field Own%'] = te_frame['Large Field Own%'] * te_large_norm_var
|
448 |
+
te_frame['Cash Own%'] = te_frame['Cash Own%'] * te_cash_norm_var
|
449 |
+
|
450 |
+
dst_reg_norm_var = 100 / dst_frame['Own'].sum()
|
451 |
+
dst_small_norm_var = 100 / dst_frame['Small Field Own%'].sum()
|
452 |
+
dst_large_norm_var = 100 / dst_frame['Large Field Own%'].sum()
|
453 |
+
dst_cash_norm_var = 100 / dst_frame['Cash Own%'].sum()
|
454 |
+
dst_frame['Own'] = dst_frame['Own'] * dst_reg_norm_var
|
455 |
+
dst_frame['Own'] = np_where(dst_frame['Own'] < 0, 1, dst_frame['Own'])
|
456 |
+
dst_frame['Small Field Own%'] = dst_frame['Small Field Own%'] * dst_small_norm_var
|
457 |
+
dst_frame['Small Field Own%'] = np_where(dst_frame['Small Field Own%'] < 0, 1, dst_frame['Small Field Own%'])
|
458 |
+
dst_frame['Large Field Own%'] = dst_frame['Large Field Own%'] * dst_large_norm_var
|
459 |
+
dst_frame['Large Field Own%'] = np_where(dst_frame['Large Field Own%'] < 0, 1, dst_frame['Large Field Own%'])
|
460 |
+
dst_frame['Cash Own%'] = dst_frame['Cash Own%'] * dst_cash_norm_var
|
461 |
+
dst_frame['Cash Own%'] = np_where(dst_frame['Cash Own%'] < 0, 1, dst_frame['Cash Own%'])
|
462 |
+
|
463 |
+
basic_own_df = pd_concat([qb_frame, rb_frame, wr_frame, te_frame, dst_frame])
|
464 |
+
|
465 |
+
basic_own_df = calculate_ownership_overall(basic_own_df)
|
466 |
+
|
467 |
+
own_norm_var_reg = 900 / basic_own_df['Own'].sum()
|
468 |
+
own_norm_var_small = 900 / basic_own_df['Small Field Own%'].sum()
|
469 |
+
own_norm_var_large = 900 / basic_own_df['Large Field Own%'].sum()
|
470 |
+
own_norm_var_cash = 900 / basic_own_df['Cash Own%'].sum()
|
471 |
+
basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
|
472 |
+
basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
|
473 |
+
basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
|
474 |
+
basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
|
475 |
+
|
476 |
+
basic_own_df['Own'] = np_where(basic_own_df['Own'] > 75, 75, basic_own_df['Own'])
|
477 |
+
|
478 |
+
# Apply the function to each dataframe
|
479 |
+
basic_own_df = calculate_ownership_overall(basic_own_df)
|
480 |
+
|
481 |
+
own_norm_var_reg = 900 / basic_own_df['Own'].sum()
|
482 |
+
own_norm_var_small = 900 / basic_own_df['Small Field Own%'].sum()
|
483 |
+
own_norm_var_large = 900 / basic_own_df['Large Field Own%'].sum()
|
484 |
+
own_norm_var_cash = 900 / basic_own_df['Cash Own%'].sum()
|
485 |
+
basic_own_df['Own'] = basic_own_df['Own'] * own_norm_var_reg
|
486 |
+
basic_own_df['Small_Own'] = basic_own_df['Small Field Own%'] * own_norm_var_small
|
487 |
+
basic_own_df['Large_Own'] = basic_own_df['Large Field Own%'] * own_norm_var_large
|
488 |
+
basic_own_df['Cash_Own'] = basic_own_df['Cash Own%'] * own_norm_var_cash
|
489 |
+
|
490 |
+
own_dict = dict(zip(basic_own_df.Player, basic_own_df.Own))
|
491 |
+
small_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Small Field Own%']))
|
492 |
+
large_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Large Field Own%']))
|
493 |
+
cash_own_dict = dict(zip(basic_own_df.Player, basic_own_df['Cash Own%']))
|
494 |
+
team_dict = dict(zip(basic_own_df.Player, basic_own_df.Team))
|
495 |
+
opp_dict = dict(zip(basic_own_df.Player, basic_own_df.Opp))
|
496 |
+
|
497 |
+
flex_file = projections_file[['Player', 'Position', 'Salary', 'Median', 'Rush Yards', 'Receptions']]
|
498 |
+
flex_file['Floor'] = np_where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
499 |
+
flex_file['Ceiling_raw'] = np_where(flex_file['Position'] == 'QB',(flex_file['Median'] * 1.75) + (flex_file['Rush Yards']*.01), (flex_file['Median'] * 1.75) + flex_file['Receptions'])
|
500 |
+
flex_file['Ceiling'] = np_where(flex_file['Position'] == 'K', (flex_file['Median'] * 1.25), flex_file['Ceiling_raw'])
|
501 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
502 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
503 |
+
flex_file = flex_file.reset_index(drop=True)
|
504 |
+
hold_file = flex_file.copy()
|
505 |
+
overall_file = flex_file.copy()
|
506 |
+
salary_file = flex_file.copy()
|
507 |
+
|
508 |
+
try:
|
509 |
+
overall_floor_gpu = np_array(overall_file['Floor'])
|
510 |
+
overall_ceiling_gpu = np_array(overall_file['Ceiling'])
|
511 |
+
overall_median_gpu = np_array(overall_file['Median'])
|
512 |
+
overall_std_gpu = np_array(overall_file['STD'])
|
513 |
+
overall_salary_gpu = np_array(overall_file['Salary'])
|
514 |
+
|
515 |
+
data_shape = (len(overall_file['Player']), total_sims) # Example: 1000 rows
|
516 |
+
salary_array = np_zeros(data_shape)
|
517 |
+
sim_array = np_zeros(data_shape)
|
518 |
+
|
519 |
+
for x in range(0, total_sims):
|
520 |
+
result_gpu = overall_salary_gpu
|
521 |
+
salary_array[:, x] = result_gpu
|
522 |
+
cupy_array = salary_array
|
523 |
+
|
524 |
+
salary_file = salary_file.reset_index(drop=True)
|
525 |
+
salary_cupy = DataFrame(cupy_array, columns=list(range(0, total_sims)))
|
526 |
+
salary_check_file = pd_concat([salary_file, salary_cupy], axis=1)
|
527 |
+
except:
|
528 |
+
for x in range(0,total_sims):
|
529 |
+
salary_file[x] = salary_file['Salary']
|
530 |
+
salary_check_file = salary_file.copy()
|
531 |
+
|
532 |
+
salary_file=salary_check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
533 |
+
|
534 |
+
salary_file = salary_file.div(1000)
|
535 |
+
|
536 |
+
try:
|
537 |
+
for x in range(0, total_sims):
|
538 |
+
if distribution_type == 'normal':
|
539 |
+
# Normal distribution (existing logic)
|
540 |
+
result_gpu = np_random.normal(overall_median_gpu, overall_std_gpu)
|
541 |
+
elif distribution_type == 'poisson':
|
542 |
+
# Poisson distribution - using median as lambda
|
543 |
+
result_gpu = np_random.poisson(overall_median_gpu)
|
544 |
+
elif distribution_type == 'bimodal':
|
545 |
+
# Bimodal distribution - mixture of two normal distributions
|
546 |
+
# First peak centered at 80% of median, second at 120% of median
|
547 |
+
if np_random.random() < 0.5:
|
548 |
+
result_gpu = np_random.normal(overall_floor_gpu, overall_std_gpu)
|
549 |
+
else:
|
550 |
+
result_gpu = np_random.normal(overall_ceiling_gpu, overall_std_gpu)
|
551 |
+
else:
|
552 |
+
raise ValueError("Invalid distribution type. Must be 'normal', 'poisson', or 'bimodal'")
|
553 |
+
|
554 |
+
sim_array[:, x] = result_gpu
|
555 |
+
add_array = sim_array
|
556 |
+
|
557 |
+
overall_file = overall_file.reset_index(drop=True)
|
558 |
+
df2 = DataFrame(add_array, columns=list(range(0, total_sims)))
|
559 |
+
check_file = pd_concat([overall_file, df2], axis=1)
|
560 |
+
except:
|
561 |
+
for x in range(0,total_sims):
|
562 |
+
if distribution_type == 'normal':
|
563 |
+
overall_file[x] = np_random.normal(overall_file['Median'], overall_file['STD'])
|
564 |
+
elif distribution_type == 'poisson':
|
565 |
+
overall_file[x] = np_random.poisson(overall_file['Median'])
|
566 |
+
elif distribution_type == 'bimodal':
|
567 |
+
# Bimodal distribution fallback
|
568 |
+
if np_random.random() < 0.5:
|
569 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 0.8, overall_file['STD'])
|
570 |
+
else:
|
571 |
+
overall_file[x] = np_random.normal(overall_file['Median'] * 1.2, overall_file['STD'])
|
572 |
+
check_file = overall_file.copy()
|
573 |
+
|
574 |
+
overall_file=check_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
575 |
+
|
576 |
+
players_only = hold_file[['Player']]
|
577 |
+
raw_lineups_file = players_only
|
578 |
+
|
579 |
+
for x in range(0,total_sims):
|
580 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,overall_file[x]))}
|
581 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
582 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
583 |
+
|
584 |
+
players_only=players_only.drop(['Player'], axis=1)
|
585 |
+
|
586 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
587 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
588 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
589 |
+
|
590 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
591 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
592 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
593 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
594 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
595 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
596 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
597 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
598 |
+
|
599 |
+
players_only['Player'] = hold_file[['Player']]
|
600 |
+
|
601 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
602 |
+
|
603 |
+
final_Proj = pd_merge(hold_file, final_outcomes, on="Player")
|
604 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
605 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
606 |
+
final_Proj['Small_Field_Own'] = final_Proj['Player'].map(small_own_dict)
|
607 |
+
final_Proj['Large_Field_Own'] = final_Proj['Player'].map(large_own_dict)
|
608 |
+
final_Proj['Cash_Field_Own'] = final_Proj['Player'].map(cash_own_dict)
|
609 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
610 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
611 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%',
|
612 |
+
'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own']]
|
613 |
+
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
614 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
615 |
+
|
616 |
+
return final_Proj.copy()
|
function_hold/NHL_functions.py
CHANGED
@@ -240,7 +240,8 @@ def DK_NHL_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribu
|
|
240 |
final_Proj['name_team'] = final_Proj['Player'] + final_Proj['Position']
|
241 |
final_Proj['Team'] = final_Proj['name_team'].map(basic_team_dict)
|
242 |
final_Proj['Opp'] = final_Proj['Player'].map(basic_opp_dict)
|
243 |
-
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own',
|
|
|
244 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
245 |
|
246 |
return final_Proj.copy()
|
@@ -467,7 +468,7 @@ def FD_NHL_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribu
|
|
467 |
|
468 |
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
469 |
|
470 |
-
final_Proj =
|
471 |
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
472 |
final_Proj['Own'] = final_Proj['Player'].map(basic_own_dict).astype(float)
|
473 |
final_Proj['Small Field Own%'] = final_Proj['Player'].map(small_own_dict).astype(float)
|
@@ -476,7 +477,8 @@ def FD_NHL_ROO_Build(projections_file, floor_var, ceiling_var, std_var, distribu
|
|
476 |
final_Proj['name_team'] = final_Proj['Player'] + final_Proj['Position']
|
477 |
final_Proj['Team'] = final_Proj['name_team'].map(basic_team_dict)
|
478 |
final_Proj['Opp'] = final_Proj['Player'].map(basic_opp_dict)
|
479 |
-
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own',
|
|
|
480 |
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
481 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
482 |
|
|
|
240 |
final_Proj['name_team'] = final_Proj['Player'] + final_Proj['Position']
|
241 |
final_Proj['Team'] = final_Proj['name_team'].map(basic_team_dict)
|
242 |
final_Proj['Opp'] = final_Proj['Player'].map(basic_opp_dict)
|
243 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own',
|
244 |
+
'Small Field Own%', 'Large Field Own%', 'Cash Own%']]
|
245 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
246 |
|
247 |
return final_Proj.copy()
|
|
|
468 |
|
469 |
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
470 |
|
471 |
+
final_Proj = pd_merge(hold_file, final_outcomes, on="Player")
|
472 |
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
473 |
final_Proj['Own'] = final_Proj['Player'].map(basic_own_dict).astype(float)
|
474 |
final_Proj['Small Field Own%'] = final_Proj['Player'].map(small_own_dict).astype(float)
|
|
|
477 |
final_Proj['name_team'] = final_Proj['Player'] + final_Proj['Position']
|
478 |
final_Proj['Team'] = final_Proj['name_team'].map(basic_team_dict)
|
479 |
final_Proj['Opp'] = final_Proj['Player'].map(basic_opp_dict)
|
480 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own',
|
481 |
+
'Small Field Own%', 'Large Field Own%', 'Cash Own%']]
|
482 |
final_Proj['Salary'] = final_Proj['Salary'].astype(int)
|
483 |
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
484 |
|