shwetashweta05 commited on
Commit
318cce1
·
verified ·
1 Parent(s): 9b5ef69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +117 -140
app.py CHANGED
@@ -3,147 +3,124 @@ import pandas as pd
3
  import plotly.express as px
4
  import plotly.graph_objects as go
5
 
6
- st.markdown("""
 
 
 
 
7
  <style>
8
- .stApp {
9
- background-color: #E3F2FD;
10
- }
11
- .title {
12
- text-align: center;
13
- font-size: 28px;
14
- font-weight: bold;
15
- color: #2C3E50;
16
- }
17
- .subtitle {
18
- text-align: center;
19
- font-size: 30px;
20
- font-weight: bold;
21
- color: #003366;
22
- margin-top: 10px;
23
- }
24
- .stButton > button {
25
- width: 100%;
26
- background-color: #1E88E5;
27
- color: white;
28
- font-size: 16px;
29
- font-weight: bold;
30
- border-radius: 6px;
31
- padding: 8px;
32
- transition: 0.3s;
33
- }
34
- .stButton > button:hover {
35
- background-color: #1565C0;
36
- }
37
- .result-box {
38
- text-align: center;
39
- font-size: 22px;
40
- font-weight: bold;
41
- color: white;
42
- padding: 15px;
43
- border-radius: 8px;
44
- margin-top: 20px;
45
- background-color: #388E3C;
46
- }
47
  </style>
48
- """, unsafe_allow_html=True)
49
-
50
- # Load dataset
51
- df = pd.read_csv("Cleaned_data.csv")
52
-
53
- st.markdown("<h1 class='title'>Player Performance Analysis</h1>", unsafe_allow_html=True)
54
-
55
- st.markdown("<hr style='border:1px solid #ddd;'>", unsafe_allow_html=True)
56
-
57
- default_player = "Virat Kohli"
58
- player_name = st.selectbox(
59
- "Select a Player:",
60
- df['Player'].unique(),
61
- index=list(df['Player'].unique()).index(default_player)
62
  )
63
 
64
- # Filter data for selected player
65
- player_data = df[df['Player'] == player_name].iloc[0]
66
- formats = ['Test', 'ODI', 'T20', 'IPL']
67
-
68
- st.markdown("<br>", unsafe_allow_html=True)
69
-
70
- st.markdown("<h3 class='title'>Batting Career Summary</h3>", unsafe_allow_html=True)
71
-
72
- batting_summary = []
73
-
74
- for fmt in formats:
75
- batting_summary.append([
76
- fmt,
77
- player_data[f'Matches_{fmt}'],
78
- player_data[f'batting_Innings_{fmt}'],
79
- player_data[f'batting_Runs_{fmt}'],
80
- player_data[f'batting_Balls_{fmt}'],
81
- player_data[f'batting_Highest_{fmt}'],
82
- player_data[f'batting_Average_{fmt}'],
83
- player_data[f'batting_SR_{fmt}'],
84
- player_data[f'batting_Not Out_{fmt}'],
85
- player_data[f'batting_Fours_{fmt}'],
86
- player_data[f'batting_Sixes_{fmt}'],
87
- player_data[f'batting_50s_{fmt}'],
88
- player_data[f'batting_100s_{fmt}'],
89
- player_data[f'batting_200s_{fmt}']
90
- ])
91
-
92
- batting_df = pd.DataFrame(batting_summary, columns=[
93
- 'Format', 'M', 'Inn', 'Runs', 'BF', 'HS', 'Avg', 'SR', 'NO', 'Fours', 'Sixes', '50s', '100s', '200s'
94
- ])
95
-
96
- st.dataframe(batting_df.style.set_properties(**{'text-align': 'center'}))
97
-
98
- st.markdown("<br>", unsafe_allow_html=True)
99
-
100
- st.markdown("<h3 class='title'>Bowling Career Summary</h3>", unsafe_allow_html=True)
101
-
102
- bowling_summary = []
103
-
104
- for fmt in formats:
105
- bowling_summary.append([
106
- fmt,
107
- player_data[f'Matches_{fmt}'],
108
- player_data[f'bowling_{fmt}_Innings'],
109
- player_data[f'bowling_{fmt}_Balls'],
110
- player_data[f'bowling_{fmt}_Runs'],
111
- player_data[f'bowling_{fmt}_Wickets'],
112
- player_data[f'bowling_{fmt}_Avg'],
113
- player_data[f'bowling_{fmt}_Eco'],
114
- player_data[f'bowling_{fmt}_SR'],
115
- player_data[f'bowling_{fmt}_BBI'],
116
- player_data[f'bowling_{fmt}_BBM'],
117
- player_data[f'bowling_{fmt}_5w'],
118
- player_data[f'bowling_{fmt}_10w']
119
- ])
120
-
121
- bowling_df = pd.DataFrame(bowling_summary, columns=[
122
- 'Format', 'M', 'Inn', 'B', 'Runs', 'Wkts', 'Avg', 'Econ', 'SR', 'BBI', 'BBM', '5w', '10w'
123
- ])
124
-
125
- st.dataframe(bowling_df.style.set_properties(**{'text-align': 'center'}))
126
-
127
- st.markdown("<hr style='border:1px solid #ddd;'>", unsafe_allow_html=True)
128
-
129
- st.markdown("<h2 class='title'>🌟 Advanced Performance Insights 🌟</h2>", unsafe_allow_html=True)
130
-
131
- fig1 = px.bar(
132
- batting_df, x="Format", y="Runs", title="🏏 Total Runs per Format",
133
- text_auto=True, color_discrete_sequence=["#1E90FF"], opacity=0.9
134
- )
135
- st.plotly_chart(fig1)
136
-
137
- fig2 = px.bar(
138
- bowling_df, x="Format", y="Wkts", title="🎯 Total Wickets per Format",
139
- text_auto=True, color_discrete_sequence=["#FF4500"], opacity=0.9
140
- )
141
- st.plotly_chart(fig2)
142
-
143
- fig3 = px.pie(
144
- names=["Centuries", "Fifties"],
145
- values=[batting_df["100s"].sum(), batting_df["50s"].sum()],
146
- title="🏆 Centuries vs Fifties Contribution",
147
- hole=0.3, color_discrete_sequence=["#5DADEC", "#FFB6C1", "#7FDBB6", "#FFD700", "#FFA07A", "#BA55D3"]
148
- )
149
- st.plotly_chart(fig3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import plotly.express as px
4
  import plotly.graph_objects as go
5
 
6
+ # --- Streamlit Page Styling ---
7
+ st.set_page_config(page_title="Cricket Dashboard", layout="wide")
8
+
9
+ st.markdown(
10
+ """
11
  <style>
12
+ .stApp { background: linear-gradient(to right, #eef2ff, #c7d2fe); color: #1f2937; }
13
+ .stTitle { text-align: center; color: #374151; font-size: 28px; font-weight: bold; }
14
+ .stSelectbox { background-color: white; border-radius: 8px; padding: 5px; }
15
+ .css-1cpxqw2 { border-radius: 12px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  </style>
17
+ """,
18
+ unsafe_allow_html=True
 
 
 
 
 
 
 
 
 
 
 
 
19
  )
20
 
21
+ st.markdown("<h1 class='stTitle'>Cricket Icons Dashboard</h1>", unsafe_allow_html=True)
22
+
23
+ # --- Load Datasets ---
24
+ batting_df = pd.read_csv("Teams_batting.csv")
25
+ bowling_df = pd.read_csv("team_bowling.csv")
26
+
27
+ # --- User Selection ---
28
+ teams = batting_df["Team"].unique()
29
+ selected_team = st.selectbox("Select a Team:", teams)
30
+ players = batting_df[batting_df["Team"] == selected_team]["Player"].unique()
31
+ selected_player = st.selectbox("Select a Player:", players)
32
+
33
+ # --- Filter Player Data ---
34
+ player_batting = batting_df[batting_df["Player"] == selected_player]
35
+ player_bowling = bowling_df[bowling_df["Player"] == selected_player]
36
+
37
+ st.markdown(f"<h2 class='stTitle'>{selected_player} - Batting Performance</h2>", unsafe_allow_html=True)
38
+ st.dataframe(player_batting)
39
+
40
+ st.markdown(f"<h2 class='stTitle'>{selected_player} - Bowling Performance</h2>", unsafe_allow_html=True)
41
+ st.dataframe(player_bowling)
42
+
43
+ st.markdown("<h2 class='stTitle'>Performance Insights</h2>", unsafe_allow_html=True)
44
+
45
+ # --- Batting Performance Visualizations ---
46
+ if not player_batting.empty:
47
+ fig_runs = px.bar(
48
+ player_batting, x="Cricket Matches", y=["Matches", "Innings"],
49
+ title=f"{selected_player} - Matches & Innings", barmode="group", text_auto=True,
50
+ color_discrete_sequence=["#1E90FF"]
51
+ )
52
+ st.plotly_chart(fig_runs)
53
+
54
+ fig_scores = px.bar(
55
+ player_batting, x="Cricket Matches", y=["Runs", "Balls"],
56
+ title=f"{selected_player} - Runs & Balls Faced", barmode="group", text_auto=True,
57
+ color_discrete_sequence=["#FFA500"]
58
+ )
59
+ st.plotly_chart(fig_scores)
60
+
61
+ fig_boundaries = go.Figure()
62
+ fig_boundaries.add_trace(go.Bar(
63
+ name="Fours", x=player_batting["Cricket Matches"], y=player_batting["Fours"],
64
+ marker=dict(color="lime", line=dict(width=2, color="black"))
65
+ ))
66
+ fig_boundaries.add_trace(go.Bar(
67
+ name="Sixes", x=player_batting["Cricket Matches"], y=player_batting["Sixes"],
68
+ marker=dict(color="purple", line=dict(width=2, color="black"))
69
+ ))
70
+ fig_boundaries.update_layout(title=f"{selected_player} - Fours & Sixes", barmode="group")
71
+ st.plotly_chart(fig_boundaries)
72
+
73
+ fig_centuries = px.pie(
74
+ names=["50s", "100s", "200s", "300s", "400s"],
75
+ values=[player_batting["50s"].sum(), player_batting["100s"].sum(), player_batting["200s"].sum(), player_batting["300s"].sum(), player_batting["400s"].sum()],
76
+ title=f"{selected_player} - Milestone Contributions",
77
+ hole=0.3, color_discrete_sequence=["#5DADEC", "#FFB6C1", "#FFD700", "#BA55D3", "#FFA07A"]
78
+ )
79
+ st.plotly_chart(fig_centuries)
80
+
81
+ # --- Strike Rate Chart ---
82
+ if "SR" in player_batting.columns:
83
+ fig_sr = go.Figure()
84
+ fig_sr.add_trace(
85
+ go.Scatter(
86
+ x=player_batting["Cricket Matches"], y=player_batting["SR"], mode='lines+markers',
87
+ marker=dict(size=10, color='blue', symbol="diamond", line=dict(color='black', width=2)),
88
+ line=dict(width=3, dash="dashdot", color='blue'), name="Strike Rate"
89
+ )
90
+ )
91
+ max_sr_idx = player_batting["SR"].idxmax()
92
+ fig_sr.add_annotation(
93
+ x=player_batting["Cricket Matches"].iloc[max_sr_idx], y=player_batting["SR"].iloc[max_sr_idx],
94
+ text=f"🔥 Highest SR: {player_batting['SR'].iloc[max_sr_idx]:.2f}",
95
+ showarrow=True, arrowhead=2, bgcolor="white"
96
+ )
97
+ fig_sr.update_layout(title="🚀 Strike Rate in Different Matches", xaxis_title="Matches", yaxis_title="Strike Rate")
98
+ st.plotly_chart(fig_sr)
99
+
100
+ # --- Bowling Performance Visualizations ---
101
+ if not player_bowling.empty:
102
+ fig_wickets = px.bar(
103
+ player_bowling, x="Cricket Matches", y=["Balls", "Maidens", "Wickets", "4w", "5w", "10w"],
104
+ title=f"{selected_player} - Bowling Statistics", barmode="group", text_auto=True,
105
+ color_discrete_sequence=["#FF4500"]
106
+ )
107
+ st.plotly_chart(fig_wickets)
108
+
109
+ # --- Bowling Economy Chart ---
110
+ if "Econ" in player_bowling.columns:
111
+ fig_econ = go.Figure()
112
+ fig_econ.add_trace(
113
+ go.Scatter(
114
+ name="Economy Rate", x=player_bowling["Cricket Matches"], y=player_bowling["Econ"], mode="lines+markers",
115
+ marker=dict(color="red", size=12, symbol="star", line=dict(color="black", width=2)),
116
+ line=dict(width=3, dash="dot", color="red")
117
+ )
118
+ )
119
+ min_econ_idx = player_bowling["Econ"].idxmin()
120
+ fig_econ.add_annotation(
121
+ x=player_bowling["Cricket Matches"].iloc[min_econ_idx], y=player_bowling["Econ"].iloc[min_econ_idx],
122
+ text=f"🎯 Best Economy: {player_bowling['Econ'].iloc[min_econ_idx]:.2f}",
123
+ showarrow=True, arrowhead=2, bgcolor="white"
124
+ )
125
+ fig_econ.update_layout(title="🎯 Bowling Economy Comparison", xaxis_title="Matches", yaxis_title="Economy Rate")
126
+ st.plotly_chart(fig_econ)