nesticot commited on
Commit
4cc9b5c
·
1 Parent(s): 502ed5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -112,7 +112,7 @@ schedule_df['home_sym'] = 'vs'
112
 
113
 
114
  #if not os.path.isfile('standings/standings_'+str(date.today())+'.csv'):
115
- standings_df_old = pd.read_html('https://www.hockey-reference.com/leagues/NHL_2023_standings.html')[0].append(pd.read_html('https://www.hockey-reference.com/leagues/NHL_2023_standings.html')[1])
116
  # standings_df_old.to_csv('standings/standings_'+str(date.today())+'.csv')
117
  #standings_df_old = pd.read_csv('standings/standings_'+str(date.today())+'.csv',index_col=[0])
118
 
@@ -163,15 +163,23 @@ schedule_stack['home_b2b'] = home_b2b
163
 
164
  schedule_stack['away_b2b'] = schedule_stack['away_b2b'].replace(1,' 😴')
165
  schedule_stack['away_b2b'] = schedule_stack['away_b2b'].replace(0,'')
 
 
 
 
 
 
 
166
  schedule_stack.head()
167
 
168
  FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')
 
169
  try:
170
- data_r = requests.get("https://pub-api-ro.fantasysports.yahoo.com/fantasy/v2/league/427.l.public;out=settings/players;position=ALL;start=0;count=3000;sort=rank_season;search=;out=percent_owned;out=auction_values,ranks;ranks=season;ranks_by_position=season;out=expert_ranks;expert_ranks.rank_type=projected_season_remaining/draft_analysis;cut_types=diamond;slices=last7days?format=json_f").json()
171
  key_check = data_r['fantasy_content']['league']['players']
172
 
173
  except KeyError:
174
- data_r = requests.get("https://pub-api-ro.fantasysports.yahoo.com/fantasy/v2/league/427.l.public;out=settings/players;position=ALL;start=0;count=1151;sort=rank_season;search=;out=percent_owned;out=auction_values,ranks;ranks=season;ranks_by_position=season;out=expert_ranks;expert_ranks.rank_type=projected_season_remaining/draft_analysis;cut_types=diamond;slices=last7days?format=json_f").json()
175
  print('key_checked')
176
 
177
  total_list = []
@@ -195,7 +203,6 @@ for x in data_r['fantasy_content']['league']['players']:
195
  single_list.append(0)
196
  total_list.append(single_list)
197
 
198
-
199
  df_2023 = pd.DataFrame(data=total_list,columns=['player_id','rank_value','full','first','last','average_pick', 'average_cost','display_position','projected_auction_value','editorial_team_abbr','percent_owned'])
200
 
201
  week_dict = yahoo_weeks.set_index('Number')['Week'].sort_index().to_dict()
@@ -216,7 +223,11 @@ import matplotlib.image as mpimg
216
  # ui.panel_main(ui.output_plot("plot",height = "750px",width="1250px")),
217
  # #ui.download_button('test','Download'),
218
  # )
219
- app_ui = ui.page_fluid(ui.layout_sidebar(
 
 
 
 
220
  # Available themes:
221
  # cerulean, cosmo, cyborg, darkly, flatly, journal, litera, lumen, lux,
222
  # materia, minty, morph, pulse, quartz, sandstone, simplex, sketchy, slate,
@@ -367,7 +378,8 @@ def server(input, output, session):
367
  test_df = pd.DataFrame()
368
  test_df['Team'] = list(team_abv['team_abv'])
369
  test_df['Total'] = test_df.merge(right=weekly_stack.groupby('team_abv')['team_abv'].apply(lambda x: x[x != ''].count()),left_on=['Team'],right_index=True,how='left').fillna(0)['team_abv']
370
- test_df['Off-Night'] = test_df.merge(right=weekly_stack.groupby('team_abv').sum()['offnight'],left_on=['Team'],right_index=True,how='left').fillna(0)['offnight']
 
371
  test_df['B2B']= test_df.merge(right=weekly_stack.groupby('team_abv').sum()['b2b'],left_on=['Team'],right_index=True,how='left').fillna(0)['b2b']
372
 
373
 
@@ -380,12 +392,14 @@ def server(input, output, session):
380
 
381
  games_vs_tired = 0.4*np.array(test_df.merge(right=weekly_stack.groupby('team_abv')['away_b2b'].apply(lambda x: x[x != ''].count()),left_on=['Team'],right_index=True,how='left').fillna(0)['away_b2b'])
382
 
383
-
384
- team_score = test_df['Total']+test_df['Off-Night']*0.5+test_df['B2B']*-0.2+games_vs_tired*0.3+gf_rank*0.1+ga_rank*0.1
385
-
 
386
  test_df['Score'] = team_score
387
 
388
-
 
389
  cols = test_df.columns.tolist();
390
  L = len(cols)
391
  test_df = test_df[cols[4:]+cols[0:4]]
 
112
 
113
 
114
  #if not os.path.isfile('standings/standings_'+str(date.today())+'.csv'):
115
+ standings_df_old = pd.read_html('https://www.hockey-reference.com/leagues/NHL_2024_standings.html')[0].append(pd.read_html('https://www.hockey-reference.com/leagues/NHL_2024_standings.html')[1])
116
  # standings_df_old.to_csv('standings/standings_'+str(date.today())+'.csv')
117
  #standings_df_old = pd.read_csv('standings/standings_'+str(date.today())+'.csv',index_col=[0])
118
 
 
163
 
164
  schedule_stack['away_b2b'] = schedule_stack['away_b2b'].replace(1,' 😴')
165
  schedule_stack['away_b2b'] = schedule_stack['away_b2b'].replace(0,'')
166
+
167
+ schedule_stack['offnight_score'] = schedule_stack.groupby('date').team.transform('count')
168
+ print('we made it',schedule_stack.offnight_score.max())
169
+ schedule_stack.offnight_score = schedule_stack.offnight_score - 16
170
+ #schedule_stack.loc[schedule_stack['offnight_score'] > 0,'offnight_score'] = 0
171
+ schedule_stack.offnight_score = -1*schedule_stack.offnight_score
172
+ #print(schedule_stack.offnight_score.max())
173
  schedule_stack.head()
174
 
175
  FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')
176
+
177
  try:
178
+ data_r = requests.get("https://pub-api-ro.fantasysports.yahoo.com/fantasy/v2/league/427.l.public;out=settings/players;position=ALL;start=0;count=3000;sort=percent_owned;search=;out=percent_owned;out=auction_values,ranks;ranks=season;ranks_by_position=season;out=expert_ranks;expert_ranks.rank_type=projected_season_remaining/draft_analysis;cut_types=diamond;slices=last7days?format=json_f").json()
179
  key_check = data_r['fantasy_content']['league']['players']
180
 
181
  except KeyError:
182
+ data_r = requests.get("https://pub-api-ro.fantasysports.yahoo.com/fantasy/v2/league/427.l.public;out=settings/players;position=ALL;start=0;count=1151;sort=percent_owned;search=;out=percent_owned;out=auction_values,ranks;ranks=season;ranks_by_position=season;out=expert_ranks;expert_ranks.rank_type=projected_season_remaining/draft_analysis;cut_types=diamond;slices=last7days?format=json_f").json()
183
  print('key_checked')
184
 
185
  total_list = []
 
203
  single_list.append(0)
204
  total_list.append(single_list)
205
 
 
206
  df_2023 = pd.DataFrame(data=total_list,columns=['player_id','rank_value','full','first','last','average_pick', 'average_cost','display_position','projected_auction_value','editorial_team_abbr','percent_owned'])
207
 
208
  week_dict = yahoo_weeks.set_index('Number')['Week'].sort_index().to_dict()
 
223
  # ui.panel_main(ui.output_plot("plot",height = "750px",width="1250px")),
224
  # #ui.download_button('test','Download'),
225
  # )
226
+ import shinyswatch
227
+ app_ui = ui.page_fluid(
228
+ #shinyswatch.theme.cosmo(),
229
+ ui.layout_sidebar(
230
+
231
  # Available themes:
232
  # cerulean, cosmo, cyborg, darkly, flatly, journal, litera, lumen, lux,
233
  # materia, minty, morph, pulse, quartz, sandstone, simplex, sketchy, slate,
 
378
  test_df = pd.DataFrame()
379
  test_df['Team'] = list(team_abv['team_abv'])
380
  test_df['Total'] = test_df.merge(right=weekly_stack.groupby('team_abv')['team_abv'].apply(lambda x: x[x != ''].count()),left_on=['Team'],right_index=True,how='left').fillna(0)['team_abv']
381
+
382
+ test_df['Off-Night'] = test_df.merge(right=weekly_stack.groupby('team_abv').sum()['offnight_score'],left_on=['Team'],right_index=True,how='left').fillna(0)['offnight_score']
383
  test_df['B2B']= test_df.merge(right=weekly_stack.groupby('team_abv').sum()['b2b'],left_on=['Team'],right_index=True,how='left').fillna(0)['b2b']
384
 
385
 
 
392
 
393
  games_vs_tired = 0.4*np.array(test_df.merge(right=weekly_stack.groupby('team_abv')['away_b2b'].apply(lambda x: x[x != ''].count()),left_on=['Team'],right_index=True,how='left').fillna(0)['away_b2b'])
394
 
395
+ print('test_df')
396
+ print(test_df)
397
+ #team_score = test_df['Total']+test_df['Off-Night']*0.5+test_df['B2B']*-0.2+games_vs_tired*0.3+gf_rank*0.1+ga_rank*0.1
398
+ team_score = test_df['Total']+test_df['Off-Night']*0.03+test_df['B2B']*-0.2+games_vs_tired*0.3+gf_rank*0.1+ga_rank*0.1
399
  test_df['Score'] = team_score
400
 
401
+ test_df['Off-Night'] = test_df.merge(right=weekly_stack.groupby('team_abv').sum()['offnight'],left_on=['Team'],right_index=True,how='left').fillna(0)['offnight']
402
+
403
  cols = test_df.columns.tolist();
404
  L = len(cols)
405
  test_df = test_df[cols[4:]+cols[0:4]]