James McCool
commited on
Commit
·
4c05307
1
Parent(s):
e31f557
Enhance salary retrieval functions to accept slate type parameter for improved data handling. Implement logic for 'Main', 'Secondary', and 'Auxiliary' slates to manage player records effectively, including sorting and deduplication strategies.
Browse files
app.py
CHANGED
|
@@ -128,12 +128,37 @@ st.markdown("""
|
|
| 128 |
|
| 129 |
</style>""", unsafe_allow_html=True)
|
| 130 |
|
| 131 |
-
def grab_nfl_reg_salaries():
|
| 132 |
collection = salaries_db["NFL_reg_player_info"]
|
| 133 |
today_str = datetime.now().strftime("%Y%m%d")
|
| 134 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 135 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 136 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
return records
|
| 138 |
|
| 139 |
def grab_nfl_showdown_salaries():
|
|
@@ -144,12 +169,37 @@ def grab_nfl_showdown_salaries():
|
|
| 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")
|
| 150 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 151 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 152 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
return records
|
| 154 |
|
| 155 |
def grab_nba_showdown_salaries():
|
|
@@ -160,12 +210,37 @@ def grab_nba_showdown_salaries():
|
|
| 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")
|
| 166 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 167 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 168 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
return records
|
| 170 |
|
| 171 |
def grab_mlb_showdown_salaries():
|
|
@@ -176,12 +251,37 @@ def grab_mlb_showdown_salaries():
|
|
| 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")
|
| 182 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 183 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 184 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
return records
|
| 186 |
|
| 187 |
def grab_nhl_showdown_salaries():
|
|
@@ -282,11 +382,6 @@ except:
|
|
| 282 |
nba_slate_names_fd = []
|
| 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):
|
| 292 |
"""Process name matching in chunks to reduce memory usage"""
|
|
@@ -649,6 +744,11 @@ with st.container():
|
|
| 649 |
salary_max = 60000
|
| 650 |
elif type_var == 'Showdown':
|
| 651 |
salary_max = 60000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
|
| 653 |
with st.expander("Info and Filters"):
|
| 654 |
prio_col, optimals_site_col, optimals_salary_col, optimals_stacks_col = st.columns(4)
|
|
|
|
| 128 |
|
| 129 |
</style>""", unsafe_allow_html=True)
|
| 130 |
|
| 131 |
+
def grab_nfl_reg_salaries(slate_var: str):
|
| 132 |
collection = salaries_db["NFL_reg_player_info"]
|
| 133 |
today_str = datetime.now().strftime("%Y%m%d")
|
| 134 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 135 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 136 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 137 |
+
if slate_var == 'Main':
|
| 138 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 139 |
+
records = records.drop_duplicates(subset=['Name'], keep='first')
|
| 140 |
+
elif slate_var == 'Secondary':
|
| 141 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 142 |
+
# Keep middle occurrence: drop first and last, keep middle
|
| 143 |
+
grouped = records.groupby('Name')
|
| 144 |
+
middle_records = []
|
| 145 |
+
for name, group in grouped:
|
| 146 |
+
if len(group) == 1:
|
| 147 |
+
# Only one record, keep it
|
| 148 |
+
middle_records.append(group)
|
| 149 |
+
elif len(group) == 2:
|
| 150 |
+
# Two records, keep the second one (last)
|
| 151 |
+
middle_records.append(group.iloc[1:2])
|
| 152 |
+
else:
|
| 153 |
+
# Three or more records, keep the middle one(s)
|
| 154 |
+
# For odd number of records, keep the true middle
|
| 155 |
+
# For even number of records, keep the record at index len//2
|
| 156 |
+
middle_idx = len(group) // 2
|
| 157 |
+
middle_records.append(group.iloc[middle_idx:middle_idx+1])
|
| 158 |
+
records = pd.concat(middle_records, ignore_index=True)
|
| 159 |
+
elif slate_var == 'Auxiliary':
|
| 160 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 161 |
+
records = records.drop_duplicates(subset=['Name'], keep='last')
|
| 162 |
return records
|
| 163 |
|
| 164 |
def grab_nfl_showdown_salaries():
|
|
|
|
| 169 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 170 |
return records
|
| 171 |
|
| 172 |
+
def grab_nba_reg_salaries(slate_var: str):
|
| 173 |
collection = salaries_db["NBA_reg_player_info"]
|
| 174 |
today_str = datetime.now().strftime("%Y%m%d")
|
| 175 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 176 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 177 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 178 |
+
if slate_var == 'Main':
|
| 179 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 180 |
+
records = records.drop_duplicates(subset=['Name'], keep='first')
|
| 181 |
+
elif slate_var == 'Secondary':
|
| 182 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 183 |
+
# Keep middle occurrence: drop first and last, keep middle
|
| 184 |
+
grouped = records.groupby('Name')
|
| 185 |
+
middle_records = []
|
| 186 |
+
for name, group in grouped:
|
| 187 |
+
if len(group) == 1:
|
| 188 |
+
# Only one record, keep it
|
| 189 |
+
middle_records.append(group)
|
| 190 |
+
elif len(group) == 2:
|
| 191 |
+
# Two records, keep the second one (last)
|
| 192 |
+
middle_records.append(group.iloc[1:2])
|
| 193 |
+
else:
|
| 194 |
+
# Three or more records, keep the middle one(s)
|
| 195 |
+
# For odd number of records, keep the true middle
|
| 196 |
+
# For even number of records, keep the record at index len//2
|
| 197 |
+
middle_idx = len(group) // 2
|
| 198 |
+
middle_records.append(group.iloc[middle_idx:middle_idx+1])
|
| 199 |
+
records = pd.concat(middle_records, ignore_index=True)
|
| 200 |
+
elif slate_var == 'Auxiliary':
|
| 201 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 202 |
+
records = records.drop_duplicates(subset=['Name'], keep='last')
|
| 203 |
return records
|
| 204 |
|
| 205 |
def grab_nba_showdown_salaries():
|
|
|
|
| 210 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 211 |
return records
|
| 212 |
|
| 213 |
+
def grab_mlb_reg_salaries(slate_var: str):
|
| 214 |
collection = salaries_db["MLB_reg_player_info"]
|
| 215 |
today_str = datetime.now().strftime("%Y%m%d")
|
| 216 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 217 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 218 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 219 |
+
if slate_var == 'Main':
|
| 220 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 221 |
+
records = records.drop_duplicates(subset=['Name'], keep='first')
|
| 222 |
+
elif slate_var == 'Secondary':
|
| 223 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 224 |
+
# Keep middle occurrence: drop first and last, keep middle
|
| 225 |
+
grouped = records.groupby('Name')
|
| 226 |
+
middle_records = []
|
| 227 |
+
for name, group in grouped:
|
| 228 |
+
if len(group) == 1:
|
| 229 |
+
# Only one record, keep it
|
| 230 |
+
middle_records.append(group)
|
| 231 |
+
elif len(group) == 2:
|
| 232 |
+
# Two records, keep the second one (last)
|
| 233 |
+
middle_records.append(group.iloc[1:2])
|
| 234 |
+
else:
|
| 235 |
+
# Three or more records, keep the middle one(s)
|
| 236 |
+
# For odd number of records, keep the true middle
|
| 237 |
+
# For even number of records, keep the record at index len//2
|
| 238 |
+
middle_idx = len(group) // 2
|
| 239 |
+
middle_records.append(group.iloc[middle_idx:middle_idx+1])
|
| 240 |
+
records = pd.concat(middle_records, ignore_index=True)
|
| 241 |
+
elif slate_var == 'Auxiliary':
|
| 242 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 243 |
+
records = records.drop_duplicates(subset=['Name'], keep='last')
|
| 244 |
return records
|
| 245 |
|
| 246 |
def grab_mlb_showdown_salaries():
|
|
|
|
| 251 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 252 |
return records
|
| 253 |
|
| 254 |
+
def grab_nhl_reg_salaries(slate_var: str):
|
| 255 |
collection = salaries_db["NHL_reg_player_info"]
|
| 256 |
today_str = datetime.now().strftime("%Y%m%d")
|
| 257 |
records = pd.DataFrame(list(collection.find({'Contest Date': {'$gte': today_str}})))
|
| 258 |
records = records[['Display Name', 'draftableId', 'Position', 'Salary']]
|
| 259 |
records = records.rename(columns={'Display Name': 'Name', 'draftableId': 'ID', 'Position': 'Roster Position'})
|
| 260 |
+
if slate_var == 'Main':
|
| 261 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 262 |
+
records = records.drop_duplicates(subset=['Name'], keep='first')
|
| 263 |
+
elif slate_var == 'Secondary':
|
| 264 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 265 |
+
# Keep middle occurrence: drop first and last, keep middle
|
| 266 |
+
grouped = records.groupby('Name')
|
| 267 |
+
middle_records = []
|
| 268 |
+
for name, group in grouped:
|
| 269 |
+
if len(group) == 1:
|
| 270 |
+
# Only one record, keep it
|
| 271 |
+
middle_records.append(group)
|
| 272 |
+
elif len(group) == 2:
|
| 273 |
+
# Two records, keep the second one (last)
|
| 274 |
+
middle_records.append(group.iloc[1:2])
|
| 275 |
+
else:
|
| 276 |
+
# Three or more records, keep the middle one(s)
|
| 277 |
+
# For odd number of records, keep the true middle
|
| 278 |
+
# For even number of records, keep the record at index len//2
|
| 279 |
+
middle_idx = len(group) // 2
|
| 280 |
+
middle_records.append(group.iloc[middle_idx:middle_idx+1])
|
| 281 |
+
records = pd.concat(middle_records, ignore_index=True)
|
| 282 |
+
elif slate_var == 'Auxiliary':
|
| 283 |
+
records = records.sort_values(by='ID', ascending=True)
|
| 284 |
+
records = records.drop_duplicates(subset=['Name'], keep='last')
|
| 285 |
return records
|
| 286 |
|
| 287 |
def grab_nhl_showdown_salaries():
|
|
|
|
| 382 |
nba_slate_names_fd = []
|
| 383 |
nba_slate_name_lookup_fd = {}
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
# Memory optimization helper functions
|
| 386 |
def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
|
| 387 |
"""Process name matching in chunks to reduce memory usage"""
|
|
|
|
| 744 |
salary_max = 60000
|
| 745 |
elif type_var == 'Showdown':
|
| 746 |
salary_max = 60000
|
| 747 |
+
|
| 748 |
+
nfl_reg_salaries = grab_nfl_reg_salaries(slate_var3)
|
| 749 |
+
nfl_showdown_salaries = grab_nfl_showdown_salaries(slate_var3)
|
| 750 |
+
nba_reg_salaries = grab_nba_reg_salaries(slate_var3)
|
| 751 |
+
nba_showdown_salaries = grab_nba_showdown_salaries(slate_var3)
|
| 752 |
|
| 753 |
with st.expander("Info and Filters"):
|
| 754 |
prio_col, optimals_site_col, optimals_salary_col, optimals_stacks_col = st.columns(4)
|