Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,10 +42,12 @@ wr_te_util = {'Routes%': '{:.2%}','Targets%': '{:.2%}', 'Air Yards%': '{:.2%}',
|
|
42 |
|
43 |
wr_matchups_form = {'Opp Man%': '{:.2%}','Opp Zone%': '{:.2%}'}
|
44 |
|
|
|
|
|
45 |
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=179416653'
|
46 |
|
47 |
-
@st.cache_resource(ttl =
|
48 |
-
def
|
49 |
sh = gc.open_by_url(all_dk_player_projections)
|
50 |
worksheet = sh.worksheet('RB_Util')
|
51 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
@@ -54,12 +56,8 @@ def rb_util_weekly():
|
|
54 |
'tprr', 'player_SDD_snaps_per', 'inside_five_rush_per', 'player_LDD_snaps_per', 'two_min_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
55 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Week', 'Team-Season', 'Player Snaps%', 'Rush Att%', 'Routes%', 'Targets%',
|
56 |
'TPRR', 'SDD Snaps%', 'i5 Rush%', 'LDD Snaps%', '2-min%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
@st.cache_resource(ttl = 300)
|
61 |
-
def wr_te_util_weekly():
|
62 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
63 |
worksheet = sh.worksheet('WR_TE_Util')
|
64 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
65 |
raw_display = raw_display.replace('', np.nan)
|
@@ -67,12 +65,8 @@ def wr_te_util_weekly():
|
|
67 |
'ayprr', 'endzone_targets_per', 'third_fourth_per', 'third_fourth_target_per', 'play_action_targets_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
68 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Week', 'Team-Season', 'Routes%', 'Targets%', 'TPRR' , 'ADOT', 'Air Yards%',
|
69 |
'AYPRR', 'Endzone Targets%', 'Third/Fourth%', 'Third/Fourth Targets%', 'Play Action Targets%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
@st.cache_resource(ttl = 300)
|
74 |
-
def rb_util_season():
|
75 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
76 |
worksheet = sh.worksheet('RB_Util_Season')
|
77 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
78 |
raw_display = raw_display.replace('', np.nan)
|
@@ -80,12 +74,8 @@ def rb_util_season():
|
|
80 |
'tprr', 'player_SDD_snaps_per', 'inside_five_rush_per', 'player_LDD_snaps_per', 'two_min_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
81 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Team-Season', 'Player Snaps%', 'Rush Att%', 'Routes%', 'Targets%',
|
82 |
'TPRR', 'SDD Snaps%', 'i5 Rush%', 'LDD Snaps%', '2-min%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
@st.cache_resource(ttl = 300)
|
87 |
-
def wr_te_util_season():
|
88 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
89 |
worksheet = sh.worksheet('WR_TE_Util_Season')
|
90 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
91 |
raw_display = raw_display.replace('', np.nan)
|
@@ -93,42 +83,35 @@ def wr_te_util_season():
|
|
93 |
'ayprr', 'endzone_targets_per', 'third_fourth_per', 'third_fourth_target_per', 'play_action_targets_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
94 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Team-Season', 'Routes%', 'Targets%', 'TPRR' , 'ADOT', 'Air Yards%',
|
95 |
'AYPRR', 'Endzone Targets%', 'Third/Fourth%', 'Third/Fourth Targets%', 'Play Action Targets%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
@st.cache_resource(ttl = 300)
|
100 |
-
def coverage_matchups():
|
101 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
102 |
worksheet = sh.worksheet('Defensive Matchups')
|
103 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
104 |
raw_display = raw_display.replace('', np.nan)
|
105 |
raw_display = raw_display.dropna(subset='Weighted Targets')
|
106 |
raw_display = raw_display[raw_display['Weighted Targets'] != '#DIV/0!']
|
107 |
raw_display = raw_display[raw_display['Weighted Targets'] != '#N/A']
|
108 |
-
|
109 |
|
110 |
-
return raw_display
|
111 |
-
|
112 |
-
@st.cache_resource(ttl = 300)
|
113 |
-
def macro_pull():
|
114 |
-
sh = gc.open_by_url(all_dk_player_projections)
|
115 |
worksheet = sh.worksheet('FL_Macro')
|
116 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
117 |
raw_display = raw_display.replace('', np.nan)
|
118 |
raw_display = raw_display.dropna(subset='team')
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
@st.cache_data
|
124 |
def convert_df_to_csv(df):
|
125 |
return df.to_csv().encode('utf-8')
|
126 |
-
|
127 |
-
wr_search =
|
128 |
-
rb_season = rb_util_season()
|
129 |
-
wr_season = wr_te_util_season()
|
130 |
-
wr_matchups = coverage_matchups()
|
131 |
-
macro_data = macro_pull()
|
132 |
pos_list = ['RB', 'WR', 'TE']
|
133 |
|
134 |
tab1, tab2 = st.tabs(["Season Long Research", "Slate Specific"])
|
@@ -138,11 +121,7 @@ with tab1:
|
|
138 |
with col1:
|
139 |
if st.button("Load/Reset Data", key='reset1'):
|
140 |
st.cache_data.clear()
|
141 |
-
rb_search =
|
142 |
-
wr_search = wr_te_util_season()
|
143 |
-
rb_season = rb_util_season()
|
144 |
-
wr_season = wr_te_util_season()
|
145 |
-
macro_data = macro_pull()
|
146 |
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')
|
147 |
split_var1 = st.radio("Are you running the the whole league or certain teams?", ('All Teams', 'Specific Teams'), key='split_var1')
|
148 |
pos_split1 = st.radio("Are you viewing all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split1')
|
@@ -198,14 +177,17 @@ with tab2:
|
|
198 |
with col1:
|
199 |
if st.button("Load/Reset Data", key='reset2'):
|
200 |
st.cache_data.clear()
|
201 |
-
wr_matchups =
|
202 |
-
stat_type_var2 = st.radio("What table are you loading?", ('WR/TE Coverage Matchups', 'Nothing idk lol'))
|
203 |
if stat_type_var2 == 'WR/TE Coverage Matchups':
|
204 |
routes_var2 = st.slider("Is there a certain price range of routes you want to include?", 0, 50, (10, 50), key='sal_var2')
|
205 |
split_var2 = st.radio("Are you running the the whole league or certain teams?", ('All Teams', 'Specific Teams'))
|
206 |
pos_split2 = st.radio("Are you viewing all positions or specific positions?", ('All Positions', 'Specific Positions'))
|
207 |
if pos_split2 == 'Specific Positions':
|
208 |
-
|
|
|
|
|
|
|
209 |
elif pos_split2 == 'All Positions':
|
210 |
pos_var2 = pos_list
|
211 |
if split_var2 == 'Specific Teams':
|
@@ -218,13 +200,19 @@ with tab2:
|
|
218 |
slate_table_instance = slate_table_instance[slate_table_instance['Position'].isin(pos_var2)]
|
219 |
slate_table_instance = slate_table_instance[slate_table_instance['Avg Routes'] >= routes_var2[0]]
|
220 |
slate_table_instance = slate_table_instance[slate_table_instance['Avg Routes'] <= routes_var2[1]]
|
221 |
-
slate_table_instance = slate_table_instance.set_index('name')
|
|
|
|
|
|
|
|
|
222 |
elif stat_type_var1 == 'Nothing idk lol':
|
223 |
slate_table_instance = wr_matchups
|
224 |
|
225 |
with col2:
|
226 |
if stat_type_var2 == 'WR/TE Coverage Matchups':
|
227 |
st.dataframe(slate_table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').format(wr_matchups_form, precision=2), use_container_width = True)
|
|
|
|
|
228 |
elif stat_type_var2 == 'Nothing idk lol':
|
229 |
st.write('lol same bro but yo the vibes immaculate')
|
230 |
if stat_type_var2 == 'WR/TE Coverage Matchups':
|
|
|
42 |
|
43 |
wr_matchups_form = {'Opp Man%': '{:.2%}','Opp Zone%': '{:.2%}'}
|
44 |
|
45 |
+
trending_form = {'Trend': '{:.2%}'}
|
46 |
+
|
47 |
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=179416653'
|
48 |
|
49 |
+
@st.cache_resource(ttl = 600)
|
50 |
+
def pull_baselines():
|
51 |
sh = gc.open_by_url(all_dk_player_projections)
|
52 |
worksheet = sh.worksheet('RB_Util')
|
53 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
|
|
56 |
'tprr', 'player_SDD_snaps_per', 'inside_five_rush_per', 'player_LDD_snaps_per', 'two_min_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
57 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Week', 'Team-Season', 'Player Snaps%', 'Rush Att%', 'Routes%', 'Targets%',
|
58 |
'TPRR', 'SDD Snaps%', 'i5 Rush%', 'LDD Snaps%', '2-min%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
59 |
+
rb_search = raw_display.sort_values(by='Utilization Rank', ascending=True)
|
60 |
+
|
|
|
|
|
|
|
|
|
61 |
worksheet = sh.worksheet('WR_TE_Util')
|
62 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
63 |
raw_display = raw_display.replace('', np.nan)
|
|
|
65 |
'ayprr', 'endzone_targets_per', 'third_fourth_per', 'third_fourth_target_per', 'play_action_targets_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
66 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Week', 'Team-Season', 'Routes%', 'Targets%', 'TPRR' , 'ADOT', 'Air Yards%',
|
67 |
'AYPRR', 'Endzone Targets%', 'Third/Fourth%', 'Third/Fourth Targets%', 'Play Action Targets%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
68 |
+
wr_search = raw_display.sort_values(by='Utilization Rank', ascending=True)
|
69 |
+
|
|
|
|
|
|
|
|
|
70 |
worksheet = sh.worksheet('RB_Util_Season')
|
71 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
72 |
raw_display = raw_display.replace('', np.nan)
|
|
|
74 |
'tprr', 'player_SDD_snaps_per', 'inside_five_rush_per', 'player_LDD_snaps_per', 'two_min_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
75 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Team-Season', 'Player Snaps%', 'Rush Att%', 'Routes%', 'Targets%',
|
76 |
'TPRR', 'SDD Snaps%', 'i5 Rush%', 'LDD Snaps%', '2-min%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
77 |
+
rb_season = raw_display.sort_values(by='Utilization Rank', ascending=True)
|
78 |
+
|
|
|
|
|
|
|
|
|
79 |
worksheet = sh.worksheet('WR_TE_Util_Season')
|
80 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
81 |
raw_display = raw_display.replace('', np.nan)
|
|
|
83 |
'ayprr', 'endzone_targets_per', 'third_fourth_per', 'third_fourth_target_per', 'play_action_targets_per', 'exPPR', 'ppr_fantasy', 'UR_Rank']]
|
84 |
raw_display = raw_display.set_axis(['Player', 'Position', 'Team-Season', 'Routes%', 'Targets%', 'TPRR' , 'ADOT', 'Air Yards%',
|
85 |
'AYPRR', 'Endzone Targets%', 'Third/Fourth%', 'Third/Fourth Targets%', 'Play Action Targets%', 'Expected PPR', 'PPR', 'Utilization Rank'], axis='columns')
|
86 |
+
wr_season = raw_display.sort_values(by='Utilization Rank', ascending=True)
|
87 |
+
|
|
|
|
|
|
|
|
|
88 |
worksheet = sh.worksheet('Defensive Matchups')
|
89 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
90 |
raw_display = raw_display.replace('', np.nan)
|
91 |
raw_display = raw_display.dropna(subset='Weighted Targets')
|
92 |
raw_display = raw_display[raw_display['Weighted Targets'] != '#DIV/0!']
|
93 |
raw_display = raw_display[raw_display['Weighted Targets'] != '#N/A']
|
94 |
+
wr_matchups = raw_display.sort_values(by='Weighted Targets', ascending=False)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
96 |
worksheet = sh.worksheet('FL_Macro')
|
97 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
98 |
raw_display = raw_display.replace('', np.nan)
|
99 |
raw_display = raw_display.dropna(subset='team')
|
100 |
+
macro_data = raw_display.sort_values(by='Team Total', ascending=False)
|
101 |
+
|
102 |
+
worksheet = sh.worksheet('Ownership Trend')
|
103 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
104 |
+
raw_display = raw_display.replace('', np.nan)
|
105 |
+
raw_display = raw_display.dropna(subset='Team')
|
106 |
+
trending_data = raw_display.sort_values(by='Trend', ascending=False)
|
107 |
+
|
108 |
+
return rb_search, wr_search, rb_season, wr_season, wr_matchups, macro_data, trending_data
|
109 |
|
110 |
@st.cache_data
|
111 |
def convert_df_to_csv(df):
|
112 |
return df.to_csv().encode('utf-8')
|
113 |
+
|
114 |
+
rb_search, wr_search, rb_season, wr_season, wr_matchups, macro_data, trending_data = pull_baselines()
|
|
|
|
|
|
|
|
|
115 |
pos_list = ['RB', 'WR', 'TE']
|
116 |
|
117 |
tab1, tab2 = st.tabs(["Season Long Research", "Slate Specific"])
|
|
|
121 |
with col1:
|
122 |
if st.button("Load/Reset Data", key='reset1'):
|
123 |
st.cache_data.clear()
|
124 |
+
rb_search, wr_search, rb_season, wr_season, wr_matchups, macro_data, trending_data = pull_baselines()
|
|
|
|
|
|
|
|
|
125 |
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')
|
126 |
split_var1 = st.radio("Are you running the the whole league or certain teams?", ('All Teams', 'Specific Teams'), key='split_var1')
|
127 |
pos_split1 = st.radio("Are you viewing all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_split1')
|
|
|
177 |
with col1:
|
178 |
if st.button("Load/Reset Data", key='reset2'):
|
179 |
st.cache_data.clear()
|
180 |
+
rb_search, wr_search, rb_season, wr_season, wr_matchups, macro_data, trending_data = pull_baselines()
|
181 |
+
stat_type_var2 = st.radio("What table are you loading?", ('WR/TE Coverage Matchups', 'Ownership Trends', 'Nothing idk lol'))
|
182 |
if stat_type_var2 == 'WR/TE Coverage Matchups':
|
183 |
routes_var2 = st.slider("Is there a certain price range of routes you want to include?", 0, 50, (10, 50), key='sal_var2')
|
184 |
split_var2 = st.radio("Are you running the the whole league or certain teams?", ('All Teams', 'Specific Teams'))
|
185 |
pos_split2 = st.radio("Are you viewing all positions or specific positions?", ('All Positions', 'Specific Positions'))
|
186 |
if pos_split2 == 'Specific Positions':
|
187 |
+
if stat_type_var2 == 'WR/TE Coverage Matchups':
|
188 |
+
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['RB', 'WR', 'TE'])
|
189 |
+
elif stat_type_var2 == 'Ownership Trends':
|
190 |
+
pos_var2 = st.multiselect('What Positions would you like to view?', options = ['QB', 'RB', 'WR', 'TE', 'DST'])
|
191 |
elif pos_split2 == 'All Positions':
|
192 |
pos_var2 = pos_list
|
193 |
if split_var2 == 'Specific Teams':
|
|
|
200 |
slate_table_instance = slate_table_instance[slate_table_instance['Position'].isin(pos_var2)]
|
201 |
slate_table_instance = slate_table_instance[slate_table_instance['Avg Routes'] >= routes_var2[0]]
|
202 |
slate_table_instance = slate_table_instance[slate_table_instance['Avg Routes'] <= routes_var2[1]]
|
203 |
+
slate_table_instance = slate_table_instance.set_index('name')
|
204 |
+
elif stat_type_var2 == 'Ownership Trends':
|
205 |
+
slate_table_instance = trending_data
|
206 |
+
slate_table_instance = slate_table_instance[slate_table_instance['Team'].isin(team_var2)]
|
207 |
+
slate_table_instance = slate_table_instance[slate_table_instance['Position'].isin(pos_var2)]
|
208 |
elif stat_type_var1 == 'Nothing idk lol':
|
209 |
slate_table_instance = wr_matchups
|
210 |
|
211 |
with col2:
|
212 |
if stat_type_var2 == 'WR/TE Coverage Matchups':
|
213 |
st.dataframe(slate_table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').format(wr_matchups_form, precision=2), use_container_width = True)
|
214 |
+
elif stat_type_var2 == 'Ownership Trends':
|
215 |
+
st.dataframe(slate_table_instance.style.background_gradient(axis=0).background_gradient(cmap = 'RdYlGn').format(trending_form, precision=2), use_container_width = True)
|
216 |
elif stat_type_var2 == 'Nothing idk lol':
|
217 |
st.write('lol same bro but yo the vibes immaculate')
|
218 |
if stat_type_var2 == 'WR/TE Coverage Matchups':
|