trohith89 commited on
Commit
bcdaf69
·
verified ·
1 Parent(s): 626c2e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py CHANGED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)