Spaces:
Running
Running
James McCool
commited on
Commit
·
271fbcf
1
Parent(s):
ad0272f
Enhance app.py by adding support for 'Walks (Hitters)' and 'Hits (Hitters)' prop categories, updating data processing logic accordingly. Modify median and flex file calculations to accommodate new categories, and update user interface messages for clarity.
Browse files
app.py
CHANGED
@@ -377,7 +377,7 @@ with tab5:
|
|
377 |
key='prop_source',
|
378 |
)
|
379 |
prop_type_var = st.selectbox('Select prop category', options = ['Strikeouts (Pitchers)', 'Total Outs (Pitchers)', 'Earned Runs (Pitchers)', 'Hits Against (Pitchers)',
|
380 |
-
'Walks Allowed (Pitchers)', 'Total Bases (Hitters)', 'Stolen Bases (Hitters)'])
|
381 |
|
382 |
if st.button('Simulate Prop Category'):
|
383 |
with col2:
|
@@ -456,6 +456,15 @@ with tab5:
|
|
456 |
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
457 |
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
458 |
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
prop_dict = dict(zip(df.Player, df.Prop))
|
461 |
over_dict = dict(zip(df.Player, df.Over))
|
@@ -478,7 +487,11 @@ with tab5:
|
|
478 |
elif prop_type_var == "Total Bases (Hitters)":
|
479 |
df['Median'] = df['Total Bases']
|
480 |
elif prop_type_var == "Stolen Bases (Hitters)":
|
481 |
-
df['Median'] = df['
|
|
|
|
|
|
|
|
|
482 |
|
483 |
flex_file = df
|
484 |
if prop_type_var == 'Strikeouts (Pitchers)':
|
@@ -529,6 +542,20 @@ with tab5:
|
|
529 |
flex_file['STD'] = flex_file['Median'] / 1.5
|
530 |
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
531 |
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
|
533 |
hold_file = flex_file
|
534 |
overall_file = flex_file
|
@@ -594,39 +621,4 @@ with tab5:
|
|
594 |
)
|
595 |
|
596 |
with tab6:
|
597 |
-
|
598 |
-
st.info('This sheet is more or less a static represenation of the Stat Specific Simulations. ROR is rate of return based on hit rate and payout. Use the over and under EDGEs to place bets. 20%+ should be considered a 1 unit bet, 15-20% is .75 units, 10-15% is .50 units, 5-10% is .25 units, and 0-5% is .1 units.')
|
599 |
-
if st.button("Reset Data", key='reset6'):
|
600 |
-
st.cache_data.clear()
|
601 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
602 |
-
with col1:
|
603 |
-
split_var6 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var6')
|
604 |
-
if split_var6 == 'Specific Teams':
|
605 |
-
team_var6 = st.multiselect('Which teams would you like to include in the tables?', options = betsheet_frame['Team'].unique(), key='team_var6')
|
606 |
-
elif split_var6 == 'All':
|
607 |
-
team_var6 = betsheet_frame.Team.values.tolist()
|
608 |
-
with col2:
|
609 |
-
prop_choice_var6 = st.radio("Would you like to view all prop types or specific ones?", ('All', 'Specific Props'), key='prop_choice_var6')
|
610 |
-
if prop_choice_var6 == 'Specific Props':
|
611 |
-
prop_var6 = st.multiselect('Which props would you like to include in the tables?', options = betsheet_frame['prop_type'].unique(), key='prop_var6')
|
612 |
-
elif prop_choice_var6 == 'All':
|
613 |
-
prop_var6 = betsheet_frame.prop_type.values.tolist()
|
614 |
-
with col3:
|
615 |
-
player_choice_var6 = st.radio("Would you like to view all players props or specific ones?", ('All', 'Specific Players'), key='player_choice_var6')
|
616 |
-
if player_choice_var6 == 'Specific Players':
|
617 |
-
player_var6 = st.multiselect('Which players would you like to include in the tables?', options = betsheet_frame['Player'].unique(), key='player_var6')
|
618 |
-
elif player_choice_var6 == 'All':
|
619 |
-
player_var6 = betsheet_frame.Player.values.tolist()
|
620 |
-
betsheet_disp = betsheet_frame.copy()
|
621 |
-
betsheet_disp = betsheet_disp[betsheet_disp['Team'].isin(team_var6)]
|
622 |
-
betsheet_disp = betsheet_disp[betsheet_disp['prop_type'].isin(prop_var6)]
|
623 |
-
betsheet_disp = betsheet_disp[betsheet_disp['Player'].isin(player_var6)]
|
624 |
-
betsheet_disp = betsheet_disp.sort_values(by='over_EDGE', ascending=False)
|
625 |
-
st.dataframe(betsheet_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=750, use_container_width = True)
|
626 |
-
st.download_button(
|
627 |
-
label="Export Betsheet",
|
628 |
-
data=convert_df_to_csv(betsheet_disp),
|
629 |
-
file_name='MLB_Betsheet_export.csv',
|
630 |
-
mime='text/csv',
|
631 |
-
key='MLB_Betsheet_export',
|
632 |
-
)
|
|
|
377 |
key='prop_source',
|
378 |
)
|
379 |
prop_type_var = st.selectbox('Select prop category', options = ['Strikeouts (Pitchers)', 'Total Outs (Pitchers)', 'Earned Runs (Pitchers)', 'Hits Against (Pitchers)',
|
380 |
+
'Walks Allowed (Pitchers)', 'Total Bases (Hitters)', 'Stolen Bases (Hitters)', 'Walks (Hitters)'])
|
381 |
|
382 |
if st.button('Simulate Prop Category'):
|
383 |
with col2:
|
|
|
456 |
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
457 |
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
458 |
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
459 |
+
elif prop_type_var == "Walks (Hitters)":
|
460 |
+
player_df = hitter_stats
|
461 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'batter_walks']
|
462 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
463 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
464 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
465 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
466 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
467 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
468 |
|
469 |
prop_dict = dict(zip(df.Player, df.Prop))
|
470 |
over_dict = dict(zip(df.Player, df.Over))
|
|
|
487 |
elif prop_type_var == "Total Bases (Hitters)":
|
488 |
df['Median'] = df['Total Bases']
|
489 |
elif prop_type_var == "Stolen Bases (Hitters)":
|
490 |
+
df['Median'] = df['Steals']
|
491 |
+
elif prop_type_var == "Hits (Hitters)":
|
492 |
+
df['Median'] = df['Hits']
|
493 |
+
elif prop_type_var == "Walks (Hitters)":
|
494 |
+
df['Median'] = df['Walks']
|
495 |
|
496 |
flex_file = df
|
497 |
if prop_type_var == 'Strikeouts (Pitchers)':
|
|
|
542 |
flex_file['STD'] = flex_file['Median'] / 1.5
|
543 |
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
544 |
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
545 |
+
|
546 |
+
elif prop_type_var == 'Hits (Hitters)':
|
547 |
+
flex_file['Floor'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * .20, 0)
|
548 |
+
flex_file['Ceiling'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * 1.8, flex_file['Median'] * 4)
|
549 |
+
flex_file['STD'] = flex_file['Median'] / 1.5
|
550 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
551 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
552 |
+
|
553 |
+
elif prop_type_var == 'Walks (Hitters)':
|
554 |
+
flex_file['Floor'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * .20, 0)
|
555 |
+
flex_file['Ceiling'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * 1.8, flex_file['Median'] * 4)
|
556 |
+
flex_file['STD'] = flex_file['Median'] / 1.5
|
557 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
558 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
559 |
|
560 |
hold_file = flex_file
|
561 |
overall_file = flex_file
|
|
|
621 |
)
|
622 |
|
623 |
with tab6:
|
624 |
+
st.info("This sheet is currently under reconstruction, it'll be back soon!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|