Spaces:
Running
Running
James McCool
commited on
Commit
·
c7d49f4
1
Parent(s):
fad8a64
Refactor data processing in app.py to streamline the initialization of pitcher and hitter statistics. Updated variable names and removed unnecessary return values for improved clarity and efficiency.
Browse files
app.py
CHANGED
@@ -75,18 +75,18 @@ def init_baselines():
|
|
75 |
collection = db["Pitcher_Stats"]
|
76 |
cursor = collection.find()
|
77 |
raw_display = pd.DataFrame(cursor)
|
78 |
-
|
79 |
-
|
80 |
-
pitcher_stats =
|
81 |
|
82 |
collection = db['Hitter_Stats']
|
83 |
cursor = collection.find()
|
84 |
raw_display = pd.DataFrame(cursor)
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
hitter_stats =
|
90 |
|
91 |
collection = db['Game_Betting_Model']
|
92 |
cursor = collection.find()
|
@@ -113,9 +113,9 @@ def init_baselines():
|
|
113 |
raw_display.replace('', np.nan, inplace=True)
|
114 |
pick_frame = raw_display.dropna(subset='Player')
|
115 |
|
116 |
-
return pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
117 |
|
118 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
119 |
|
120 |
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Game Betting Model", "Pitcher Prop Projections", "Hitter Prop Projections", "Player Prop Simulations", "Stat Specific Simulations", "Bet Sheet"])
|
121 |
|
@@ -123,10 +123,9 @@ def convert_df_to_csv(df):
|
|
123 |
return df.to_csv().encode('utf-8')
|
124 |
|
125 |
with tab1:
|
126 |
-
st.info(t_stamp)
|
127 |
if st.button("Reset Data", key='reset1'):
|
128 |
st.cache_data.clear()
|
129 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
130 |
line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
|
131 |
if line_var1 == 'Percentage':
|
132 |
team_frame = team_frame[['Names', 'Game', 'Moneyline', 'Win Percentage', 'ML_Value', 'Spread', 'Cover Spread Percentage', 'Spread_Value', 'Avg Score', 'Game Total', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage']]
|
@@ -147,10 +146,9 @@ with tab1:
|
|
147 |
)
|
148 |
|
149 |
with tab2:
|
150 |
-
st.info(t_stamp)
|
151 |
if st.button("Reset Data", key='reset2'):
|
152 |
st.cache_data.clear()
|
153 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
154 |
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
155 |
if split_var1 == 'Specific Teams':
|
156 |
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = pitcher_stats['Team'].unique(), key='team_var1')
|
@@ -169,10 +167,9 @@ with tab2:
|
|
169 |
)
|
170 |
|
171 |
with tab3:
|
172 |
-
st.info(t_stamp)
|
173 |
if st.button("Reset Data", key='reset3'):
|
174 |
st.cache_data.clear()
|
175 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
176 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
177 |
if split_var2 == 'Specific Teams':
|
178 |
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = hitter_stats['Team'].unique(), key='team_var2')
|
@@ -191,10 +188,9 @@ with tab3:
|
|
191 |
)
|
192 |
|
193 |
with tab4:
|
194 |
-
st.info(t_stamp)
|
195 |
if st.button("Reset Data", key='reset4'):
|
196 |
st.cache_data.clear()
|
197 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
198 |
col1, col2 = st.columns([1, 5])
|
199 |
|
200 |
with col2:
|
@@ -355,13 +351,10 @@ with tab4:
|
|
355 |
st.plotly_chart(fig, use_container_width=True)
|
356 |
|
357 |
with tab5:
|
358 |
-
st.info(t_stamp)
|
359 |
st.info('The Over and Under percentages are a compositve percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
360 |
if st.button("Reset Data/Load Data", key='reset5'):
|
361 |
-
# Clear values from *all* all in-memory and on-disk data caches:
|
362 |
-
# i.e. clear values from both square and cube
|
363 |
st.cache_data.clear()
|
364 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, pick_frame
|
365 |
col1, col2 = st.columns([1, 5])
|
366 |
|
367 |
with col2:
|
@@ -604,11 +597,10 @@ with tab5:
|
|
604 |
|
605 |
with tab6:
|
606 |
col1, col2, col3 = st.columns([2, 2, 2])
|
607 |
-
st.info(t_stamp)
|
608 |
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.')
|
609 |
if st.button("Reset Data", key='reset6'):
|
610 |
st.cache_data.clear()
|
611 |
-
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
612 |
with col1:
|
613 |
split_var6 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var6')
|
614 |
if split_var6 == 'Specific Teams':
|
|
|
75 |
collection = db["Pitcher_Stats"]
|
76 |
cursor = collection.find()
|
77 |
raw_display = pd.DataFrame(cursor)
|
78 |
+
raw_display.rename(columns={"Names": "Player"}, inplace = True)
|
79 |
+
pitcher_stats = raw_display[['Player', 'Team', 'BB', 'Hits', 'HRs', 'ERs', 'Ks', 'Outs', 'Fantasy', 'FD_Fantasy', 'PrizePicks']]
|
80 |
+
pitcher_stats = pitcher_stats.drop_duplicates(subset='Player')
|
81 |
|
82 |
collection = db['Hitter_Stats']
|
83 |
cursor = collection.find()
|
84 |
raw_display = pd.DataFrame(cursor)
|
85 |
+
raw_display.rename(columns={"Names": "Player"}, inplace = True)
|
86 |
+
hitter_stats = raw_display[['Player', 'Team', 'Walks', 'Steals', 'Hits', 'Singles', 'Doubles', 'HRs', 'RBIs', 'Runs', 'Fantasy', 'FD_Fantasy', 'PrizePicks']]
|
87 |
+
hitter_stats['Total Bases'] = hitter_stats['Singles'] + (hitter_stats['Doubles'] * 2) + (hitter_stats['HRs'] * 4)
|
88 |
+
hitter_stats['Hits + Runs + RBIs'] = hitter_stats['Hits'] + hitter_stats['Runs'] + hitter_stats['RBIs']
|
89 |
+
hitter_stats = hitter_stats.drop_duplicates(subset='Player')
|
90 |
|
91 |
collection = db['Game_Betting_Model']
|
92 |
cursor = collection.find()
|
|
|
113 |
raw_display.replace('', np.nan, inplace=True)
|
114 |
pick_frame = raw_display.dropna(subset='Player')
|
115 |
|
116 |
+
return pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame
|
117 |
|
118 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
119 |
|
120 |
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Game Betting Model", "Pitcher Prop Projections", "Hitter Prop Projections", "Player Prop Simulations", "Stat Specific Simulations", "Bet Sheet"])
|
121 |
|
|
|
123 |
return df.to_csv().encode('utf-8')
|
124 |
|
125 |
with tab1:
|
|
|
126 |
if st.button("Reset Data", key='reset1'):
|
127 |
st.cache_data.clear()
|
128 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
129 |
line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
|
130 |
if line_var1 == 'Percentage':
|
131 |
team_frame = team_frame[['Names', 'Game', 'Moneyline', 'Win Percentage', 'ML_Value', 'Spread', 'Cover Spread Percentage', 'Spread_Value', 'Avg Score', 'Game Total', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage']]
|
|
|
146 |
)
|
147 |
|
148 |
with tab2:
|
|
|
149 |
if st.button("Reset Data", key='reset2'):
|
150 |
st.cache_data.clear()
|
151 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
152 |
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
153 |
if split_var1 == 'Specific Teams':
|
154 |
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = pitcher_stats['Team'].unique(), key='team_var1')
|
|
|
167 |
)
|
168 |
|
169 |
with tab3:
|
|
|
170 |
if st.button("Reset Data", key='reset3'):
|
171 |
st.cache_data.clear()
|
172 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
173 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
174 |
if split_var2 == 'Specific Teams':
|
175 |
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = hitter_stats['Team'].unique(), key='team_var2')
|
|
|
188 |
)
|
189 |
|
190 |
with tab4:
|
|
|
191 |
if st.button("Reset Data", key='reset4'):
|
192 |
st.cache_data.clear()
|
193 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
194 |
col1, col2 = st.columns([1, 5])
|
195 |
|
196 |
with col2:
|
|
|
351 |
st.plotly_chart(fig, use_container_width=True)
|
352 |
|
353 |
with tab5:
|
|
|
354 |
st.info('The Over and Under percentages are a compositve percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
355 |
if st.button("Reset Data/Load Data", key='reset5'):
|
|
|
|
|
356 |
st.cache_data.clear()
|
357 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, pick_frame = init_baselines()
|
358 |
col1, col2 = st.columns([1, 5])
|
359 |
|
360 |
with col2:
|
|
|
597 |
|
598 |
with tab6:
|
599 |
col1, col2, col3 = st.columns([2, 2, 2])
|
|
|
600 |
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.')
|
601 |
if st.button("Reset Data", key='reset6'):
|
602 |
st.cache_data.clear()
|
603 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame = init_baselines()
|
604 |
with col1:
|
605 |
split_var6 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var6')
|
606 |
if split_var6 == 'Specific Teams':
|