Spaces:
Runtime error
Runtime error
James McCool
commited on
Commit
·
b2288d3
1
Parent(s):
87e322f
Removed GPP sepcific options, set optimizer to be bare bones
Browse files
app.py
CHANGED
|
@@ -15,34 +15,51 @@ from itertools import combinations
|
|
| 15 |
|
| 16 |
@st.cache_resource
|
| 17 |
def init_conn():
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
expose_format = {'Proj Own': '{:.2%}','Exposure': '{:.2%}'}
|
| 40 |
|
| 41 |
-
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1NmKa-b-2D3w7rRxwMPSchh31GKfJ1XcDI2GU8rXWnHI/edit#gid=943304327'
|
| 42 |
-
|
| 43 |
@st.cache_resource(ttl = 599)
|
| 44 |
def grab_baseline_stuff():
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
worksheet = sh.worksheet('Player_Data_Master')
|
| 47 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 48 |
raw_display.replace(' - ', 0, inplace=True)
|
|
@@ -53,15 +70,6 @@ def grab_baseline_stuff():
|
|
| 53 |
dk_raw_proj = dk_raw_proj.dropna(subset='Salary')
|
| 54 |
fd_raw_proj = raw_display[[' Clean Name ', ' Team ', ' Opp ', ' Line ', ' PP Unit ', ' FD Position ', ' FD Salary ', ' Final FD Projection ', ' FD uploadID ', 'FD_Own', ' MainSlateFD ']]
|
| 55 |
fd_raw_proj = fd_raw_proj.set_axis(['Player', 'Team', 'Opp', 'Line', 'PP Unit', 'Position', 'Salary', 'Median', 'player_id', 'Own', 'MainSlateFD'], axis=1)
|
| 56 |
-
# fd_raw_proj = fd_raw_proj.dropna(subset='Salary')
|
| 57 |
-
# dk_raw_proj['Salary'] = dk_raw_proj['Salary'].str.replace(',', '')
|
| 58 |
-
# dk_raw_proj['Salary'] = dk_raw_proj['Salary'].str.replace('.', '')
|
| 59 |
-
# dk_raw_proj['Median'] = dk_raw_proj['Median'].astype(float)
|
| 60 |
-
# dk_raw_proj['Salary'] = dk_raw_proj['Salary'].str[:-2].astype(int)
|
| 61 |
-
# fd_raw_proj['Salary'] = fd_raw_proj['Salary'].str.replace(',', '')
|
| 62 |
-
# fd_raw_proj['Salary'] = fd_raw_proj['Salary'].str.replace('.', '')
|
| 63 |
-
# fd_raw_proj['Median'] = fd_raw_proj['Median'].astype(float)
|
| 64 |
-
# fd_raw_proj['Salary'] = fd_raw_proj['Salary'].str[:-2].astype(int)
|
| 65 |
dk_raw_proj['Own'] = dk_raw_proj['Own'].astype(float)
|
| 66 |
fd_raw_proj['Own'] = fd_raw_proj['Own'].astype(float)
|
| 67 |
dk_raw_proj['player_id'] = dk_raw_proj['player_id'].astype(str)
|
|
@@ -91,25 +99,9 @@ dk_raw_proj, fd_raw_proj, dkid_dict, fdid_dict, timestamp, line_frame = grab_bas
|
|
| 91 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 92 |
opp_dict = dict(zip(dk_raw_proj.Team, dk_raw_proj.Opp))
|
| 93 |
|
| 94 |
-
tab1, tab2 = st.tabs(['Uploads and Info'
|
| 95 |
-
|
| 96 |
-
with tab1:
|
| 97 |
-
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', 'Line', 'PP Unit', 'Own', and 'player_id'. The player_id is the draftkings or fanduel ID associated with the player for upload.")
|
| 98 |
-
col1, col2 = st.columns([1, 5])
|
| 99 |
-
|
| 100 |
-
with col1:
|
| 101 |
-
proj_file = st.file_uploader("Upload Projections File", key = 'proj_uploader')
|
| 102 |
-
|
| 103 |
-
if proj_file is not None:
|
| 104 |
-
try:
|
| 105 |
-
proj_dataframe = pd.read_csv(proj_file)
|
| 106 |
-
except:
|
| 107 |
-
proj_dataframe = pd.read_excel(proj_file)
|
| 108 |
-
with col2:
|
| 109 |
-
if proj_file is not None:
|
| 110 |
-
st.dataframe(proj_dataframe.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 111 |
|
| 112 |
-
with
|
| 113 |
col1, col2 = st.columns([1, 5])
|
| 114 |
with col1:
|
| 115 |
st.info(t_stamp)
|
|
@@ -143,15 +135,7 @@ with tab2:
|
|
| 143 |
init_baselines = init_baselines.loc[init_baselines['MainSlateFD'] == ' Main ']
|
| 144 |
if mainvar1 != 'Main Slate':
|
| 145 |
init_baselines = init_baselines.loc[init_baselines['MainSlateFD'] != ' Main ']
|
| 146 |
-
contest_var1 = st.selectbox("What contest type are you optimizing for?", ('Cash', '
|
| 147 |
-
if contest_var1 != 'Cash':
|
| 148 |
-
stack_var1 = st.selectbox('Which team are you stacking?', options = init_baselines['Team'].unique(), key='stack_var1')
|
| 149 |
-
stack_size_var1 = st.selectbox('What size of stack?', options = [3, 4], key='stack_size_var1')
|
| 150 |
-
line_choice_var1 = st.selectbox('Which line for main?', options = [1, 2, 3, 4], key='line_choice_var1')
|
| 151 |
-
ministack_var1 = st.selectbox('Who should be the secondary stack?', options = init_baselines['Team'].unique(), key='ministack_var1')
|
| 152 |
-
ministack_size_var1 = st.selectbox('What size of secondary stack?', options = [2, 3, 4], key='ministack_size_var1')
|
| 153 |
-
miniline_choice_var1 = st.selectbox('Which line for secondary?', options = [1, 2, 3, 4], key='miniline_choice_var1')
|
| 154 |
-
opp_var1 = opp_dict[stack_var1]
|
| 155 |
split_var1 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var1')
|
| 156 |
if split_var1 == 'Specific Games':
|
| 157 |
team_var1 = st.multiselect('Which teams would you like to include in the optimization?', options = init_baselines['Team'].unique(), key='team_var1')
|
|
@@ -161,30 +145,15 @@ with tab2:
|
|
| 161 |
avoid_var1 = st.multiselect("Are there any players you want to remove from the pool (Drop Button)?", options = init_baselines['Player'].unique(), key='avoid_var1')
|
| 162 |
linenum_var1 = st.number_input("How many lineups would you like to produce?", min_value = 1, max_value = 300, value = 20, step = 1, key='linenum_var1')
|
| 163 |
if site_var1 == 'Draftkings':
|
| 164 |
-
min_sal1 = st.number_input('Min Salary', min_value = 35000, max_value = 49900, value =
|
| 165 |
max_sal1 = st.number_input('Max Salary', min_value = 35000, max_value = 50000, value = 50000, step = 100, key='max_sal1')
|
| 166 |
elif site_var1 == 'Fanduel':
|
| 167 |
-
min_sal1 = st.number_input('Min Salary', min_value = 45000, max_value = 54900, value =
|
| 168 |
max_sal1 = st.number_input('Max Salary', min_value = 45000, max_value = 55000, value = 55000, step = 100, key='max_sal1')
|
| 169 |
with col2:
|
| 170 |
init_baselines = init_baselines[init_baselines['Team'].isin(team_var1)]
|
| 171 |
init_baselines = init_baselines[~init_baselines['Player'].isin(avoid_var1)]
|
| 172 |
ownframe = init_baselines.copy()
|
| 173 |
-
if contest_var1 == 'Cash':
|
| 174 |
-
ownframe['Own%'] = np.where((ownframe['Position'] == 'G') & (ownframe['Own'] - ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean() >= 0), ownframe['Own'] * (10 * (ownframe['Own'] - ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean())/100) + ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean(), ownframe['Own'])
|
| 175 |
-
ownframe['Own%'] = np.where((ownframe['Position'] != 'G') & (ownframe['Own'] - ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean() >= 0), ownframe['Own'] * (5 * (ownframe['Own'] - ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean())/100) + ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean(), ownframe['Own%'])
|
| 176 |
-
ownframe['Own%'] = np.where(ownframe['Own%'] > 75, 75, ownframe['Own%'])
|
| 177 |
-
ownframe['Own'] = ownframe['Own%'] * (900 / ownframe['Own%'].sum())
|
| 178 |
-
if contest_var1 == 'Small Field GPP':
|
| 179 |
-
ownframe['Own%'] = np.where((ownframe['Position'] == 'G') & (ownframe['Own'] - ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean() >= 0), ownframe['Own'] * (6 * (ownframe['Own'] - ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean())/100) + ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean(), ownframe['Own'])
|
| 180 |
-
ownframe['Own%'] = np.where((ownframe['Position'] != 'G') & (ownframe['Own'] - ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean() >= 0), ownframe['Own'] * (3 * (ownframe['Own'] - ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean())/100) + ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean(), ownframe['Own%'])
|
| 181 |
-
ownframe['Own%'] = np.where(ownframe['Own%'] > 75, 75, ownframe['Own%'])
|
| 182 |
-
ownframe['Own'] = ownframe['Own%'] * (900 / ownframe['Own%'].sum())
|
| 183 |
-
if contest_var1 == 'Large Field GPP':
|
| 184 |
-
ownframe['Own%'] = np.where((ownframe['Position'] == 'G') & (ownframe['Own'] - ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean() >= 0), ownframe['Own'] * (3 * (ownframe['Own'] - ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean())/100) + ownframe.loc[ownframe['Position'] == 'G', 'Own'].mean(), ownframe['Own'])
|
| 185 |
-
ownframe['Own%'] = np.where((ownframe['Position'] != 'G') & (ownframe['Own'] - ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean() >= 0), ownframe['Own'] * (1.5 * (ownframe['Own'] - ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean())/100) + ownframe.loc[ownframe['Position'] != 'G', 'Own'].mean(), ownframe['Own%'])
|
| 186 |
-
ownframe['Own%'] = np.where(ownframe['Own%'] > 75, 75, ownframe['Own%'])
|
| 187 |
-
ownframe['Own'] = ownframe['Own%'] * (900 / ownframe['Own%'].sum())
|
| 188 |
raw_baselines = ownframe[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Line', 'PP Unit', 'Median', 'Own']]
|
| 189 |
raw_baselines = raw_baselines.sort_values(by='Median', ascending=False)
|
| 190 |
raw_baselines['lock'] = np.where(raw_baselines['Player'].isin(lock_var1), 1, 0)
|
|
@@ -252,19 +221,9 @@ with tab2:
|
|
| 252 |
|
| 253 |
if site_var1 == 'Draftkings':
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) <= 4
|
| 259 |
-
elif contest_var1 != 'Cash':
|
| 260 |
-
for flex in flex_file['Team'].unique():
|
| 261 |
-
sub_idx = flex_file[(flex_file['Team'] == stack_var1) & (flex_file['Position'] != 'G') & (flex_file['Position'] != 'D')
|
| 262 |
-
& (flex_file['Line'] == line_choice_var1)].index
|
| 263 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == stack_size_var1
|
| 264 |
-
for flex in flex_file['Team'].unique():
|
| 265 |
-
sub_idx = flex_file[(flex_file['Team'] == ministack_var1) & (flex_file['Position'] != 'G') & (flex_file['Position'] != 'D')
|
| 266 |
-
& (flex_file['Line'] == miniline_choice_var1)].index
|
| 267 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == ministack_size_var1
|
| 268 |
|
| 269 |
for flex in flex_file['lock'].unique():
|
| 270 |
sub_idx = flex_file[flex_file['lock'] == 1].index
|
|
@@ -304,19 +263,9 @@ with tab2:
|
|
| 304 |
|
| 305 |
elif site_var1 == 'Fanduel':
|
| 306 |
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) <= 4
|
| 311 |
-
elif contest_var1 != 'Cash':
|
| 312 |
-
for flex in flex_file['Team'].unique():
|
| 313 |
-
sub_idx = flex_file[(flex_file['Team'] == stack_var1) & (flex_file['Position'] != 'G') & (flex_file['Position'] != 'D')
|
| 314 |
-
& (flex_file['Line'] == line_choice_var1)].index
|
| 315 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == stack_size_var1
|
| 316 |
-
for flex in flex_file['Team'].unique():
|
| 317 |
-
sub_idx = flex_file[(flex_file['Team'] == ministack_var1) & (flex_file['Position'] != 'G') & (flex_file['Position'] != 'D')
|
| 318 |
-
& (flex_file['Line'] == miniline_choice_var1)].index
|
| 319 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == ministack_size_var1
|
| 320 |
|
| 321 |
for flex in flex_file['lock'].unique():
|
| 322 |
sub_idx = flex_file[flex_file['lock'] == 1].index
|
|
@@ -651,4 +600,20 @@ with tab2:
|
|
| 651 |
with freq_container:
|
| 652 |
freq_container = st.empty()
|
| 653 |
if 'player_freq' in st.session_state:
|
| 654 |
-
st.dataframe(st.session_state.player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(expose_format, precision=2), use_container_width = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
@st.cache_resource
|
| 17 |
def init_conn():
|
| 18 |
+
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
| 19 |
+
|
| 20 |
+
credentials = {
|
| 21 |
+
"type": "service_account",
|
| 22 |
+
"project_id": "model-sheets-connect",
|
| 23 |
+
"private_key_id": st.secrets['model_sheets_connect_pk'],
|
| 24 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23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KDupJEYqSrseRbK/ax43DDITS77/DWwHl33D3FYC\nMblUm8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
|
| 25 |
+
"client_email": "gspread-connection@model-sheets-connect.iam.gserviceaccount.com",
|
| 26 |
+
"client_id": "100369174533302798535",
|
| 27 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 28 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 29 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 30 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
credentials2 = {
|
| 34 |
+
"type": "service_account",
|
| 35 |
+
"project_id": "sheets-api-connect-378620",
|
| 36 |
+
"private_key_id": st.secrets['sheets_api_connect_pk'],
|
| 37 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnb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ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
| 38 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
| 39 |
+
"client_id": "106625872877651920064",
|
| 40 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 41 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 42 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 43 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
NHL_Data = st.secrets['NHL_Data']
|
| 47 |
+
|
| 48 |
+
gc = gspread.service_account_from_dict(credentials)
|
| 49 |
+
gc2 = gspread.service_account_from_dict(credentials2)
|
| 50 |
+
|
| 51 |
+
return gc, gc2, NHL_Data
|
| 52 |
+
|
| 53 |
+
gcservice_account, gcservice_account2, NHL_Data = init_conn()
|
| 54 |
|
| 55 |
expose_format = {'Proj Own': '{:.2%}','Exposure': '{:.2%}'}
|
| 56 |
|
|
|
|
|
|
|
| 57 |
@st.cache_resource(ttl = 599)
|
| 58 |
def grab_baseline_stuff():
|
| 59 |
+
try:
|
| 60 |
+
sh = gcservice_account.open_by_url(NHL_Data)
|
| 61 |
+
except:
|
| 62 |
+
sh = gcservice_account2.open_by_url(NHL_Data)
|
| 63 |
worksheet = sh.worksheet('Player_Data_Master')
|
| 64 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 65 |
raw_display.replace(' - ', 0, inplace=True)
|
|
|
|
| 70 |
dk_raw_proj = dk_raw_proj.dropna(subset='Salary')
|
| 71 |
fd_raw_proj = raw_display[[' Clean Name ', ' Team ', ' Opp ', ' Line ', ' PP Unit ', ' FD Position ', ' FD Salary ', ' Final FD Projection ', ' FD uploadID ', 'FD_Own', ' MainSlateFD ']]
|
| 72 |
fd_raw_proj = fd_raw_proj.set_axis(['Player', 'Team', 'Opp', 'Line', 'PP Unit', 'Position', 'Salary', 'Median', 'player_id', 'Own', 'MainSlateFD'], axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
dk_raw_proj['Own'] = dk_raw_proj['Own'].astype(float)
|
| 74 |
fd_raw_proj['Own'] = fd_raw_proj['Own'].astype(float)
|
| 75 |
dk_raw_proj['player_id'] = dk_raw_proj['player_id'].astype(str)
|
|
|
|
| 99 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 100 |
opp_dict = dict(zip(dk_raw_proj.Team, dk_raw_proj.Opp))
|
| 101 |
|
| 102 |
+
tab1, tab2 = st.tabs(['Optimizer', 'Uploads and Info'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
with tab1:
|
| 105 |
col1, col2 = st.columns([1, 5])
|
| 106 |
with col1:
|
| 107 |
st.info(t_stamp)
|
|
|
|
| 135 |
init_baselines = init_baselines.loc[init_baselines['MainSlateFD'] == ' Main ']
|
| 136 |
if mainvar1 != 'Main Slate':
|
| 137 |
init_baselines = init_baselines.loc[init_baselines['MainSlateFD'] != ' Main ']
|
| 138 |
+
contest_var1 = st.selectbox("What contest type are you optimizing for?", ('Cash', 'GPP'), key='contest_var1')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
split_var1 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var1')
|
| 140 |
if split_var1 == 'Specific Games':
|
| 141 |
team_var1 = st.multiselect('Which teams would you like to include in the optimization?', options = init_baselines['Team'].unique(), key='team_var1')
|
|
|
|
| 145 |
avoid_var1 = st.multiselect("Are there any players you want to remove from the pool (Drop Button)?", options = init_baselines['Player'].unique(), key='avoid_var1')
|
| 146 |
linenum_var1 = st.number_input("How many lineups would you like to produce?", min_value = 1, max_value = 300, value = 20, step = 1, key='linenum_var1')
|
| 147 |
if site_var1 == 'Draftkings':
|
| 148 |
+
min_sal1 = st.number_input('Min Salary', min_value = 35000, max_value = 49900, value = 49000, step = 100, key='min_sal1')
|
| 149 |
max_sal1 = st.number_input('Max Salary', min_value = 35000, max_value = 50000, value = 50000, step = 100, key='max_sal1')
|
| 150 |
elif site_var1 == 'Fanduel':
|
| 151 |
+
min_sal1 = st.number_input('Min Salary', min_value = 45000, max_value = 54900, value = 54000, step = 100, key='min_sal1')
|
| 152 |
max_sal1 = st.number_input('Max Salary', min_value = 45000, max_value = 55000, value = 55000, step = 100, key='max_sal1')
|
| 153 |
with col2:
|
| 154 |
init_baselines = init_baselines[init_baselines['Team'].isin(team_var1)]
|
| 155 |
init_baselines = init_baselines[~init_baselines['Player'].isin(avoid_var1)]
|
| 156 |
ownframe = init_baselines.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
raw_baselines = ownframe[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Line', 'PP Unit', 'Median', 'Own']]
|
| 158 |
raw_baselines = raw_baselines.sort_values(by='Median', ascending=False)
|
| 159 |
raw_baselines['lock'] = np.where(raw_baselines['Player'].isin(lock_var1), 1, 0)
|
|
|
|
| 221 |
|
| 222 |
if site_var1 == 'Draftkings':
|
| 223 |
|
| 224 |
+
for flex in flex_file['Team'].unique():
|
| 225 |
+
sub_idx = flex_file[(flex_file['Team'] == flex) & (flex_file['Position'] != 'G')].index
|
| 226 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) <= 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
for flex in flex_file['lock'].unique():
|
| 229 |
sub_idx = flex_file[flex_file['lock'] == 1].index
|
|
|
|
| 263 |
|
| 264 |
elif site_var1 == 'Fanduel':
|
| 265 |
|
| 266 |
+
for flex in flex_file['Team'].unique():
|
| 267 |
+
sub_idx = flex_file[(flex_file['Team'] == flex) & (flex_file['Position'] != 'G')].index
|
| 268 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) <= 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
for flex in flex_file['lock'].unique():
|
| 271 |
sub_idx = flex_file[flex_file['lock'] == 1].index
|
|
|
|
| 600 |
with freq_container:
|
| 601 |
freq_container = st.empty()
|
| 602 |
if 'player_freq' in st.session_state:
|
| 603 |
+
st.dataframe(st.session_state.player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(expose_format, precision=2), use_container_width = True)
|
| 604 |
+
|
| 605 |
+
with tab2:
|
| 606 |
+
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', 'Line', 'PP Unit', 'Own', and 'player_id'. The player_id is the draftkings or fanduel ID associated with the player for upload.")
|
| 607 |
+
col1, col2 = st.columns([1, 5])
|
| 608 |
+
|
| 609 |
+
with col1:
|
| 610 |
+
proj_file = st.file_uploader("Upload Projections File", key = 'proj_uploader')
|
| 611 |
+
|
| 612 |
+
if proj_file is not None:
|
| 613 |
+
try:
|
| 614 |
+
proj_dataframe = pd.read_csv(proj_file)
|
| 615 |
+
except:
|
| 616 |
+
proj_dataframe = pd.read_excel(proj_file)
|
| 617 |
+
with col2:
|
| 618 |
+
if proj_file is not None:
|
| 619 |
+
st.dataframe(proj_dataframe.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|