Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -150,152 +150,304 @@ elif page == "π Player Career Info":
|
|
| 150 |
st.plotly_chart(fig5)
|
| 151 |
|
| 152 |
|
| 153 |
-
if page == "Player Comparision(π§ββοΈ vs π§ββοΈ)":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
st.title("π Player Recognition & Performance Analysis")
|
| 155 |
player_stats_df = pd.read_csv("final_cricket_dataset.csv")
|
| 156 |
model = joblib.load("svc_face_classifier.pkl")
|
| 157 |
label_encoder = joblib.load("label_encoder.pkl")
|
| 158 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 159 |
-
|
| 160 |
-
# Streamlit Page Setup
|
| 161 |
-
|
| 162 |
-
# Image Preprocessing + Face Detection Function
|
| 163 |
def detect_and_predict_face(image_file):
|
| 164 |
image = Image.open(image_file).convert("RGB")
|
| 165 |
img_np = np.array(image)
|
| 166 |
gray = cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)
|
| 167 |
-
|
| 168 |
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
|
|
|
| 169 |
if len(faces) == 0:
|
| 170 |
return None, "No face detected!"
|
| 171 |
-
|
| 172 |
x, y, w, h = faces[0]
|
| 173 |
face = gray[y:y+h, x:x+w]
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
return
|
| 180 |
-
|
| 181 |
-
# Upload images
|
| 182 |
col1, col2 = st.columns(2)
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
img2 = st.file_uploader("Upload Second Player Image", type=["jpg", "png", "jpeg"], key="img2")
|
| 187 |
-
|
| 188 |
if img1 and img2:
|
| 189 |
p1_name, err1 = detect_and_predict_face(img1)
|
| 190 |
p2_name, err2 = detect_and_predict_face(img2)
|
| 191 |
-
|
| 192 |
-
if err1:
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
st.error(f"Image 2: {err2}")
|
| 196 |
-
|
| 197 |
if not err1 and not err2:
|
| 198 |
st.success(f"β
Player 1 Detected: {p1_name}")
|
| 199 |
st.success(f"β
Player 2 Detected: {p2_name}")
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
df = player_stats_df
|
| 203 |
-
players = [p1_name, p2_name]
|
| 204 |
-
|
| 205 |
if p1_name not in df['Label'].values or p2_name not in df['Label'].values:
|
| 206 |
st.error("One or both players not found in dataset.")
|
| 207 |
st.stop()
|
| 208 |
-
|
| 209 |
p1_data = df[df['Label'] == p1_name].iloc[0]
|
| 210 |
p2_data = df[df['Label'] == p2_name].iloc[0]
|
| 211 |
-
|
| 212 |
-
st.
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 226 |
-
|
| 227 |
-
# Bowling Summary
|
| 228 |
-
st.markdown("### π― Bowling Career Summary")
|
| 229 |
-
bowling_summary = []
|
| 230 |
-
for fmt in formats:
|
| 231 |
-
bowling_summary.append({
|
| 232 |
-
"Format": fmt,
|
| 233 |
-
p1_name: p1_data.get(f'bowling_{fmt}_Wickets', 0),
|
| 234 |
-
p2_name: p2_data.get(f'bowling_{fmt}_Wickets', 0)
|
| 235 |
})
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
title=f"{stat} Achievements Comparison")
|
| 274 |
st.plotly_chart(fig, use_container_width=True)
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
fig = px.pie(values=
|
| 283 |
-
title=f"{
|
| 284 |
st.plotly_chart(fig, use_container_width=True)
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
sns.barplot(x=formats,
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
st.pyplot(fig)
|
| 299 |
-
|
| 300 |
-
|
| 301 |
|
|
|
|
| 150 |
st.plotly_chart(fig5)
|
| 151 |
|
| 152 |
|
| 153 |
+
# if page == "Player Comparision(π§ββοΈ vs π§ββοΈ)":
|
| 154 |
+
# st.title("π Player Recognition & Performance Analysis")
|
| 155 |
+
# player_stats_df = pd.read_csv("final_cricket_dataset.csv")
|
| 156 |
+
# model = joblib.load("svc_face_classifier.pkl")
|
| 157 |
+
# label_encoder = joblib.load("label_encoder.pkl")
|
| 158 |
+
# face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 159 |
+
|
| 160 |
+
# # Streamlit Page Setup
|
| 161 |
+
|
| 162 |
+
# # Image Preprocessing + Face Detection Function
|
| 163 |
+
# def detect_and_predict_face(image_file):
|
| 164 |
+
# image = Image.open(image_file).convert("RGB")
|
| 165 |
+
# img_np = np.array(image)
|
| 166 |
+
# gray = cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)
|
| 167 |
+
|
| 168 |
+
# faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
| 169 |
+
# if len(faces) == 0:
|
| 170 |
+
# return None, "No face detected!"
|
| 171 |
+
|
| 172 |
+
# x, y, w, h = faces[0]
|
| 173 |
+
# face = gray[y:y+h, x:x+w]
|
| 174 |
+
# resized_face = cv2.resize(face, (64, 64))
|
| 175 |
+
# flattened = resized_face.flatten().reshape(1, -1)
|
| 176 |
+
|
| 177 |
+
# pred_label = model.predict(flattened)[0]
|
| 178 |
+
# pred_name = label_encoder.inverse_transform([pred_label])[0]
|
| 179 |
+
# return pred_name, None
|
| 180 |
+
|
| 181 |
+
# # Upload images
|
| 182 |
+
# col1, col2 = st.columns(2)
|
| 183 |
+
# with col1:
|
| 184 |
+
# img1 = st.file_uploader("Upload First Player Image", type=["jpg", "png", "jpeg"], key="img1")
|
| 185 |
+
# with col2:
|
| 186 |
+
# img2 = st.file_uploader("Upload Second Player Image", type=["jpg", "png", "jpeg"], key="img2")
|
| 187 |
+
|
| 188 |
+
# if img1 and img2:
|
| 189 |
+
# p1_name, err1 = detect_and_predict_face(img1)
|
| 190 |
+
# p2_name, err2 = detect_and_predict_face(img2)
|
| 191 |
+
|
| 192 |
+
# if err1:
|
| 193 |
+
# st.error(f"Image 1: {err1}")
|
| 194 |
+
# if err2:
|
| 195 |
+
# st.error(f"Image 2: {err2}")
|
| 196 |
+
|
| 197 |
+
# if not err1 and not err2:
|
| 198 |
+
# st.success(f"β
Player 1 Detected: {p1_name}")
|
| 199 |
+
# st.success(f"β
Player 2 Detected: {p2_name}")
|
| 200 |
+
|
| 201 |
+
# formats = ['Test', 'ODI', 'T20', 'IPL']
|
| 202 |
+
# df = player_stats_df
|
| 203 |
+
# players = [p1_name, p2_name]
|
| 204 |
+
|
| 205 |
+
# if p1_name not in df['Label'].values or p2_name not in df['Label'].values:
|
| 206 |
+
# st.error("One or both players not found in dataset.")
|
| 207 |
+
# st.stop()
|
| 208 |
+
|
| 209 |
+
# p1_data = df[df['Label'] == p1_name].iloc[0]
|
| 210 |
+
# p2_data = df[df['Label'] == p2_name].iloc[0]
|
| 211 |
+
|
| 212 |
+
# st.markdown("## π Comparative Stats")
|
| 213 |
+
|
| 214 |
+
# # Batting Summary
|
| 215 |
+
# st.markdown("### π Batting Career Summary")
|
| 216 |
+
# batting_summary = []
|
| 217 |
+
# for fmt in formats:
|
| 218 |
+
# batting_summary.append({
|
| 219 |
+
# "Format": fmt,
|
| 220 |
+
# p1_name: p1_data.get(f'batting_Runs_{fmt}', 0),
|
| 221 |
+
# p2_name: p2_data.get(f'batting_Runs_{fmt}', 0)
|
| 222 |
+
# })
|
| 223 |
+
# batting_df = pd.DataFrame(batting_summary)
|
| 224 |
+
# fig = px.bar(batting_df, x="Format", y=[p1_name, p2_name], barmode="group", title="Total Runs by Format")
|
| 225 |
+
# st.plotly_chart(fig, use_container_width=True)
|
| 226 |
+
|
| 227 |
+
# # Bowling Summary
|
| 228 |
+
# st.markdown("### π― Bowling Career Summary")
|
| 229 |
+
# bowling_summary = []
|
| 230 |
+
# for fmt in formats:
|
| 231 |
+
# bowling_summary.append({
|
| 232 |
+
# "Format": fmt,
|
| 233 |
+
# p1_name: p1_data.get(f'bowling_{fmt}_Wickets', 0),
|
| 234 |
+
# p2_name: p2_data.get(f'bowling_{fmt}_Wickets', 0)
|
| 235 |
+
# })
|
| 236 |
+
# bowling_df = pd.DataFrame(bowling_summary)
|
| 237 |
+
# fig = px.bar(bowling_df, x="Format", y=[p1_name, p2_name], barmode="group", title="Total Wickets by Format")
|
| 238 |
+
# st.plotly_chart(fig, use_container_width=True)
|
| 239 |
+
|
| 240 |
+
# # Strike Rate vs Runs
|
| 241 |
+
# st.markdown("### β‘ Strike Rate vs Runs")
|
| 242 |
+
# data = {
|
| 243 |
+
# "Format": formats,
|
| 244 |
+
# f"{p1_name} Runs": [p1_data.get(f'batting_Runs_{fmt}', 0) for fmt in formats],
|
| 245 |
+
# f"{p1_name} SR": [p1_data.get(f'batting_SR_{fmt}', 0) for fmt in formats],
|
| 246 |
+
# f"{p2_name} Runs": [p2_data.get(f'batting_Runs_{fmt}', 0) for fmt in formats],
|
| 247 |
+
# f"{p2_name} SR": [p2_data.get(f'batting_SR_{fmt}', 0) for fmt in formats],
|
| 248 |
+
# }
|
| 249 |
+
|
| 250 |
+
# fig = px.scatter(x=data[f"{p1_name} Runs"] + data[f"{p2_name} Runs"],
|
| 251 |
+
# y=data[f"{p1_name} SR"] + data[f"{p2_name} SR"],
|
| 252 |
+
# color=["Player 1"] * 4 + ["Player 2"] * 4,
|
| 253 |
+
# text=formats * 2,
|
| 254 |
+
# labels={"x": "Runs", "y": "Strike Rate"},
|
| 255 |
+
# title="Runs vs Strike Rate Comparison")
|
| 256 |
+
# st.plotly_chart(fig, use_container_width=True)
|
| 257 |
+
|
| 258 |
+
# # Milestones
|
| 259 |
+
# st.markdown("### π Milestone Comparison")
|
| 260 |
+
# milestone_df = pd.DataFrame({
|
| 261 |
+
# "Format": formats * 2,
|
| 262 |
+
# "Player": [p1_name] * 4 + [p2_name] * 4,
|
| 263 |
+
# "50s": [p1_data.get(f"batting_50s_{fmt}", 0) for fmt in formats] +
|
| 264 |
+
# [p2_data.get(f"batting_50s_{fmt}", 0) for fmt in formats],
|
| 265 |
+
# "100s": [p1_data.get(f"batting_100s_{fmt}", 0) for fmt in formats] +
|
| 266 |
+
# [p2_data.get(f"batting_100s_{fmt}", 0) for fmt in formats],
|
| 267 |
+
# "200s": [p1_data.get(f"batting_200s_{fmt}", 0) for fmt in formats] +
|
| 268 |
+
# [p2_data.get(f"batting_200s_{fmt}", 0) for fmt in formats]
|
| 269 |
+
# })
|
| 270 |
+
|
| 271 |
+
# for stat in ['50s', '100s', '200s']:
|
| 272 |
+
# fig = px.bar(milestone_df, x="Format", y=stat, color="Player", barmode="group",
|
| 273 |
+
# title=f"{stat} Achievements Comparison")
|
| 274 |
+
# st.plotly_chart(fig, use_container_width=True)
|
| 275 |
+
|
| 276 |
+
# # Pie Chart - Matches Played
|
| 277 |
+
# st.markdown("### π§© Matches Played by Format")
|
| 278 |
+
# for i, data_player in enumerate([p1_data, p2_data]):
|
| 279 |
+
# match_data = {
|
| 280 |
+
# fmt: data_player.get(f"Matches_{fmt}", 0) for fmt in formats
|
| 281 |
+
# }
|
| 282 |
+
# fig = px.pie(values=list(match_data.values()), names=list(match_data.keys()),
|
| 283 |
+
# title=f"{players[i]} Matches Distribution")
|
| 284 |
+
# st.plotly_chart(fig, use_container_width=True)
|
| 285 |
+
|
| 286 |
+
# # Final Trend Overview
|
| 287 |
+
# st.markdown("### π Trend Overview")
|
| 288 |
+
# fig, ax = plt.subplots(1, 2, figsize=(14, 5))
|
| 289 |
+
# sns.barplot(x=formats, y=[p1_data.get(f'batting_Runs_{fmt}', 0) for fmt in formats], ax=ax[0], label=p1_name)
|
| 290 |
+
# sns.barplot(x=formats, y=[p2_data.get(f'batting_Runs_{fmt}', 0) for fmt in formats], ax=ax[0], label=p2_name)
|
| 291 |
+
# ax[0].set_title("Batting Runs Trend")
|
| 292 |
+
# ax[0].legend()
|
| 293 |
+
|
| 294 |
+
# sns.barplot(x=formats, y=[p1_data.get(f'bowling_{fmt}_Wickets', 0) for fmt in formats], ax=ax[1], label=p1_name)
|
| 295 |
+
# sns.barplot(x=formats, y=[p2_data.get(f'bowling_{fmt}_Wickets', 0) for fmt in formats], ax=ax[1], label=p2_name)
|
| 296 |
+
# ax[1].set_title("Bowling Wickets Trend")
|
| 297 |
+
# ax[1].legend()
|
| 298 |
+
# st.pyplot(fig)
|
| 299 |
+
|
| 300 |
+
elif page == "Player Comparision(π§ββοΈ vs π§ββοΈ)":
|
| 301 |
st.title("π Player Recognition & Performance Analysis")
|
| 302 |
player_stats_df = pd.read_csv("final_cricket_dataset.csv")
|
| 303 |
model = joblib.load("svc_face_classifier.pkl")
|
| 304 |
label_encoder = joblib.load("label_encoder.pkl")
|
| 305 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 306 |
+
|
|
|
|
|
|
|
|
|
|
| 307 |
def detect_and_predict_face(image_file):
|
| 308 |
image = Image.open(image_file).convert("RGB")
|
| 309 |
img_np = np.array(image)
|
| 310 |
gray = cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)
|
|
|
|
| 311 |
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
| 312 |
+
|
| 313 |
if len(faces) == 0:
|
| 314 |
return None, "No face detected!"
|
| 315 |
+
|
| 316 |
x, y, w, h = faces[0]
|
| 317 |
face = gray[y:y+h, x:x+w]
|
| 318 |
+
resized = cv2.resize(face, (64, 64))
|
| 319 |
+
flat = resized.flatten().reshape(1, -1)
|
| 320 |
+
|
| 321 |
+
pred = model.predict(flat)[0]
|
| 322 |
+
name = label_encoder.inverse_transform([pred])[0]
|
| 323 |
+
return name, None
|
| 324 |
+
|
|
|
|
| 325 |
col1, col2 = st.columns(2)
|
| 326 |
+
img1 = col1.file_uploader("Upload First Player Image", type=["jpg", "jpeg", "png"], key="img1")
|
| 327 |
+
img2 = col2.file_uploader("Upload Second Player Image", type=["jpg", "jpeg", "png"], key="img2")
|
| 328 |
+
|
|
|
|
|
|
|
| 329 |
if img1 and img2:
|
| 330 |
p1_name, err1 = detect_and_predict_face(img1)
|
| 331 |
p2_name, err2 = detect_and_predict_face(img2)
|
| 332 |
+
|
| 333 |
+
if err1: st.error(f"Image 1: {err1}")
|
| 334 |
+
if err2: st.error(f"Image 2: {err2}")
|
| 335 |
+
|
|
|
|
|
|
|
| 336 |
if not err1 and not err2:
|
| 337 |
st.success(f"β
Player 1 Detected: {p1_name}")
|
| 338 |
st.success(f"β
Player 2 Detected: {p2_name}")
|
| 339 |
+
|
| 340 |
+
df = player_stats_df.copy()
|
|
|
|
|
|
|
|
|
|
| 341 |
if p1_name not in df['Label'].values or p2_name not in df['Label'].values:
|
| 342 |
st.error("One or both players not found in dataset.")
|
| 343 |
st.stop()
|
| 344 |
+
|
| 345 |
p1_data = df[df['Label'] == p1_name].iloc[0]
|
| 346 |
p2_data = df[df['Label'] == p2_name].iloc[0]
|
| 347 |
+
|
| 348 |
+
st.write("### π Player Data Preview")
|
| 349 |
+
st.write(p1_data)
|
| 350 |
+
st.write(p2_data)
|
| 351 |
+
|
| 352 |
+
formats = ['Test', 'ODI', 'T20', 'IPL']
|
| 353 |
+
|
| 354 |
+
def plot_bar(compare_col, title, y_label):
|
| 355 |
+
vals1 = [p1_data.get(f"{compare_col}_{fmt}", 0) for fmt in formats]
|
| 356 |
+
vals2 = [p2_data.get(f"{compare_col}_{fmt}", 0) for fmt in formats]
|
| 357 |
+
df_plot = pd.DataFrame({
|
| 358 |
+
"Format": formats,
|
| 359 |
+
p1_name: vals1,
|
| 360 |
+
p2_name: vals2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
})
|
| 362 |
+
if df_plot[[p1_name, p2_name]].sum().sum() == 0:
|
| 363 |
+
st.warning(f"No data to plot for {title}.")
|
| 364 |
+
return
|
| 365 |
+
try:
|
| 366 |
+
fig = px.bar(df_plot, x="Format", y=[p1_name, p2_name], barmode="group", title=title)
|
| 367 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 368 |
+
except Exception as e:
|
| 369 |
+
st.error(f"Could not render {title}: {e}")
|
| 370 |
+
|
| 371 |
+
st.markdown("## π Comparative Stats")
|
| 372 |
+
st.subheader("π‘οΈ Batting β Total Runs by Format")
|
| 373 |
+
plot_bar("batting_Runs", "Total Runs by Format", "Runs")
|
| 374 |
+
st.subheader("π― Bowling β Total Wickets by Format")
|
| 375 |
+
plot_bar("bowling_Wickets", "Total Wickets by Format", "Wickets")
|
| 376 |
+
|
| 377 |
+
st.subheader("β‘ Runs vs Strike Rate Scatter")
|
| 378 |
+
|
| 379 |
+
data_pts = []
|
| 380 |
+
for player, pdata in [(p1_name, p1_data), (p2_name, p2_data)]:
|
| 381 |
+
runs = [pdata.get(f"batting_Runs_{fmt}", 0) for fmt in formats]
|
| 382 |
+
sr = [pdata.get(f"batting_SR_{fmt}", 0) for fmt in formats]
|
| 383 |
+
for fmt, r, s in zip(formats, runs, sr):
|
| 384 |
+
data_pts.append({
|
| 385 |
+
"Player": player,
|
| 386 |
+
"Format": fmt,
|
| 387 |
+
"Runs": r,
|
| 388 |
+
"Strike Rate": s
|
| 389 |
+
})
|
| 390 |
+
scatter_df = pd.DataFrame(data_pts)
|
| 391 |
+
if scatter_df[['Runs', 'Strike Rate']].sum().sum() == 0:
|
| 392 |
+
st.warning("Not enough data for scatter plot.")
|
| 393 |
+
else:
|
| 394 |
+
fig = px.scatter(scatter_df, x="Runs", y="Strike Rate",
|
| 395 |
+
color="Player", text="Format",
|
| 396 |
+
title="Runs vs Strike Rate Comparison",
|
| 397 |
+
labels={"Runs": "Runs", "Strike Rate": "Strike Rate"})
|
| 398 |
+
fig.update_traces(textposition='top center')
|
| 399 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 400 |
+
|
| 401 |
+
st.subheader("π Milestone Comparison")
|
| 402 |
+
milestone_data = []
|
| 403 |
+
for player, pdata in [(p1_name, p1_data), (p2_name, p2_data)]:
|
| 404 |
+
for fmt in formats:
|
| 405 |
+
milestone_data.append({
|
| 406 |
+
"Player": player,
|
| 407 |
+
"Format": fmt,
|
| 408 |
+
"50s": pdata.get(f"batting_50s_{fmt}", 0),
|
| 409 |
+
"100s": pdata.get(f"batting_100s_{fmt}", 0),
|
| 410 |
+
"200s": pdata.get(f"batting_200s_{fmt}", 0)
|
| 411 |
+
})
|
| 412 |
+
ms_df = pd.DataFrame(milestone_data)
|
| 413 |
+
for stat in ["50s", "100s", "200s"]:
|
| 414 |
+
fig = px.bar(ms_df, x="Format", y=stat,
|
| 415 |
+
color="Player", barmode="group",
|
| 416 |
title=f"{stat} Achievements Comparison")
|
| 417 |
st.plotly_chart(fig, use_container_width=True)
|
| 418 |
+
|
| 419 |
+
st.subheader("π§© Matches Distribution by Format")
|
| 420 |
+
for player, pdata in [(p1_name, p1_data), (p2_name, p2_data)]:
|
| 421 |
+
match_counts = [pdata.get(f"Matches_{fmt}", 0) for fmt in formats]
|
| 422 |
+
if sum(match_counts) == 0:
|
| 423 |
+
st.warning(f"No match data for {player}.")
|
| 424 |
+
continue
|
| 425 |
+
fig = px.pie(values=match_counts, names=formats,
|
| 426 |
+
title=f"{player} β Matches Distribution")
|
| 427 |
st.plotly_chart(fig, use_container_width=True)
|
| 428 |
+
|
| 429 |
+
st.subheader("π Final Trends Overview")
|
| 430 |
+
fig, axes = plt.subplots(1, 2, figsize=(14, 5))
|
| 431 |
+
sns.set_theme(style="whitegrid")
|
| 432 |
+
|
| 433 |
+
sns.barplot(x=formats,
|
| 434 |
+
y=[p1_data.get(f"batting_Runs_{fmt}", 0) for fmt in formats],
|
| 435 |
+
ax=axes[0], label=p1_name, color="b", alpha=0.6)
|
| 436 |
+
sns.barplot(x=formats,
|
| 437 |
+
y=[p2_data.get(f"batting_Runs_{fmt}", 0) for fmt in formats],
|
| 438 |
+
ax=axes[0], label=p2_name, color="r", alpha=0.6)
|
| 439 |
+
axes[0].set_title("Batting Runs Trend")
|
| 440 |
+
axes[0].legend()
|
| 441 |
+
|
| 442 |
+
sns.barplot(x=formats,
|
| 443 |
+
y=[p1_data.get(f"bowling_Test_Wickets", 0) for fmt in formats],
|
| 444 |
+
ax=axes[1], label=p1_name, color="b", alpha=0.6)
|
| 445 |
+
sns.barplot(x=formats,
|
| 446 |
+
y=[p2_data.get(f"bowling_Test_Wickets", 0) for fmt in formats],
|
| 447 |
+
ax=axes[1], label=p2_name, color="r", alpha=0.6)
|
| 448 |
+
axes[1].set_title("Bowling Wickets Trend")
|
| 449 |
+
axes[1].legend()
|
| 450 |
+
|
| 451 |
st.pyplot(fig)
|
| 452 |
+
|
|
|
|
| 453 |
|