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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pulp
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import streamlit as st
|
5 |
+
import gspread
|
6 |
+
from itertools import combinations
|
7 |
+
|
8 |
+
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
9 |
+
"https://www.googleapis.com/auth/drive"]
|
10 |
+
|
11 |
+
credentials = {
|
12 |
+
"type": "service_account",
|
13 |
+
"project_id": "sheets-api-connect-378620",
|
14 |
+
"private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
|
15 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5Evq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v7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
16 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
17 |
+
"client_id": "106625872877651920064",
|
18 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
19 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
20 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
21 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
22 |
+
}
|
23 |
+
|
24 |
+
gc = gspread.service_account_from_dict(credentials)
|
25 |
+
|
26 |
+
st.set_page_config(layout="wide")
|
27 |
+
|
28 |
+
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
29 |
+
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
30 |
+
|
31 |
+
team_roo_format = {'Top Score%': '{:.2%}','0 Runs': '{:.2%}', '1 Run': '{:.2%}', '2 Runs': '{:.2%}', '3 Runs': '{:.2%}', '4 Runs': '{:.2%}',
|
32 |
+
'5 Runs': '{:.2%}','6 Runs': '{:.2%}', '7 Runs': '{:.2%}', '8 Runs': '{:.2%}', '9 Runs': '{:.2%}', '10 Runs': '{:.2%}'}
|
33 |
+
|
34 |
+
wrong_acro = ['WSH', 'AZ']
|
35 |
+
right_acro = ['WAS', 'ARI']
|
36 |
+
|
37 |
+
dk_player_projections = 'https://docs.google.com/spreadsheets/d/1MdzPFqIT0MFid2IhegWf39VNR8IXUyo_Fb5dolOSt3o/edit#gid=340831852'
|
38 |
+
fd_player_projections = 'https://docs.google.com/spreadsheets/d/1MdzPFqIT0MFid2IhegWf39VNR8IXUyo_Fb5dolOSt3o/edit#gid=340831852'
|
39 |
+
|
40 |
+
secondary_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1lP4t8N7UhjR94MEwPn6powRyLl_cQBDUMSCs6cbL9ms/edit#gid=340831852'
|
41 |
+
secondary_fd_player_projections = 'https://docs.google.com/spreadsheets/d/1lP4t8N7UhjR94MEwPn6powRyLl_cQBDUMSCs6cbL9ms/edit#gid=340831852'
|
42 |
+
|
43 |
+
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=500994479'
|
44 |
+
all_fd_player_projections = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=500994479'
|
45 |
+
final_Proj = 0
|
46 |
+
|
47 |
+
@st.cache_data
|
48 |
+
def load_time():
|
49 |
+
sh = gc.open_by_url(dk_player_projections)
|
50 |
+
worksheet = sh.worksheet('Timestamp')
|
51 |
+
raw_stamp = worksheet.acell('a1').value
|
52 |
+
|
53 |
+
t_stamp = f"Last update was at {raw_stamp}"
|
54 |
+
|
55 |
+
return t_stamp
|
56 |
+
|
57 |
+
@st.cache_data
|
58 |
+
def set_slate_teams():
|
59 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
60 |
+
worksheet = sh.worksheet('Site_Info')
|
61 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
62 |
+
|
63 |
+
for checkVar in range(len(wrong_acro)):
|
64 |
+
raw_display['FD Main'] = raw_display['FD Main'].replace(wrong_acro, right_acro)
|
65 |
+
|
66 |
+
for checkVar in range(len(wrong_acro)):
|
67 |
+
raw_display['FD Secondary'] = raw_display['FD Secondary'].replace(wrong_acro, right_acro)
|
68 |
+
|
69 |
+
for checkVar in range(len(wrong_acro)):
|
70 |
+
raw_display['FD Overall'] = raw_display['FD Overall'].replace(wrong_acro, right_acro)
|
71 |
+
|
72 |
+
return raw_display
|
73 |
+
|
74 |
+
@st.cache_data
|
75 |
+
def load_dk_player_projections(URL):
|
76 |
+
sh = gc.open_by_url(URL)
|
77 |
+
worksheet = sh.worksheet('DK_Projections')
|
78 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
79 |
+
load_display.replace('', np.nan, inplace=True)
|
80 |
+
raw_display = load_display.dropna(subset=['Median'])
|
81 |
+
|
82 |
+
return raw_display
|
83 |
+
|
84 |
+
@st.cache_data
|
85 |
+
def load_fd_player_projections(URL):
|
86 |
+
sh = gc.open_by_url(URL)
|
87 |
+
worksheet = sh.worksheet('FD_Projections')
|
88 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
89 |
+
load_display.replace('', np.nan, inplace=True)
|
90 |
+
raw_display = load_display.dropna(subset=['Median'])
|
91 |
+
|
92 |
+
return raw_display
|
93 |
+
|
94 |
+
@st.cache_data
|
95 |
+
def convert_df_to_csv(df):
|
96 |
+
return df.to_csv().encode('utf-8')
|
97 |
+
|
98 |
+
t_stamp = load_time()
|
99 |
+
site_slates = set_slate_teams()
|
100 |
+
col1, col2 = st.columns([1, 5])
|
101 |
+
|
102 |
+
with col1:
|
103 |
+
st.info(t_stamp)
|
104 |
+
if st.button("Load/Reset Data", key='reset4'):
|
105 |
+
st.cache_data.clear()
|
106 |
+
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'All Games'), key='slate_var1')
|
107 |
+
site_var2 = st.radio("What site are you playing?", ('Draftkings', 'Fanduel'), key='site_var2')
|
108 |
+
if slate_var1 == 'Main Slate':
|
109 |
+
if site_var2 == 'Draftkings':
|
110 |
+
slate_teams = site_slates['DK Main'].values.tolist()
|
111 |
+
raw_baselines = load_dk_player_projections(all_dk_player_projections)
|
112 |
+
raw_baselines = raw_baselines[raw_baselines['Team'].isin(slate_teams)]
|
113 |
+
elif site_var2 == 'Fanduel':
|
114 |
+
slate_teams = site_slates['FD Main'].values.tolist()
|
115 |
+
raw_baselines = load_fd_player_projections(all_fd_player_projections)
|
116 |
+
raw_baselines = raw_baselines[raw_baselines['Team'].isin(slate_teams)]
|
117 |
+
elif slate_var1 == 'Secondary Slate':
|
118 |
+
if site_var2 == 'Draftkings':
|
119 |
+
slate_teams = site_slates['DK Secondary'].values.tolist()
|
120 |
+
raw_baselines = load_dk_player_projections(all_dk_player_projections)
|
121 |
+
raw_baselines = raw_baselines[raw_baselines['Team'].isin(slate_teams)]
|
122 |
+
elif site_var2 == 'Fanduel':
|
123 |
+
slate_teams = site_slates['FD Secondary'].values.tolist()
|
124 |
+
raw_baselines = load_fd_player_projections(all_fd_player_projections)
|
125 |
+
raw_baselines = raw_baselines[raw_baselines['Team'].isin(slate_teams)]
|
126 |
+
elif slate_var1 == 'All Games':
|
127 |
+
if site_var2 == 'Draftkings':
|
128 |
+
slate_teams = site_slates['DK Overall'].values.tolist()
|
129 |
+
raw_baselines = load_dk_player_projections(all_dk_player_projections)
|
130 |
+
raw_baselines = raw_baselines[raw_baselines['Team'].isin(slate_teams)]
|
131 |
+
elif site_var2 == 'Fanduel':
|
132 |
+
slate_teams = site_slates['FD Overall'].values.tolist()
|
133 |
+
raw_baselines = load_fd_player_projections(all_fd_player_projections)
|
134 |
+
raw_baselines = raw_baselines[raw_baselines['Team'].isin(slate_teams)]
|
135 |
+
split_var2 = st.radio("Would you like to run stack analysis for the full slate or individual teams?", ('Full Slate Run', 'Specific Teams'), key='split_var2')
|
136 |
+
if split_var2 == 'Specific Teams':
|
137 |
+
team_var2 = st.multiselect('Which teams would you like to include in the analysis?', options = raw_baselines['Team'].unique(), key='team_var2')
|
138 |
+
elif split_var2 == 'Full Slate Run':
|
139 |
+
team_var2 = raw_baselines.Team.unique().tolist()
|
140 |
+
pos_split2 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split2')
|
141 |
+
if pos_split2 == 'Specific Positions':
|
142 |
+
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['SP', 'P', 'C', '1B', '2B', '3B', 'SS', 'OF'])
|
143 |
+
elif pos_split2 == 'All Positions':
|
144 |
+
pos_var2 = 'All'
|
145 |
+
if site_var2 == 'Draftkings':
|
146 |
+
max_sal2 = st.number_input('Max Salary', min_value = 5000, max_value = 50000, value = 35000, step = 100, key='max_sal2')
|
147 |
+
elif site_var2 == 'Fanduel':
|
148 |
+
max_sal2 = st.number_input('Max Salary', min_value = 5000, max_value = 35000, value = 25000, step = 100, key='max_sal2')
|
149 |
+
size_var2 = st.selectbox('What size of stacks are you analyzing?', options = ['3-man', '4-man', '5-man'])
|
150 |
+
if size_var2 == '3-man':
|
151 |
+
stack_size = 3
|
152 |
+
if size_var2 == '4-man':
|
153 |
+
stack_size = 4
|
154 |
+
if size_var2 == '5-man':
|
155 |
+
stack_size = 5
|
156 |
+
|
157 |
+
team_dict = dict(zip(raw_baselines.Player, raw_baselines.Team))
|
158 |
+
proj_dict = dict(zip(raw_baselines.Player, raw_baselines.Median))
|
159 |
+
own_dict = dict(zip(raw_baselines.Player, raw_baselines.Own))
|
160 |
+
cost_dict = dict(zip(raw_baselines.Player, raw_baselines.Salary))
|
161 |
+
|
162 |
+
with col2:
|
163 |
+
stack_hold_container = st.empty()
|
164 |
+
if st.button('Run stack analysis'):
|
165 |
+
comb_list = []
|
166 |
+
if pos_split2 == 'All Positions':
|
167 |
+
raw_baselines = raw_baselines
|
168 |
+
elif pos_split2 != 'All Positions':
|
169 |
+
raw_baselines = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var2))]
|
170 |
+
|
171 |
+
for cur_team in team_var2:
|
172 |
+
working_baselines = raw_baselines
|
173 |
+
working_baselines = working_baselines[working_baselines['Team'] == cur_team]
|
174 |
+
working_baselines = working_baselines[working_baselines['Position'] != 'SP']
|
175 |
+
working_baselines = working_baselines[working_baselines['Position'] != 'P']
|
176 |
+
order_list = working_baselines['Player']
|
177 |
+
|
178 |
+
comb = combinations(order_list, stack_size)
|
179 |
+
|
180 |
+
for i in list(comb):
|
181 |
+
comb_list.append(i)
|
182 |
+
|
183 |
+
comb_DF = pd.DataFrame(comb_list)
|
184 |
+
|
185 |
+
if stack_size == 3:
|
186 |
+
comb_DF['Team'] = comb_DF[0].map(team_dict)
|
187 |
+
|
188 |
+
comb_DF['Proj'] = sum([comb_DF[0].map(proj_dict),
|
189 |
+
comb_DF[1].map(proj_dict),
|
190 |
+
comb_DF[2].map(proj_dict)])
|
191 |
+
|
192 |
+
comb_DF['Salary'] = sum([comb_DF[0].map(cost_dict),
|
193 |
+
comb_DF[1].map(cost_dict),
|
194 |
+
comb_DF[2].map(cost_dict)])
|
195 |
+
|
196 |
+
comb_DF['Own%'] = sum([comb_DF[0].map(own_dict),
|
197 |
+
comb_DF[1].map(own_dict),
|
198 |
+
comb_DF[2].map(own_dict)])
|
199 |
+
elif stack_size == 4:
|
200 |
+
comb_DF['Team'] = comb_DF[0].map(team_dict)
|
201 |
+
|
202 |
+
comb_DF['Proj'] = sum([comb_DF[0].map(proj_dict),
|
203 |
+
comb_DF[1].map(proj_dict),
|
204 |
+
comb_DF[2].map(proj_dict),
|
205 |
+
comb_DF[3].map(proj_dict)])
|
206 |
+
|
207 |
+
comb_DF['Salary'] = sum([comb_DF[0].map(cost_dict),
|
208 |
+
comb_DF[1].map(cost_dict),
|
209 |
+
comb_DF[2].map(cost_dict),
|
210 |
+
comb_DF[3].map(cost_dict)])
|
211 |
+
|
212 |
+
comb_DF['Own%'] = sum([comb_DF[0].map(own_dict),
|
213 |
+
comb_DF[1].map(own_dict),
|
214 |
+
comb_DF[2].map(own_dict),
|
215 |
+
comb_DF[3].map(own_dict)])
|
216 |
+
elif stack_size == 5:
|
217 |
+
comb_DF['Team'] = comb_DF[0].map(team_dict)
|
218 |
+
|
219 |
+
comb_DF['Proj'] = sum([comb_DF[0].map(proj_dict),
|
220 |
+
comb_DF[1].map(proj_dict),
|
221 |
+
comb_DF[2].map(proj_dict),
|
222 |
+
comb_DF[3].map(proj_dict),
|
223 |
+
comb_DF[4].map(proj_dict)])
|
224 |
+
|
225 |
+
comb_DF['Salary'] = sum([comb_DF[0].map(cost_dict),
|
226 |
+
comb_DF[1].map(cost_dict),
|
227 |
+
comb_DF[2].map(cost_dict),
|
228 |
+
comb_DF[3].map(cost_dict),
|
229 |
+
comb_DF[4].map(cost_dict)])
|
230 |
+
|
231 |
+
comb_DF['Own%'] = sum([comb_DF[0].map(own_dict),
|
232 |
+
comb_DF[1].map(own_dict),
|
233 |
+
comb_DF[2].map(own_dict),
|
234 |
+
comb_DF[3].map(own_dict),
|
235 |
+
comb_DF[4].map(own_dict)])
|
236 |
+
|
237 |
+
comb_DF = comb_DF.sort_values(by='Proj', ascending=False)
|
238 |
+
comb_DF = comb_DF.loc[comb_DF['Salary'] <= max_sal2]
|
239 |
+
|
240 |
+
cut_var = 0
|
241 |
+
|
242 |
+
if stack_size == 3:
|
243 |
+
while cut_var <= int(len(comb_DF)):
|
244 |
+
try:
|
245 |
+
if int(cut_var) == 0:
|
246 |
+
cur_proj = float(comb_DF.iat[cut_var,4])
|
247 |
+
cur_own = float(comb_DF.iat[cut_var,6])
|
248 |
+
elif int(cut_var) >= 1:
|
249 |
+
check_own = float(comb_DF.iat[cut_var,6])
|
250 |
+
if check_own > cur_own:
|
251 |
+
comb_DF = comb_DF.drop([cut_var])
|
252 |
+
cur_own = cur_own
|
253 |
+
cut_var = cut_var - 1
|
254 |
+
comb_DF = comb_DF.reset_index()
|
255 |
+
comb_DF = comb_DF.drop(['index'], axis=1)
|
256 |
+
elif check_own <= cur_own:
|
257 |
+
cur_own = float(comb_DF.iat[cut_var,6])
|
258 |
+
cut_var = cut_var
|
259 |
+
cut_var += 1
|
260 |
+
except:
|
261 |
+
cut_var += 1
|
262 |
+
elif stack_size == 4:
|
263 |
+
while cut_var <= int(len(comb_DF)):
|
264 |
+
try:
|
265 |
+
if int(cut_var) == 0:
|
266 |
+
cur_proj = float(comb_DF.iat[cut_var,5])
|
267 |
+
cur_own = float(comb_DF.iat[cut_var,7])
|
268 |
+
elif int(cut_var) >= 1:
|
269 |
+
check_own = float(comb_DF.iat[cut_var,7])
|
270 |
+
if check_own > cur_own:
|
271 |
+
comb_DF = comb_DF.drop([cut_var])
|
272 |
+
cur_own = cur_own
|
273 |
+
cut_var = cut_var - 1
|
274 |
+
comb_DF = comb_DF.reset_index()
|
275 |
+
comb_DF = comb_DF.drop(['index'], axis=1)
|
276 |
+
elif check_own <= cur_own:
|
277 |
+
cur_own = float(comb_DF.iat[cut_var,7])
|
278 |
+
cut_var = cut_var
|
279 |
+
cut_var += 1
|
280 |
+
except:
|
281 |
+
cut_var += 1
|
282 |
+
elif stack_size == 5:
|
283 |
+
while cut_var <= int(len(comb_DF)):
|
284 |
+
try:
|
285 |
+
if int(cut_var) == 0:
|
286 |
+
cur_proj = float(comb_DF.iat[cut_var,6])
|
287 |
+
cur_own = float(comb_DF.iat[cut_var,8])
|
288 |
+
elif int(cut_var) >= 1:
|
289 |
+
check_own = float(comb_DF.iat[cut_var,8])
|
290 |
+
if check_own > cur_own:
|
291 |
+
comb_DF = comb_DF.drop([cut_var])
|
292 |
+
cur_own = cur_own
|
293 |
+
cut_var = cut_var - 1
|
294 |
+
comb_DF = comb_DF.reset_index()
|
295 |
+
comb_DF = comb_DF.drop(['index'], axis=1)
|
296 |
+
elif check_own <= cur_own:
|
297 |
+
cur_own = float(comb_DF.iat[cut_var,8])
|
298 |
+
cut_var = cut_var
|
299 |
+
cut_var += 1
|
300 |
+
except:
|
301 |
+
cut_var += 1
|
302 |
+
|
303 |
+
with stack_hold_container:
|
304 |
+
stack_hold_container = st.empty()
|
305 |
+
st.dataframe(comb_DF.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
306 |
+
st.download_button(
|
307 |
+
label="Export Tables",
|
308 |
+
data=convert_df_to_csv(comb_DF),
|
309 |
+
file_name='MLB_Stack_Options_export.csv',
|
310 |
+
mime='text/csv',
|
311 |
+
)
|