Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,7 +142,18 @@ if option == "Team Info" and team_info:
|
|
| 142 |
st.subheader(f"{team_info} Format-wise Statistics")
|
| 143 |
team_stats = combined_stats_df[combined_stats_df['Team'] == team_info]
|
| 144 |
st.dataframe(team_stats.reset_index(drop=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
|
|
|
| 146 |
elif option == "Team Stats Comparison" and selected_teams_stats:
|
| 147 |
st.title("Team Stats Comparison")
|
| 148 |
odi_df['Format'] = 'ODI'
|
|
@@ -165,16 +176,31 @@ elif option == "Team Stats Comparison" and selected_teams_stats:
|
|
| 165 |
}
|
| 166 |
stat_choice = st.selectbox("Select Stat to Compare", list(stat_options.keys()), format_func=lambda x: stat_options[x])
|
| 167 |
|
|
|
|
| 168 |
fig = px.bar(
|
| 169 |
selected_data,
|
| 170 |
x='Team',
|
| 171 |
y=stat_choice,
|
| 172 |
-
color='
|
| 173 |
barmode='group',
|
| 174 |
title=f"{stat_options[stat_choice]} by Team in {selected_format}"
|
| 175 |
)
|
| 176 |
st.plotly_chart(fig, use_container_width=True)
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
elif option == "Player Stats" and selected_player:
|
| 180 |
st.title(f"Player Dashboard - {selected_player}")
|
|
@@ -215,6 +241,7 @@ elif option == "Player Stats" and selected_player:
|
|
| 215 |
st.plotly_chart(px.line(player_bowling, x='Format', y='Eco'))
|
| 216 |
st.plotly_chart(px.pie(player_bowling, values='Wickets', names='Format'))
|
| 217 |
|
|
|
|
| 218 |
elif option == "Player Comparison" and player1 and player2:
|
| 219 |
st.title(f"Player Comparison: {player1} vs {player2}")
|
| 220 |
|
|
@@ -228,7 +255,30 @@ elif option == "Player Comparison" and player1 and player2:
|
|
| 228 |
bat2, bowl2 = get_player_data(player2)
|
| 229 |
|
| 230 |
st.subheader("Batting Comparison")
|
| 231 |
-
|
|
|
|
| 232 |
|
| 233 |
st.subheader("Bowling Comparison")
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
st.subheader(f"{team_info} Format-wise Statistics")
|
| 143 |
team_stats = combined_stats_df[combined_stats_df['Team'] == team_info]
|
| 144 |
st.dataframe(team_stats.reset_index(drop=True))
|
| 145 |
+
st.subheader(f"{team_info} Format-wise Statistics")
|
| 146 |
+
|
| 147 |
+
if st.button("Show Format-wise Visualizations"):
|
| 148 |
+
st.plotly_chart(px.bar(team_stats, x='Format', y='Mat', color='Format', title="Matches by Format"))
|
| 149 |
+
st.plotly_chart(px.pie(team_stats, values='Won', names='Format', title="Win Distribution by Format"))
|
| 150 |
+
st.plotly_chart(px.line(team_stats, x='Format', y='W/L', title="Win/Loss Ratio by Format"))
|
| 151 |
+
|
| 152 |
+
# if st.button("Show Raw Data"):
|
| 153 |
+
# st.dataframe(team_stats.reset_index(drop=True))
|
| 154 |
+
|
| 155 |
|
| 156 |
+
# 3. Team Stats Comparison
|
| 157 |
elif option == "Team Stats Comparison" and selected_teams_stats:
|
| 158 |
st.title("Team Stats Comparison")
|
| 159 |
odi_df['Format'] = 'ODI'
|
|
|
|
| 176 |
}
|
| 177 |
stat_choice = st.selectbox("Select Stat to Compare", list(stat_options.keys()), format_func=lambda x: stat_options[x])
|
| 178 |
|
| 179 |
+
st.subheader("\ud83d\udd39 Type 1: Bar Chart")
|
| 180 |
fig = px.bar(
|
| 181 |
selected_data,
|
| 182 |
x='Team',
|
| 183 |
y=stat_choice,
|
| 184 |
+
color='Team',
|
| 185 |
barmode='group',
|
| 186 |
title=f"{stat_options[stat_choice]} by Team in {selected_format}"
|
| 187 |
)
|
| 188 |
st.plotly_chart(fig, use_container_width=True)
|
| 189 |
+
|
| 190 |
+
st.subheader("\ud83d\udd39 Type 2: Win Percentage Pie Chart")
|
| 191 |
+
pie_data = selected_data[['Team', '%W']]
|
| 192 |
+
fig_pie = px.pie(pie_data, values='%W', names='Team', title='Win % Comparison')
|
| 193 |
+
st.plotly_chart(fig_pie)
|
| 194 |
+
|
| 195 |
+
st.subheader("\ud83d\udd39 Type 3: Radar Chart (Normalized)")
|
| 196 |
+
radar_data = selected_data[['Team', 'Won', 'Lost', 'Draw']].set_index('Team')
|
| 197 |
+
radar_data_norm = (radar_data - radar_data.min()) / (radar_data.max() - radar_data.min())
|
| 198 |
+
radar_data_norm.reset_index(inplace=True)
|
| 199 |
+
fig_radar = px.line_polar(radar_data_norm, r='Won', theta='Team', line_close=True, title='Normalized Team Stats (Radar)')
|
| 200 |
+
st.plotly_chart(fig_radar)
|
| 201 |
+
|
| 202 |
+
if st.button("Show Raw Data"):
|
| 203 |
+
st.dataframe(selected_data.reset_index(drop=True))
|
| 204 |
|
| 205 |
elif option == "Player Stats" and selected_player:
|
| 206 |
st.title(f"Player Dashboard - {selected_player}")
|
|
|
|
| 241 |
st.plotly_chart(px.line(player_bowling, x='Format', y='Eco'))
|
| 242 |
st.plotly_chart(px.pie(player_bowling, values='Wickets', names='Format'))
|
| 243 |
|
| 244 |
+
# 4. Player Comparison
|
| 245 |
elif option == "Player Comparison" and player1 and player2:
|
| 246 |
st.title(f"Player Comparison: {player1} vs {player2}")
|
| 247 |
|
|
|
|
| 255 |
bat2, bowl2 = get_player_data(player2)
|
| 256 |
|
| 257 |
st.subheader("Batting Comparison")
|
| 258 |
+
fig_bat = px.bar(pd.concat([bat1, bat2]), x='Format', y='Runs', color='player_name', barmode='group')
|
| 259 |
+
st.plotly_chart(fig_bat)
|
| 260 |
|
| 261 |
st.subheader("Bowling Comparison")
|
| 262 |
+
fig_bowl = px.bar(pd.concat([bowl1, bowl2]), x='Format', y='Wickets', color='player_name', barmode='group')
|
| 263 |
+
st.plotly_chart(fig_bowl)
|
| 264 |
+
|
| 265 |
+
st.subheader("Key Stats Radar")
|
| 266 |
+
key_stats = pd.DataFrame({
|
| 267 |
+
'Stat': ['Runs', 'Average', 'Strike Rate', 'Wickets', 'Economy'],
|
| 268 |
+
player1: [
|
| 269 |
+
bat1['Runs'].sum(), bat1['Ave'].mean(), bat1['SR'].mean(),
|
| 270 |
+
bowl1['Wickets'].sum(), bowl1['Eco'].mean()
|
| 271 |
+
],
|
| 272 |
+
player2: [
|
| 273 |
+
bat2['Runs'].sum(), bat2['Ave'].mean(), bat2['SR'].mean(),
|
| 274 |
+
bowl2['Wickets'].sum(), bowl2['Eco'].mean()
|
| 275 |
+
]
|
| 276 |
+
})
|
| 277 |
+
|
| 278 |
+
fig_radar = px.line_polar(key_stats, r=player1, theta='Stat', line_close=True, title=f'{player1} vs {player2} - Radar Chart')
|
| 279 |
+
fig_radar.add_scatterpolar(r=key_stats[player2], theta=key_stats['Stat'], line_close=True, name=player2)
|
| 280 |
+
st.plotly_chart(fig_radar)
|
| 281 |
+
|
| 282 |
+
if st.button("Show Raw Stats"):
|
| 283 |
+
st.dataframe(pd.concat([bat1, bowl1, bat2, bowl2]))
|
| 284 |
+
|