Spaces:
Running
Running
James McCool
commited on
Commit
·
2e3b8fd
1
Parent(s):
d69c0ed
Enhance scoring percentages by adding 'Top Score' metric and updating data handling for DK and FD ownership calculations. Adjusted UI options for slate selection and improved data filtering.
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ def init_conn():
|
|
17 |
|
18 |
db, db2 = init_conn()
|
19 |
|
20 |
-
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
21 |
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
22 |
|
23 |
player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
|
@@ -50,12 +50,15 @@ def init_baselines():
|
|
50 |
cursor = collection.find()
|
51 |
team_frame = pd.DataFrame(cursor)
|
52 |
scoring_percentages = team_frame.drop(columns=['_id'])
|
53 |
-
scoring_percentages = scoring_percentages[['Names', 'Avg First Inning', 'First Inning Lead Percentage', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage', 'Avg Score', '8+ runs', 'Win Percentage']]
|
54 |
scoring_percentages['8+ runs'] = scoring_percentages['8+ runs'].replace('%', '', regex=True).astype(float)
|
55 |
scoring_percentages['Win Percentage'] = scoring_percentages['Win Percentage'].replace('%', '', regex=True).astype(float)
|
|
|
56 |
dk_hitters_only = dk_roo[dk_roo['pos_group'] != 'Pitchers']
|
|
|
57 |
dk_team_ownership = dk_hitters_only.groupby('Team')['Own%'].sum().reset_index()
|
58 |
fd_hitters_only = fd_roo[fd_roo['pos_group'] != 'Pitchers']
|
|
|
59 |
fd_team_ownership = fd_hitters_only.groupby('Team')['Own%'].sum().reset_index()
|
60 |
scoring_percentages = scoring_percentages.merge(dk_team_ownership, left_on='Names', right_on='Team', how='left')
|
61 |
scoring_percentages.rename(columns={'Own%': 'DK Own%'}, inplace=True)
|
@@ -63,6 +66,8 @@ def init_baselines():
|
|
63 |
scoring_percentages = scoring_percentages.merge(fd_team_ownership, left_on='Names', right_on='Team', how='left')
|
64 |
scoring_percentages.rename(columns={'Own%': 'FD Own%'}, inplace=True)
|
65 |
scoring_percentages.drop('Team', axis=1, inplace=True)
|
|
|
|
|
66 |
|
67 |
return roo_data, sd_roo_data, scoring_percentages, dk_roo, fd_roo
|
68 |
|
@@ -244,8 +249,17 @@ with tab1:
|
|
244 |
st.header("Scoring Percentages")
|
245 |
with st.expander("Info and Filters"):
|
246 |
with st.container():
|
247 |
-
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', '
|
248 |
own_var1 = st.radio("How would you like to display team ownership?", ('Sum', 'Average'), key='own_var1')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
if view_var == "Simple":
|
250 |
scoring_percentages = scoring_percentages[['Names', 'Avg Score', '8+ runs', 'Win Percentage']]
|
251 |
st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
|
|
17 |
|
18 |
db, db2 = init_conn()
|
19 |
|
20 |
+
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}', 'Top Score': '{:.2%}',
|
21 |
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
22 |
|
23 |
player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
|
|
|
50 |
cursor = collection.find()
|
51 |
team_frame = pd.DataFrame(cursor)
|
52 |
scoring_percentages = team_frame.drop(columns=['_id'])
|
53 |
+
scoring_percentages = scoring_percentages[['Names', 'Avg First Inning', 'First Inning Lead Percentage', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage', 'Avg Score', '8+ runs', 'Win Percentage', 'Slate', 'Top Score']]
|
54 |
scoring_percentages['8+ runs'] = scoring_percentages['8+ runs'].replace('%', '', regex=True).astype(float)
|
55 |
scoring_percentages['Win Percentage'] = scoring_percentages['Win Percentage'].replace('%', '', regex=True).astype(float)
|
56 |
+
scoring_percentages['Top Score'] = scoring_percentages['Top Score'].replace('', np.nan).astype(float)
|
57 |
dk_hitters_only = dk_roo[dk_roo['pos_group'] != 'Pitchers']
|
58 |
+
dk_hitters_only = dk_hitters_only.replace('CWS', 'CHW')
|
59 |
dk_team_ownership = dk_hitters_only.groupby('Team')['Own%'].sum().reset_index()
|
60 |
fd_hitters_only = fd_roo[fd_roo['pos_group'] != 'Pitchers']
|
61 |
+
fd_hitters_only = fd_hitters_only.replace('CWS', 'CHW')
|
62 |
fd_team_ownership = fd_hitters_only.groupby('Team')['Own%'].sum().reset_index()
|
63 |
scoring_percentages = scoring_percentages.merge(dk_team_ownership, left_on='Names', right_on='Team', how='left')
|
64 |
scoring_percentages.rename(columns={'Own%': 'DK Own%'}, inplace=True)
|
|
|
66 |
scoring_percentages = scoring_percentages.merge(fd_team_ownership, left_on='Names', right_on='Team', how='left')
|
67 |
scoring_percentages.rename(columns={'Own%': 'FD Own%'}, inplace=True)
|
68 |
scoring_percentages.drop('Team', axis=1, inplace=True)
|
69 |
+
scoring_percentages['DK LevX'] = scoring_percentages['Top Score'].rank(pct=True).astype(float) - scoring_percentages['DK Own%'].rank(pct=True).astype(float)
|
70 |
+
scoring_percentages['FD LevX'] = scoring_percentages['Top Score'].rank(pct=True).astype(float) - scoring_percentages['FD Own%'].rank(pct=True).astype(float)
|
71 |
|
72 |
return roo_data, sd_roo_data, scoring_percentages, dk_roo, fd_roo
|
73 |
|
|
|
249 |
st.header("Scoring Percentages")
|
250 |
with st.expander("Info and Filters"):
|
251 |
with st.container():
|
252 |
+
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'All Games'), key='slate_var1')
|
253 |
own_var1 = st.radio("How would you like to display team ownership?", ('Sum', 'Average'), key='own_var1')
|
254 |
+
|
255 |
+
if slate_var1 == 'Main Slate':
|
256 |
+
scoring_percentages = scoring_percentages[scoring_percentages['Slate'] == 'Main']
|
257 |
+
elif slate_var1 != 'Main Slate':
|
258 |
+
pass
|
259 |
+
|
260 |
+
scoring_percentages = scoring_percentages.sort_values(by='8+ runs', ascending=False)
|
261 |
+
scoring_percentages = scoring_percentages.drop('Slate', axis=1)
|
262 |
+
|
263 |
if view_var == "Simple":
|
264 |
scoring_percentages = scoring_percentages[['Names', 'Avg Score', '8+ runs', 'Win Percentage']]
|
265 |
st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
|