Spaces:
Running
Running
James McCool
commited on
Commit
·
6a4d277
1
Parent(s):
3573b17
Refactor user configuration for fantasy football settings to support default values for flex percentages, multipliers, and VORP limiters. Enhanced handling of both nested and flat dictionary structures for improved flexibility in league settings.
Browse files- src/streamlit_app.py +63 -20
src/streamlit_app.py
CHANGED
@@ -173,9 +173,14 @@ def create_user_config_interface():
|
|
173 |
'TE': te_flex_pct,
|
174 |
}
|
175 |
else:
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
user_flex_percentiles = {
|
181 |
'RB': rb_flex_pct,
|
@@ -185,10 +190,15 @@ def create_user_config_interface():
|
|
185 |
|
186 |
# Flex Multipliers Configuration
|
187 |
st.sidebar.subheader("Position Multipliers")
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
user_flex_multipliers = {
|
194 |
'QB': qb_mult,
|
@@ -199,10 +209,15 @@ def create_user_config_interface():
|
|
199 |
|
200 |
# VORP Limiters Configuration
|
201 |
st.sidebar.subheader("VORP Rank Adjustments")
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
user_pos_vorp_limiters = {
|
208 |
'QB': qb_vorp_lim,
|
@@ -258,10 +273,19 @@ def designate_custom_position_reqs(league_settings: dict, flex_percentiles: dict
|
|
258 |
wr_base = league_settings['WR'] * league_settings['TEAMS']
|
259 |
te_base = league_settings['TE'] * league_settings['TEAMS']
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
print(f"Need {qb_rv_index} for QB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
267 |
print(f"Need {rb_rv_index} for RB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
@@ -283,10 +307,19 @@ def designate_base_position_reqs(league_settings: dict, flex_percentiles: dict,
|
|
283 |
wr_base = league_settings['WR'] * league_settings['TEAMS']
|
284 |
te_base = league_settings['TE'] * league_settings['TEAMS']
|
285 |
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
print(f"Need {qb_rv_index} for QB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
292 |
print(f"Need {rb_rv_index} for RB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
@@ -355,8 +388,18 @@ def assign_vorp(frame: pd.DataFrame, halfPpr_rv: dict, custom_rv: dict, league_s
|
|
355 |
vorp_frame['halfPpr_vorp_rank'] = vorp_frame['halfPpr_VORP'].rank(method='max', ascending=False)
|
356 |
vorp_frame['custom_vorp_rank'] = vorp_frame['custom_VORP'].rank(method='max', ascending=False)
|
357 |
vorp_frame['vorp_diff'] = vorp_frame['halfPpr_vorp_rank'] - vorp_frame['custom_vorp_rank']
|
|
|
|
|
358 |
for positions in ['QB', 'RB', 'WR', 'TE']:
|
359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
vorp_frame['custom_rank'] = vorp_frame['Rank_Adjust'].rank(method='first', ascending=True)
|
361 |
|
362 |
print(vorp_frame.sort_values(by='custom_vorp_rank', ascending=True).head(50))
|
|
|
173 |
'TE': te_flex_pct,
|
174 |
}
|
175 |
else:
|
176 |
+
# Get default values for the selected league type
|
177 |
+
default_rb = type_flex_percentiles.get(league_type, {}).get('RB', 0.4)
|
178 |
+
default_wr = type_flex_percentiles.get(league_type, {}).get('WR', 0.55)
|
179 |
+
default_te = type_flex_percentiles.get(league_type, {}).get('TE', 0.05)
|
180 |
+
|
181 |
+
rb_flex_pct = st.sidebar.slider("RB Flex %", 0.0, 1.0, default_rb, 0.01)
|
182 |
+
wr_flex_pct = st.sidebar.slider("WR Flex %", 0.0, 1.0, default_wr, 0.01)
|
183 |
+
te_flex_pct = st.sidebar.slider("TE Flex %", 0.0, 1.0, default_te, 0.01)
|
184 |
|
185 |
user_flex_percentiles = {
|
186 |
'RB': rb_flex_pct,
|
|
|
190 |
|
191 |
# Flex Multipliers Configuration
|
192 |
st.sidebar.subheader("Position Multipliers")
|
193 |
+
default_qb_mult = flex_multipliers.get(league_type, {}).get('QB', 2.0)
|
194 |
+
default_rb_mult = flex_multipliers.get(league_type, {}).get('RB', 2.0)
|
195 |
+
default_wr_mult = flex_multipliers.get(league_type, {}).get('WR', 2.0)
|
196 |
+
default_te_mult = flex_multipliers.get(league_type, {}).get('TE', 2.0)
|
197 |
+
|
198 |
+
qb_mult = st.sidebar.number_input("QB Multiplier", min_value=1.0, max_value=5.0, value=float(default_qb_mult), step=0.5)
|
199 |
+
rb_mult = st.sidebar.number_input("RB Multiplier", min_value=1.0, max_value=5.0, value=float(default_rb_mult), step=0.5)
|
200 |
+
wr_mult = st.sidebar.number_input("WR Multiplier", min_value=1.0, max_value=5.0, value=float(default_wr_mult), step=0.5)
|
201 |
+
te_mult = st.sidebar.number_input("TE Multiplier", min_value=1.0, max_value=5.0, value=float(default_te_mult), step=0.5)
|
202 |
|
203 |
user_flex_multipliers = {
|
204 |
'QB': qb_mult,
|
|
|
209 |
|
210 |
# VORP Limiters Configuration
|
211 |
st.sidebar.subheader("VORP Rank Adjustments")
|
212 |
+
default_qb_vorp = pos_vorp_limiters.get(league_type, {}).get('QB', 0.5)
|
213 |
+
default_rb_vorp = pos_vorp_limiters.get(league_type, {}).get('RB', 0.75)
|
214 |
+
default_wr_vorp = pos_vorp_limiters.get(league_type, {}).get('WR', 0.75)
|
215 |
+
default_te_vorp = pos_vorp_limiters.get(league_type, {}).get('TE', 0.5)
|
216 |
+
|
217 |
+
qb_vorp_lim = st.sidebar.slider("QB VORP Limiter", 0.0, 1.0, default_qb_vorp, 0.01)
|
218 |
+
rb_vorp_lim = st.sidebar.slider("RB VORP Limiter", 0.0, 1.0, default_rb_vorp, 0.01)
|
219 |
+
wr_vorp_lim = st.sidebar.slider("WR VORP Limiter", 0.0, 1.0, default_wr_vorp, 0.01)
|
220 |
+
te_vorp_lim = st.sidebar.slider("TE VORP Limiter", 0.0, 1.0, default_te_vorp, 0.01)
|
221 |
|
222 |
user_pos_vorp_limiters = {
|
223 |
'QB': qb_vorp_lim,
|
|
|
273 |
wr_base = league_settings['WR'] * league_settings['TEAMS']
|
274 |
te_base = league_settings['TE'] * league_settings['TEAMS']
|
275 |
|
276 |
+
# Handle both nested and flat dictionary structures
|
277 |
+
if 'QB' in flex_percentiles:
|
278 |
+
# User configuration (flat structure)
|
279 |
+
qb_rv_index = math.ceil((qb_base) * flex_multipliers['QB'])
|
280 |
+
rb_rv_index = math.ceil((rb_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles['RB'])) * flex_multipliers['RB'])
|
281 |
+
wr_rv_index = math.ceil((wr_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles['WR'])) * flex_multipliers['WR'])
|
282 |
+
te_rv_index = math.ceil((te_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles['TE'])) * flex_multipliers['TE'])
|
283 |
+
else:
|
284 |
+
# Default configuration (nested structure)
|
285 |
+
qb_rv_index = math.ceil((qb_base) * flex_multipliers[league_settings['TYPE']]['QB'])
|
286 |
+
rb_rv_index = math.ceil((rb_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles[league_settings['TYPE']]['RB'])) * flex_multipliers[league_settings['TYPE']]['RB'])
|
287 |
+
wr_rv_index = math.ceil((wr_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles[league_settings['TYPE']]['WR'])) * flex_multipliers[league_settings['TYPE']]['WR'])
|
288 |
+
te_rv_index = math.ceil((te_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles[league_settings['TYPE']]['TE'])) * flex_multipliers[league_settings['TYPE']]['TE'])
|
289 |
|
290 |
print(f"Need {qb_rv_index} for QB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
291 |
print(f"Need {rb_rv_index} for RB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
|
|
307 |
wr_base = league_settings['WR'] * league_settings['TEAMS']
|
308 |
te_base = league_settings['TE'] * league_settings['TEAMS']
|
309 |
|
310 |
+
# Handle both nested and flat dictionary structures
|
311 |
+
if 'QB' in flex_percentiles:
|
312 |
+
# User configuration (flat structure)
|
313 |
+
qb_rv_index = math.ceil(qb_base * flex_multipliers['QB'])
|
314 |
+
rb_rv_index = math.ceil((rb_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles['RB'])) * flex_multipliers['RB'])
|
315 |
+
wr_rv_index = math.ceil((wr_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles['WR'])) * flex_multipliers['WR'])
|
316 |
+
te_rv_index = math.ceil((te_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles['TE'])) * flex_multipliers['TE'])
|
317 |
+
else:
|
318 |
+
# Default configuration (nested structure)
|
319 |
+
qb_rv_index = math.ceil(qb_base * flex_multipliers[league_settings['TYPE']]['QB'])
|
320 |
+
rb_rv_index = math.ceil((rb_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles[league_settings['TYPE']]['RB'])) * flex_multipliers[league_settings['TYPE']]['RB'])
|
321 |
+
wr_rv_index = math.ceil((wr_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles[league_settings['TYPE']]['WR'])) * flex_multipliers[league_settings['TYPE']]['WR'])
|
322 |
+
te_rv_index = math.ceil((te_base + ((league_settings['TEAMS'] * league_settings['FLEX']) * flex_percentiles[league_settings['TYPE']]['TE'])) * flex_multipliers[league_settings['TYPE']]['TE'])
|
323 |
|
324 |
print(f"Need {qb_rv_index} for QB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
325 |
print(f"Need {rb_rv_index} for RB in {league_settings['TEAMS']} teams with type {league_settings['TYPE']}")
|
|
|
388 |
vorp_frame['halfPpr_vorp_rank'] = vorp_frame['halfPpr_VORP'].rank(method='max', ascending=False)
|
389 |
vorp_frame['custom_vorp_rank'] = vorp_frame['custom_VORP'].rank(method='max', ascending=False)
|
390 |
vorp_frame['vorp_diff'] = vorp_frame['halfPpr_vorp_rank'] - vorp_frame['custom_vorp_rank']
|
391 |
+
|
392 |
+
# Handle both nested and flat dictionary structures
|
393 |
for positions in ['QB', 'RB', 'WR', 'TE']:
|
394 |
+
if 'QB' in pos_vorp_limiters:
|
395 |
+
# User configuration (flat structure)
|
396 |
+
limiter = pos_vorp_limiters[positions]
|
397 |
+
else:
|
398 |
+
# Default configuration (nested structure)
|
399 |
+
limiter = pos_vorp_limiters[league_settings['TYPE']][positions]
|
400 |
+
|
401 |
+
vorp_frame.loc[vorp_frame['Pos'] == positions, 'Rank_Adjust'] = (vorp_frame['Rank'] - (vorp_frame['vorp_diff'] * limiter)).astype(float)
|
402 |
+
|
403 |
vorp_frame['custom_rank'] = vorp_frame['Rank_Adjust'].rank(method='first', ascending=True)
|
404 |
|
405 |
print(vorp_frame.sort_values(by='custom_vorp_rank', ascending=True).head(50))
|