Spaces:
Running
Running
James McCool
commited on
Commit
·
c1e67a6
1
Parent(s):
ae5c57d
Enhance baseline initialization by incorporating player hand and order information for hitters. Update scoring percentage calculations to include 'Runs/$' metric. Improve dataframe styling for player display, ensuring better visual representation of key metrics in the UI.
Browse files
app.py
CHANGED
@@ -29,12 +29,26 @@ fd_sd_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'T
|
|
29 |
|
30 |
@st.cache_resource(ttl = 60)
|
31 |
def init_baselines():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
collection = db["Player_Range_Of_Outcomes"]
|
33 |
cursor = collection.find()
|
34 |
player_frame = pd.DataFrame(cursor)
|
35 |
|
36 |
roo_data = player_frame.drop(columns=['_id'])
|
37 |
roo_data['Salary'] = roo_data['Salary'].astype(int)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
dk_roo = roo_data[roo_data['Site'] == 'Draftkings']
|
40 |
dk_id_map = dict(zip(dk_roo['Player'], dk_roo['player_ID']))
|
@@ -53,7 +67,8 @@ def init_baselines():
|
|
53 |
cursor = collection.find()
|
54 |
team_frame = pd.DataFrame(cursor)
|
55 |
scoring_percentages = team_frame.drop(columns=['_id'])
|
56 |
-
scoring_percentages = scoring_percentages[
|
|
|
57 |
'DK Main Slate', 'DK Secondary Slate', 'DK Turbo Slate', 'FD Main Slate', 'FD Secondary Slate', 'FD Turbo Slate', 'DK Main Top Score', 'FD Main Top Score', 'DK Secondary Top Score', 'FD Secondary Top Score',
|
58 |
'DK Turbo Top Score', 'FD Turbo Top Score']]
|
59 |
scoring_percentages['8+ runs'] = scoring_percentages['8+ runs'].replace('%', '', regex=True).astype(float)
|
@@ -416,18 +431,18 @@ with tab2:
|
|
416 |
try:
|
417 |
player_roo_disp = player_roo_disp[['Player', 'Salary', 'Median', 'Ceiling', 'Own%', 'Position', 'Team']]
|
418 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
419 |
-
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True)
|
420 |
except:
|
421 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
422 |
-
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True)
|
423 |
|
424 |
elif view_var == "Advanced":
|
425 |
try:
|
426 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
427 |
-
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True)
|
428 |
except:
|
429 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
430 |
-
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True)
|
431 |
|
432 |
with tab3:
|
433 |
st.header("Optimals")
|
|
|
29 |
|
30 |
@st.cache_resource(ttl = 60)
|
31 |
def init_baselines():
|
32 |
+
|
33 |
+
collection = db["Hitter_Info"]
|
34 |
+
cursor = collection.find()
|
35 |
+
Hitter_info = pd.DataFrame(cursor)
|
36 |
+
LHP_Info = Hitter_info[Hitter_info['Set'] == 'LHP'].drop_duplicates(subset=['Player'])
|
37 |
+
RHP_Info = Hitter_info[Hitter_info['Set'] == 'RHP'].drop_duplicates(subset=['Player'])
|
38 |
+
|
39 |
collection = db["Player_Range_Of_Outcomes"]
|
40 |
cursor = collection.find()
|
41 |
player_frame = pd.DataFrame(cursor)
|
42 |
|
43 |
roo_data = player_frame.drop(columns=['_id'])
|
44 |
roo_data['Salary'] = roo_data['Salary'].astype(int)
|
45 |
+
hold_frame = roo_data.copy()
|
46 |
+
|
47 |
+
hold_frame['Order'] = np.where(hold_frame['pos_group'] == 'Hitters', hold_frame['Player'].map(RHP_Info.set_index('Player')['Order']), 0)
|
48 |
+
hold_frame['Hand'] = np.where(hold_frame['pos_group'] == 'Hitters', hold_frame['Player'].map(RHP_Info.set_index('Player')['bats']), 'Pitcher')
|
49 |
+
|
50 |
+
roo_data.insert(3, 'Hand', hold_frame['Hand'])
|
51 |
+
roo_data.insert(4, 'Order', hold_frame['Order'].astype(int))
|
52 |
|
53 |
dk_roo = roo_data[roo_data['Site'] == 'Draftkings']
|
54 |
dk_id_map = dict(zip(dk_roo['Player'], dk_roo['player_ID']))
|
|
|
67 |
cursor = collection.find()
|
68 |
team_frame = pd.DataFrame(cursor)
|
69 |
scoring_percentages = team_frame.drop(columns=['_id'])
|
70 |
+
scoring_percentages['Runs/$'] = scoring_percentages['Avg Score'] / (scoring_percentages['Avg_Salary'] / 1000)
|
71 |
+
scoring_percentages = scoring_percentages[['Names', 'Avg_Salary', 'Stack_Prio', 'Opp_SP', 'Avg First Inning', 'First Inning Lead Percentage', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage', 'Avg Score', 'Runs/$', '8+ runs', 'Win Percentage',
|
72 |
'DK Main Slate', 'DK Secondary Slate', 'DK Turbo Slate', 'FD Main Slate', 'FD Secondary Slate', 'FD Turbo Slate', 'DK Main Top Score', 'FD Main Top Score', 'DK Secondary Top Score', 'FD Secondary Top Score',
|
73 |
'DK Turbo Top Score', 'FD Turbo Top Score']]
|
74 |
scoring_percentages['8+ runs'] = scoring_percentages['8+ runs'].replace('%', '', regex=True).astype(float)
|
|
|
431 |
try:
|
432 |
player_roo_disp = player_roo_disp[['Player', 'Salary', 'Median', 'Ceiling', 'Own%', 'Position', 'Team']]
|
433 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
434 |
+
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Salary', 'Own%']).format(player_roo_format, precision=2), height=750, use_container_width = True)
|
435 |
except:
|
436 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
437 |
+
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Salary', 'Own%']).format(player_roo_format, precision=2), height=750, use_container_width = True)
|
438 |
|
439 |
elif view_var == "Advanced":
|
440 |
try:
|
441 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
442 |
+
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Order', 'Salary', 'Own%', 'Small Field Own%', 'Large Field Own%', 'Cash Own%']).format(player_roo_format, precision=2), height=750, use_container_width = True)
|
443 |
except:
|
444 |
player_roo_disp = player_roo_disp.set_index('Player', drop=True)
|
445 |
+
st.dataframe(player_roo_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Order', 'Salary', 'Own%', 'Small Field Own%', 'Large Field Own%', 'Cash Own%']).format(player_roo_format, precision=2), height=750, use_container_width = True)
|
446 |
|
447 |
with tab3:
|
448 |
st.header("Optimals")
|