trohith89 commited on
Commit
4377ba1
·
verified ·
1 Parent(s): 3e6d172

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -79
app.py CHANGED
@@ -1,100 +1,156 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
- from pathlib import Path
5
 
6
- # Set page configuration
7
- st.set_page_config(page_title="BowLChaL", layout="wide")
8
 
9
- # Load datasets
10
- @st.cache
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
- h1 {
31
- animation: fadeIn 3s;
 
 
 
32
  }
33
  </style>
34
- """,
35
- unsafe_allow_html=True,
36
- )
 
 
37
 
38
- st.markdown("## Select a Team to View Player Statistics")
 
 
39
 
40
- # Extract unique teams
41
- teams = batting_df['Team'].unique()
 
42
 
43
- # Display teams in a grid layout with animations
44
- cols = st.columns(5)
45
- for index, team in enumerate(teams):
46
- with cols[index % 5]:
47
- if st.button(team):
48
- selected_team = team
49
 
50
- # If a team is selected, show player dropdown
51
- if 'selected_team' in locals():
52
- st.markdown(f"### Players in {selected_team}")
53
- team_players = batting_df[batting_df['Team'] == selected_team]['Player'].unique()
54
- selected_player = st.selectbox("Select a Player", team_players)
 
 
 
 
 
55
 
56
- # Display player stats and visualizations
57
- if selected_player:
58
- st.markdown(f"## {selected_player}'s Statistics")
59
 
60
- # Filter data for the selected player
61
- player_batting_stats = batting_df[batting_df['Player'] == selected_player]
62
- player_bowling_stats = bowling_df[bowling_df['Player'] == selected_player]
63
 
64
- # Option to select stats type
65
- stats_type = st.radio(
66
- "Choose Stats to Display",
67
- ('All Stats', 'Batting Stats', 'Bowling Stats')
68
- )
69
 
70
- # Display Batting Stats
71
- if stats_type in ['All Stats', 'Batting Stats']:
72
- st.markdown("### Batting Statistics")
73
- st.dataframe(player_batting_stats)
 
74
 
75
- # Example Plotly visualization for batting
76
- fig = px.bar(
77
- player_batting_stats,
78
- x='Matches',
79
- y='Runs',
80
- title=f'Runs per Match for {selected_player}',
81
- labels={'Runs': 'Runs Scored', 'Matches': 'Match Number'},
82
- color_discrete_sequence=['#1f77b4']
83
- )
84
- st.plotly_chart(fig)
85
 
86
- # Display Bowling Stats
87
- if stats_type in ['All Stats', 'Bowling Stats']:
88
- st.markdown("### Bowling Statistics")
89
- st.dataframe(player_bowling_stats)
 
 
 
 
 
 
 
 
90
 
91
- # Example Plotly visualization for bowling
92
- fig = px.line(
93
- player_bowling_stats,
94
- x='Matches',
95
- y='Wickets',
96
- title=f'Wickets per Match for {selected_player}',
97
- labels={'Wickets': 'Wickets Taken', 'Matches': 'Match Number'},
98
- color_discrete_sequence=['#ff7f0e']
99
- )
100
- st.plotly_chart(fig)
 
 
 
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)