Spaces:
Sleeping
Sleeping
Update pages/1player_information.py
Browse files- pages/1player_information.py +77 -4
pages/1player_information.py
CHANGED
@@ -13,13 +13,12 @@ player_names = df["Player"].unique()
|
|
13 |
|
14 |
# Search box for filtering player names
|
15 |
search_query = st.text_input("Search Player Name:")
|
16 |
-
filtered_players = [name for name in player_names if search_query.lower() in name.lower()] if search_query else
|
17 |
-
|
18 |
if len(filtered_players) == 0:
|
19 |
st.warning("Player not found. Please try a different name.")
|
20 |
|
21 |
# Player selection dropdown
|
22 |
-
selected_player = st.selectbox("Select Player", filtered_players)
|
23 |
|
24 |
# Buttons for Batting and Bowling
|
25 |
show_batting = st.button("Show Batting Stats")
|
@@ -31,7 +30,7 @@ if selected_player:
|
|
31 |
|
32 |
if show_batting:
|
33 |
st.subheader(f"Batting Stats for {selected_player}")
|
34 |
-
|
35 |
col1, col2 = st.columns(2)
|
36 |
with col1:
|
37 |
# Pie Chart - Matches Played
|
@@ -60,6 +59,64 @@ if selected_player:
|
|
60 |
ax.set_title(f"Runs Scored by {selected_player}")
|
61 |
st.pyplot(fig)
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
if show_bowling:
|
64 |
st.subheader(f"Bowling Stats for {selected_player}")
|
65 |
|
@@ -90,3 +147,19 @@ if selected_player:
|
|
90 |
ax.set_ylabel("Innings Bowled")
|
91 |
ax.set_title(f"Bowling Innings of {selected_player}")
|
92 |
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Search box for filtering player names
|
15 |
search_query = st.text_input("Search Player Name:")
|
16 |
+
filtered_players = [name for name in player_names if search_query.lower() in name.lower()] if search_query else player_names
|
|
|
17 |
if len(filtered_players) == 0:
|
18 |
st.warning("Player not found. Please try a different name.")
|
19 |
|
20 |
# Player selection dropdown
|
21 |
+
selected_player = st.selectbox("Select Player", filtered_players)
|
22 |
|
23 |
# Buttons for Batting and Bowling
|
24 |
show_batting = st.button("Show Batting Stats")
|
|
|
30 |
|
31 |
if show_batting:
|
32 |
st.subheader(f"Batting Stats for {selected_player}")
|
33 |
+
|
34 |
col1, col2 = st.columns(2)
|
35 |
with col1:
|
36 |
# Pie Chart - Matches Played
|
|
|
59 |
ax.set_title(f"Runs Scored by {selected_player}")
|
60 |
st.pyplot(fig)
|
61 |
|
62 |
+
col3, col4 = st.columns(2)
|
63 |
+
with col3:
|
64 |
+
# Stacked Bar Chart - 100s and 50s
|
65 |
+
hundreds = [
|
66 |
+
player_data.get("batting_100s_Test", 0),
|
67 |
+
player_data.get("batting_100s_ODI", 0),
|
68 |
+
player_data.get("batting_100s_T20", 0),
|
69 |
+
player_data.get("batting_100s_IPL", 0)
|
70 |
+
]
|
71 |
+
fifties = [
|
72 |
+
player_data.get("batting_50s_Test", 0),
|
73 |
+
player_data.get("batting_50s_ODI", 0),
|
74 |
+
player_data.get("batting_50s_T20", 0),
|
75 |
+
player_data.get("batting_50s_IPL", 0)
|
76 |
+
]
|
77 |
+
fig, ax = plt.subplots()
|
78 |
+
ax.bar(labels, hundreds, label="100s", color="gold")
|
79 |
+
ax.bar(labels, fifties, label="50s", color="blue", bottom=hundreds)
|
80 |
+
ax.set_ylabel("Count")
|
81 |
+
ax.set_title(f"Centuries & Fifties by {selected_player}")
|
82 |
+
ax.legend()
|
83 |
+
st.pyplot(fig)
|
84 |
+
|
85 |
+
with col4:
|
86 |
+
# Line Chart - Strike Rate & Average
|
87 |
+
strike_rate = [
|
88 |
+
player_data.get("batting_SR_Test", 0),
|
89 |
+
player_data.get("batting_SR_ODI", 0),
|
90 |
+
player_data.get("batting_SR_T20", 0),
|
91 |
+
player_data.get("batting_SR_IPL", 0)
|
92 |
+
]
|
93 |
+
batting_avg = [
|
94 |
+
player_data.get("batting_Average_Test", 0),
|
95 |
+
player_data.get("batting_Average_ODI", 0),
|
96 |
+
player_data.get("batting_Average_T20", 0),
|
97 |
+
player_data.get("batting_Average_IPL", 0)
|
98 |
+
]
|
99 |
+
fig, ax = plt.subplots()
|
100 |
+
ax.plot(labels, strike_rate, marker='o', linestyle='-', color='red', label="Strike Rate")
|
101 |
+
ax.plot(labels, batting_avg, marker='s', linestyle='--', color='green', label="Batting Average")
|
102 |
+
ax.set_ylabel("Value")
|
103 |
+
ax.set_title(f"Strike Rate & Batting Average of {selected_player}")
|
104 |
+
ax.legend()
|
105 |
+
st.pyplot(fig)
|
106 |
+
|
107 |
+
# Bar Chart - Balls Faced
|
108 |
+
batting_balls = [
|
109 |
+
player_data.get("batting_Balls_Test", 0),
|
110 |
+
player_data.get("batting_Balls_ODI", 0),
|
111 |
+
player_data.get("batting_Balls_T20", 0),
|
112 |
+
player_data.get("batting_Balls_IPL", 0)
|
113 |
+
]
|
114 |
+
fig, ax = plt.subplots(figsize=(5,3))
|
115 |
+
ax.bar(labels, batting_balls, color=["red", "green", "blue", "purple"])
|
116 |
+
ax.set_ylabel("Balls Faced")
|
117 |
+
ax.set_title(f"Balls Faced by {selected_player}")
|
118 |
+
st.pyplot(fig)
|
119 |
+
|
120 |
if show_bowling:
|
121 |
st.subheader(f"Bowling Stats for {selected_player}")
|
122 |
|
|
|
147 |
ax.set_ylabel("Innings Bowled")
|
148 |
ax.set_title(f"Bowling Innings of {selected_player}")
|
149 |
st.pyplot(fig)
|
150 |
+
|
151 |
+
# Balls Bowled
|
152 |
+
balls_bowled = [
|
153 |
+
player_data.get("bowling_Test_Balls", 0),
|
154 |
+
player_data.get("bowling_ODI_Balls", 0),
|
155 |
+
player_data.get("bowling_T20_Balls", 0),
|
156 |
+
player_data.get("bowling_IPL_Balls", 0)
|
157 |
+
]
|
158 |
+
fig, ax = plt.subplots(figsize=(5, 3))
|
159 |
+
ax.bar(labels, balls_bowled, color=["red", "yellow", "blue", "green"])
|
160 |
+
ax.set_ylabel("Balls Bowled")
|
161 |
+
ax.set_title(f"Balls Bowled by {selected_player}")
|
162 |
+
st.pyplot(fig)
|
163 |
+
|
164 |
+
|
165 |
+
add a message to the code if the player name was not found and displaye the message
|