Professional Predictive Maintenance Dashboard
Here's a streamlined implementation using Python and Dash:
import dash
from dash import dcc, html, Input, Output
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# Initialize the app
app = dash.Dash(__name__, title="Predictive Maintenance Dashboard")
# Sample data generation (replace with your actual data source)
def generate_sample_data():
# Equipment health data
equipment_ids = ["Pump-101", "Motor-A42", "Compressor-37", "Turbine-09", "Boiler-14"]
health_scores = [87, 62, 93, 78, 81]
predicted_days = [42, 7, 65, 21, 30]
status = ["Normal", "Warning", "Normal", "Normal", "Normal"]
last_maintenance = [(datetime.now() - timedelta(days=np.random.randint(10, 90))).strftime("%Y-%m-%d") for _ in range(5)]
equipment_df = pd.DataFrame({
"equipment_id": equipment_ids,
"health_score": health_scores,
"days_to_failure": predicted_days,
"status": status,
"last_maintenance": last_maintenance
})
# Sensor data for last 30 days
dates = pd.date_range(end=datetime.now(), periods=30)
sensor_df = pd.DataFrame()
for equip in equipment_ids:
base = np.random.randint(50, 150)
trend = np.linspace(0, np.random.choice([-15, 15]), 30)
noise = np.random.normal(0, 5, 30)
values = base + trend + noise
temp_df = pd.DataFrame({
"date": dates,
"equipment_id": equip,
"sensor_value": values
})
sensor_df = pd.concat([sensor_df, temp_df])
return equipment_df, sensor_df
equipment_df, sensor_df = generate_sample_data()
# Dashboard layout
app.layout = html.Div([
# Header
html.Div([
html.H2("Predictive Maintenance Dashboard", style={"margin-bottom": "0px"}),
html.P("Real-time equipment monitoring and failure prediction", style={"margin-top": "0px"}),
], style={"text-align": "left", "padding": "10px 25px", "background-color": "#2c3e50", "color": "white"}),
# KPI Cards Row
html.Div([
html.Div([
html.H4("Equipment Monitored"),
html.P(len(equipment_df), style={"font-size": "32px", "margin": "0"})
], className="kpi-card"),
html.Div([
html.H4("Critical Alerts"),
html.P(sum(equipment_df["status"] == "Warning"), style={"font-size": "32px", "margin": "0", "color": "#e74c3c"})
], className="kpi-card"),
html.Div([
html.H4("Avg Health Score"),
html.P(f"{equipment_df['health_score'].mean():.1f}%", style={"font-size": "32px", "margin": "0"})
], className="kpi-card"),
html.Div([
html.H4("Maintenance Required"),
html.P(sum(equipment_df["days_to_failure"] < 14), style={"font-size": "32px", "margin": "0"})
], className="kpi-card"),
], style={"display": "flex", "justify-content": "space-between", "margin": "20px"}),
# Main content area
html.Div([
# Left panel - Equipment List
html.Div([
html.H3("Equipment Status"),
html.Div([
html.Div([
html.Div(f"{row['equipment_id']}", style={"font-weight": "bold"}),
html.Div([
html.Div(f"Health: {row['health_score']}%", style={"margin-right": "15px"}),
html.Div(f"Pred. Failure: {row['days_to_failure']} days",
style={"color": "#e74c3c" if row['days_to_failure'] < 14 else "inherit"})
], style={"display": "flex"}),
], className="equipment-item", style={"border-left": "4px solid #e74c3c" if row["status"] == "Warning" else "4px solid #2ecc71"})
for _, row in equipment_df.iterrows()
]),
], style={"width": "30%", "padding": "15px", "background-color": "#f8f9fa", "border-radius": "5px"}),
# Right panel - Charts
html.Div([
# Equipment selector
html.Div([
html.Label("Select Equipment:"),
dcc.Dropdown(
id="equipment-selector",
options=[{"label": eq, "value": eq} for eq in equipment_df["equipment_id"]],
value=equipment_df["equipment_id"][0],
style={"width": "100%"}
),
], style={"margin-bottom": "20px"}),
# Sensor trend chart
html.Div([
html.H3("Sensor Readings Trend"),
dcc.Graph(id="sensor-trend-chart")
], style={"margin-bottom": "20px"}),
# Health prediction chart
html.Div([
html.H3("Health Score Forecast"),
dcc.Graph(id="health-forecast-chart")
]),
], style={"width": "68%", "padding": "15px", "background-color": "#f8f9fa", "border-radius": "5px"}),
], style={"display": "flex", "justify-content": "space-between", "margin": "20px"}),
# CSS
html.Style("""
.kpi-card {
background-color: white;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
width: 23%;
text-align: center;
}
.equipment-item {
padding: 15px;
margin-bottom: 10px;
background-color: white;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
""")
])
# Callback for sensor trend chart
@app.callback(
Output("sensor-trend-chart", "figure"),
Input("equipment-selector", "value")
)
def update_sensor_chart(equipment_id):
filtered_data = sensor_df[sensor_df["equipment_id"] == equipment_id]
fig = px.line(filtered_data, x="date", y="sensor_value",
title=f"Sensor Readings - {equipment_id}")
# Add threshold lines
fig.add_shape(type="line", x0=filtered_data["date"].min(), x1=filtered_data["date"].max(),
y0=135, y1=135, line=dict(color="red", width=2, dash="dash"))
fig.update_layout(
xaxis_title="Date",
yaxis_title="Sensor Value",
hovermode="x unified",
margin=dict(l=0, r=0, t=30, b=0),
)
return fig
# Callback for health forecast chart
@app.callback(
Output("health-forecast-chart", "figure"),
Input("equipment-selector", "value")
)
def update_forecast_chart(equipment_id):
# Get current health score
health_score = equipment_df[equipment_df["equipment_id"] == equipment_id]["health_score"].values[0]
days_to_failure = equipment_df[equipment_df["equipment_id"] == equipment_id]["days_to_failure"].values[0]
# Generate forecast data
days = list(range(0, days_to_failure + 15))
decay_rate = health_score / days_to_failure if days_to_failure > 0 else 0.1
forecast = [max(0, health_score - day * decay_rate) for day in days]
# Create forecast figure
fig = go.Figure()
fig.add_trace(go.Scatter(
x=days, y=forecast,
mode="lines",
name="Health Score",
line=dict(color="#3498db", width=3)
))
# Add maintenance threshold
fig.add_shape(type="line", x0=0, x1=days[-1],
y0=50, y1=50, line=dict(color="#e74c3c", width=2, dash="dash"))
fig.add_annotation(x=days[-1], y=50,
text="Maintenance Threshold",
showarrow=False,
yshift=10)
# Add failure point
fig.add_vline(x=days_to_failure, line_width=2, line_dash="dash", line_color="orange")
fig.add_annotation(x=days_to_failure, y=forecast[days_to_failure],
text="Predicted Failure",
showarrow=True,
arrowhead=1)
fig.update_layout(
xaxis_title="Days from Now",
yaxis_title="Health Score (%)",
yaxis=dict(range=[0, 100]),
margin=dict(l=0, r=0, t=10, b=0),
)
return fig
# Run the app
if __name__ == "__main__":
app.run_server(debug=True)
Would you like me to explain or break down the code?