App that shows monthly metrics for IT Support data This would consist of KPIs and breakdown charts
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime, timedelta
# Set page config
st.set_page_config(page_title="IT Support Metrics", layout="wide")
# Generate sample data
def generate_sample_data(months=12):
np.random.seed(42)
dates = pd.date_range(end=datetime.now(), periods=months, freq='M')
data = {
'Date': dates,
'Total_Tickets': np.random.randint(100, 500, months),
'Resolved_Tickets': [],
'Response_Time_Hrs': np.random.uniform(1, 24, months),
'Customer_Satisfaction': np.random.uniform(3.5, 5, months),
}
# Calculate resolved tickets (80-95% of total tickets)
for i in range(months):
resolution_rate = np.random.uniform(0.80, 0.95)
data['Resolved_Tickets'].append(int(data['Total_Tickets'][i] * resolution_rate))
df = pd.DataFrame(data)
# Calculate additional metrics
df['Resolution_Rate'] = (df['Resolved_Tickets'] / df['Total_Tickets'] * 100).round(2)
df['Open_Tickets'] = df['Total_Tickets'] - df['Resolved_Tickets']
# Generate priority breakdown
priorities = ['High', 'Medium', 'Low']
for priority in priorities:
df[f'{priority}_Priority'] = np.random.randint(10, 100, months)
# Generate category breakdown
categories = ['Hardware', 'Software', 'Network', 'Access', 'Other']
for category in categories:
df[f'{category}'] = np.random.randint(20, 100, months)
return df
# Main app
st.title("IT Support Dashboard")
st.markdown("### Monthly Performance Metrics")
# Generate data
df = generate_sample_data()
# KPI Metrics for the latest month
latest_month = df.iloc[-1]
# Create three columns for KPIs
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric(
"Total Tickets",
latest_month['Total_Tickets'],
f"{latest_month['Total_Tickets'] - df.iloc[-2]['Total_Tickets']}"
)
with col2:
st.metric(
"Resolution Rate",
f"{latest_month['Resolution_Rate']}%",
f"{(latest_month['Resolution_Rate'] - df.iloc[-2]['Resolution_Rate']).round(2)}%"
)
with col3:
st.metric(
"Avg Response Time",
f"{latest_month['Response_Time_Hrs']:.1f}h",
f"{(df.iloc[-2]['Response_Time_Hrs'] - latest_month['Response_Time_Hrs']).round(1)}h"
)
with col4:
st.metric(
"Customer Satisfaction",
f"{latest_month['Customer_Satisfaction']:.2f}",
f"{(latest_month['Customer_Satisfaction'] - df.iloc[-2]['Customer_Satisfaction']).round(2)}"
)
st.markdown("---")
# Create two columns for charts
col1, col2 = st.columns(2)
with col1:
st.markdown("### Ticket Volume Trend")
fig = go.Figure()
fig.add_trace(go.Scatter(x=df['Date'], y=df['Total_Tickets'], name='Total Tickets', line=dict(color='#1f77b4')))
fig.add_trace(go.Scatter(x=df['Date'], y=df['Resolved_Tickets'], name='Resolved Tickets', line=dict(color='#2ca02c')))
fig.update_layout(height=400, margin=dict(l=20, r=20, t=20, b=20))
st.plotly_chart(fig, use_container_width=True)
with col2:
st.markdown("### Resolution Rate Trend")
fig = px.line(df, x='Date', y='Resolution_Rate',
line_shape='spline')
fig.update_traces(line_color='#ff7f0e')
fig.update_layout(height=400, margin=dict(l=20, r=20, t=20, b=20),
yaxis_title='Resolution Rate (%)')
st.plotly_chart(fig, use_container_width=True)
# Create two columns for more charts
col1, col2 = st.columns(2)
with col1:
st.markdown("### Ticket Priority Distribution")
priority_data = df[['High_Priority', 'Medium_Priority', 'Low_Priority']].iloc[-1]
fig = px.pie(values=priority_data, names=priority_data.index,
title='Current Month Priority Distribution',
color_discrete_sequence=px.colors.qualitative.Set3)
fig.update_layout(height=400, margin=dict(l=20, r=20, t=40, b=20))
st.plotly_chart(fig, use_container_width=True)
with col2:
st.markdown("### Ticket Category Distribution")
category_data = df[['Hardware', 'Software', 'Network', 'Access', 'Other']].iloc[-1]
fig = px.bar(x=category_data.index, y=category_data.values,
title='Current Month Category Distribution',
color_discrete_sequence=px.colors.qualitative.Set2)
fig.update_layout(height=400, margin=dict(l=20, r=20, t=40, b=20),
xaxis_title='Category', yaxis_title='Number of Tickets')
st.plotly_chart(fig, use_container_width=True)
# Detailed metrics table
st.markdown("### Monthly Details")
detailed_df = df[['Date', 'Total_Tickets', 'Resolved_Tickets', 'Resolution_Rate',
'Response_Time_Hrs', 'Customer_Satisfaction']].copy()
detailed_df['Date'] = detailed_df['Date'].dt.strftime('%B %Y')
st.dataframe(detailed_df.style.format({
'Resolution_Rate': '{:.2f}%',
'Response_Time_Hrs': '{:.1f}',
'Customer_Satisfaction': '{:.2f}'
}), use_container_width=True)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?