Update app.py
Browse files
app.py
CHANGED
|
@@ -1,100 +1,156 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
-
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
st.set_page_config(page_title="BowLChaL", layout="wide")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
def load_data():
|
| 12 |
-
data_path = Path(__file__).parent / "data"
|
| 13 |
-
batting_df = pd.read_csv(data_path / "batting_stats.csv")
|
| 14 |
-
bowling_df = pd.read_csv(data_path / "bowling_stats.csv")
|
| 15 |
-
return batting_df, bowling_df
|
| 16 |
-
|
| 17 |
-
batting_df, bowling_df = load_data()
|
| 18 |
-
|
| 19 |
-
# Title with animation
|
| 20 |
-
st.markdown(
|
| 21 |
-
"""
|
| 22 |
-
<h1 style='text-align: center; font-size: 60px; color: #4CAF50;'>
|
| 23 |
-
BowLChaL
|
| 24 |
-
</h1>
|
| 25 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
@keyframes fadeIn {
|
| 27 |
-
0% {opacity: 0;}
|
| 28 |
-
100% {opacity: 1;}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
</style>
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
for index, team in enumerate(teams):
|
| 46 |
-
with cols[index % 5]:
|
| 47 |
-
if st.button(team):
|
| 48 |
-
selected_team = team
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
player_bowling_stats = bowling_df[bowling_df['Player'] == selected_player]
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
('All Stats', 'Batting Stats', 'Bowling Stats')
|
| 68 |
-
)
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
labels={'Runs': 'Runs Scored', 'Matches': 'Match Number'},
|
| 82 |
-
color_discrete_sequence=['#1f77b4']
|
| 83 |
-
)
|
| 84 |
-
st.plotly_chart(fig)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
# Streamlit App Configuration
|
| 7 |
+
st.set_page_config(page_title="BowLChaL - Cricket Dashboard", layout="wide")
|
| 8 |
|
| 9 |
+
# Custom CSS for animations and transitions
|
| 10 |
+
st.markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
<style>
|
| 12 |
+
/* General Styling */
|
| 13 |
+
body {
|
| 14 |
+
background-color: #f0f2f6;
|
| 15 |
+
font-family: 'Arial', sans-serif;
|
| 16 |
+
}
|
| 17 |
+
.title {
|
| 18 |
+
font-size: 3.5rem;
|
| 19 |
+
font-weight: bold;
|
| 20 |
+
color: #2c3e50;
|
| 21 |
+
text-align: center;
|
| 22 |
+
margin-bottom: 2rem;
|
| 23 |
+
animation: fadeInDown 1s ease-in-out;
|
| 24 |
+
}
|
| 25 |
+
.subheader {
|
| 26 |
+
font-size: 1.8rem;
|
| 27 |
+
color: #34495e;
|
| 28 |
+
margin-top: 2rem;
|
| 29 |
+
animation: fadeIn 1.5s ease-in-out;
|
| 30 |
+
}
|
| 31 |
+
.data-container {
|
| 32 |
+
background: linear-gradient(135deg, #ffffff, #e6ecf0);
|
| 33 |
+
border-radius: 15px;
|
| 34 |
+
padding: 20px;
|
| 35 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
| 36 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 37 |
+
margin-bottom: 2rem;
|
| 38 |
+
}
|
| 39 |
+
.data-container:hover {
|
| 40 |
+
transform: translateY(-10px);
|
| 41 |
+
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
|
| 42 |
+
}
|
| 43 |
+
.select-box {
|
| 44 |
+
display: flex;
|
| 45 |
+
justify-content: center;
|
| 46 |
+
gap: 2rem;
|
| 47 |
+
margin-bottom: 2rem;
|
| 48 |
+
animation: slideInUp 1s ease-in-out;
|
| 49 |
+
}
|
| 50 |
+
.stSelectbox > div > div {
|
| 51 |
+
background-color: #3498db;
|
| 52 |
+
color: white;
|
| 53 |
+
border-radius: 10px;
|
| 54 |
+
padding: 10px;
|
| 55 |
+
transition: background-color 0.3s ease;
|
| 56 |
+
}
|
| 57 |
+
.stSelectbox > div > div:hover {
|
| 58 |
+
background-color: #2980b9;
|
| 59 |
+
}
|
| 60 |
+
/* Animations */
|
| 61 |
+
@keyframes fadeInDown {
|
| 62 |
+
0% { opacity: 0; transform: translateY(-20px); }
|
| 63 |
+
100% { opacity: 1; transform: translateY(0); }
|
| 64 |
+
}
|
| 65 |
@keyframes fadeIn {
|
| 66 |
+
0% { opacity: 0; }
|
| 67 |
+
100% { opacity: 1; }
|
| 68 |
+
}
|
| 69 |
+
@keyframes slideInUp {
|
| 70 |
+
0% { opacity: 0; transform: translateY(20px); }
|
| 71 |
+
100% { opacity: 1; transform: translateY(0); }
|
| 72 |
}
|
| 73 |
+
/* Dataframe Styling */
|
| 74 |
+
.stDataFrame {
|
| 75 |
+
border-radius: 10px;
|
| 76 |
+
overflow: hidden;
|
| 77 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 78 |
}
|
| 79 |
</style>
|
| 80 |
+
""", unsafe_allow_html=True)
|
| 81 |
+
|
| 82 |
+
# Create a folder to save CSVs if not exists
|
| 83 |
+
data_folder = "data"
|
| 84 |
+
os.makedirs(data_folder, exist_ok=True)
|
| 85 |
|
| 86 |
+
# File paths
|
| 87 |
+
batting_path = "Batting_10_Teams_Final.csv"
|
| 88 |
+
bowling_path = "Bowling_10_Teams_Final.csv"
|
| 89 |
|
| 90 |
+
# Load saved CSVs
|
| 91 |
+
batting_df = pd.read_csv(batting_path)
|
| 92 |
+
bowling_df = pd.read_csv(bowling_path)
|
| 93 |
|
| 94 |
+
# Extract unique teams and players
|
| 95 |
+
teams = sorted(set(batting_df['Country'].unique()).union(bowling_df['Country'].unique()))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
# Team and Player Selection (Moved to main body)
|
| 98 |
+
st.markdown('<h1 class="title">BowLChaL</h1>', unsafe_allow_html=True)
|
| 99 |
+
col_team, col_player = st.columns(2)
|
| 100 |
+
with col_team:
|
| 101 |
+
team = st.selectbox("Select Team", teams, key="team_select")
|
| 102 |
+
with col_player:
|
| 103 |
+
batting_players = batting_df[batting_df['Country'] == team]['player_name'].unique()
|
| 104 |
+
bowling_players = bowling_df[bowling_df['Country'] == team]['player_name'].unique()
|
| 105 |
+
players = sorted(set(batting_players).union(bowling_players))
|
| 106 |
+
player = st.selectbox("Select Player", players, key="player_select")
|
| 107 |
|
| 108 |
+
# Filter data for the selected player
|
| 109 |
+
player_batting = batting_df[(batting_df['player_name'] == player) & (batting_df['Country'] == team)]
|
| 110 |
+
player_bowling = bowling_df[(bowling_df['player_name'] == player) & (bowling_df['Country'] == team)]
|
| 111 |
|
| 112 |
+
# Display Player Performance Dashboard
|
| 113 |
+
st.markdown(f'<h2 class="subheader">{player}\'s Performance Dashboard</h2>', unsafe_allow_html=True)
|
|
|
|
| 114 |
|
| 115 |
+
# Player Data Section
|
| 116 |
+
st.markdown('<div class="data-container">', unsafe_allow_html=True)
|
| 117 |
+
st.markdown('<h3 class="subheader">Player Data</h3>', unsafe_allow_html=True)
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
if len(player_batting) > 0:
|
| 120 |
+
st.write("### Batting Data")
|
| 121 |
+
st.dataframe(player_batting.iloc[:min(17, len(player_batting)), :17])
|
| 122 |
+
else:
|
| 123 |
+
st.write("No batting data available.")
|
| 124 |
|
| 125 |
+
if len(player_bowling) > 0:
|
| 126 |
+
st.write("### Bowling Data")
|
| 127 |
+
st.dataframe(player_bowling.iloc[:min(15, len(player_bowling)), :15])
|
| 128 |
+
else:
|
| 129 |
+
st.write("No bowling data available.")
|
| 130 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
# Batting Visualization
|
| 133 |
+
if not player_batting.empty:
|
| 134 |
+
st.markdown('<div class="data-container">', unsafe_allow_html=True)
|
| 135 |
+
st.markdown('<h3 class="subheader">Batting Stats</h3>', unsafe_allow_html=True)
|
| 136 |
+
col1, col2 = st.columns(2)
|
| 137 |
+
with col1:
|
| 138 |
+
fig_bat_runs = px.bar(player_batting, x='Format', y='Runs', color='Format', title='Runs by Format')
|
| 139 |
+
st.plotly_chart(fig_bat_runs, use_container_width=True)
|
| 140 |
+
with col2:
|
| 141 |
+
fig_bat_sr = px.line(player_batting, x='Format', y='SR', title='Strike Rate by Format')
|
| 142 |
+
st.plotly_chart(fig_bat_sr, use_container_width=True)
|
| 143 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 144 |
|
| 145 |
+
# Bowling Visualization
|
| 146 |
+
if not player_bowling.empty:
|
| 147 |
+
st.markdown('<div class="data-container">', unsafe_allow_html=True)
|
| 148 |
+
st.markdown('<h3 class="subheader">Bowling Stats</h3>', unsafe_allow_html=True)
|
| 149 |
+
col3, col4 = st.columns(2)
|
| 150 |
+
with col3:
|
| 151 |
+
fig_bowl_wickets = px.bar(player_bowling, x='Format', y='Wickets', color='Format', title='Wickets by Format')
|
| 152 |
+
st.plotly_chart(fig_bowl_wickets, use_container_width=True)
|
| 153 |
+
with col4:
|
| 154 |
+
fig_bowl_eco = px.line(player_bowling, x='Format', y='Eco', title='Economy Rate by Format')
|
| 155 |
+
st.plotly_chart(fig_bowl_eco, use_container_width=True)
|
| 156 |
+
st.markdown('</div>', unsafe_allow_html=True)
|