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 |
+
import numpy as np
|
10 |
+
import pandas as pd
|
11 |
+
import streamlit as st
|
12 |
+
import gspread
|
13 |
+
from itertools import combinations
|
14 |
+
|
15 |
+
@st.cache_resource
|
16 |
+
def init_conn():
|
17 |
+
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
18 |
+
"https://www.googleapis.com/auth/drive"]
|
19 |
+
|
20 |
+
credentials = {
|
21 |
+
"type": "service_account",
|
22 |
+
"project_id": "sheets-api-connect-378620",
|
23 |
+
"private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
|
24 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5EvqkZvSyMJHV0EEahZStwhjCfnDB/cxyix\nZ+kFhv4y9eK+kFpUAhBy5nX6T0O+2T6WvzAwbmbVsZ+X8kJyPuF9m8ldcPlD0sce\ntj8NwVq1ys52eosqs7zi2vjt+eMcaY393l4ls+vNq8Yf27cfyFw45W45CH/97/Nu\n5AmuzlCOAfFF+z4OC5g4rei4E/Qgpxa7/uom+BVfv9G0DIGW/tU6Sne0+37uoGKt\nW6DzhgtebUtoYkG7ZJ05BTXGp2lwgVcNRoPwnKJDxQKBgQDT5wYPUBDW+FHbvZSp\nd1m1UQuXyerqOTA9smFaM8sr/UraeH85DJPEIEk8qsntMBVMhvD3Pw8uIUeFNMYj\naLmZFObsL+WctepXrVo5NB6RtLB/jZYxiKMatMLUJIYtcKIp+2z/YtKiWcLnwotB\nWdCjVnPTxpkurmF2fWP/eewZ+wKBgQDRMtJg7etjvKyjYNQ5fARnCc+XsI3gkBe1\nX9oeXfhyfZFeBXWnZzN1ITgFHplDznmBdxAyYGiQdbbkdKQSghviUQ0igBvoDMYy\n1rWcy+a17Mj98uyNEfmb3X2cC6WpvOZaGHwg9+GY67BThwI3FqHIbyk6Ko09WlTX\nQpRQjMzU7QKBgAfi1iflu+q0LR+3a3vvFCiaToskmZiD7latd9AKk2ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
25 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
26 |
+
"client_id": "106625872877651920064",
|
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%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
31 |
+
}
|
32 |
+
|
33 |
+
gc = gspread.service_account_from_dict(credentials)
|
34 |
+
return gc
|
35 |
+
|
36 |
+
gc = init_conn()
|
37 |
+
|
38 |
+
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
39 |
+
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
40 |
+
|
41 |
+
player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
|
42 |
+
'4x%': '{:.2%}','GPP%': '{:.2%}'}
|
43 |
+
|
44 |
+
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348'
|
45 |
+
|
46 |
+
@st.cache_resource(ttl=3600)
|
47 |
+
def set_slate_teams():
|
48 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
49 |
+
worksheet = sh.worksheet('Site_Info')
|
50 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
51 |
+
|
52 |
+
return raw_display
|
53 |
+
|
54 |
+
@st.cache_resource(ttl=600)
|
55 |
+
def player_stat_table():
|
56 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
57 |
+
worksheet = sh.worksheet('Player_Projections')
|
58 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
59 |
+
|
60 |
+
return raw_display
|
61 |
+
|
62 |
+
@st.cache_resource(ttl=600)
|
63 |
+
def load_dk_player_projections():
|
64 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
65 |
+
worksheet = sh.worksheet('DK_ROO')
|
66 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
67 |
+
load_display.replace('', np.nan, inplace=True)
|
68 |
+
raw_display = load_display.dropna(subset=['Median'])
|
69 |
+
|
70 |
+
return raw_display
|
71 |
+
|
72 |
+
@st.cache_resource(ttl=600)
|
73 |
+
def load_fd_player_projections():
|
74 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
75 |
+
worksheet = sh.worksheet('FD_ROO')
|
76 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
77 |
+
load_display.replace('', np.nan, inplace=True)
|
78 |
+
raw_display = load_display.dropna(subset=['Median'])
|
79 |
+
|
80 |
+
return raw_display
|
81 |
+
|
82 |
+
@st.cache_resource(ttl=600)
|
83 |
+
def load_dk_stacks():
|
84 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
85 |
+
worksheet = sh.worksheet('DK_Stacks')
|
86 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
87 |
+
raw_display = load_display
|
88 |
+
|
89 |
+
return raw_display
|
90 |
+
|
91 |
+
@st.cache_resource(ttl=600)
|
92 |
+
def load_fd_stacks():
|
93 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
94 |
+
worksheet = sh.worksheet('FD_Stacks')
|
95 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
96 |
+
raw_display = load_display
|
97 |
+
|
98 |
+
return raw_display
|
99 |
+
|
100 |
+
@st.cache_data
|
101 |
+
def convert_df_to_csv(df):
|
102 |
+
return df.to_csv().encode('utf-8')
|
103 |
+
|
104 |
+
player_stats = player_stat_table()
|
105 |
+
dk_stacks_raw = load_dk_stacks()
|
106 |
+
fd_stacks_raw = load_fd_stacks()
|
107 |
+
dk_roo_raw = load_dk_player_projections()
|
108 |
+
fd_roo_raw = load_fd_player_projections()
|
109 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
110 |
+
site_slates = set_slate_teams()
|
111 |
+
|
112 |
+
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Team Stacks Range of Outcomes", "Overall Range of Outcomes", "QB Range of Outcomes", "RB Range of Outcomes", "WR Range of Outcomes", "TE Range of Outcomes"])
|
113 |
+
|
114 |
+
with tab1:
|
115 |
+
col1, col2 = st.columns([1, 5])
|
116 |
+
with col1:
|
117 |
+
st.info(t_stamp)
|
118 |
+
if st.button("Load/Reset Data", key='reset1'):
|
119 |
+
st.cache_data.clear()
|
120 |
+
player_stats = player_stat_table()
|
121 |
+
dk_stacks_raw = load_dk_stacks()
|
122 |
+
fd_stacks_raw = load_fd_stacks()
|
123 |
+
dk_roo_raw = load_dk_player_projections()
|
124 |
+
fd_roo_raw = load_fd_player_projections()
|
125 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
126 |
+
site_slates = set_slate_teams()
|
127 |
+
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate'), key='slate_var1')
|
128 |
+
site_var1 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var1')
|
129 |
+
custom_var1 = st.radio("Are you creating a custom table?", ('No', 'Yes'), key='custom_var1')
|
130 |
+
if custom_var1 == 'No':
|
131 |
+
if site_var1 == 'Draftkings':
|
132 |
+
raw_baselines = dk_stacks_raw[dk_stacks_raw['slate'] == str(slate_var1)]
|
133 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
134 |
+
raw_baselines = raw_baselines.iloc[:,:-2]
|
135 |
+
elif site_var1 == 'Fanduel':
|
136 |
+
raw_baselines = fd_stacks_raw[fd_stacks_raw['slate'] == str(slate_var1)]
|
137 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
138 |
+
raw_baselines = raw_baselines.iloc[:,:-2]
|
139 |
+
split_var1 = st.radio("Would you like to view the whole slate or just specific 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 ROO?', options = raw_baselines['Team'].unique(), key='team_var1')
|
142 |
+
elif split_var1 == 'Full Slate Run':
|
143 |
+
team_var1 = raw_baselines.Team.values.tolist()
|
144 |
+
if custom_var1 == 'Yes':
|
145 |
+
contest_var1 = st.selectbox("What contest type are you running for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var1')
|
146 |
+
if site_var1 == 'Draftkings':
|
147 |
+
raw_baselines = dk_stacks_raw[dk_stacks_raw['slate'] == str(slate_var1)]
|
148 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
149 |
+
elif site_var1 == 'Fanduel':
|
150 |
+
raw_baselines = fd_stacks_raw[fd_stacks_raw['slate'] == str(slate_var1)]
|
151 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
152 |
+
split_var1 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var1')
|
153 |
+
if split_var1 == 'Specific Games':
|
154 |
+
team_var1 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var1')
|
155 |
+
elif split_var1 == 'Full Slate Run':
|
156 |
+
team_var1 = raw_baselines.Team.values.tolist()
|
157 |
+
|
158 |
+
|
159 |
+
with col2:
|
160 |
+
if custom_var1 == 'No':
|
161 |
+
final_stacks = raw_baselines[raw_baselines['Team'].isin(team_var1)]
|
162 |
+
st.dataframe(final_stacks.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
163 |
+
st.download_button(
|
164 |
+
label="Export Tables",
|
165 |
+
data=convert_df_to_csv(final_stacks),
|
166 |
+
file_name='NFL_stacks_export.csv',
|
167 |
+
mime='text/csv',
|
168 |
+
)
|
169 |
+
elif custom_var1 == 'Yes':
|
170 |
+
hold_container = st.empty()
|
171 |
+
if st.button('Create Range of Outcomes for Slate'):
|
172 |
+
with hold_container:
|
173 |
+
if site_var1 == 'Draftkings':
|
174 |
+
working_roo = player_stats
|
175 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "PPR": "Fantasy"}, inplace = True)
|
176 |
+
working_roo.replace('', 0, inplace=True)
|
177 |
+
if site_var1 == 'Fanduel':
|
178 |
+
working_roo = player_stats
|
179 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "Half_PPR": "Fantasy"}, inplace = True)
|
180 |
+
working_roo.replace('', 0, inplace=True)
|
181 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var1)]
|
182 |
+
|
183 |
+
total_sims = 1000
|
184 |
+
|
185 |
+
salary_dict = dict(zip(working_roo.name, working_roo.Salary))
|
186 |
+
own_dict = dict(zip(working_roo.name, working_roo.Own))
|
187 |
+
fantasy_dict = dict(zip(working_roo.name, working_roo.Fantasy))
|
188 |
+
|
189 |
+
QB_group = working_roo.loc[working_roo['Position'] == 'QB']
|
190 |
+
stacks_df = pd.DataFrame(columns=['Team','QB', 'WR1', 'WR2_TE'])
|
191 |
+
|
192 |
+
for stack in range(0,len(QB_group)):
|
193 |
+
team_var = QB_group.iat[stack,1]
|
194 |
+
WR_group_1 = working_roo.loc[working_roo['Position'] == 'WR']
|
195 |
+
WR_group_2 = WR_group_1.loc[working_roo['Team'] == team_var]
|
196 |
+
TE_group_1 = working_roo.loc[working_roo['Position'] == 'TE']
|
197 |
+
TE_group_2 = TE_group_1.loc[working_roo['Team'] == team_var]
|
198 |
+
cur_list = []
|
199 |
+
qb_piece = QB_group.iat[stack,0]
|
200 |
+
wr_piece = WR_group_2.iat[0,0]
|
201 |
+
te_piece = TE_group_2.iat[0,0]
|
202 |
+
cur_list.append(team_var)
|
203 |
+
cur_list.append(qb_piece)
|
204 |
+
cur_list.append(wr_piece)
|
205 |
+
cur_list.append(te_piece)
|
206 |
+
stacks_df.loc[len(stacks_df)] = cur_list
|
207 |
+
cur_list = []
|
208 |
+
qb_piece = QB_group.iat[stack,0]
|
209 |
+
wr_piece = WR_group_2.iat[1,0]
|
210 |
+
te_piece = TE_group_2.iat[0,0]
|
211 |
+
cur_list.append(team_var)
|
212 |
+
cur_list.append(qb_piece)
|
213 |
+
cur_list.append(wr_piece)
|
214 |
+
cur_list.append(te_piece)
|
215 |
+
stacks_df.loc[len(stacks_df)] = cur_list
|
216 |
+
cur_list = []
|
217 |
+
qb_piece = QB_group.iat[stack,0]
|
218 |
+
wr_piece = WR_group_2.iat[0,0]
|
219 |
+
te_piece = WR_group_2.iat[1,0]
|
220 |
+
cur_list.append(team_var)
|
221 |
+
cur_list.append(qb_piece)
|
222 |
+
cur_list.append(wr_piece)
|
223 |
+
cur_list.append(te_piece)
|
224 |
+
stacks_df.loc[len(stacks_df)] = cur_list
|
225 |
+
|
226 |
+
stacks_df['Salary'] = sum([stacks_df['QB'].map(salary_dict),
|
227 |
+
stacks_df['WR1'].map(salary_dict),
|
228 |
+
stacks_df['WR2_TE'].map(salary_dict)])
|
229 |
+
|
230 |
+
stacks_df['Fantasy'] = sum([stacks_df['QB'].map(fantasy_dict),
|
231 |
+
stacks_df['WR1'].map(fantasy_dict),
|
232 |
+
stacks_df['WR2_TE'].map(fantasy_dict)])
|
233 |
+
|
234 |
+
stacks_df['Own'] = sum([stacks_df['QB'].map(own_dict),
|
235 |
+
stacks_df['WR1'].map(own_dict),
|
236 |
+
stacks_df['WR2_TE'].map(own_dict)])
|
237 |
+
|
238 |
+
stacks_df['team_combo'] = stacks_df['Team'] + " " + stacks_df['QB'] + " " + stacks_df['WR1'] + " " + stacks_df['WR2_TE']
|
239 |
+
|
240 |
+
own_dict = dict(zip(stacks_df.team_combo, stacks_df.Own))
|
241 |
+
qb_dict = dict(zip(stacks_df.team_combo, stacks_df.QB))
|
242 |
+
wr1_dict = dict(zip(stacks_df.team_combo, stacks_df.WR1))
|
243 |
+
wr2_dict = dict(zip(stacks_df.team_combo, stacks_df.WR2_TE))
|
244 |
+
team_dict = dict(zip(stacks_df.team_combo, stacks_df.Team))
|
245 |
+
|
246 |
+
flex_file = stacks_df[['team_combo', 'Salary', 'Fantasy']]
|
247 |
+
flex_file.rename(columns={"Fantasy": "Median"}, inplace = True)
|
248 |
+
flex_file['Floor'] = flex_file['Median']*.25
|
249 |
+
flex_file['Ceiling'] = flex_file['Median'] + flex_file['Floor']
|
250 |
+
flex_file['STD'] = flex_file['Median']/4
|
251 |
+
flex_file = flex_file[['team_combo', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
252 |
+
hold_file = flex_file
|
253 |
+
overall_file = flex_file
|
254 |
+
salary_file = flex_file
|
255 |
+
|
256 |
+
overall_players = overall_file[['team_combo']]
|
257 |
+
|
258 |
+
for x in range(0,total_sims):
|
259 |
+
salary_file[x] = salary_file['Salary']
|
260 |
+
|
261 |
+
salary_file=salary_file.drop(['team_combo', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
262 |
+
salary_file.astype('int').dtypes
|
263 |
+
|
264 |
+
salary_file = salary_file.div(1000)
|
265 |
+
|
266 |
+
for x in range(0,total_sims):
|
267 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
268 |
+
|
269 |
+
overall_file=overall_file.drop(['team_combo', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
270 |
+
overall_file.astype('int').dtypes
|
271 |
+
|
272 |
+
players_only = hold_file[['team_combo']]
|
273 |
+
raw_lineups_file = players_only
|
274 |
+
|
275 |
+
for x in range(0,total_sims):
|
276 |
+
maps_dict = {'proj_map':dict(zip(hold_file.team_combo,hold_file[x]))}
|
277 |
+
raw_lineups_file[x] = sum([raw_lineups_file['team_combo'].map(maps_dict['proj_map'])])
|
278 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
279 |
+
|
280 |
+
players_only=players_only.drop(['team_combo'], axis=1)
|
281 |
+
players_only.astype('int').dtypes
|
282 |
+
|
283 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
284 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
285 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
286 |
+
|
287 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
288 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
289 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
290 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
291 |
+
players_only['60+%'] = overall_file[overall_file >= 60].count(axis=1)/float(total_sims)
|
292 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
293 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
294 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
295 |
+
|
296 |
+
players_only['team_combo'] = hold_file[['team_combo']]
|
297 |
+
|
298 |
+
final_outcomes = players_only[['team_combo', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '60+%', '2x%', '3x%', '4x%']]
|
299 |
+
|
300 |
+
final_stacks = pd.merge(hold_file, final_outcomes, on="team_combo")
|
301 |
+
final_stacks = final_stacks[['team_combo', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '60+%', '2x%', '3x%', '4x%']]
|
302 |
+
final_stacks['Own'] = final_stacks['team_combo'].map(own_dict)
|
303 |
+
final_stacks = final_stacks[['team_combo', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '60+%', '2x%', '3x%', '4x%', 'Own']]
|
304 |
+
final_stacks['Projection Rank'] = final_stacks.Median.rank(pct = True)
|
305 |
+
final_stacks['Own Rank'] = final_stacks.Own.rank(pct = True)
|
306 |
+
final_stacks['LevX'] = final_stacks['Projection Rank'] - final_stacks['Own Rank']
|
307 |
+
final_stacks['Team'] = final_stacks['team_combo'].map(team_dict)
|
308 |
+
final_stacks['QB'] = final_stacks['team_combo'].map(qb_dict)
|
309 |
+
final_stacks['WR1_TE'] = final_stacks['team_combo'].map(wr1_dict)
|
310 |
+
final_stacks['WR2_TE'] = final_stacks['team_combo'].map(wr2_dict)
|
311 |
+
|
312 |
+
final_stacks = final_stacks[['Team', 'QB', 'WR1_TE', 'WR2_TE', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish',
|
313 |
+
'Top_10_finish', '60+%', '2x%', '3x%', '4x%', 'Own', 'LevX']]
|
314 |
+
|
315 |
+
final_stacks = final_stacks.sort_values(by='Median', ascending=False)
|
316 |
+
|
317 |
+
with hold_container:
|
318 |
+
hold_container = st.empty()
|
319 |
+
final_stacks = final_stacks
|
320 |
+
st.dataframe(final_stacks.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
321 |
+
|
322 |
+
st.download_button(
|
323 |
+
label="Export Tables",
|
324 |
+
data=convert_df_to_csv(final_stacks),
|
325 |
+
file_name='Custom_NFL_stacks_export.csv',
|
326 |
+
mime='text/csv',
|
327 |
+
)
|
328 |
+
|
329 |
+
with tab2:
|
330 |
+
col1, col2 = st.columns([1, 5])
|
331 |
+
with col1:
|
332 |
+
st.info(t_stamp)
|
333 |
+
if st.button("Load/Reset Data", key='reset2'):
|
334 |
+
st.cache_data.clear()
|
335 |
+
player_stats = player_stat_table()
|
336 |
+
dk_stacks_raw = load_dk_stacks()
|
337 |
+
fd_stacks_raw = load_fd_stacks()
|
338 |
+
dk_roo_raw = load_dk_player_projections()
|
339 |
+
fd_roo_raw = load_fd_player_projections()
|
340 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
341 |
+
site_slates = set_slate_teams()
|
342 |
+
slate_var2 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate'), key='slate_var2')
|
343 |
+
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
344 |
+
custom_var2 = st.radio("Are you creating a custom table?", ('No', 'Yes'), key='custom_var2')
|
345 |
+
if custom_var2 == 'No':
|
346 |
+
if site_var2 == 'Draftkings':
|
347 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var2)]
|
348 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
349 |
+
raw_baselines = raw_baselines.iloc[:,:-2]
|
350 |
+
elif site_var2 == 'Fanduel':
|
351 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var2)]
|
352 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
353 |
+
raw_baselines = raw_baselines.iloc[:,:-2]
|
354 |
+
split_var2 = st.radio("Would you like to view the whole slate or just specific games?", ('Full Slate Run', 'Specific Games'), key='split_var2')
|
355 |
+
if split_var2 == 'Specific Games':
|
356 |
+
team_var2 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var2')
|
357 |
+
elif split_var2 == 'Full Slate Run':
|
358 |
+
team_var2 = raw_baselines.Team.values.tolist()
|
359 |
+
pos_split2 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split2')
|
360 |
+
if pos_split2 == 'Specific Positions':
|
361 |
+
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['QB', 'RB', 'WR', 'TE'])
|
362 |
+
elif pos_split2 == 'All Positions':
|
363 |
+
pos_var2 = 'All'
|
364 |
+
sal_var2 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var2')
|
365 |
+
if custom_var2 == 'Yes':
|
366 |
+
contest_var2 = st.selectbox("What contest type are you running for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var2')
|
367 |
+
if site_var2 == 'Draftkings':
|
368 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var2)]
|
369 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
370 |
+
elif site_var2 == 'Fanduel':
|
371 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var2)]
|
372 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
373 |
+
split_var2 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var2')
|
374 |
+
if split_var2 == 'Specific Games':
|
375 |
+
team_var2 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var2')
|
376 |
+
elif split_var2 == 'Full Slate Run':
|
377 |
+
team_var2 = raw_baselines.Team.values.tolist()
|
378 |
+
pos_split2 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split2')
|
379 |
+
if pos_split2 == 'Specific Positions':
|
380 |
+
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['QB', 'RB', 'WR', 'TE'])
|
381 |
+
elif pos_split2 == 'All Positions':
|
382 |
+
pos_var2 = 'All'
|
383 |
+
sal_var2 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var2')
|
384 |
+
|
385 |
+
|
386 |
+
with col2:
|
387 |
+
if custom_var2 == 'No':
|
388 |
+
final_Proj = raw_baselines[raw_baselines['Team'].isin(team_var2)]
|
389 |
+
final_Proj = final_Proj[final_Proj['Salary'] >= sal_var2[0]]
|
390 |
+
final_Proj = final_Proj[final_Proj['Salary'] <= sal_var2[1]]
|
391 |
+
if pos_var2 != 'All':
|
392 |
+
final_Proj = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var2))]
|
393 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
394 |
+
final_Proj = final_Proj.set_index('Player')
|
395 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
396 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
397 |
+
st.download_button(
|
398 |
+
label="Export Tables",
|
399 |
+
data=convert_df_to_csv(final_Proj),
|
400 |
+
file_name='NFL_overall_export.csv',
|
401 |
+
mime='text/csv',
|
402 |
+
)
|
403 |
+
elif custom_var2 == 'Yes':
|
404 |
+
hold_container = st.empty()
|
405 |
+
if st.button('Create Range of Outcomes for Slate'):
|
406 |
+
with hold_container:
|
407 |
+
if site_var2 == 'Draftkings':
|
408 |
+
working_roo = player_stats
|
409 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "PPR": "Fantasy"}, inplace = True)
|
410 |
+
working_roo.replace('', 0, inplace=True)
|
411 |
+
if site_var2 == 'Fanduel':
|
412 |
+
working_roo = player_stats
|
413 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "Half_PPR": "Fantasy"}, inplace = True)
|
414 |
+
working_roo.replace('', 0, inplace=True)
|
415 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var2)]
|
416 |
+
working_roo = working_roo[working_roo['Salary'] >= sal_var2[0]]
|
417 |
+
working_roo = working_roo[working_roo['Salary'] <= sal_var2[1]]
|
418 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
419 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
420 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
421 |
+
total_sims = 1000
|
422 |
+
|
423 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Fantasy', 'Rush Yards', 'Receptions']]
|
424 |
+
flex_file.rename(columns={"Fantasy": "Median", "Pos": "Position"}, inplace = True)
|
425 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
426 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median'] + flex_file['Floor']) + (flex_file['Rush Yards']*.01), flex_file['Median'] + flex_file['Floor'] + flex_file['Receptions'])
|
427 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
428 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
429 |
+
hold_file = flex_file
|
430 |
+
overall_file = flex_file
|
431 |
+
salary_file = flex_file
|
432 |
+
|
433 |
+
overall_players = overall_file[['Player']]
|
434 |
+
|
435 |
+
for x in range(0,total_sims):
|
436 |
+
salary_file[x] = salary_file['Salary']
|
437 |
+
|
438 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
439 |
+
salary_file.astype('int').dtypes
|
440 |
+
|
441 |
+
salary_file = salary_file.div(1000)
|
442 |
+
|
443 |
+
for x in range(0,total_sims):
|
444 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
445 |
+
|
446 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
447 |
+
overall_file.astype('int').dtypes
|
448 |
+
|
449 |
+
players_only = hold_file[['Player']]
|
450 |
+
raw_lineups_file = players_only
|
451 |
+
|
452 |
+
for x in range(0,total_sims):
|
453 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
454 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
455 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
456 |
+
|
457 |
+
players_only=players_only.drop(['Player'], axis=1)
|
458 |
+
players_only.astype('int').dtypes
|
459 |
+
|
460 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
461 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
462 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
463 |
+
|
464 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
465 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
466 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
467 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
468 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
469 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
470 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
471 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
472 |
+
|
473 |
+
players_only['Player'] = hold_file[['Player']]
|
474 |
+
|
475 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
476 |
+
|
477 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
478 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
479 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
480 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
481 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
482 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
483 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
484 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
485 |
+
final_Proj['LevX'] = 0
|
486 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
487 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
488 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
489 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
490 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
491 |
+
|
492 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
493 |
+
final_Proj = final_Proj.set_index('Player')
|
494 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
495 |
+
|
496 |
+
with hold_container:
|
497 |
+
hold_container = st.empty()
|
498 |
+
final_Proj = final_Proj
|
499 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
500 |
+
|
501 |
+
st.download_button(
|
502 |
+
label="Export Tables",
|
503 |
+
data=convert_df_to_csv(final_Proj),
|
504 |
+
file_name='Custom_NFL_overall_export.csv',
|
505 |
+
mime='text/csv',
|
506 |
+
)
|
507 |
+
|
508 |
+
with tab3:
|
509 |
+
col1, col2 = st.columns([1, 5])
|
510 |
+
with col1:
|
511 |
+
st.info(t_stamp)
|
512 |
+
if st.button("Load/Reset Data", key='reset3'):
|
513 |
+
st.cache_data.clear()
|
514 |
+
player_stats = player_stat_table()
|
515 |
+
dk_stacks_raw = load_dk_stacks()
|
516 |
+
fd_stacks_raw = load_fd_stacks()
|
517 |
+
dk_roo_raw = load_dk_player_projections()
|
518 |
+
fd_roo_raw = load_fd_player_projections()
|
519 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
520 |
+
site_slates = set_slate_teams()
|
521 |
+
slate_var3 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate'), key='slate_var3')
|
522 |
+
site_var3 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var3')
|
523 |
+
custom_var3 = st.radio("Are you creating a custom table?", ('No', 'Yes'), key='custom_var3')
|
524 |
+
if custom_var3 == 'No':
|
525 |
+
if site_var3 == 'Draftkings':
|
526 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var3)]
|
527 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_qbs']
|
528 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
529 |
+
elif site_var3 == 'Fanduel':
|
530 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var3)]
|
531 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_qbs']
|
532 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
533 |
+
split_var3 = st.radio("Would you like to view the whole slate or just specific games?", ('Full Slate Run', 'Specific Games'), key='split_var3')
|
534 |
+
if split_var3 == 'Specific Games':
|
535 |
+
team_var3 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var3')
|
536 |
+
elif split_var3 == 'Full Slate Run':
|
537 |
+
team_var3 = raw_baselines.Team.values.tolist()
|
538 |
+
pos_split3 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split3')
|
539 |
+
if pos_split3 == 'Specific Positions':
|
540 |
+
pos_var3 = st.multiselect('What Positions would you like to view?', options = ['QB'], key='pos_var3')
|
541 |
+
elif pos_split3 == 'All Positions':
|
542 |
+
pos_var3 = 'All'
|
543 |
+
sal_var3 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var3')
|
544 |
+
if custom_var3 == 'Yes':
|
545 |
+
contest_var3 = st.selectbox("What contest type are you running for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var3')
|
546 |
+
if site_var3 == 'Draftkings':
|
547 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var3)]
|
548 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_qbs']
|
549 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
550 |
+
elif site_var3 == 'Fanduel':
|
551 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var3)]
|
552 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_qbs']
|
553 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
554 |
+
split_var3 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var3')
|
555 |
+
if split_var3 == 'Specific Games':
|
556 |
+
team_var3 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var3')
|
557 |
+
elif split_var3 == 'Full Slate Run':
|
558 |
+
team_var3 = raw_baselines.Team.values.tolist()
|
559 |
+
pos_split3 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split3')
|
560 |
+
if pos_split3 == 'Specific Positions':
|
561 |
+
pos_var3 = st.multiselect('What Positions would you like to view?', options = ['QB'])
|
562 |
+
elif pos_split3 == 'All Positions':
|
563 |
+
pos_var3 = 'All'
|
564 |
+
sal_var3 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var3')
|
565 |
+
|
566 |
+
|
567 |
+
with col2:
|
568 |
+
if custom_var3 == 'No':
|
569 |
+
final_Proj = raw_baselines[raw_baselines['Team'].isin(team_var3)]
|
570 |
+
final_Proj = final_Proj[final_Proj['Salary'] >= sal_var3[0]]
|
571 |
+
final_Proj = final_Proj[final_Proj['Salary'] <= sal_var3[1]]
|
572 |
+
if pos_var3 != 'All':
|
573 |
+
final_Proj = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var3))]
|
574 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
575 |
+
final_Proj = final_Proj.set_index('Player')
|
576 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
577 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
578 |
+
st.download_button(
|
579 |
+
label="Export Tables",
|
580 |
+
data=convert_df_to_csv(final_Proj),
|
581 |
+
file_name='NFL_qb_export.csv',
|
582 |
+
mime='text/csv',
|
583 |
+
)
|
584 |
+
elif custom_var3 == 'Yes':
|
585 |
+
hold_container = st.empty()
|
586 |
+
if st.button('Create Range of Outcomes for Slate'):
|
587 |
+
with hold_container:
|
588 |
+
if site_var3 == 'Draftkings':
|
589 |
+
working_roo = player_stats
|
590 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "PPR": "Fantasy"}, inplace = True)
|
591 |
+
working_roo.replace('', 0, inplace=True)
|
592 |
+
working_roo = working_roo[working_roo['Position'] == 'QB']
|
593 |
+
if site_var3 == 'Fanduel':
|
594 |
+
working_roo = player_stats
|
595 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "Half_PPR": "Fantasy"}, inplace = True)
|
596 |
+
working_roo.replace('', 0, inplace=True)
|
597 |
+
working_roo = working_roo[working_roo['Position'] == 'QB']
|
598 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var3)]
|
599 |
+
working_roo = working_roo[working_roo['Salary'] >= sal_var2[0]]
|
600 |
+
working_roo = working_roo[working_roo['Salary'] <= sal_var2[1]]
|
601 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
602 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
603 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
604 |
+
total_sims = 1000
|
605 |
+
|
606 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Fantasy', 'Rush Yards', 'Receptions']]
|
607 |
+
flex_file.rename(columns={"Fantasy": "Median", "Pos": "Position"}, inplace = True)
|
608 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
609 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median'] + flex_file['Floor']) + (flex_file['Rush Yards']*.01), flex_file['Median'] + flex_file['Floor'] + flex_file['Receptions'])
|
610 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
611 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
612 |
+
hold_file = flex_file
|
613 |
+
overall_file = flex_file
|
614 |
+
salary_file = flex_file
|
615 |
+
|
616 |
+
overall_players = overall_file[['Player']]
|
617 |
+
|
618 |
+
for x in range(0,total_sims):
|
619 |
+
salary_file[x] = salary_file['Salary']
|
620 |
+
|
621 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
622 |
+
salary_file.astype('int').dtypes
|
623 |
+
|
624 |
+
salary_file = salary_file.div(1000)
|
625 |
+
|
626 |
+
for x in range(0,total_sims):
|
627 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
628 |
+
|
629 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
630 |
+
overall_file.astype('int').dtypes
|
631 |
+
|
632 |
+
players_only = hold_file[['Player']]
|
633 |
+
raw_lineups_file = players_only
|
634 |
+
|
635 |
+
for x in range(0,total_sims):
|
636 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
637 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
638 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
639 |
+
|
640 |
+
players_only=players_only.drop(['Player'], axis=1)
|
641 |
+
players_only.astype('int').dtypes
|
642 |
+
|
643 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
644 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
645 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
646 |
+
|
647 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
648 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
649 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
650 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
651 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
652 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
653 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
654 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
655 |
+
|
656 |
+
players_only['Player'] = hold_file[['Player']]
|
657 |
+
|
658 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
659 |
+
|
660 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
661 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
662 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
663 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
664 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
665 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
666 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
667 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
668 |
+
final_Proj['LevX'] = 0
|
669 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
670 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
671 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
672 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
673 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
674 |
+
|
675 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
676 |
+
final_Proj = final_Proj.set_index('Player')
|
677 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
678 |
+
|
679 |
+
with hold_container:
|
680 |
+
hold_container = st.empty()
|
681 |
+
final_Proj = final_Proj
|
682 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
683 |
+
|
684 |
+
st.download_button(
|
685 |
+
label="Export Tables",
|
686 |
+
data=convert_df_to_csv(final_Proj),
|
687 |
+
file_name='Custom_NFL_qb_export.csv',
|
688 |
+
mime='text/csv',
|
689 |
+
)
|
690 |
+
|
691 |
+
with tab4:
|
692 |
+
col1, col2 = st.columns([1, 5])
|
693 |
+
with col1:
|
694 |
+
st.info(t_stamp)
|
695 |
+
if st.button("Load/Reset Data", key='reset4'):
|
696 |
+
st.cache_data.clear()
|
697 |
+
player_stats = player_stat_table()
|
698 |
+
dk_stacks_raw = load_dk_stacks()
|
699 |
+
fd_stacks_raw = load_fd_stacks()
|
700 |
+
dk_roo_raw = load_dk_player_projections()
|
701 |
+
fd_roo_raw = load_fd_player_projections()
|
702 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
703 |
+
site_slates = set_slate_teams()
|
704 |
+
slate_var4 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate'), key='slate_var4')
|
705 |
+
site_var4 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var4')
|
706 |
+
custom_var4 = st.radio("Are you creating a custom table?", ('No', 'Yes'), key='custom_var4')
|
707 |
+
if custom_var4 == 'No':
|
708 |
+
if site_var4 == 'Draftkings':
|
709 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var4)]
|
710 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_rbs']
|
711 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
712 |
+
elif site_var4 == 'Fanduel':
|
713 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var4)]
|
714 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_rbs']
|
715 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
716 |
+
split_var4 = st.radio("Would you like to view the whole slate or just specific games?", ('Full Slate Run', 'Specific Games'), key='split_var4')
|
717 |
+
if split_var4 == 'Specific Games':
|
718 |
+
team_var4 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var4')
|
719 |
+
elif split_var4 == 'Full Slate Run':
|
720 |
+
team_var4 = raw_baselines.Team.values.tolist()
|
721 |
+
pos_split4 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split4')
|
722 |
+
if pos_split4 == 'Specific Positions':
|
723 |
+
pos_var4 = st.multiselect('What Positions would you like to view?', options = ['RB'], key='pos_var4')
|
724 |
+
elif pos_split4 == 'All Positions':
|
725 |
+
pos_var4 = 'All'
|
726 |
+
sal_var4 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var4')
|
727 |
+
if custom_var4 == 'Yes':
|
728 |
+
contest_var4 = st.selectbox("What contest type are you running for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var4')
|
729 |
+
if site_var4 == 'Draftkings':
|
730 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var4)]
|
731 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_rbs']
|
732 |
+
elif site_var4 == 'Fanduel':
|
733 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var4)]
|
734 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_rbs']
|
735 |
+
split_var4 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var4')
|
736 |
+
if split_var4 == 'Specific Games':
|
737 |
+
team_var4 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var4')
|
738 |
+
elif split_var4 == 'Full Slate Run':
|
739 |
+
team_var4 = raw_baselines.Team.values.tolist()
|
740 |
+
pos_split4 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split4')
|
741 |
+
if pos_split4 == 'Specific Positions':
|
742 |
+
pos_var4 = st.multiselect('What Positions would you like to view?', options = ['RB'])
|
743 |
+
elif pos_split4 == 'All Positions':
|
744 |
+
pos_var4 = 'All'
|
745 |
+
sal_var4 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var4')
|
746 |
+
|
747 |
+
|
748 |
+
with col2:
|
749 |
+
if custom_var4 == 'No':
|
750 |
+
final_Proj = raw_baselines[raw_baselines['Team'].isin(team_var4)]
|
751 |
+
final_Proj = final_Proj[final_Proj['Salary'] >= sal_var4[0]]
|
752 |
+
final_Proj = final_Proj[final_Proj['Salary'] <= sal_var4[1]]
|
753 |
+
if pos_var4 != 'All':
|
754 |
+
final_Proj = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var4))]
|
755 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
756 |
+
final_Proj = final_Proj.set_index('Player')
|
757 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
758 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
759 |
+
st.download_button(
|
760 |
+
label="Export Tables",
|
761 |
+
data=convert_df_to_csv(final_Proj),
|
762 |
+
file_name='NFL_rb_export.csv',
|
763 |
+
mime='text/csv',
|
764 |
+
)
|
765 |
+
elif custom_var4 == 'Yes':
|
766 |
+
hold_container = st.empty()
|
767 |
+
if st.button('Create Range of Outcomes for Slate'):
|
768 |
+
with hold_container:
|
769 |
+
if site_var4 == 'Draftkings':
|
770 |
+
working_roo = player_stats
|
771 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "PPR": "Fantasy"}, inplace = True)
|
772 |
+
working_roo.replace('', 0, inplace=True)
|
773 |
+
working_roo = working_roo[working_roo['Position'] == 'RB']
|
774 |
+
if site_var4 == 'Fanduel':
|
775 |
+
working_roo = player_stats
|
776 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "Half_PPR": "Fantasy"}, inplace = True)
|
777 |
+
working_roo.replace('', 0, inplace=True)
|
778 |
+
working_roo = working_roo[working_roo['Position'] == 'RB']
|
779 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var4)]
|
780 |
+
working_roo = working_roo[working_roo['Salary'] >= sal_var4[0]]
|
781 |
+
working_roo = working_roo[working_roo['Salary'] <= sal_var4[1]]
|
782 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
783 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
784 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
785 |
+
total_sims = 1000
|
786 |
+
|
787 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Fantasy', 'Rush Yards', 'Receptions']]
|
788 |
+
flex_file.rename(columns={"Fantasy": "Median", "Pos": "Position"}, inplace = True)
|
789 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
790 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median'] + flex_file['Floor']) + (flex_file['Rush Yards']*.01), flex_file['Median'] + flex_file['Floor'] + flex_file['Receptions'])
|
791 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
792 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
793 |
+
hold_file = flex_file
|
794 |
+
overall_file = flex_file
|
795 |
+
salary_file = flex_file
|
796 |
+
|
797 |
+
overall_players = overall_file[['Player']]
|
798 |
+
|
799 |
+
for x in range(0,total_sims):
|
800 |
+
salary_file[x] = salary_file['Salary']
|
801 |
+
|
802 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
803 |
+
salary_file.astype('int').dtypes
|
804 |
+
|
805 |
+
salary_file = salary_file.div(1000)
|
806 |
+
|
807 |
+
for x in range(0,total_sims):
|
808 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
809 |
+
|
810 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
811 |
+
overall_file.astype('int').dtypes
|
812 |
+
|
813 |
+
players_only = hold_file[['Player']]
|
814 |
+
raw_lineups_file = players_only
|
815 |
+
|
816 |
+
for x in range(0,total_sims):
|
817 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
818 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
819 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
820 |
+
|
821 |
+
players_only=players_only.drop(['Player'], axis=1)
|
822 |
+
players_only.astype('int').dtypes
|
823 |
+
|
824 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
825 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
826 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
827 |
+
|
828 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
829 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
830 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
831 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
832 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
833 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
834 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
835 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
836 |
+
|
837 |
+
players_only['Player'] = hold_file[['Player']]
|
838 |
+
|
839 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
840 |
+
|
841 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
842 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
843 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
844 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
845 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
846 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
847 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
848 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
849 |
+
final_Proj['LevX'] = 0
|
850 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
851 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
852 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
853 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
854 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
855 |
+
|
856 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
857 |
+
final_Proj = final_Proj.set_index('Player')
|
858 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
859 |
+
|
860 |
+
with hold_container:
|
861 |
+
hold_container = st.empty()
|
862 |
+
final_Proj = final_Proj
|
863 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
864 |
+
|
865 |
+
st.download_button(
|
866 |
+
label="Export Tables",
|
867 |
+
data=convert_df_to_csv(final_Proj),
|
868 |
+
file_name='Custom_NFL_rb_export.csv',
|
869 |
+
mime='text/csv',
|
870 |
+
)
|
871 |
+
|
872 |
+
with tab5:
|
873 |
+
col1, col2 = st.columns([1, 5])
|
874 |
+
with col1:
|
875 |
+
st.info(t_stamp)
|
876 |
+
if st.button("Load/Reset Data", key='reset5'):
|
877 |
+
st.cache_data.clear()
|
878 |
+
player_stats = player_stat_table()
|
879 |
+
dk_stacks_raw = load_dk_stacks()
|
880 |
+
fd_stacks_raw = load_fd_stacks()
|
881 |
+
dk_roo_raw = load_dk_player_projections()
|
882 |
+
fd_roo_raw = load_fd_player_projections()
|
883 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
884 |
+
site_slates = set_slate_teams()
|
885 |
+
slate_var5 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate'), key='slate_var5')
|
886 |
+
site_var5 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var5')
|
887 |
+
custom_var5 = st.radio("Are you creating a custom table?", ('No', 'Yes'), key='custom_var5')
|
888 |
+
if custom_var5 == 'No':
|
889 |
+
if site_var5 == 'Draftkings':
|
890 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var5)]
|
891 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_wrs']
|
892 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
893 |
+
elif site_var5 == 'Fanduel':
|
894 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var5)]
|
895 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_wrs']
|
896 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
897 |
+
split_var5 = st.radio("Would you like to view the whole slate or just specific games?", ('Full Slate Run', 'Specific Games'), key='split_var5')
|
898 |
+
if split_var5 == 'Specific Games':
|
899 |
+
team_var5 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var5')
|
900 |
+
elif split_var5 == 'Full Slate Run':
|
901 |
+
team_var5 = raw_baselines.Team.values.tolist()
|
902 |
+
pos_split5 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split5')
|
903 |
+
if pos_split5 == 'Specific Positions':
|
904 |
+
pos_var5 = st.multiselect('What Positions would you like to view?', options = ['WR'], key='pos_var5')
|
905 |
+
elif pos_split5 == 'All Positions':
|
906 |
+
pos_var5 = 'All'
|
907 |
+
sal_var5 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var5')
|
908 |
+
if custom_var5 == 'Yes':
|
909 |
+
contest_var5 = st.selectbox("What contest type are you running for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var5')
|
910 |
+
if site_var5 == 'Draftkings':
|
911 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var5)]
|
912 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_wrs']
|
913 |
+
elif site_var5 == 'Fanduel':
|
914 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var5)]
|
915 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_wrs']
|
916 |
+
split_var5 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var5')
|
917 |
+
if split_var5 == 'Specific Games':
|
918 |
+
team_var5 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var5')
|
919 |
+
elif split_var5 == 'Full Slate Run':
|
920 |
+
team_var5 = raw_baselines.Team.values.tolist()
|
921 |
+
pos_split5 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split5')
|
922 |
+
if pos_split5 == 'Specific Positions':
|
923 |
+
pos_var5 = st.multiselect('What Positions would you like to view?', options = ['WR'])
|
924 |
+
elif pos_split5 == 'All Positions':
|
925 |
+
pos_var5 = 'All'
|
926 |
+
sal_var5 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var5')
|
927 |
+
|
928 |
+
|
929 |
+
with col2:
|
930 |
+
if custom_var5 == 'No':
|
931 |
+
final_Proj = raw_baselines[raw_baselines['Team'].isin(team_var5)]
|
932 |
+
final_Proj = final_Proj[final_Proj['Salary'] >= sal_var5[0]]
|
933 |
+
final_Proj = final_Proj[final_Proj['Salary'] <= sal_var5[1]]
|
934 |
+
if pos_var5 != 'All':
|
935 |
+
final_Proj = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var5))]
|
936 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
937 |
+
final_Proj = final_Proj.set_index('Player')
|
938 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
939 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
940 |
+
st.download_button(
|
941 |
+
label="Export Tables",
|
942 |
+
data=convert_df_to_csv(final_Proj),
|
943 |
+
file_name='NFL_wr_export.csv',
|
944 |
+
mime='text/csv',
|
945 |
+
)
|
946 |
+
elif custom_var5 == 'Yes':
|
947 |
+
hold_container = st.empty()
|
948 |
+
if st.button('Create Range of Outcomes for Slate'):
|
949 |
+
with hold_container:
|
950 |
+
if site_var5 == 'Draftkings':
|
951 |
+
working_roo = player_stats
|
952 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "PPR": "Fantasy"}, inplace = True)
|
953 |
+
working_roo.replace('', 0, inplace=True)
|
954 |
+
working_roo = working_roo[working_roo['Position'] == 'WR']
|
955 |
+
if site_var5 == 'Fanduel':
|
956 |
+
working_roo = player_stats
|
957 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "Half_PPR": "Fantasy"}, inplace = True)
|
958 |
+
working_roo.replace('', 0, inplace=True)
|
959 |
+
working_roo = working_roo[working_roo['Position'] == 'WR']
|
960 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var5)]
|
961 |
+
working_roo = working_roo[working_roo['Salary'] >= sal_var5[0]]
|
962 |
+
working_roo = working_roo[working_roo['Salary'] <= sal_var5[1]]
|
963 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
964 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
965 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
966 |
+
total_sims = 1000
|
967 |
+
|
968 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Fantasy', 'Rush Yards', 'Receptions']]
|
969 |
+
flex_file.rename(columns={"Fantasy": "Median", "Pos": "Position"}, inplace = True)
|
970 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
971 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median'] + flex_file['Floor']) + (flex_file['Rush Yards']*.01), flex_file['Median'] + flex_file['Floor'] + flex_file['Receptions'])
|
972 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
973 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
974 |
+
hold_file = flex_file
|
975 |
+
overall_file = flex_file
|
976 |
+
salary_file = flex_file
|
977 |
+
|
978 |
+
overall_players = overall_file[['Player']]
|
979 |
+
|
980 |
+
for x in range(0,total_sims):
|
981 |
+
salary_file[x] = salary_file['Salary']
|
982 |
+
|
983 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
984 |
+
salary_file.astype('int').dtypes
|
985 |
+
|
986 |
+
salary_file = salary_file.div(1000)
|
987 |
+
|
988 |
+
for x in range(0,total_sims):
|
989 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
990 |
+
|
991 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
992 |
+
overall_file.astype('int').dtypes
|
993 |
+
|
994 |
+
players_only = hold_file[['Player']]
|
995 |
+
raw_lineups_file = players_only
|
996 |
+
|
997 |
+
for x in range(0,total_sims):
|
998 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
999 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
1000 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
1001 |
+
|
1002 |
+
players_only=players_only.drop(['Player'], axis=1)
|
1003 |
+
players_only.astype('int').dtypes
|
1004 |
+
|
1005 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
1006 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
1007 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
1008 |
+
|
1009 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
1010 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
1011 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
1012 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
1013 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
1014 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
1015 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
1016 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
1017 |
+
|
1018 |
+
players_only['Player'] = hold_file[['Player']]
|
1019 |
+
|
1020 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
1021 |
+
|
1022 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
1023 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
1024 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
1025 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
1026 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
1027 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
1028 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
1029 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
1030 |
+
final_Proj['LevX'] = 0
|
1031 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1032 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1033 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1034 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1035 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
1036 |
+
|
1037 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
1038 |
+
final_Proj = final_Proj.set_index('Player')
|
1039 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
1040 |
+
|
1041 |
+
with hold_container:
|
1042 |
+
hold_container = st.empty()
|
1043 |
+
final_Proj = final_Proj
|
1044 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
1045 |
+
|
1046 |
+
st.download_button(
|
1047 |
+
label="Export Tables",
|
1048 |
+
data=convert_df_to_csv(final_Proj),
|
1049 |
+
file_name='Custom_NFL_wr_export.csv',
|
1050 |
+
mime='text/csv',
|
1051 |
+
)
|
1052 |
+
|
1053 |
+
with tab6:
|
1054 |
+
col1, col2 = st.columns([1, 5])
|
1055 |
+
with col1:
|
1056 |
+
st.info(t_stamp)
|
1057 |
+
if st.button("Load/Reset Data", key='reset6'):
|
1058 |
+
st.cache_data.clear()
|
1059 |
+
player_stats = player_stat_table()
|
1060 |
+
dk_stacks_raw = load_dk_stacks()
|
1061 |
+
fd_stacks_raw = load_fd_stacks()
|
1062 |
+
dk_roo_raw = load_dk_player_projections()
|
1063 |
+
fd_roo_raw = load_fd_player_projections()
|
1064 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
1065 |
+
site_slates = set_slate_teams()
|
1066 |
+
slate_var6 = st.radio("Which data are you loading?", ('Main Slate', 'Secondary Slate', 'Thurs-Mon Slate'), key='slate_var6')
|
1067 |
+
site_var6 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var6')
|
1068 |
+
custom_var6 = st.radio("Are you creating a custom table?", ('No', 'Yes'), key='custom_var6')
|
1069 |
+
if custom_var6 == 'No':
|
1070 |
+
if site_var6 == 'Draftkings':
|
1071 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var6)]
|
1072 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_tes']
|
1073 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
1074 |
+
elif site_var6 == 'Fanduel':
|
1075 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var6)]
|
1076 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_tes']
|
1077 |
+
raw_baselines = raw_baselines.iloc[:,:-3]
|
1078 |
+
split_var6 = st.radio("Would you like to view the whole slate or just specific games?", ('Full Slate Run', 'Specific Games'), key='split_var6')
|
1079 |
+
if split_var6 == 'Specific Games':
|
1080 |
+
team_var6 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var6')
|
1081 |
+
elif split_var6 == 'Full Slate Run':
|
1082 |
+
team_var6 = raw_baselines.Team.values.tolist()
|
1083 |
+
pos_split6 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split6')
|
1084 |
+
if pos_split6 == 'Specific Positions':
|
1085 |
+
pos_var6 = st.multiselect('What Positions would you like to view?', options = ['TE'], key='pos_var6')
|
1086 |
+
elif pos_split5 == 'All Positions':
|
1087 |
+
pos_var6 = 'All'
|
1088 |
+
sal_var6 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var6')
|
1089 |
+
if custom_var6 == 'Yes':
|
1090 |
+
contest_var6 = st.selectbox("What contest type are you running for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var6')
|
1091 |
+
if site_var6 == 'Draftkings':
|
1092 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var6)]
|
1093 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'dk_tes']
|
1094 |
+
elif site_var6 == 'Fanduel':
|
1095 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var6)]
|
1096 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'fd_tes']
|
1097 |
+
split_var6 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var6')
|
1098 |
+
if split_var6 == 'Specific Games':
|
1099 |
+
team_var6 = st.multiselect('Which teams would you like to include in the ROO?', options = raw_baselines['Team'].unique(), key='team_var6')
|
1100 |
+
elif split_var6 == 'Full Slate Run':
|
1101 |
+
team_var6 = raw_baselines.Team.values.tolist()
|
1102 |
+
pos_split6 = st.radio("Are you viewing all positions, specific groups, or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split6')
|
1103 |
+
if pos_split6 == 'Specific Positions':
|
1104 |
+
pos_var6 = st.multiselect('What Positions would you like to view?', options = ['TE'])
|
1105 |
+
elif pos_split6 == 'All Positions':
|
1106 |
+
pos_var6 = 'All'
|
1107 |
+
sal_var6 = st.slider("Is there a certain price range you want to view?", 2000, 10000, (2000, 10000), key='sal_var6')
|
1108 |
+
|
1109 |
+
|
1110 |
+
with col2:
|
1111 |
+
if custom_var6 == 'No':
|
1112 |
+
final_Proj = raw_baselines[raw_baselines['Team'].isin(team_var6)]
|
1113 |
+
final_Proj = final_Proj[final_Proj['Salary'] >= sal_var6[0]]
|
1114 |
+
final_Proj = final_Proj[final_Proj['Salary'] <= sal_var6[1]]
|
1115 |
+
if pos_var6 != 'All':
|
1116 |
+
final_Proj = raw_baselines[raw_baselines['Position'].str.contains('|'.join(pos_var6))]
|
1117 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
1118 |
+
final_Proj = final_Proj.set_index('Player')
|
1119 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
1120 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
1121 |
+
st.download_button(
|
1122 |
+
label="Export Tables",
|
1123 |
+
data=convert_df_to_csv(final_Proj),
|
1124 |
+
file_name='NFL_te_export.csv',
|
1125 |
+
mime='text/csv',
|
1126 |
+
)
|
1127 |
+
elif custom_var6 == 'Yes':
|
1128 |
+
hold_container = st.empty()
|
1129 |
+
if st.button('Create Range of Outcomes for Slate'):
|
1130 |
+
with hold_container:
|
1131 |
+
if site_var6 == 'Draftkings':
|
1132 |
+
working_roo = player_stats
|
1133 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "PPR": "Fantasy"}, inplace = True)
|
1134 |
+
working_roo.replace('', 0, inplace=True)
|
1135 |
+
working_roo = working_roo[working_roo['Position'] == 'TE']
|
1136 |
+
if site_var6 == 'Fanduel':
|
1137 |
+
working_roo = player_stats
|
1138 |
+
working_roo.rename(columns={"name": "Player", "rush_yards": "Rush Yards", "rec": "Receptions", "Half_PPR": "Fantasy"}, inplace = True)
|
1139 |
+
working_roo.replace('', 0, inplace=True)
|
1140 |
+
working_roo = working_roo[working_roo['Position'] == 'TE']
|
1141 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var6)]
|
1142 |
+
working_roo = working_roo[working_roo['Salary'] >= sal_var6[0]]
|
1143 |
+
working_roo = working_roo[working_roo['Salary'] <= sal_var6[1]]
|
1144 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
1145 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
1146 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
1147 |
+
total_sims = 1000
|
1148 |
+
|
1149 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Fantasy', 'Rush Yards', 'Receptions']]
|
1150 |
+
flex_file.rename(columns={"Fantasy": "Median", "Pos": "Position"}, inplace = True)
|
1151 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median']*.25) + (flex_file['Rush Yards']*.01),flex_file['Median']*.25)
|
1152 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB',(flex_file['Median'] + flex_file['Floor']) + (flex_file['Rush Yards']*.01), flex_file['Median'] + flex_file['Floor'] + flex_file['Receptions'])
|
1153 |
+
flex_file['STD'] = (flex_file['Median']/4) + flex_file['Receptions']
|
1154 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
1155 |
+
hold_file = flex_file
|
1156 |
+
overall_file = flex_file
|
1157 |
+
salary_file = flex_file
|
1158 |
+
|
1159 |
+
overall_players = overall_file[['Player']]
|
1160 |
+
|
1161 |
+
for x in range(0,total_sims):
|
1162 |
+
salary_file[x] = salary_file['Salary']
|
1163 |
+
|
1164 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
1165 |
+
salary_file.astype('int').dtypes
|
1166 |
+
|
1167 |
+
salary_file = salary_file.div(1000)
|
1168 |
+
|
1169 |
+
for x in range(0,total_sims):
|
1170 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
1171 |
+
|
1172 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
1173 |
+
overall_file.astype('int').dtypes
|
1174 |
+
|
1175 |
+
players_only = hold_file[['Player']]
|
1176 |
+
raw_lineups_file = players_only
|
1177 |
+
|
1178 |
+
for x in range(0,total_sims):
|
1179 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
1180 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
1181 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
1182 |
+
|
1183 |
+
players_only=players_only.drop(['Player'], axis=1)
|
1184 |
+
players_only.astype('int').dtypes
|
1185 |
+
|
1186 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
1187 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
1188 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
1189 |
+
|
1190 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
1191 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
1192 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
1193 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
1194 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
1195 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
1196 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
1197 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
1198 |
+
|
1199 |
+
players_only['Player'] = hold_file[['Player']]
|
1200 |
+
|
1201 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
1202 |
+
|
1203 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
1204 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
1205 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
1206 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
1207 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
1208 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
1209 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
1210 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
1211 |
+
final_Proj['LevX'] = 0
|
1212 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1213 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1214 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1215 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
1216 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
1217 |
+
|
1218 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'CPT_Own', 'LevX']]
|
1219 |
+
final_Proj = final_Proj.set_index('Player')
|
1220 |
+
final_Proj = final_Proj.sort_values(by='Median', ascending=False)
|
1221 |
+
|
1222 |
+
with hold_container:
|
1223 |
+
hold_container = st.empty()
|
1224 |
+
final_Proj = final_Proj
|
1225 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
1226 |
+
|
1227 |
+
st.download_button(
|
1228 |
+
label="Export Tables",
|
1229 |
+
data=convert_df_to_csv(final_Proj),
|
1230 |
+
file_name='Custom_NFL_te_export.csv',
|
1231 |
+
mime='text/csv',
|
1232 |
+
)
|