Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,113 +34,101 @@ def init_conn():
|
|
34 |
|
35 |
gcservice_account = init_conn()
|
36 |
|
37 |
-
|
38 |
|
39 |
@st.cache_resource(ttl = 600)
|
40 |
def init_baselines():
|
41 |
-
sh = gcservice_account.open_by_url(
|
42 |
|
43 |
worksheet = sh.worksheet('Gamelog')
|
44 |
raw_display = pd.DataFrame(worksheet.get_values())
|
45 |
raw_display.columns = raw_display.iloc[0]
|
46 |
raw_display = raw_display[1:]
|
47 |
raw_display = raw_display.reset_index(drop=True)
|
48 |
-
gamelog_table = raw_display[raw_display['
|
49 |
-
gamelog_table = gamelog_table[['
|
50 |
-
'
|
51 |
-
'
|
52 |
-
|
53 |
-
gamelog_table['
|
54 |
-
gamelog_table['passes'].replace("", 0, inplace=True)
|
55 |
-
gamelog_table['touches'].replace("", 0, inplace=True)
|
56 |
-
gamelog_table['Fantasy'].replace("", 0, inplace=True)
|
57 |
-
gamelog_table['FD_Fantasy'].replace("", 0, inplace=True)
|
58 |
-
gamelog_table['REB'] = gamelog_table['REB'].astype(int)
|
59 |
-
gamelog_table['assists'] = gamelog_table['assists'].astype(int)
|
60 |
-
gamelog_table['reboundChancesTotal'] = gamelog_table['reboundChancesTotal'].astype(int)
|
61 |
-
gamelog_table['passes'] = gamelog_table['passes'].astype(int)
|
62 |
-
gamelog_table['touches'] = gamelog_table['touches'].astype(int)
|
63 |
-
gamelog_table['Fantasy'] = gamelog_table['Fantasy'].astype(float)
|
64 |
-
gamelog_table['FD_Fantasy'] = gamelog_table['FD_Fantasy'].astype(float)
|
65 |
-
gamelog_table['rebound%'] = gamelog_table['REB'] / gamelog_table['reboundChancesTotal']
|
66 |
-
gamelog_table['assists_per_pass'] = gamelog_table['assists'] / gamelog_table['passes']
|
67 |
-
gamelog_table['Fantasy_per_touch'] = gamelog_table['Fantasy'] / gamelog_table['touches']
|
68 |
-
gamelog_table['FD_Fantasy_per_touch'] = gamelog_table['FD_Fantasy'] / gamelog_table['touches']
|
69 |
-
data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'TEAM_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
|
70 |
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
71 |
-
gamelog_table['
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
'
|
|
|
|
|
77 |
|
78 |
return gamelog_table
|
79 |
|
80 |
@st.cache_data(show_spinner=False)
|
81 |
def seasonlong_build(data_sample):
|
82 |
season_long_table = data_sample[['Player', 'Team']]
|
83 |
-
season_long_table['
|
84 |
-
season_long_table['
|
85 |
-
season_long_table['
|
86 |
-
season_long_table['
|
87 |
-
season_long_table['
|
88 |
-
season_long_table['
|
89 |
-
|
90 |
-
season_long_table['
|
91 |
-
season_long_table['
|
92 |
-
season_long_table['
|
93 |
-
|
94 |
-
season_long_table['
|
95 |
-
season_long_table['
|
96 |
-
season_long_table['
|
97 |
-
|
98 |
-
season_long_table['
|
99 |
-
season_long_table['
|
100 |
-
season_long_table['
|
101 |
-
season_long_table['
|
102 |
-
season_long_table['
|
103 |
-
season_long_table['
|
104 |
-
season_long_table['
|
105 |
-
season_long_table['
|
106 |
-
season_long_table['
|
107 |
-
season_long_table['
|
108 |
-
season_long_table['
|
109 |
-
season_long_table['
|
110 |
-
season_long_table['Tov'] = data_sample.groupby(['Player', 'Season'], sort=False)['Tov'].transform('mean').astype(float)
|
111 |
-
season_long_table['PF'] = data_sample.groupby(['Player', 'Season'], sort=False)['PF'].transform('mean').astype(float)
|
112 |
-
season_long_table['DD'] = data_sample.groupby(['Player', 'Season'], sort=False)['DD'].transform('mean').astype(float)
|
113 |
-
season_long_table['TD'] = data_sample.groupby(['Player', 'Season'], sort=False)['TD'].transform('mean').astype(float)
|
114 |
-
season_long_table['Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('mean').astype(float)
|
115 |
-
season_long_table['FD_Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
|
116 |
-
season_long_table['Rebound%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['REB'].transform('sum').astype(int) /
|
117 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('sum').astype(int))
|
118 |
-
season_long_table['Assists/Pass'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('sum').astype(int) /
|
119 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('sum').astype(int))
|
120 |
-
season_long_table['Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('sum').astype(int) /
|
121 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
122 |
-
season_long_table['FD Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
|
123 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
124 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
125 |
|
126 |
-
season_long_table = season_long_table.set_axis(['Player', 'Team', '
|
127 |
-
'
|
128 |
-
'
|
129 |
-
'
|
130 |
|
131 |
return season_long_table
|
132 |
|
133 |
@st.cache_data(show_spinner=False)
|
134 |
def run_fantasy_corr(data_sample):
|
135 |
cor_testing = data_sample
|
136 |
-
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
137 |
date_list = cor_testing['Date'].unique().tolist()
|
138 |
player_list = cor_testing['Player'].unique().tolist()
|
139 |
corr_frame = pd.DataFrame()
|
140 |
corr_frame['DATE'] = date_list
|
141 |
for player in player_list:
|
142 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
143 |
-
fantasy_map = dict(zip(player_testing['Date'], player_testing['
|
144 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
145 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
146 |
corrM = players_fantasy.corr()
|
@@ -150,14 +138,13 @@ def run_fantasy_corr(data_sample):
|
|
150 |
@st.cache_data(show_spinner=False)
|
151 |
def run_min_corr(data_sample):
|
152 |
cor_testing = data_sample
|
153 |
-
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
154 |
date_list = cor_testing['Date'].unique().tolist()
|
155 |
player_list = cor_testing['Player'].unique().tolist()
|
156 |
corr_frame = pd.DataFrame()
|
157 |
corr_frame['DATE'] = date_list
|
158 |
for player in player_list:
|
159 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
160 |
-
fantasy_map = dict(zip(player_testing['Date'], player_testing['
|
161 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
162 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
163 |
corrM = players_fantasy.corr()
|
@@ -204,10 +191,10 @@ with tab1:
|
|
204 |
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
205 |
|
206 |
if split_var3 == 'Specific Dates':
|
207 |
-
low_date = st.date_input('Min Date:', value=None, format="
|
208 |
if low_date is not None:
|
209 |
low_date = pd.to_datetime(low_date).date()
|
210 |
-
high_date = st.date_input('Max Date:', value=None, format="
|
211 |
if high_date is not None:
|
212 |
high_date = pd.to_datetime(high_date).date()
|
213 |
elif split_var3 == 'All':
|
@@ -221,15 +208,15 @@ with tab1:
|
|
221 |
elif split_var4 == 'All':
|
222 |
player_var1 = total_players
|
223 |
|
224 |
-
min_var1 = st.slider("Is there a certain
|
225 |
|
226 |
with col2:
|
227 |
if split_var1 == 'Season Logs':
|
228 |
display = st.container()
|
229 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
230 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
231 |
-
gamelog_table = gamelog_table[gamelog_table['
|
232 |
-
gamelog_table = gamelog_table[gamelog_table['
|
233 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
234 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
235 |
season_long_table = seasonlong_build(gamelog_table)
|
@@ -239,8 +226,8 @@ with tab1:
|
|
239 |
elif split_var1 == 'Gamelogs':
|
240 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
241 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
242 |
-
gamelog_table = gamelog_table[gamelog_table['
|
243 |
-
gamelog_table = gamelog_table[gamelog_table['
|
244 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
245 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
246 |
gamelog_table = gamelog_table.reset_index(drop=True)
|
@@ -276,7 +263,7 @@ with tab2:
|
|
276 |
total_players = indv_players.Player.values.tolist()
|
277 |
total_dates = gamelog_table.Date.values.tolist()
|
278 |
|
279 |
-
corr_var = st.radio("Are you correlating fantasy or
|
280 |
|
281 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
282 |
|
@@ -288,17 +275,17 @@ with tab2:
|
|
288 |
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
289 |
|
290 |
if split_var2_t2 == 'Specific Dates':
|
291 |
-
low_date_t2 = st.date_input('Min Date:', value=None, format="
|
292 |
if low_date_t2 is not None:
|
293 |
low_date_t2 = pd.to_datetime(low_date_t2).date()
|
294 |
-
high_date_t2 = st.date_input('Max Date:', value=None, format="
|
295 |
if high_date_t2 is not None:
|
296 |
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
297 |
elif split_var2_t2 == 'All':
|
298 |
low_date_t2 = gamelog_table['Date'].min()
|
299 |
high_date_t2 = gamelog_table['Date'].max()
|
300 |
|
301 |
-
min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0,
|
302 |
|
303 |
with col2:
|
304 |
if split_var1_t2 == 'Specific Teams':
|
@@ -306,12 +293,12 @@ with tab2:
|
|
306 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
307 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
308 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
309 |
-
gamelog_table = gamelog_table[gamelog_table['
|
310 |
-
gamelog_table = gamelog_table[gamelog_table['
|
311 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
312 |
if corr_var == 'Fantasy':
|
313 |
corr_display = run_fantasy_corr(gamelog_table)
|
314 |
-
elif corr_var == '
|
315 |
corr_display = run_min_corr(gamelog_table)
|
316 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
317 |
|
@@ -320,11 +307,11 @@ with tab2:
|
|
320 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
321 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
322 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
323 |
-
gamelog_table = gamelog_table[gamelog_table['
|
324 |
-
gamelog_table = gamelog_table[gamelog_table['
|
325 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
326 |
if corr_var == 'Fantasy':
|
327 |
corr_display = run_fantasy_corr(gamelog_table)
|
328 |
-
elif corr_var == '
|
329 |
corr_display = run_min_corr(gamelog_table)
|
330 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
34 |
|
35 |
gcservice_account = init_conn()
|
36 |
|
37 |
+
NHL_Data = 'https://docs.google.com/spreadsheets/d/1NmKa-b-2D3w7rRxwMPSchh31GKfJ1XcDI2GU8rXWnHI/edit#gid=1158895881'
|
38 |
|
39 |
@st.cache_resource(ttl = 600)
|
40 |
def init_baselines():
|
41 |
+
sh = gcservice_account.open_by_url(NHL_Data)
|
42 |
|
43 |
worksheet = sh.worksheet('Gamelog')
|
44 |
raw_display = pd.DataFrame(worksheet.get_values())
|
45 |
raw_display.columns = raw_display.iloc[0]
|
46 |
raw_display = raw_display[1:]
|
47 |
raw_display = raw_display.reset_index(drop=True)
|
48 |
+
gamelog_table = raw_display[raw_display['Player'] != ""]
|
49 |
+
gamelog_table = gamelog_table[['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points', 'IPP',
|
50 |
+
'Shots', 'SH%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
51 |
+
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
52 |
+
'Faceoffs Lost', 'Faceoffs %']]
|
53 |
+
data_cols = gamelog_table.columns.drop(['Player', 'Team', 'Position', 'Date'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
55 |
+
gamelog_table['Date'] = pd.to_datetime(gamelog_table['Date']).dt.date
|
56 |
+
# gamelog_table['Shots'].replace("", 0, inplace=True)
|
57 |
+
# gamelog_table['Shots Blocked'].replace("", 0, inplace=True)
|
58 |
+
# gamelog_table['Goals'].replace("", 0, inplace=True)
|
59 |
+
# gamelog_table['Total Points'].replace("", 0, inplace=True)
|
60 |
+
# gamelog_table['Shots'] = gamelog_table['Shots'].astype(int)
|
61 |
+
# gamelog_table['Shots Blocked'] = gamelog_table['Shots Blocked'].astype(int)
|
62 |
+
# gamelog_table['Goals'] = gamelog_table['Goals'].astype(int)
|
63 |
+
# gamelog_table['Total Points'] = gamelog_table['Total Points'].astype(int)
|
64 |
+
gamelog_table['dk_shots_bonus'] = np.where((gamelog_table['Shots'] >= 5), 1, 0)
|
65 |
+
gamelog_table['dk_blocks_bonus'] = np.where((gamelog_table['Shots Blocked'] >= 3), 1, 0)
|
66 |
+
gamelog_table['dk_goals_bonus'] = np.where((gamelog_table['Goals'] >= 3), 1, 0)
|
67 |
+
gamelog_table['dk_points_bonus'] = np.where((gamelog_table['Total Points'] >= 3), 1, 0)
|
68 |
+
gamelog_table['dk_fantasy'] = sum([(gamelog_table['Goals'] * 8.5), (gamelog_table['Total Assists'] * 5), (gamelog_table['Shots'] * 1.5),
|
69 |
+
(gamelog_table['Shots Blocked'] * 1.3), (gamelog_table['dk_shots_bonus'] * 3), (gamelog_table['dk_blocks_bonus'] * 3),
|
70 |
+
(gamelog_table['dk_goals_bonus'] * 3), (gamelog_table['dk_points_bonus'] * 3)]).astype(float).round(2)
|
71 |
+
gamelog_table['fd_fantasy'] = sum([(gamelog_table['Goals'] * 12), (gamelog_table['Total Assists'] * 8), (gamelog_table['Shots'] * 1.6),
|
72 |
+
(gamelog_table['Shots Blocked'] * 1.6)]).astype(float).round(2)
|
73 |
|
74 |
+
|
75 |
+
|
76 |
+
gamelog_table = gamelog_table.set_axis(['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points', 'IPP',
|
77 |
+
'Shots', 'Shots%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
78 |
+
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
79 |
+
'Faceoffs Lost', 'Faceoffs%'], axis=1)
|
80 |
|
81 |
return gamelog_table
|
82 |
|
83 |
@st.cache_data(show_spinner=False)
|
84 |
def seasonlong_build(data_sample):
|
85 |
season_long_table = data_sample[['Player', 'Team']]
|
86 |
+
season_long_table['TOI'] = data_sample.groupby(['Player', 'Team'], sort=False)['TOI'].transform('mean').astype(float)
|
87 |
+
season_long_table['Goals'] = data_sample.groupby(['Player', 'Team'], sort=False)['Goals'].transform('mean').astype(float)
|
88 |
+
season_long_table['Total Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Assists'].transform('mean').astype(float)
|
89 |
+
season_long_table['First Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['First Assists'].transform('mean').astype(float)
|
90 |
+
season_long_table['Second Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['Second Assists'].transform('mean').astype(float)
|
91 |
+
season_long_table['Total Points'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Points'].transform('mean').astype(float)
|
92 |
+
season_long_table['IPP'] = data_sample.groupby(['Player', 'Team'], sort=False)['IPP'].transform('mean').astype(float)
|
93 |
+
season_long_table['Shots'] = data_sample.groupby(['Player', 'Team'], sort=False)['Shots'].transform('mean').astype(float)
|
94 |
+
season_long_table['ixG'] = data_sample.groupby(['Player', 'Team'], sort=False)['ixG'].transform('mean').astype(float)
|
95 |
+
season_long_table['iCF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iCF'].transform('mean').astype(float)
|
96 |
+
season_long_table['iFF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iFF'].transform('mean').astype(float)
|
97 |
+
season_long_table['iSCF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iSCF'].transform('mean').astype(float)
|
98 |
+
season_long_table['iHDCF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iHDCF'].transform('mean').astype(float)
|
99 |
+
season_long_table['Rush Attempts'] = data_sample.groupby(['Player', 'Team'], sort=False)['Rush Attempts'].transform('mean').astype(float)
|
100 |
+
season_long_table['Rebounds Created'] = data_sample.groupby(['Player', 'Team'], sort=False)['Rebounds Created'].transform('mean').astype(float)
|
101 |
+
season_long_table['PIM'] = data_sample.groupby(['Player', 'Team'], sort=False)['PIM'].transform('mean').astype(float)
|
102 |
+
season_long_table['Total Penalties'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Penalties'].transform('mean').astype(float)
|
103 |
+
season_long_table['Minor'] = data_sample.groupby(['Player', 'Team'], sort=False)['Minor'].transform('mean').astype(float)
|
104 |
+
season_long_table['Major'] = data_sample.groupby(['Player', 'Team'], sort=False)['Major'].transform('mean').astype(float)
|
105 |
+
season_long_table['Penalties Drawn'] = data_sample.groupby(['Player', 'Team'], sort=False)['Penalties Drawn'].transform('mean').astype(float)
|
106 |
+
season_long_table['Giveaways'] = data_sample.groupby(['Player', 'Team'], sort=False)['Giveaways'].transform('mean').astype(float)
|
107 |
+
season_long_table['Takeaways'] = data_sample.groupby(['Player', 'Team'], sort=False)['Takeaways'].transform('mean').astype(float)
|
108 |
+
season_long_table['Hits'] = data_sample.groupby(['Player', 'Team'], sort=False)['Hits'].transform('mean').astype(float)
|
109 |
+
season_long_table['Hits Taken'] = data_sample.groupby(['Player', 'Team'], sort=False)['Hits Taken'].transform('mean').astype(float)
|
110 |
+
season_long_table['Shots Blocked'] = data_sample.groupby(['Player', 'Team'], sort=False)['Shots Blocked'].transform('mean').astype(float)
|
111 |
+
season_long_table['Faceoffs Won'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Won'].transform('mean').astype(float)
|
112 |
+
season_long_table['Faceoffs Lost'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Lost'].transform('mean').astype(float)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
114 |
|
115 |
+
season_long_table = season_long_table.set_axis(['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points',
|
116 |
+
'IPP', 'Shots', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties',
|
117 |
+
'Minor', 'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
118 |
+
'Faceoffs Lost'], axis=1)
|
119 |
|
120 |
return season_long_table
|
121 |
|
122 |
@st.cache_data(show_spinner=False)
|
123 |
def run_fantasy_corr(data_sample):
|
124 |
cor_testing = data_sample
|
|
|
125 |
date_list = cor_testing['Date'].unique().tolist()
|
126 |
player_list = cor_testing['Player'].unique().tolist()
|
127 |
corr_frame = pd.DataFrame()
|
128 |
corr_frame['DATE'] = date_list
|
129 |
for player in player_list:
|
130 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
131 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['dk_fantasy']))
|
132 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
133 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
134 |
corrM = players_fantasy.corr()
|
|
|
138 |
@st.cache_data(show_spinner=False)
|
139 |
def run_min_corr(data_sample):
|
140 |
cor_testing = data_sample
|
|
|
141 |
date_list = cor_testing['Date'].unique().tolist()
|
142 |
player_list = cor_testing['Player'].unique().tolist()
|
143 |
corr_frame = pd.DataFrame()
|
144 |
corr_frame['DATE'] = date_list
|
145 |
for player in player_list:
|
146 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
147 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['TOI']))
|
148 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
149 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
150 |
corrM = players_fantasy.corr()
|
|
|
191 |
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
192 |
|
193 |
if split_var3 == 'Specific Dates':
|
194 |
+
low_date = st.date_input('Min Date:', value=None, format="MM/DD/YYYY", key='low_date')
|
195 |
if low_date is not None:
|
196 |
low_date = pd.to_datetime(low_date).date()
|
197 |
+
high_date = st.date_input('Max Date:', value=None, format="MM/DD/YYYY", key='high_date')
|
198 |
if high_date is not None:
|
199 |
high_date = pd.to_datetime(high_date).date()
|
200 |
elif split_var3 == 'All':
|
|
|
208 |
elif split_var4 == 'All':
|
209 |
player_var1 = total_players
|
210 |
|
211 |
+
min_var1 = st.slider("Is there a certain TOI range you want to view?", 0, 50, (0, 50), key='min_var1')
|
212 |
|
213 |
with col2:
|
214 |
if split_var1 == 'Season Logs':
|
215 |
display = st.container()
|
216 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
217 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
218 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1[0]]
|
219 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1[1]]
|
220 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
221 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
222 |
season_long_table = seasonlong_build(gamelog_table)
|
|
|
226 |
elif split_var1 == 'Gamelogs':
|
227 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
228 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
229 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1[0]]
|
230 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1[1]]
|
231 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
232 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
233 |
gamelog_table = gamelog_table.reset_index(drop=True)
|
|
|
263 |
total_players = indv_players.Player.values.tolist()
|
264 |
total_dates = gamelog_table.Date.values.tolist()
|
265 |
|
266 |
+
corr_var = st.radio("Are you correlating fantasy or TOI?", ('Fantasy', 'TOI'), key='corr_var')
|
267 |
|
268 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
269 |
|
|
|
275 |
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
276 |
|
277 |
if split_var2_t2 == 'Specific Dates':
|
278 |
+
low_date_t2 = st.date_input('Min Date:', value=None, format="MM/DD/YYYY", key='low_date_t2')
|
279 |
if low_date_t2 is not None:
|
280 |
low_date_t2 = pd.to_datetime(low_date_t2).date()
|
281 |
+
high_date_t2 = st.date_input('Max Date:', value=None, format="MM/DD/YYYY", key='high_date_t2')
|
282 |
if high_date_t2 is not None:
|
283 |
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
284 |
elif split_var2_t2 == 'All':
|
285 |
low_date_t2 = gamelog_table['Date'].min()
|
286 |
high_date_t2 = gamelog_table['Date'].max()
|
287 |
|
288 |
+
min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0, 50, (0, 50), key='min_var1_t2')
|
289 |
|
290 |
with col2:
|
291 |
if split_var1_t2 == 'Specific Teams':
|
|
|
293 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
294 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
295 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
296 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1_t2[0]]
|
297 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1_t2[1]]
|
298 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
299 |
if corr_var == 'Fantasy':
|
300 |
corr_display = run_fantasy_corr(gamelog_table)
|
301 |
+
elif corr_var == 'TOI':
|
302 |
corr_display = run_min_corr(gamelog_table)
|
303 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
304 |
|
|
|
307 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
308 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
309 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
310 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1_t2[0]]
|
311 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1_t2[1]]
|
312 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
313 |
if corr_var == 'Fantasy':
|
314 |
corr_display = run_fantasy_corr(gamelog_table)
|
315 |
+
elif corr_var == 'TOI':
|
316 |
corr_display = run_min_corr(gamelog_table)
|
317 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|