Multichem commited on
Commit
1a2fb86
·
1 Parent(s): 40ce91b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -11
app.py CHANGED
@@ -43,7 +43,7 @@ wr_te_util = {'Routes%': '{:.2%}','Targets%': '{:.2%}', 'Air Yards%': '{:.2%}',
43
  all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=179416653'
44
 
45
  @st.cache_resource(ttl = 300)
46
- def rb_util_season():
47
  sh = gc.open_by_url(all_dk_player_projections)
48
  worksheet = sh.worksheet('RB_Util')
49
  raw_display = pd.DataFrame(worksheet.get_all_records())
@@ -56,7 +56,7 @@ def rb_util_season():
56
  return raw_display
57
 
58
  @st.cache_resource(ttl = 300)
59
- def wr_te_util_season():
60
  sh = gc.open_by_url(all_dk_player_projections)
61
  worksheet = sh.worksheet('WR_TE_Util')
62
  raw_display = pd.DataFrame(worksheet.get_all_records())
@@ -68,6 +68,32 @@ def wr_te_util_season():
68
  raw_display = raw_display.sort_values(by='Utilization Rank', ascending=True)
69
  return raw_display
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  @st.cache_resource(ttl = 300)
72
  def macro_pull():
73
  sh = gc.open_by_url(all_dk_player_projections)
@@ -80,9 +106,10 @@ def macro_pull():
80
  @st.cache_data
81
  def convert_df_to_csv(df):
82
  return df.to_csv().encode('utf-8')
83
-
84
- rb_search = rb_util_season()
85
- wr_search = wr_te_util_season()
 
86
  macro_data = macro_pull()
87
  pos_list = ['RB', 'WR', 'TE']
88
 
@@ -94,7 +121,7 @@ with col1:
94
  rb_search = rb_util_season()
95
  wr_search = wr_te_util_season()
96
  macro_data = macro_pull()
97
- stat_type_var1 = st.radio("What table are you loading?", ('Macro Table', 'RB Usage', 'WR/TE Usage'), key='stat_type_var1')
98
  split_var1 = st.radio("Are you running the the whole league or certain teams?", ('All Teams', 'Specific Teams'), key='split_var1')
99
  pos_split1 = st.radio("Are you viewing all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split1')
100
  if pos_split1 == 'Specific Positions':
@@ -108,26 +135,38 @@ with col1:
108
  if stat_type_var1 == 'Macro Table':
109
  table_instance = macro_data
110
  table_instance = table_instance.set_index('team')
111
- elif stat_type_var1 == 'RB Usage':
112
  table_instance = rb_search
113
  table_instance = table_instance[table_instance['Team-Season'].isin(team_var1)]
114
  table_instance = table_instance[table_instance['Position'].isin(pos_var1)]
115
- elif stat_type_var1 == 'WR/TE Usage':
116
  table_instance = wr_search
117
  table_instance = table_instance[table_instance['Team-Season'].isin(team_var1)]
118
  table_instance = table_instance[table_instance['Position'].isin(pos_var1)]
 
 
 
 
 
 
 
 
119
 
120
  with col2:
121
  if stat_type_var1 == 'Macro Table':
122
  st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').format(game_format, precision=2), use_container_width = True)
123
- elif stat_type_var1 == 'RB Usage':
 
 
 
 
124
  st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').background_gradient(cmap='RdYlGn_r', subset = 'Utilization Rank').format(rb_util, precision=2), use_container_width = True)
125
- elif stat_type_var1 == 'WR/TE Usage':
126
  st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').background_gradient(cmap='RdYlGn_r', subset = 'Utilization Rank').format(wr_te_util, precision=2), use_container_width = True)
127
 
128
  st.download_button(
129
  label="Export Tables",
130
  data=convert_df_to_csv(table_instance),
131
- file_name='MLB_Research_export.csv',
132
  mime='text/csv',
133
  )
 
43
  all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=179416653'
44
 
45
  @st.cache_resource(ttl = 300)
46
+ def rb_util_weekly():
47
  sh = gc.open_by_url(all_dk_player_projections)
48
  worksheet = sh.worksheet('RB_Util')
49
  raw_display = pd.DataFrame(worksheet.get_all_records())
 
56
  return raw_display
57
 
58
  @st.cache_resource(ttl = 300)
59
+ def wr_te_util_weekly():
60
  sh = gc.open_by_url(all_dk_player_projections)
61
  worksheet = sh.worksheet('WR_TE_Util')
62
  raw_display = pd.DataFrame(worksheet.get_all_records())
 
68
  raw_display = raw_display.sort_values(by='Utilization Rank', ascending=True)
69
  return raw_display
70
 
71
+ @st.cache_resource(ttl = 300)
72
+ def rb_util_season():
73
+ sh = gc.open_by_url(all_dk_player_projections)
74
+ worksheet = sh.worksheet('RB_Util_Season')
75
+ raw_display = pd.DataFrame(worksheet.get_all_records())
76
+ raw_display = raw_display.replace('', np.nan)
77
+ raw_display = raw_display[['player_name', 'position', 'team_season', 'player_snaps_per', 'rush_attempts_per', 'routes_per', 'targets_per',
78
+ 'tprr', 'player_SDD_snaps_per', 'inside_five_rush_per', 'player_LDD_snaps_per', 'two_min_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
79
+ raw_display = raw_display.set_axis(['Player', 'Position', 'Week', 'Team-Season', 'Player Snaps%', 'Rush Att%', 'Routes%', 'Targets%',
80
+ 'TPRR', 'SDD Snaps%', 'i5 Rush%', 'LDD Snaps%', '2-min%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
81
+ raw_display = raw_display.sort_values(by='Utilization Rank', ascending=True)
82
+ return raw_display
83
+
84
+ @st.cache_resource(ttl = 300)
85
+ def wr_te_util_season():
86
+ sh = gc.open_by_url(all_dk_player_projections)
87
+ worksheet = sh.worksheet('WR_TE_Util_Season')
88
+ raw_display = pd.DataFrame(worksheet.get_all_records())
89
+ raw_display = raw_display.replace('', np.nan)
90
+ raw_display = raw_display[['player_name', 'position', 'team_season', 'routes_per', 'targets_per', 'tprr' , 'adot', 'air_yards_per',
91
+ 'ayprr', 'endzone_targets_per', 'third_fourth_per', 'third_fourth_target_per', 'play_action_targets_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
92
+ raw_display = raw_display.set_axis(['Player', 'Position', 'Week', 'Team-Season', 'Routes%', 'Targets%', 'TPRR' , 'ADOT', 'Air Yards%',
93
+ 'AYPRR', 'Endzone Targets%', 'Third/Fourth%', 'Third/Fourth Targets%', 'Play Action Targets%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
94
+ raw_display = raw_display.sort_values(by='Utilization Rank', ascending=True)
95
+ return raw_display
96
+
97
  @st.cache_resource(ttl = 300)
98
  def macro_pull():
99
  sh = gc.open_by_url(all_dk_player_projections)
 
106
  @st.cache_data
107
  def convert_df_to_csv(df):
108
  return df.to_csv().encode('utf-8')
109
+ rb_search = rb_util_weekly()
110
+ wr_search = wr_te_util_weekly()
111
+ rb_season = rb_util_season()
112
+ wr_season = wr_te_util_season()
113
  macro_data = macro_pull()
114
  pos_list = ['RB', 'WR', 'TE']
115
 
 
121
  rb_search = rb_util_season()
122
  wr_search = wr_te_util_season()
123
  macro_data = macro_pull()
124
+ stat_type_var1 = st.radio("What table are you loading?", ('Macro Table', 'RB Usage (Weekly)', 'WR/TE Usage (Weekly)', 'RB Usage (Season)', 'WR/TE Usage (Season)'), key='stat_type_var1')
125
  split_var1 = st.radio("Are you running the the whole league or certain teams?", ('All Teams', 'Specific Teams'), key='split_var1')
126
  pos_split1 = st.radio("Are you viewing all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split1')
127
  if pos_split1 == 'Specific Positions':
 
135
  if stat_type_var1 == 'Macro Table':
136
  table_instance = macro_data
137
  table_instance = table_instance.set_index('team')
138
+ elif stat_type_var1 == 'RB Usage (Weekly)':
139
  table_instance = rb_search
140
  table_instance = table_instance[table_instance['Team-Season'].isin(team_var1)]
141
  table_instance = table_instance[table_instance['Position'].isin(pos_var1)]
142
+ elif stat_type_var1 == 'WR/TE Usage (Weekly)':
143
  table_instance = wr_search
144
  table_instance = table_instance[table_instance['Team-Season'].isin(team_var1)]
145
  table_instance = table_instance[table_instance['Position'].isin(pos_var1)]
146
+ elif stat_type_var1 == 'RB Usage (Season)':
147
+ table_instance = rb_season
148
+ table_instance = table_instance[table_instance['Team-Season'].isin(team_var1)]
149
+ table_instance = table_instance[table_instance['Position'].isin(pos_var1)]
150
+ elif stat_type_var1 == 'WR/TE Usage (Season)':
151
+ table_instance = wr_season
152
+ table_instance = table_instance[table_instance['Team-Season'].isin(team_var1)]
153
+ table_instance = table_instance[table_instance['Position'].isin(pos_var1)]
154
 
155
  with col2:
156
  if stat_type_var1 == 'Macro Table':
157
  st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').format(game_format, precision=2), use_container_width = True)
158
+ elif stat_type_var1 == 'RB Usage (Weekly)':
159
+ st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').background_gradient(cmap='RdYlGn_r', subset = 'Utilization Rank').format(rb_util, precision=2), use_container_width = True)
160
+ elif stat_type_var1 == 'WR/TE Usage (Weekly)':
161
+ st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').background_gradient(cmap='RdYlGn_r', subset = 'Utilization Rank').format(wr_te_util, precision=2), use_container_width = True)
162
+ elif stat_type_var1 == 'RB Usage (Season)':
163
  st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').background_gradient(cmap='RdYlGn_r', subset = 'Utilization Rank').format(rb_util, precision=2), use_container_width = True)
164
+ elif stat_type_var1 == 'WR/TE Usage (Season)':
165
  st.dataframe(table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').background_gradient(cmap='RdYlGn_r', subset = 'Utilization Rank').format(wr_te_util, precision=2), use_container_width = True)
166
 
167
  st.download_button(
168
  label="Export Tables",
169
  data=convert_df_to_csv(table_instance),
170
+ file_name='NFL_Research_export.csv',
171
  mime='text/csv',
172
  )