James McCool
commited on
Commit
·
08ef694
1
Parent(s):
ef81816
introducing NBA functions
Browse files- app.py +91 -8
- database_queries.py +389 -0
app.py
CHANGED
|
@@ -38,9 +38,17 @@ dk_db_nfl_showdown_selections = ['DK_NFL_SD_seed_frame_Showdown #1', 'DK_NFL_SD_
|
|
| 38 |
fd_db_nfl_showdown_selections = ['FD_NFL_SD_seed_frame_Showdown #1', 'FD_NFL_SD_seed_frame_Showdown #2', 'FD_NFL_SD_seed_frame_Showdown #3', 'FD_NFL_SD_seed_frame_Showdown #4', 'FD_NFL_SD_seed_frame_Showdown #5', 'FD_NFL_SD_seed_frame_Showdown #6',
|
| 39 |
'FD_NFL_SD_seed_frame_Showdown #7', 'FD_NFL_SD_seed_frame_Showdown #8', 'FD_NFL_SD_seed_frame_Showdown #9', 'FD_NFL_SD_seed_frame_Showdown #10', 'FD_NFL_SD_seed_frame_Showdown #11', 'FD_NFL_SD_seed_frame_Showdown #12', 'FD_NFL_SD_seed_frame_Showdown #13',
|
| 40 |
'FD_NFL_SD_seed_frame_Showdown #14', 'FD_NFL_SD_seed_frame_Showdown #15']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
dk_nfl_showdown_db_translation = dict(zip(showdown_selections, dk_db_nfl_showdown_selections))
|
| 43 |
fd_nfl_showdown_db_translation = dict(zip(showdown_selections, fd_db_nfl_showdown_selections))
|
|
|
|
|
|
|
| 44 |
|
| 45 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Lineup Edge_Raw': '{:.2%}', 'Win%': '{:.2%}'}
|
| 46 |
stacking_sports = ['MLB', 'NHL', 'NFL', 'LOL', 'NCAAF']
|
|
@@ -196,7 +204,54 @@ except:
|
|
| 196 |
nfl_slate_names_fd = []
|
| 197 |
nfl_slate_name_lookup_fd = {}
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
nfl_reg_salaries = grab_nfl_reg_salaries()
|
|
|
|
| 200 |
|
| 201 |
# Memory optimization helper functions
|
| 202 |
def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
|
|
@@ -568,9 +623,19 @@ with st.container():
|
|
| 568 |
|
| 569 |
with optimals_site_col:
|
| 570 |
if site_var == 'Draftkings':
|
| 571 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
elif site_var == 'Fanduel':
|
| 573 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
|
| 575 |
with optimals_macro_col:
|
| 576 |
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1, key='lineup_num_var_input')
|
|
@@ -627,7 +692,10 @@ if selected_tab == 'Data Load':
|
|
| 627 |
if st.button("Load from Paydirt DB"):
|
| 628 |
if 'csv_file' in st.session_state:
|
| 629 |
del st.session_state['csv_file']
|
| 630 |
-
|
|
|
|
|
|
|
|
|
|
| 631 |
st.session_state['pricing_loaded'] = True
|
| 632 |
|
| 633 |
try:
|
|
@@ -693,9 +761,15 @@ if selected_tab == 'Data Load':
|
|
| 693 |
if st.button("Load from Database after inserting site CSV"):
|
| 694 |
if site_var == 'Draftkings':
|
| 695 |
if type_var != 'Showdown':
|
| 696 |
-
|
|
|
|
|
|
|
|
|
|
| 697 |
else:
|
| 698 |
-
|
|
|
|
|
|
|
|
|
|
| 699 |
st.session_state['db_portfolio_file'] = pd.DataFrame(portfolio_load)
|
| 700 |
st.session_state['portfolio_loaded'] = True
|
| 701 |
if 'portfolio' in st.session_state:
|
|
@@ -704,9 +778,15 @@ if selected_tab == 'Data Load':
|
|
| 704 |
del st.session_state['export_portfolio']
|
| 705 |
else:
|
| 706 |
if type_var != 'Showdown':
|
| 707 |
-
|
|
|
|
|
|
|
|
|
|
| 708 |
else:
|
| 709 |
-
|
|
|
|
|
|
|
|
|
|
| 710 |
st.session_state['db_portfolio_file'] = pd.DataFrame(portfolio_load)
|
| 711 |
st.session_state['portfolio_loaded'] = True
|
| 712 |
if 'portfolio' in st.session_state:
|
|
@@ -801,7 +881,10 @@ if selected_tab == 'Data Load':
|
|
| 801 |
st.session_state['projections_loaded'] = True
|
| 802 |
elif proj_options == 'Paydirt DB':
|
| 803 |
if st.button("Load from Database"):
|
| 804 |
-
|
|
|
|
|
|
|
|
|
|
| 805 |
st.session_state['db_projections_file'] = projections_file
|
| 806 |
st.session_state['projections_loaded'] = True
|
| 807 |
if 'projections_df' in st.session_state:
|
|
|
|
| 38 |
fd_db_nfl_showdown_selections = ['FD_NFL_SD_seed_frame_Showdown #1', 'FD_NFL_SD_seed_frame_Showdown #2', 'FD_NFL_SD_seed_frame_Showdown #3', 'FD_NFL_SD_seed_frame_Showdown #4', 'FD_NFL_SD_seed_frame_Showdown #5', 'FD_NFL_SD_seed_frame_Showdown #6',
|
| 39 |
'FD_NFL_SD_seed_frame_Showdown #7', 'FD_NFL_SD_seed_frame_Showdown #8', 'FD_NFL_SD_seed_frame_Showdown #9', 'FD_NFL_SD_seed_frame_Showdown #10', 'FD_NFL_SD_seed_frame_Showdown #11', 'FD_NFL_SD_seed_frame_Showdown #12', 'FD_NFL_SD_seed_frame_Showdown #13',
|
| 40 |
'FD_NFL_SD_seed_frame_Showdown #14', 'FD_NFL_SD_seed_frame_Showdown #15']
|
| 41 |
+
dk_db_nba_showdown_selections = ['DK_NBA_SD_seed_frame_Showdown #1', 'DK_NBA_SD_seed_frame_Showdown #2', 'DK_NBA_SD_seed_frame_Showdown #3', 'DK_NBA_SD_seed_frame_Showdown #4', 'DK_NBA_SD_seed_frame_Showdown #5', 'DK_NBA_SD_seed_frame_Showdown #6',
|
| 42 |
+
'DK_NBA_SD_seed_frame_Showdown #7', 'DK_NBA_SD_seed_frame_Showdown #8', 'DK_NBA_SD_seed_frame_Showdown #9', 'DK_NBA_SD_seed_frame_Showdown #10', 'DK_NBA_SD_seed_frame_Showdown #11', 'DK_NBA_SD_seed_frame_Showdown #12', 'DK_NBA_SD_seed_frame_Showdown #13',
|
| 43 |
+
'DK_NBA_SD_seed_frame_Showdown #14', 'DK_NBA_SD_seed_frame_Showdown #15']
|
| 44 |
+
fd_db_nba_showdown_selections = ['FD_NBA_SD_seed_frame_Showdown #1', 'FD_NBA_SD_seed_frame_Showdown #2', 'FD_NBA_SD_seed_frame_Showdown #3', 'FD_NBA_SD_seed_frame_Showdown #4', 'FD_NBA_SD_seed_frame_Showdown #5', 'FD_NBA_SD_seed_frame_Showdown #6',
|
| 45 |
+
'FD_NBA_SD_seed_frame_Showdown #7', 'FD_NBA_SD_seed_frame_Showdown #8', 'FD_NBA_SD_seed_frame_Showdown #9', 'FD_NBA_SD_seed_frame_Showdown #10', 'FD_NBA_SD_seed_frame_Showdown #11', 'FD_NBA_SD_seed_frame_Showdown #12', 'FD_NBA_SD_seed_frame_Showdown #13',
|
| 46 |
+
'FD_NBA_SD_seed_frame_Showdown #14', 'FD_NBA_SD_seed_frame_Showdown #15']
|
| 47 |
|
| 48 |
dk_nfl_showdown_db_translation = dict(zip(showdown_selections, dk_db_nfl_showdown_selections))
|
| 49 |
fd_nfl_showdown_db_translation = dict(zip(showdown_selections, fd_db_nfl_showdown_selections))
|
| 50 |
+
dk_nba_showdown_db_translation = dict(zip(showdown_selections, dk_db_nba_showdown_selections))
|
| 51 |
+
fd_nba_showdown_db_translation = dict(zip(showdown_selections, fd_db_nba_showdown_selections))
|
| 52 |
|
| 53 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Lineup Edge_Raw': '{:.2%}', 'Win%': '{:.2%}'}
|
| 54 |
stacking_sports = ['MLB', 'NHL', 'NFL', 'LOL', 'NCAAF']
|
|
|
|
| 204 |
nfl_slate_names_fd = []
|
| 205 |
nfl_slate_name_lookup_fd = {}
|
| 206 |
|
| 207 |
+
def define_dk_nba_showdown_slates():
|
| 208 |
+
collection = nba_db["Player_SD_Range_Of_Outcomes"]
|
| 209 |
+
cursor = collection.find()
|
| 210 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 211 |
+
raw_display = raw_display[raw_display['site'] == 'Draftkings']
|
| 212 |
+
unique_slates = raw_display['slate'].unique()
|
| 213 |
+
|
| 214 |
+
slate_names = []
|
| 215 |
+
|
| 216 |
+
for slate in unique_slates:
|
| 217 |
+
slate_data = raw_display[raw_display['slate'] == slate]
|
| 218 |
+
slate_name = slate_data.iloc[0]['Team'] + ' vs. ' + slate_data.iloc[0]['Opp']
|
| 219 |
+
slate_names.append(slate_name)
|
| 220 |
+
|
| 221 |
+
slate_name_lookup = dict(zip(slate_names, unique_slates))
|
| 222 |
+
return slate_names, slate_name_lookup
|
| 223 |
+
|
| 224 |
+
def define_fd_nba_showdown_slates():
|
| 225 |
+
collection = nba_db["Player_SD_Range_Of_Outcomes"]
|
| 226 |
+
cursor = collection.find()
|
| 227 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 228 |
+
raw_display = raw_display[raw_display['site'] == 'Fanduel']
|
| 229 |
+
unique_slates = raw_display['slate'].unique()
|
| 230 |
+
|
| 231 |
+
slate_names = []
|
| 232 |
+
|
| 233 |
+
for slate in unique_slates:
|
| 234 |
+
slate_data = raw_display[raw_display['slate'] == slate]
|
| 235 |
+
slate_name = slate_data.iloc[0]['Team'] + ' vs. ' + slate_data.iloc[0]['Opp']
|
| 236 |
+
slate_names.append(slate_name)
|
| 237 |
+
|
| 238 |
+
slate_name_lookup = dict(zip(slate_names, unique_slates))
|
| 239 |
+
return slate_names, slate_name_lookup
|
| 240 |
+
|
| 241 |
+
try:
|
| 242 |
+
nba_slate_names_dk, nba_slate_name_lookup_dk = define_dk_nba_showdown_slates()
|
| 243 |
+
except:
|
| 244 |
+
nba_slate_names_dk = []
|
| 245 |
+
nba_slate_name_lookup_dk = {}
|
| 246 |
+
|
| 247 |
+
try:
|
| 248 |
+
nba_slate_names_fd, nba_slate_name_lookup_fd = define_fd_nba_showdown_slates()
|
| 249 |
+
except:
|
| 250 |
+
nba_slate_names_fd = []
|
| 251 |
+
nba_slate_name_lookup_fd = {}
|
| 252 |
+
|
| 253 |
nfl_reg_salaries = grab_nfl_reg_salaries()
|
| 254 |
+
nba_reg_salaries = grab_nba_reg_salaries()
|
| 255 |
|
| 256 |
# Memory optimization helper functions
|
| 257 |
def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
|
|
|
|
| 623 |
|
| 624 |
with optimals_site_col:
|
| 625 |
if site_var == 'Draftkings':
|
| 626 |
+
if sport_var == 'NBA':
|
| 627 |
+
slate_var3 = st.radio("Which slate data are you loading?", (nba_slate_names_dk if type_var == 'Showdown' else ['Main', 'Secondary', 'Auxiliary']), key='slate_var3_radio')
|
| 628 |
+
elif sport_var == 'NFL':
|
| 629 |
+
slate_var3 = st.radio("Which slate data are you loading?", (nfl_slate_names_dk if type_var == 'Showdown' else ['Main', 'Secondary', 'Auxiliary']), key='slate_var3_radio')
|
| 630 |
+
else:
|
| 631 |
+
slate_var3 = st.radio("Which slate data are you loading?", (['Main', 'Secondary', 'Auxiliary']), key='slate_var3_radio')
|
| 632 |
elif site_var == 'Fanduel':
|
| 633 |
+
if sport_var == 'NBA':
|
| 634 |
+
slate_var3 = st.radio("Which slate data are you loading?", (nba_slate_names_fd if type_var == 'Showdown' else ['Main', 'Secondary', 'Auxiliary']), key='slate_var3_radio')
|
| 635 |
+
elif sport_var == 'NFL':
|
| 636 |
+
slate_var3 = st.radio("Which slate data are you loading?", (nfl_slate_names_fd if type_var == 'Showdown' else ['Main', 'Secondary', 'Auxiliary']), key='slate_var3_radio')
|
| 637 |
+
else:
|
| 638 |
+
slate_var3 = st.radio("Which slate data are you loading?", (['Main', 'Secondary', 'Auxiliary']), key='slate_var3_radio')
|
| 639 |
|
| 640 |
with optimals_macro_col:
|
| 641 |
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1, key='lineup_num_var_input')
|
|
|
|
| 692 |
if st.button("Load from Paydirt DB"):
|
| 693 |
if 'csv_file' in st.session_state:
|
| 694 |
del st.session_state['csv_file']
|
| 695 |
+
if sport_var == 'NBA':
|
| 696 |
+
st.session_state['csv_file'] = load_csv(nba_reg_salaries)
|
| 697 |
+
elif sport_var == 'NFL':
|
| 698 |
+
st.session_state['csv_file'] = load_csv(nfl_reg_salaries)
|
| 699 |
st.session_state['pricing_loaded'] = True
|
| 700 |
|
| 701 |
try:
|
|
|
|
| 761 |
if st.button("Load from Database after inserting site CSV"):
|
| 762 |
if site_var == 'Draftkings':
|
| 763 |
if type_var != 'Showdown':
|
| 764 |
+
if sport_var == 'NBA':
|
| 765 |
+
portfolio_load = init_DK_NBA_lineups(type_var, slate_var3, prio_var, 50, dk_nba_showdown_db_translation, lineup_num_var, [])
|
| 766 |
+
elif sport_var == 'NFL':
|
| 767 |
+
portfolio_load = init_DK_NFL_lineups(type_var, slate_var3, prio_var, 50, dk_nfl_showdown_db_translation, lineup_num_var, [])
|
| 768 |
else:
|
| 769 |
+
if sport_var == 'NBA':
|
| 770 |
+
portfolio_load = init_DK_NBA_lineups(type_var, nba_slate_name_lookup_dk[slate_var3], prio_var, 50, dk_nba_showdown_db_translation, lineup_num_var, [])
|
| 771 |
+
elif sport_var == 'NFL':
|
| 772 |
+
portfolio_load = init_DK_NFL_lineups(type_var, nfl_slate_name_lookup_dk[slate_var3], prio_var, 50, dk_nfl_showdown_db_translation, lineup_num_var, [])
|
| 773 |
st.session_state['db_portfolio_file'] = pd.DataFrame(portfolio_load)
|
| 774 |
st.session_state['portfolio_loaded'] = True
|
| 775 |
if 'portfolio' in st.session_state:
|
|
|
|
| 778 |
del st.session_state['export_portfolio']
|
| 779 |
else:
|
| 780 |
if type_var != 'Showdown':
|
| 781 |
+
if sport_var == 'NBA':
|
| 782 |
+
portfolio_load = init_FD_NBA_lineups(type_var, slate_var3, prio_var, 50, fd_nba_showdown_db_translation, lineup_num_var, [])
|
| 783 |
+
elif sport_var == 'NFL':
|
| 784 |
+
portfolio_load = init_FD_NFL_lineups(type_var, slate_var3, prio_var, 50, fd_nfl_showdown_db_translation, lineup_num_var, [])
|
| 785 |
else:
|
| 786 |
+
if sport_var == 'NBA':
|
| 787 |
+
portfolio_load = init_FD_NBA_lineups(type_var, nba_slate_name_lookup_fd[slate_var3], prio_var, 50, fd_nba_showdown_db_translation, lineup_num_var, [])
|
| 788 |
+
elif sport_var == 'NFL':
|
| 789 |
+
portfolio_load = init_FD_NFL_lineups(type_var, nfl_slate_name_lookup_fd[slate_var3], prio_var, 50, fd_nfl_showdown_db_translation, lineup_num_var, [])
|
| 790 |
st.session_state['db_portfolio_file'] = pd.DataFrame(portfolio_load)
|
| 791 |
st.session_state['portfolio_loaded'] = True
|
| 792 |
if 'portfolio' in st.session_state:
|
|
|
|
| 881 |
st.session_state['projections_loaded'] = True
|
| 882 |
elif proj_options == 'Paydirt DB':
|
| 883 |
if st.button("Load from Database"):
|
| 884 |
+
if sport_var == 'NBA':
|
| 885 |
+
projections_file = init_nba_baselines(type_var, site_var, slate_var3)[0]
|
| 886 |
+
elif sport_var == 'NFL':
|
| 887 |
+
projections_file = init_nfl_baselines(type_var, site_var, slate_var3)[0]
|
| 888 |
st.session_state['db_projections_file'] = projections_file
|
| 889 |
st.session_state['projections_loaded'] = True
|
| 890 |
if 'projections_df' in st.session_state:
|
database_queries.py
CHANGED
|
@@ -436,4 +436,393 @@ def init_FD_NFL_lineups(type_var, slate_var, prio_var, prio_mix, nfl_db_translat
|
|
| 436 |
|
| 437 |
FD_seed = raw_display.to_numpy()
|
| 438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
return FD_seed
|
|
|
|
| 436 |
|
| 437 |
FD_seed = raw_display.to_numpy()
|
| 438 |
|
| 439 |
+
return FD_seed
|
| 440 |
+
|
| 441 |
+
def init_nba_baselines(type_var: str, site_var: str, slate_var: str):
|
| 442 |
+
|
| 443 |
+
if slate_var == 'Main':
|
| 444 |
+
slate_var = 'Main Slate'
|
| 445 |
+
elif slate_var == 'Secondary':
|
| 446 |
+
slate_var = 'Secondary Slate'
|
| 447 |
+
elif slate_var == 'Auxiliary':
|
| 448 |
+
slate_var = 'Late Slate'
|
| 449 |
+
|
| 450 |
+
if type_var == 'Showdown':
|
| 451 |
+
collection = nba_db["Player_SD_Range_Of_Outcomes"]
|
| 452 |
+
cursor = collection.find()
|
| 453 |
+
|
| 454 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 455 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Salary', 'Median', 'Own', 'CPT_Own', 'player_id', 'slate', 'version']]
|
| 456 |
+
raw_display['Median'] = raw_display['Median'].replace('', 0).astype(float)
|
| 457 |
+
raw_display = raw_display.rename(columns={"player_id": "player_ID"})
|
| 458 |
+
raw_display = raw_display.loc[raw_display['Median'] > 0]
|
| 459 |
+
raw_display = raw_display.apply(pd.to_numeric, errors='ignore')
|
| 460 |
+
sd_raw = raw_display.sort_values(by='Median', ascending=False)
|
| 461 |
+
dk_sd_roo_raw = sd_raw[sd_raw['site'] == 'Draftkings']
|
| 462 |
+
dk_sd_id_map = dict(zip(dk_sd_roo_raw['Player'], dk_sd_roo_raw['player_ID']))
|
| 463 |
+
fd_sd_roo_raw = sd_raw[sd_raw['site'] == 'Fanduel']
|
| 464 |
+
fd_sd_id_map = dict(zip(fd_sd_roo_raw['Player'], fd_sd_roo_raw['player_ID']))
|
| 465 |
+
fd_sd_roo_raw['player_ID'] = fd_sd_roo_raw['player_ID'].astype(str)
|
| 466 |
+
fd_sd_roo_raw['player_ID'] = fd_sd_roo_raw['player_ID'].str.rsplit('-', n=1).str[0].astype(str)
|
| 467 |
+
|
| 468 |
+
timestamp = sd_raw['timestamp'].values[0]
|
| 469 |
+
|
| 470 |
+
roo_raw = None
|
| 471 |
+
dk_roo_raw = None
|
| 472 |
+
fd_roo_raw = None
|
| 473 |
+
dk_id_map = None
|
| 474 |
+
fd_id_map = None
|
| 475 |
+
|
| 476 |
+
else:
|
| 477 |
+
collection = nba_db["Player_Range_Of_Outcomes"]
|
| 478 |
+
cursor = collection.find()
|
| 479 |
+
|
| 480 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 481 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Salary', 'Median', 'Own', 'CPT_Own', 'player_id', 'slate', 'version']]
|
| 482 |
+
raw_display = raw_display.rename(columns={"player_id": "player_ID"})
|
| 483 |
+
raw_display['Median'] = raw_display['Median'].replace('', 0).astype(float)
|
| 484 |
+
raw_display = raw_display.loc[raw_display['Median'] > 0]
|
| 485 |
+
dk_roo_raw = raw_display[raw_display['site'] == 'Draftkings']
|
| 486 |
+
fd_roo_raw = raw_display[raw_display['site'] == 'Fanduel']
|
| 487 |
+
dk_id_map = dict(zip(dk_roo_raw['Player'], dk_roo_raw['player_ID']))
|
| 488 |
+
fd_id_map = dict(zip(fd_roo_raw['Player'], fd_roo_raw['player_ID']))
|
| 489 |
+
raw_display = raw_display.apply(pd.to_numeric, errors='ignore')
|
| 490 |
+
roo_raw = raw_display.sort_values(by='Median', ascending=False)
|
| 491 |
+
|
| 492 |
+
timestamp = roo_raw['timestamp'].values[0]
|
| 493 |
+
|
| 494 |
+
sd_raw = None
|
| 495 |
+
dk_sd_roo_raw = None
|
| 496 |
+
fd_sd_roo_raw = None
|
| 497 |
+
dk_sd_id_map = None
|
| 498 |
+
fd_sd_id_map = None
|
| 499 |
+
|
| 500 |
+
return roo_raw, dk_roo_raw, fd_roo_raw, sd_raw, dk_sd_roo_raw, fd_sd_roo_raw, dk_id_map, fd_id_map, dk_sd_id_map, fd_sd_id_map, timestamp
|
| 501 |
+
|
| 502 |
+
def init_DK_NBA_lineups(type_var, slate_var, prio_var, prio_mix, nba_db_translation, lineup_num, player_var2):
|
| 503 |
+
|
| 504 |
+
if prio_var == 'Mix':
|
| 505 |
+
prio_var = None
|
| 506 |
+
|
| 507 |
+
if type_var == 'Regular':
|
| 508 |
+
if slate_var == 'Main':
|
| 509 |
+
collection = nba_db['DK_NBA_name_map']
|
| 510 |
+
cursor = collection.find()
|
| 511 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 512 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 513 |
+
|
| 514 |
+
collection = nba_db['DK_NBA_seed_frame_Main Slate']
|
| 515 |
+
if prio_var == None:
|
| 516 |
+
if player_var2 != []:
|
| 517 |
+
player_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
| 518 |
+
query_conditions = []
|
| 519 |
+
|
| 520 |
+
for player in player_var2:
|
| 521 |
+
# Create a condition for each player to check if they appear in any column
|
| 522 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 523 |
+
query_conditions.append(player_condition)
|
| 524 |
+
|
| 525 |
+
# Combine all player conditions with $or
|
| 526 |
+
if query_conditions:
|
| 527 |
+
filter_query = {'$or': query_conditions}
|
| 528 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 529 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 530 |
+
else:
|
| 531 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 532 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 533 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 534 |
+
else:
|
| 535 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 536 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 537 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 538 |
+
else:
|
| 539 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 540 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 541 |
+
|
| 542 |
+
raw_display = raw_display.drop_duplicates(subset=['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX'])
|
| 543 |
+
|
| 544 |
+
raw_display = raw_display[['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']]
|
| 545 |
+
dict_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
| 546 |
+
# Map names
|
| 547 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 548 |
+
elif slate_var == 'Secondary':
|
| 549 |
+
collection = nba_db['DK_NBA_Secondary_name_map']
|
| 550 |
+
cursor = collection.find()
|
| 551 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 552 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 553 |
+
|
| 554 |
+
collection = nba_db['DK_NBA_seed_frame_Secondary Slate']
|
| 555 |
+
if prio_var == None:
|
| 556 |
+
if player_var2 != []:
|
| 557 |
+
player_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
| 558 |
+
query_conditions = []
|
| 559 |
+
|
| 560 |
+
for player in player_var2:
|
| 561 |
+
# Create a condition for each player to check if they appear in any column
|
| 562 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 563 |
+
query_conditions.append(player_condition)
|
| 564 |
+
|
| 565 |
+
# Combine all player conditions with $or
|
| 566 |
+
if query_conditions:
|
| 567 |
+
filter_query = {'$or': query_conditions}
|
| 568 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 569 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 570 |
+
else:
|
| 571 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 572 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 573 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 574 |
+
else:
|
| 575 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 576 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 577 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 578 |
+
else:
|
| 579 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 580 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 581 |
+
|
| 582 |
+
raw_display = raw_display.drop_duplicates(subset=['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX'])
|
| 583 |
+
|
| 584 |
+
raw_display = raw_display[['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']]
|
| 585 |
+
dict_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
| 586 |
+
# Map names
|
| 587 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 588 |
+
elif slate_var == 'Auxiliary':
|
| 589 |
+
collection = nba_db['DK_NBA_Late_name_map']
|
| 590 |
+
cursor = collection.find()
|
| 591 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 592 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 593 |
+
|
| 594 |
+
collection = nba_db['DK_NBA_seed_frame_Late Slate']
|
| 595 |
+
if prio_var == None:
|
| 596 |
+
if player_var2 != []:
|
| 597 |
+
player_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
| 598 |
+
query_conditions = []
|
| 599 |
+
|
| 600 |
+
for player in player_var2:
|
| 601 |
+
# Create a condition for each player to check if they appear in any column
|
| 602 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 603 |
+
query_conditions.append(player_condition)
|
| 604 |
+
|
| 605 |
+
# Combine all player conditions with $or
|
| 606 |
+
if query_conditions:
|
| 607 |
+
filter_query = {'$or': query_conditions}
|
| 608 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 609 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 610 |
+
else:
|
| 611 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 612 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 613 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 614 |
+
else:
|
| 615 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 616 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 617 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 618 |
+
else:
|
| 619 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 620 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 621 |
+
|
| 622 |
+
raw_display = raw_display.drop_duplicates(subset=['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX'])
|
| 623 |
+
|
| 624 |
+
raw_display = raw_display[['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']]
|
| 625 |
+
dict_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
| 626 |
+
# Map names
|
| 627 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 628 |
+
elif type_var == 'Showdown':
|
| 629 |
+
collection = nba_db[nba_db_translation[slate_var]]
|
| 630 |
+
if prio_var == None:
|
| 631 |
+
if player_var2 != []:
|
| 632 |
+
player_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']
|
| 633 |
+
query_conditions = []
|
| 634 |
+
|
| 635 |
+
for player in player_var2:
|
| 636 |
+
# Create a condition for each player to check if they appear in any column
|
| 637 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 638 |
+
query_conditions.append(player_condition)
|
| 639 |
+
|
| 640 |
+
# Combine all player conditions with $or
|
| 641 |
+
if query_conditions:
|
| 642 |
+
filter_query = {'$or': query_conditions}
|
| 643 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 644 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 645 |
+
else:
|
| 646 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 647 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 648 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 649 |
+
else:
|
| 650 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 651 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 652 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 653 |
+
else:
|
| 654 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 655 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 656 |
+
|
| 657 |
+
raw_display = raw_display.drop_duplicates(subset=['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5'])
|
| 658 |
+
|
| 659 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']]
|
| 660 |
+
|
| 661 |
+
DK_seed = raw_display.to_numpy()
|
| 662 |
+
|
| 663 |
+
return DK_seed
|
| 664 |
+
|
| 665 |
+
def init_FD_NBA_lineups(type_var, slate_var, prio_var, prio_mix, nba_db_translation, lineup_num, player_var2):
|
| 666 |
+
|
| 667 |
+
if prio_var == 'Mix':
|
| 668 |
+
prio_var = None
|
| 669 |
+
|
| 670 |
+
if type_var == 'Regular':
|
| 671 |
+
if slate_var == 'Main':
|
| 672 |
+
collection = nba_db['FD_NBA_name_map']
|
| 673 |
+
cursor = collection.find()
|
| 674 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 675 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 676 |
+
|
| 677 |
+
|
| 678 |
+
collection = nba_db['FD_NBA_seed_frame_Main Slate']
|
| 679 |
+
if prio_var == None:
|
| 680 |
+
if player_var2 != []:
|
| 681 |
+
player_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']
|
| 682 |
+
query_conditions = []
|
| 683 |
+
|
| 684 |
+
for player in player_var2:
|
| 685 |
+
# Create a condition for each player to check if they appear in any column
|
| 686 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 687 |
+
query_conditions.append(player_condition)
|
| 688 |
+
|
| 689 |
+
# Combine all player conditions with $or
|
| 690 |
+
if query_conditions:
|
| 691 |
+
filter_query = {'$or': query_conditions}
|
| 692 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 693 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 694 |
+
else:
|
| 695 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 696 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 697 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 698 |
+
else:
|
| 699 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 700 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 701 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 702 |
+
else:
|
| 703 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 704 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 705 |
+
|
| 706 |
+
raw_display = raw_display.drop_duplicates(subset=['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C'])
|
| 707 |
+
|
| 708 |
+
raw_display = raw_display[['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']]
|
| 709 |
+
dict_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']
|
| 710 |
+
# Map names
|
| 711 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 712 |
+
elif slate_var == 'Secondary':
|
| 713 |
+
collection = nba_db['FD_NBA_Secondary_name_map']
|
| 714 |
+
cursor = collection.find()
|
| 715 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 716 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 717 |
+
|
| 718 |
+
collection = nba_db['FD_NBA_Secondary_seed_frame_Secondary Slate']
|
| 719 |
+
if prio_var == None:
|
| 720 |
+
if player_var2 != []:
|
| 721 |
+
player_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']
|
| 722 |
+
query_conditions = []
|
| 723 |
+
|
| 724 |
+
for player in player_var2:
|
| 725 |
+
# Create a condition for each player to check if they appear in any column
|
| 726 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 727 |
+
query_conditions.append(player_condition)
|
| 728 |
+
|
| 729 |
+
# Combine all player conditions with $or
|
| 730 |
+
if query_conditions:
|
| 731 |
+
filter_query = {'$or': query_conditions}
|
| 732 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 733 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 734 |
+
else:
|
| 735 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 736 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 737 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 738 |
+
else:
|
| 739 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 740 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 741 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 742 |
+
else:
|
| 743 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 744 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 745 |
+
|
| 746 |
+
raw_display = raw_display.drop_duplicates(subset=['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C'])
|
| 747 |
+
|
| 748 |
+
raw_display = raw_display[['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']]
|
| 749 |
+
dict_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']
|
| 750 |
+
# Map names
|
| 751 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 752 |
+
elif slate_var == 'Auxiliary':
|
| 753 |
+
collection = nba_db['FD_NBA_Late_name_map']
|
| 754 |
+
cursor = collection.find()
|
| 755 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 756 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 757 |
+
|
| 758 |
+
collection = nba_db['FD_NBA_Late_seed_frame_Late Slate']
|
| 759 |
+
if prio_var == None:
|
| 760 |
+
if player_var2 != []:
|
| 761 |
+
player_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']
|
| 762 |
+
query_conditions = []
|
| 763 |
+
|
| 764 |
+
for player in player_var2:
|
| 765 |
+
# Create a condition for each player to check if they appear in any column
|
| 766 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 767 |
+
query_conditions.append(player_condition)
|
| 768 |
+
|
| 769 |
+
# Combine all player conditions with $or
|
| 770 |
+
if query_conditions:
|
| 771 |
+
filter_query = {'$or': query_conditions}
|
| 772 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 773 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num = ((100 - prio_mix) / 100)))
|
| 774 |
+
else:
|
| 775 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 776 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 777 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 778 |
+
else:
|
| 779 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 780 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 781 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 782 |
+
else:
|
| 783 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 784 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 785 |
+
|
| 786 |
+
raw_display = raw_display.drop_duplicates(subset=['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C'])
|
| 787 |
+
|
| 788 |
+
raw_display = raw_display[['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']]
|
| 789 |
+
dict_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C']
|
| 790 |
+
# Map names
|
| 791 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 792 |
+
|
| 793 |
+
elif type_var == 'Showdown':
|
| 794 |
+
collection = nba_db[nba_db_translation[slate_var]]
|
| 795 |
+
if prio_var == None:
|
| 796 |
+
if player_var2 != []:
|
| 797 |
+
player_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']
|
| 798 |
+
query_conditions = []
|
| 799 |
+
|
| 800 |
+
for player in player_var2:
|
| 801 |
+
# Create a condition for each player to check if they appear in any column
|
| 802 |
+
player_condition = {'$or': [{col: player} for col in player_columns]}
|
| 803 |
+
query_conditions.append(player_condition)
|
| 804 |
+
|
| 805 |
+
# Combine all player conditions with $or
|
| 806 |
+
if query_conditions:
|
| 807 |
+
filter_query = {'$or': query_conditions}
|
| 808 |
+
cursor1 = collection.find(filter_query).limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 809 |
+
cursor2 = collection.find(filter_query).sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 810 |
+
else:
|
| 811 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 812 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 813 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 814 |
+
else:
|
| 815 |
+
cursor1 = collection.find().limit(math.ceil(lineup_num * (prio_mix / 100)))
|
| 816 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(lineup_num * ((100 - prio_mix) / 100)))
|
| 817 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 818 |
+
else:
|
| 819 |
+
cursor = collection.find().sort(prio_var, -1).limit(lineup_num)
|
| 820 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 821 |
+
|
| 822 |
+
raw_display = raw_display.drop_duplicates(subset=['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5'])
|
| 823 |
+
|
| 824 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']]
|
| 825 |
+
|
| 826 |
+
FD_seed = raw_display.to_numpy()
|
| 827 |
+
|
| 828 |
return FD_seed
|