Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T20 dashboard analysis #1316

Closed
Harshithasharma12 opened this issue Jan 10, 2025 · 0 comments
Closed

T20 dashboard analysis #1316

Harshithasharma12 opened this issue Jan 10, 2025 · 0 comments

Comments

@Harshithasharma12
Copy link

mport pandas as pd
from dash import Dash, dcc, html, Input, Output
import plotly.express as px

Load the data

data = pd.read_excel('davp dashboard dataset.xlsx')

Create the Dash app

app = Dash(name)

Create a list of unique teams for dropdowns

teams = pd.unique(data[['Team1', 'Team2']].values.ravel('K')).tolist() # Get unique teams from both columns

Layout of the dashboard

app.layout = html.Div([
html.H1("T20 Cricket Data Analytics Dashboard"),

# Dropdown for Team1
dcc.Dropdown(
    id='team1-dropdown',
    options=[{'label': team, 'value': team} for team in teams],
    placeholder="Select Team 1"
),

# Dropdown for Team2
dcc.Dropdown(
    id='team2-dropdown',
    options=[],
    placeholder="Select Team 2"
),

# Div to hold both graphs
html.Div([
    # Graph for Winning Team
    dcc.Graph(id='winning-team-graph', style={'flex': '70%'}),
    
    # Graph for Toss Decision
    dcc.Graph(id='toss-decision-graph', style={'flex': '30%'})
], style={'display': 'flex', 'width': '100%'})

])

Callback to update Team2 dropdown based on Team1 selection

@app.callback(
Output('team2-dropdown', 'options'),
Input('team1-dropdown', 'value')
)
def set_team2_options(selected_team1):
if selected_team1 is None:
return []

# Filter data to get teams that are not the selected Team1
filtered_data = data[(data['Team1'] == selected_team1) | (data['Team2'] == selected_team1)]
team2_options = pd.unique(filtered_data[['Team1', 'Team2']].values.ravel('K'))
team2_options = [{'label': team, 'value': team} for team in team2_options if team != selected_team1]

return team2_options

Callback to update the Winning Team and Toss Decision graphs based on selections

@app.callback(
Output('winning-team-graph', 'figure'),
Output('toss-decision-graph', 'figure'),
Input('team1-dropdown', 'value'),
Input('team2-dropdown', 'value')
)
def update_graph(selected_team1, selected_team2):
# Initialize figures
winning_fig = px.bar(title='Select Teams to See Winning Team Counts') # Placeholder figure
toss_fig = px.pie(title='Select Teams to See Toss Decision Counts') # Placeholder figure

if selected_team1 and selected_team2:
    filtered_data = data[
        (data['Team1'] == selected_team1) & (data['Team2'] == selected_team2)
    ]
    
    # Create a bar plot for Winning Team
    if not filtered_data.empty:
        win_counts = filtered_data['Winning_Team'].value_counts().reset_index()
        win_counts.columns = ['Winning_Team', 'Count']
        winning_fig = px.bar(win_counts, x='Winning_Team', y='Count', title='Winning Team Counts')

        # Create a pie plot for Toss Decision
        toss_counts = filtered_data['Toss_Decision'].value_counts().reset_index()
        toss_counts.columns = ['Toss_Decision', 'Count']
        toss_fig = px.pie(toss_counts, names='Toss_Decision', values='Count', title='Toss Decision Counts')

return winning_fig, toss_fig

Run the app

if name == 'main':
app.run_server(debug=True)

@ryan-gang ryan-gang closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants