James McCool
commited on
Commit
·
91652d3
1
Parent(s):
c982556
Adding showdown support
Browse files- app.py +58 -6
- database_queries.py +4 -4
app.py
CHANGED
|
@@ -136,6 +136,14 @@ def grab_nfl_reg_salaries():
|
|
| 136 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 137 |
return records
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
def grab_nba_reg_salaries():
|
| 140 |
collection = salaries_db["NBA_reg_player_info"]
|
| 141 |
today_str = datetime.now().strftime("%Y%m%d")
|
|
@@ -144,6 +152,14 @@ def grab_nba_reg_salaries():
|
|
| 144 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 145 |
return records
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
def grab_mlb_reg_salaries():
|
| 148 |
collection = salaries_db["MLB_reg_player_info"]
|
| 149 |
today_str = datetime.now().strftime("%Y%m%d")
|
|
@@ -152,6 +168,14 @@ def grab_mlb_reg_salaries():
|
|
| 152 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 153 |
return records
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
def grab_nhl_reg_salaries():
|
| 156 |
collection = salaries_db["NHL_reg_player_info"]
|
| 157 |
today_str = datetime.now().strftime("%Y%m%d")
|
|
@@ -160,6 +184,14 @@ def grab_nhl_reg_salaries():
|
|
| 160 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 161 |
return records
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
def define_dk_nfl_showdown_slates():
|
| 164 |
collection = nfl_db["DK_SD_NFL_ROO"]
|
| 165 |
cursor = collection.find()
|
|
@@ -251,7 +283,9 @@ except:
|
|
| 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):
|
|
@@ -693,9 +727,15 @@ if selected_tab == 'Data Load':
|
|
| 693 |
if 'csv_file' in st.session_state:
|
| 694 |
del st.session_state['csv_file']
|
| 695 |
if sport_var == 'NBA':
|
| 696 |
-
|
|
|
|
|
|
|
|
|
|
| 697 |
elif sport_var == 'NFL':
|
| 698 |
-
|
|
|
|
|
|
|
|
|
|
| 699 |
st.session_state['pricing_loaded'] = True
|
| 700 |
|
| 701 |
try:
|
|
@@ -883,14 +923,26 @@ if selected_tab == 'Data Load':
|
|
| 883 |
if st.button("Load from Database"):
|
| 884 |
if sport_var == 'NBA':
|
| 885 |
if site_var == 'Draftkings':
|
| 886 |
-
|
|
|
|
|
|
|
|
|
|
| 887 |
elif site_var == 'Fanduel':
|
| 888 |
-
|
|
|
|
|
|
|
|
|
|
| 889 |
elif sport_var == 'NFL':
|
| 890 |
if site_var == 'Draftkings':
|
| 891 |
-
|
|
|
|
|
|
|
|
|
|
| 892 |
elif site_var == 'Fanduel':
|
| 893 |
-
|
|
|
|
|
|
|
|
|
|
| 894 |
st.session_state['db_projections_file'] = projections_file
|
| 895 |
st.session_state['projections_loaded'] = True
|
| 896 |
if 'projections_df' in st.session_state:
|
|
|
|
| 136 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 137 |
return records
|
| 138 |
|
| 139 |
+
def grab_nfl_showdown_salaries():
|
| 140 |
+
collection = salaries_db["NFL_showdown_player_info"]
|
| 141 |
+
today_str = datetime.now().strftime("%Y%m%d")
|
| 142 |
+
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 143 |
+
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 144 |
+
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 145 |
+
return records
|
| 146 |
+
|
| 147 |
def grab_nba_reg_salaries():
|
| 148 |
collection = salaries_db["NBA_reg_player_info"]
|
| 149 |
today_str = datetime.now().strftime("%Y%m%d")
|
|
|
|
| 152 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 153 |
return records
|
| 154 |
|
| 155 |
+
def grab_nba_showdown_salaries():
|
| 156 |
+
collection = salaries_db["NBA_showdown_player_info"]
|
| 157 |
+
today_str = datetime.now().strftime("%Y%m%d")
|
| 158 |
+
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 159 |
+
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 160 |
+
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 161 |
+
return records
|
| 162 |
+
|
| 163 |
def grab_mlb_reg_salaries():
|
| 164 |
collection = salaries_db["MLB_reg_player_info"]
|
| 165 |
today_str = datetime.now().strftime("%Y%m%d")
|
|
|
|
| 168 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 169 |
return records
|
| 170 |
|
| 171 |
+
def grab_mlb_showdown_salaries():
|
| 172 |
+
collection = salaries_db["MLB_showdown_player_info"]
|
| 173 |
+
today_str = datetime.now().strftime("%Y%m%d")
|
| 174 |
+
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 175 |
+
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 176 |
+
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 177 |
+
return records
|
| 178 |
+
|
| 179 |
def grab_nhl_reg_salaries():
|
| 180 |
collection = salaries_db["NHL_reg_player_info"]
|
| 181 |
today_str = datetime.now().strftime("%Y%m%d")
|
|
|
|
| 184 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 185 |
return records
|
| 186 |
|
| 187 |
+
def grab_nhl_showdown_salaries():
|
| 188 |
+
collection = salaries_db["NHL_showdown_player_info"]
|
| 189 |
+
today_str = datetime.now().strftime("%Y%m%d")
|
| 190 |
+
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 191 |
+
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 192 |
+
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 193 |
+
return records
|
| 194 |
+
|
| 195 |
def define_dk_nfl_showdown_slates():
|
| 196 |
collection = nfl_db["DK_SD_NFL_ROO"]
|
| 197 |
cursor = collection.find()
|
|
|
|
| 283 |
nba_slate_name_lookup_fd = {}
|
| 284 |
|
| 285 |
nfl_reg_salaries = grab_nfl_reg_salaries()
|
| 286 |
+
nfl_showdown_salaries = grab_nfl_showdown_salaries()
|
| 287 |
nba_reg_salaries = grab_nba_reg_salaries()
|
| 288 |
+
nba_showdown_salaries = grab_nba_showdown_salaries()
|
| 289 |
|
| 290 |
# Memory optimization helper functions
|
| 291 |
def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
|
|
|
|
| 727 |
if 'csv_file' in st.session_state:
|
| 728 |
del st.session_state['csv_file']
|
| 729 |
if sport_var == 'NBA':
|
| 730 |
+
if type_var == 'Classic':
|
| 731 |
+
st.session_state['csv_file'] = load_csv(nba_reg_salaries)
|
| 732 |
+
elif type_var == 'Showdown':
|
| 733 |
+
st.session_state['csv_file'] = load_csv(nba_showdown_salaries)
|
| 734 |
elif sport_var == 'NFL':
|
| 735 |
+
if type_var == 'Classic':
|
| 736 |
+
st.session_state['csv_file'] = load_csv(nfl_reg_salaries)
|
| 737 |
+
elif type_var == 'Showdown':
|
| 738 |
+
st.session_state['csv_file'] = load_csv(nfl_showdown_salaries)
|
| 739 |
st.session_state['pricing_loaded'] = True
|
| 740 |
|
| 741 |
try:
|
|
|
|
| 923 |
if st.button("Load from Database"):
|
| 924 |
if sport_var == 'NBA':
|
| 925 |
if site_var == 'Draftkings':
|
| 926 |
+
if type_var == 'Classic':
|
| 927 |
+
projections_file = init_nba_baselines(type_var, site_var, slate_var3)[0]
|
| 928 |
+
elif type_var == 'Showdown':
|
| 929 |
+
projections_file = init_nba_baselines(type_var, site_var, slate_var3)[2]
|
| 930 |
elif site_var == 'Fanduel':
|
| 931 |
+
if type_var == 'Classic':
|
| 932 |
+
projections_file = init_nba_baselines(type_var, site_var, slate_var3)[1]
|
| 933 |
+
elif type_var == 'Showdown':
|
| 934 |
+
projections_file = init_nba_baselines(type_var, site_var, slate_var3)[3]
|
| 935 |
elif sport_var == 'NFL':
|
| 936 |
if site_var == 'Draftkings':
|
| 937 |
+
if type_var == 'Classic':
|
| 938 |
+
projections_file = init_nfl_baselines(type_var, site_var, slate_var3)[0]
|
| 939 |
+
elif type_var == 'Showdown':
|
| 940 |
+
projections_file = init_nfl_baselines(type_var, site_var, slate_var3)[2]
|
| 941 |
elif site_var == 'Fanduel':
|
| 942 |
+
if type_var == 'Classic':
|
| 943 |
+
projections_file = init_nfl_baselines(type_var, site_var, slate_var3)[1]
|
| 944 |
+
elif type_var == 'Showdown':
|
| 945 |
+
projections_file = init_nfl_baselines(type_var, site_var, slate_var3)[3]
|
| 946 |
st.session_state['db_projections_file'] = projections_file
|
| 947 |
st.session_state['projections_loaded'] = True
|
| 948 |
if 'projections_df' in st.session_state:
|
database_queries.py
CHANGED
|
@@ -465,11 +465,11 @@ def init_nba_baselines(type_var: str, site_var: str, slate_var: str):
|
|
| 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 |
-
|
| 469 |
-
|
| 470 |
|
| 471 |
-
|
| 472 |
-
|
| 473 |
|
| 474 |
dk_roo_raw = None
|
| 475 |
fd_roo_raw = None
|
|
|
|
| 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 |
+
dk_sd_roo_raw = dk_sd_roo_raw.drop(columns=['player_ID', 'slate', 'version', 'timestamp', 'site'])
|
| 469 |
+
fd_sd_roo_raw = fd_sd_roo_raw.drop(columns=['player_ID', 'slate', 'version', 'timestamp', 'site'])
|
| 470 |
|
| 471 |
+
dk_sd_roo_raw = dk_sd_roo_raw.rename(columns={'Player': 'player_names', 'Position': 'position', 'Team': 'team', 'Salary': 'salary', 'Median': 'median', 'Own': 'ownership', 'CPT_Own': 'captain ownership'})
|
| 472 |
+
fd_sd_roo_raw = fd_sd_roo_raw.rename(columns={'Player': 'player_names', 'Position': 'position', 'Team': 'team', 'Salary': 'salary', 'Median': 'median', 'Own': 'ownership', 'CPT_Own': 'captain ownership'})
|
| 473 |
|
| 474 |
dk_roo_raw = None
|
| 475 |
fd_roo_raw = None
|