Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,102 +45,80 @@ def init_baselines():
|
|
| 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['
|
| 55 |
-
gamelog_table['
|
| 56 |
-
gamelog_table['
|
| 57 |
-
gamelog_table['
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
gamelog_table['
|
| 61 |
-
|
| 62 |
-
gamelog_table['
|
| 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 |
-
gamelog_table = gamelog_table.set_axis(['Player', 'Team', '
|
| 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 +128,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 +181,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 +198,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 +216,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 +253,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 +265,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 +283,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 +297,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)
|
|
|
|
| 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 |
+
gamelog_table['dk_shots_bonus'] = np.where((gamelog_table['Shots'] >= 5), 1, 0)
|
| 54 |
+
gamelog_table['dk_blocks_bonus'] = np.where((gamelog_table['Shots Blocked'] >= 3), 1, 0)
|
| 55 |
+
gamelog_table['dk_goals_bonus'] = np.where((gamelog_table['Goals'] >= 3), 1, 0)
|
| 56 |
+
gamelog_table['dk_points_bonus'] = np.where((gamelog_table['Total Points'] >= 3), 1, 0)
|
| 57 |
+
gamelog_table['dk_fantasy'] = sum([(gamelog_table['Goals'] * 8.5), (gamelog_table['Total Assists'] * 5), (gamelog_table['Shots'] * 1.5),
|
| 58 |
+
(gamelog_table['Shots Blocked'] * 1.3), (gamelog_table['dk_shots_bonus'] * 3), (gamelog_table['dk_blocks_bonus'] * 3),
|
| 59 |
+
(gamelog_table['dk_goals_bonus'] * 3), (gamelog_table['dk_points_bonus'] * 3)]).astype(float).round(2)
|
| 60 |
+
gamelog_table['fd_fantasy'] = sum([(gamelog_table['Goals'] * 12), (gamelog_table['Total Assists'] * 8), (gamelog_table['Shots'] * 1.6),
|
| 61 |
+
(gamelog_table['Shots Blocked'] * 1.6)]).astype(float).round(2)
|
| 62 |
+
data_cols = gamelog_table.columns.drop(['Player', 'Team', 'Position', 'Date'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
| 64 |
+
gamelog_table['Date'] = pd.to_datetime(gamelog_table['Date']).dt.date
|
| 65 |
|
| 66 |
+
gamelog_table = gamelog_table.set_axis(['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points', 'IPP',
|
| 67 |
+
'Shots', 'Shots%', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties', 'Minor',
|
| 68 |
+
'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 69 |
+
'Faceoffs Lost', 'Faceoffs%'], axis=1)
|
| 70 |
|
| 71 |
return gamelog_table
|
| 72 |
|
| 73 |
@st.cache_data(show_spinner=False)
|
| 74 |
def seasonlong_build(data_sample):
|
| 75 |
season_long_table = data_sample[['Player', 'Team']]
|
| 76 |
+
season_long_table['TOI'] = data_sample.groupby(['Player', 'Team'], sort=False)['TOI'].transform('mean').astype(float)
|
| 77 |
+
season_long_table['Goals'] = data_sample.groupby(['Player', 'Team'], sort=False)['Goals'].transform('mean').astype(float)
|
| 78 |
+
season_long_table['Total Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Assists'].transform('mean').astype(float)
|
| 79 |
+
season_long_table['First Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['First Assists'].transform('mean').astype(float)
|
| 80 |
+
season_long_table['Second Assists'] = data_sample.groupby(['Player', 'Team'], sort=False)['Second Assists'].transform('mean').astype(float)
|
| 81 |
+
season_long_table['Total Points'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Points'].transform('mean').astype(float)
|
| 82 |
+
season_long_table['IPP'] = data_sample.groupby(['Player', 'Team'], sort=False)['IPP'].transform('mean').astype(float)
|
| 83 |
+
season_long_table['Shots'] = data_sample.groupby(['Player', 'Team'], sort=False)['Shots'].transform('mean').astype(float)
|
| 84 |
+
season_long_table['ixG'] = data_sample.groupby(['Player', 'Team'], sort=False)['ixG'].transform('mean').astype(float)
|
| 85 |
+
season_long_table['iCF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iCF'].transform('mean').astype(float)
|
| 86 |
+
season_long_table['iFF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iFF'].transform('mean').astype(float)
|
| 87 |
+
season_long_table['iSCF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iSCF'].transform('mean').astype(float)
|
| 88 |
+
season_long_table['iHDCF'] = data_sample.groupby(['Player', 'Team'], sort=False)['iHDCF'].transform('mean').astype(float)
|
| 89 |
+
season_long_table['Rush Attempts'] = data_sample.groupby(['Player', 'Team'], sort=False)['Rush Attempts'].transform('mean').astype(float)
|
| 90 |
+
season_long_table['Rebounds Created'] = data_sample.groupby(['Player', 'Team'], sort=False)['Rebounds Created'].transform('mean').astype(float)
|
| 91 |
+
season_long_table['PIM'] = data_sample.groupby(['Player', 'Team'], sort=False)['PIM'].transform('mean').astype(float)
|
| 92 |
+
season_long_table['Total Penalties'] = data_sample.groupby(['Player', 'Team'], sort=False)['Total Penalties'].transform('mean').astype(float)
|
| 93 |
+
season_long_table['Minor'] = data_sample.groupby(['Player', 'Team'], sort=False)['Minor'].transform('mean').astype(float)
|
| 94 |
+
season_long_table['Major'] = data_sample.groupby(['Player', 'Team'], sort=False)['Major'].transform('mean').astype(float)
|
| 95 |
+
season_long_table['Penalties Drawn'] = data_sample.groupby(['Player', 'Team'], sort=False)['Penalties Drawn'].transform('mean').astype(float)
|
| 96 |
+
season_long_table['Giveaways'] = data_sample.groupby(['Player', 'Team'], sort=False)['Giveaways'].transform('mean').astype(float)
|
| 97 |
+
season_long_table['Takeaways'] = data_sample.groupby(['Player', 'Team'], sort=False)['Takeaways'].transform('mean').astype(float)
|
| 98 |
+
season_long_table['Hits'] = data_sample.groupby(['Player', 'Team'], sort=False)['Hits'].transform('mean').astype(float)
|
| 99 |
+
season_long_table['Hits Taken'] = data_sample.groupby(['Player', 'Team'], sort=False)['Hits Taken'].transform('mean').astype(float)
|
| 100 |
+
season_long_table['Shots Blocked'] = data_sample.groupby(['Player', 'Team'], sort=False)['Shots Blocked'].transform('mean').astype(float)
|
| 101 |
+
season_long_table['Faceoffs Won'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Won'].transform('mean').astype(float)
|
| 102 |
+
season_long_table['Faceoffs Lost'] = data_sample.groupby(['Player', 'Team'], sort=False)['Faceoffs Lost'].transform('mean').astype(float)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
| 104 |
|
| 105 |
+
season_long_table = season_long_table.set_axis(['Player', 'Team', 'Position', 'Date', 'TOI', 'Goals', 'Total Assists', 'First Assists', 'Second Assists', 'Total Points',
|
| 106 |
+
'IPP', 'Shots', 'ixG', 'iCF', 'iFF', 'iSCF', 'iHDCF', 'Rush Attempts', 'Rebounds Created', 'PIM', 'Total Penalties',
|
| 107 |
+
'Minor', 'Major', 'Penalties Drawn', 'Giveaways', 'Takeaways', 'Hits', 'Hits Taken', 'Shots Blocked', 'Faceoffs Won',
|
| 108 |
+
'Faceoffs Lost'], axis=1)
|
| 109 |
|
| 110 |
return season_long_table
|
| 111 |
|
| 112 |
@st.cache_data(show_spinner=False)
|
| 113 |
def run_fantasy_corr(data_sample):
|
| 114 |
cor_testing = data_sample
|
|
|
|
| 115 |
date_list = cor_testing['Date'].unique().tolist()
|
| 116 |
player_list = cor_testing['Player'].unique().tolist()
|
| 117 |
corr_frame = pd.DataFrame()
|
| 118 |
corr_frame['DATE'] = date_list
|
| 119 |
for player in player_list:
|
| 120 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
| 121 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['dk_fantasy']))
|
| 122 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
| 123 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
| 124 |
corrM = players_fantasy.corr()
|
|
|
|
| 128 |
@st.cache_data(show_spinner=False)
|
| 129 |
def run_min_corr(data_sample):
|
| 130 |
cor_testing = data_sample
|
|
|
|
| 131 |
date_list = cor_testing['Date'].unique().tolist()
|
| 132 |
player_list = cor_testing['Player'].unique().tolist()
|
| 133 |
corr_frame = pd.DataFrame()
|
| 134 |
corr_frame['DATE'] = date_list
|
| 135 |
for player in player_list:
|
| 136 |
player_testing = cor_testing[cor_testing['Player'] == player]
|
| 137 |
+
fantasy_map = dict(zip(player_testing['Date'], player_testing['TOI']))
|
| 138 |
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
| 139 |
players_fantasy = corr_frame.drop('DATE', axis=1)
|
| 140 |
corrM = players_fantasy.corr()
|
|
|
|
| 181 |
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3')
|
| 182 |
|
| 183 |
if split_var3 == 'Specific Dates':
|
| 184 |
+
low_date = st.date_input('Min Date:', value=None, format="MM/DD/YYYY", key='low_date')
|
| 185 |
if low_date is not None:
|
| 186 |
low_date = pd.to_datetime(low_date).date()
|
| 187 |
+
high_date = st.date_input('Max Date:', value=None, format="MM/DD/YYYY", key='high_date')
|
| 188 |
if high_date is not None:
|
| 189 |
high_date = pd.to_datetime(high_date).date()
|
| 190 |
elif split_var3 == 'All':
|
|
|
|
| 198 |
elif split_var4 == 'All':
|
| 199 |
player_var1 = total_players
|
| 200 |
|
| 201 |
+
min_var1 = st.slider("Is there a certain TOI range you want to view?", 0, 50, (0, 50), key='min_var1')
|
| 202 |
|
| 203 |
with col2:
|
| 204 |
if split_var1 == 'Season Logs':
|
| 205 |
display = st.container()
|
| 206 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
| 207 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
| 208 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1[0]]
|
| 209 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1[1]]
|
| 210 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
| 211 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
| 212 |
season_long_table = seasonlong_build(gamelog_table)
|
|
|
|
| 216 |
elif split_var1 == 'Gamelogs':
|
| 217 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date]
|
| 218 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date]
|
| 219 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1[0]]
|
| 220 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1[1]]
|
| 221 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(team_var1)]
|
| 222 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(player_var1)]
|
| 223 |
gamelog_table = gamelog_table.reset_index(drop=True)
|
|
|
|
| 253 |
total_players = indv_players.Player.values.tolist()
|
| 254 |
total_dates = gamelog_table.Date.values.tolist()
|
| 255 |
|
| 256 |
+
corr_var = st.radio("Are you correlating fantasy or TOI?", ('Fantasy', 'TOI'), key='corr_var')
|
| 257 |
|
| 258 |
split_var1_t2 = st.radio("Would you like to view specific teams or specific players?", ('Specific Teams', 'Specific Players'), key='split_var1_t2')
|
| 259 |
|
|
|
|
| 265 |
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
| 266 |
|
| 267 |
if split_var2_t2 == 'Specific Dates':
|
| 268 |
+
low_date_t2 = st.date_input('Min Date:', value=None, format="MM/DD/YYYY", key='low_date_t2')
|
| 269 |
if low_date_t2 is not None:
|
| 270 |
low_date_t2 = pd.to_datetime(low_date_t2).date()
|
| 271 |
+
high_date_t2 = st.date_input('Max Date:', value=None, format="MM/DD/YYYY", key='high_date_t2')
|
| 272 |
if high_date_t2 is not None:
|
| 273 |
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
| 274 |
elif split_var2_t2 == 'All':
|
| 275 |
low_date_t2 = gamelog_table['Date'].min()
|
| 276 |
high_date_t2 = gamelog_table['Date'].max()
|
| 277 |
|
| 278 |
+
min_var1_t2 = st.slider("Is there a certain minutes range you want to view?", 0, 50, (0, 50), key='min_var1_t2')
|
| 279 |
|
| 280 |
with col2:
|
| 281 |
if split_var1_t2 == 'Specific Teams':
|
|
|
|
| 283 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
| 284 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
| 285 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
| 286 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1_t2[0]]
|
| 287 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1_t2[1]]
|
| 288 |
gamelog_table = gamelog_table[gamelog_table['Team'].isin(corr_var1_t2)]
|
| 289 |
if corr_var == 'Fantasy':
|
| 290 |
corr_display = run_fantasy_corr(gamelog_table)
|
| 291 |
+
elif corr_var == 'TOI':
|
| 292 |
corr_display = run_min_corr(gamelog_table)
|
| 293 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
| 294 |
|
|
|
|
| 297 |
gamelog_table = gamelog_table.sort_values(by='Fantasy', ascending=False)
|
| 298 |
gamelog_table = gamelog_table[gamelog_table['Date'] >= low_date_t2]
|
| 299 |
gamelog_table = gamelog_table[gamelog_table['Date'] <= high_date_t2]
|
| 300 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] >= min_var1_t2[0]]
|
| 301 |
+
gamelog_table = gamelog_table[gamelog_table['TOI'] <= min_var1_t2[1]]
|
| 302 |
gamelog_table = gamelog_table[gamelog_table['Player'].isin(corr_var1_t2)]
|
| 303 |
if corr_var == 'Fantasy':
|
| 304 |
corr_display = run_fantasy_corr(gamelog_table)
|
| 305 |
+
elif corr_var == 'TOI':
|
| 306 |
corr_display = run_min_corr(gamelog_table)
|
| 307 |
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|