Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -170,6 +170,18 @@ team_dict = team_abv.set_index('team_abv').to_dict()['team_name']
|
|
170 |
|
171 |
yahoo_nhl_df = pd.read_csv('yahoo_to_nhl.csv', encoding='unicode_escape')
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
def nat_stat_convert(df):
|
174 |
for i in range(0,len(df.columns)):
|
175 |
if df.columns[i][-3:]=='/60':
|
@@ -263,70 +275,69 @@ def server(input, output, session):
|
|
263 |
if type(n_1) is not int:
|
264 |
n_1 = 1
|
265 |
|
266 |
-
if n_2 == 0:
|
267 |
list_of_columns.remove(f'L{str(n_2)} PP TOI')
|
268 |
list_of_columns.remove(f'L{str(n_2)} PP%')
|
269 |
list_of_columns_name.remove(f'L{str(n_2)} PP TOI')
|
270 |
list_of_columns_name.remove(f'L{str(n_2)} PP%')
|
271 |
|
272 |
-
if n_3 == 0:
|
273 |
list_of_columns.remove(f'L{str(n_3)} PP TOI')
|
274 |
list_of_columns.remove(f'L{str(n_3)} PP%')
|
275 |
list_of_columns_name.remove(f'L{str(n_3)} PP TOI')
|
276 |
list_of_columns_name.remove(f'L{str(n_3)} PP%')
|
277 |
|
|
|
|
|
278 |
start_date ='2023-09-01'
|
279 |
end_date = '2024-05-01'
|
280 |
|
281 |
-
df_pp_1 =
|
282 |
-
df_pp_2 =
|
283 |
-
df_pp_3 =
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
test
|
312 |
-
test
|
313 |
-
test
|
314 |
-
|
315 |
-
|
316 |
-
test['
|
317 |
-
|
318 |
-
test['
|
319 |
-
|
320 |
-
test['PP%_1'] = test['TOI_1'].astype(float)/ test['TOI'].astype(float)
|
321 |
-
test['PP%_2'] = test['TOI_2'].astype(float)/ test['TOI_2_team'].astype(float)
|
322 |
-
test['PP%_3'] = test['TOI_3'].astype(float)/ test['TOI_3_team'].astype(float)
|
323 |
-
test = test.fillna(0)
|
324 |
test['TOI_1'] = ["%d:%02d" % (int(x),(x*60)%60) for x in test['TOI_1'].astype(float)]
|
325 |
test['TOI_2'] = ["%d:%02d" % (int(x),(x*60)%60) for x in test['TOI_2'].astype(float)]
|
326 |
test['TOI_3'] = ["%d:%02d" % (int(x),(x*60)%60) for x in test['TOI_3'].astype(float)]
|
327 |
-
test = test.drop(['
|
328 |
test.columns = ['player_id','Player','Team','Position','L'+str(n_1)+' PP TOI','L'+str(n_2)+' PP TOI','L'+str(n_3)+' PP TOI','L'+str(n_1)+' PP%','L'+str(n_2)+' PP%','L'+str(n_3)+' PP%']
|
329 |
|
|
|
330 |
yahoo_df = yahoo_df_2.merge(yahoo_nhl_df,left_on = 'player_id',right_on='player_id_yahoo',suffixes=['','_y'])
|
331 |
yahoo_df.nhl_id = yahoo_df.nhl_id.astype(float)
|
332 |
test.player_id = test.player_id.astype(float)
|
@@ -415,7 +426,8 @@ def server(input, output, session):
|
|
415 |
**{'border': '1px black solid !important'},subset = ((list(top_d_score.index[:]),top_d_score.columns[:]))).set_properties(**{
|
416 |
'color': 'black'},overwrite=False).set_properties(
|
417 |
**{'border': '1px black solid !important'},subset = ((list(top_d_score.index[:]),top_d_score.columns[:]))).format(
|
418 |
-
{
|
|
|
419 |
'L'+str(n_2)+' PP%': '{:.0%}',
|
420 |
'L'+str(n_3)+' PP%': '{:.0%}',
|
421 |
'Roster%': '{:.0%}',
|
@@ -431,4 +443,4 @@ def server(input, output, session):
|
|
431 |
|
432 |
|
433 |
app = App(app_ui, server)
|
434 |
-
time.sleep(60)
|
|
|
170 |
|
171 |
yahoo_nhl_df = pd.read_csv('yahoo_to_nhl.csv', encoding='unicode_escape')
|
172 |
|
173 |
+
|
174 |
+
player_games_df = pd.read_csv('player_games_cards.csv',index_col=[0])
|
175 |
+
team_games_df = pd.read_csv('team_games.csv',index_col=[0])
|
176 |
+
|
177 |
+
team_games_df['game_count'] = team_games_df.groupby('team')['team'].cumcount()+1
|
178 |
+
team_games_df['max_games'] = team_games_df.groupby('team').game_count.transform('max')
|
179 |
+
team_games_df['abv'] = team_games_df.team.map(team_abv.set_index('team_name')['team_abv'].to_dict())
|
180 |
+
|
181 |
+
#team_abv = pd.read_csv('team_abv.csv')
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
def nat_stat_convert(df):
|
186 |
for i in range(0,len(df.columns)):
|
187 |
if df.columns[i][-3:]=='/60':
|
|
|
275 |
if type(n_1) is not int:
|
276 |
n_1 = 1
|
277 |
|
278 |
+
if (n_2 == 0) or (n_2 == n_1) or (n_2 == None):
|
279 |
list_of_columns.remove(f'L{str(n_2)} PP TOI')
|
280 |
list_of_columns.remove(f'L{str(n_2)} PP%')
|
281 |
list_of_columns_name.remove(f'L{str(n_2)} PP TOI')
|
282 |
list_of_columns_name.remove(f'L{str(n_2)} PP%')
|
283 |
|
284 |
+
if (n_3 == 0) or (n_3 == n_1) or (n_3 == n_2) or (n_3 == None):
|
285 |
list_of_columns.remove(f'L{str(n_3)} PP TOI')
|
286 |
list_of_columns.remove(f'L{str(n_3)} PP%')
|
287 |
list_of_columns_name.remove(f'L{str(n_3)} PP TOI')
|
288 |
list_of_columns_name.remove(f'L{str(n_3)} PP%')
|
289 |
|
290 |
+
|
291 |
+
|
292 |
start_date ='2023-09-01'
|
293 |
end_date = '2024-05-01'
|
294 |
|
295 |
+
df_pp_1 = player_games_df.groupby('Player').head(n_1)
|
296 |
+
df_pp_2 = player_games_df.groupby('Player').head(n_2)
|
297 |
+
df_pp_3 = player_games_df.groupby('Player').head(n_3)
|
298 |
+
|
299 |
+
|
300 |
+
team_games_df_1 = team_games_df.groupby('team').head(n_1)
|
301 |
+
team_games_df_2 = team_games_df.groupby('team').head(n_2)
|
302 |
+
team_games_df_3 = team_games_df.groupby('team').head(n_3)
|
303 |
+
|
304 |
+
df_all_pp_1 = df_pp_1.copy()
|
305 |
+
df_all_pp_2 = df_pp_2.copy()
|
306 |
+
df_all_pp_3 = df_pp_3.copy()
|
307 |
+
|
308 |
+
df_all_pp_1_final = df_all_pp_1.groupby(['player_id','Player','Team','Position']).sum()[['TOI_pp']].reset_index()
|
309 |
+
df_all_pp_2_final = df_all_pp_2.groupby(['player_id','Player','Team','Position']).sum()[['TOI_pp']].reset_index()
|
310 |
+
df_all_pp_3_final = df_all_pp_3.groupby(['player_id','Player','Team','Position']).sum()[['TOI_pp']].reset_index()
|
311 |
+
|
312 |
+
team_games_df_1_final = team_games_df_1.groupby(['abv']).sum()[['pp_toi']].reset_index()
|
313 |
+
team_games_df_2_final = team_games_df_2.groupby(['abv']).sum()[['pp_toi']].reset_index()
|
314 |
+
team_games_df_3_final = team_games_df_3.groupby(['abv']).sum()[['pp_toi']].reset_index()
|
315 |
+
|
316 |
+
df_final = df_all_pp_1_final.merge( df_all_pp_2_final,how='outer',left_on=['player_id'],right_on=['player_id'],suffixes=("","_2"))
|
317 |
+
df_final = df_final.merge( df_all_pp_3_final,how='outer',left_on=['player_id'],right_on=['player_id'],suffixes=("_1","_3"))
|
318 |
+
|
319 |
+
team_final = team_games_df_1_final.merge( team_games_df_2_final,how='outer',left_on=['abv'],right_on=['abv'],suffixes=("","_2"))
|
320 |
+
team_final = team_final.merge( team_games_df_3_final,how='outer',left_on=['abv'],right_on=['abv'],suffixes=("_1","_3"))
|
321 |
+
|
322 |
+
|
323 |
+
df_final = df_final.merge(team_final,left_on='Team_1',right_on='abv')
|
324 |
+
|
325 |
+
test = df_final[['player_id','Player_1','Team_1','Position_1','TOI_pp_1','TOI_pp_2','TOI_pp_3','pp_toi_1','pp_toi_2','pp_toi_3']]
|
326 |
+
test.columns = ['player_id','Player','Team','Position','TOI_1','TOI_2','TOI_3','pp_toi_1','pp_toi_2','pp_toi_3']
|
327 |
+
test = test.fillna('0')
|
328 |
+
|
329 |
+
|
330 |
+
test['PP%_1'] = test['TOI_1'].astype(float)/ test['pp_toi_1'].astype(float)
|
331 |
+
test['PP%_2'] = test['TOI_2'].astype(float)/ test['pp_toi_2'].astype(float)
|
332 |
+
test['PP%_3'] = test['TOI_3'].astype(float)/ test['pp_toi_3'].astype(float)
|
333 |
+
# test = test.fillna(0)
|
|
|
|
|
|
|
|
|
334 |
test['TOI_1'] = ["%d:%02d" % (int(x),(x*60)%60) for x in test['TOI_1'].astype(float)]
|
335 |
test['TOI_2'] = ["%d:%02d" % (int(x),(x*60)%60) for x in test['TOI_2'].astype(float)]
|
336 |
test['TOI_3'] = ["%d:%02d" % (int(x),(x*60)%60) for x in test['TOI_3'].astype(float)]
|
337 |
+
test = test.drop(['pp_toi_1','pp_toi_2','pp_toi_3'],axis=1)
|
338 |
test.columns = ['player_id','Player','Team','Position','L'+str(n_1)+' PP TOI','L'+str(n_2)+' PP TOI','L'+str(n_3)+' PP TOI','L'+str(n_1)+' PP%','L'+str(n_2)+' PP%','L'+str(n_3)+' PP%']
|
339 |
|
340 |
+
|
341 |
yahoo_df = yahoo_df_2.merge(yahoo_nhl_df,left_on = 'player_id',right_on='player_id_yahoo',suffixes=['','_y'])
|
342 |
yahoo_df.nhl_id = yahoo_df.nhl_id.astype(float)
|
343 |
test.player_id = test.player_id.astype(float)
|
|
|
426 |
**{'border': '1px black solid !important'},subset = ((list(top_d_score.index[:]),top_d_score.columns[:]))).set_properties(**{
|
427 |
'color': 'black'},overwrite=False).set_properties(
|
428 |
**{'border': '1px black solid !important'},subset = ((list(top_d_score.index[:]),top_d_score.columns[:]))).format(
|
429 |
+
{
|
430 |
+
'L'+str(n_1)+' PP%': '{:.0%}',
|
431 |
'L'+str(n_2)+' PP%': '{:.0%}',
|
432 |
'L'+str(n_3)+' PP%': '{:.0%}',
|
433 |
'Roster%': '{:.0%}',
|
|
|
443 |
|
444 |
|
445 |
app = App(app_ui, server)
|
446 |
+
#time.sleep(60)
|