operational-dashboard-generator
You are operational-dashboard-generator - a specialized skill for generating operational dashboards with KPI visualization and real-time monitoring capabilities.
Overview
This skill enables AI-powered dashboard generation including:
- KPI definition and calculation
- Visual hierarchy design
- Alert threshold configuration
- Trend analysis displays
- Drill-down capabilities
- Real-time data integration
- Performance comparison views
- Custom metric creation
Capabilities
1. KPI Definition Framework
import pandas as pd
import numpy as np
from dataclasses import dataclass
from typing import List, Dict, Optional
from enum import Enum
class KPICategory(Enum):
SAFETY = "safety"
QUALITY = "quality"
DELIVERY = "delivery"
COST = "cost"
PRODUCTIVITY = "productivity"
MORALE = "morale"
@dataclass
class KPIDefinition:
id: str
name: str
category: KPICategory
formula: str
unit: str
target: float
warning_threshold: float
critical_threshold: float
higher_is_better: bool = True
frequency: str = "daily"
def create_kpi_library():
"""Standard industrial KPI definitions"""
return [
KPIDefinition(
id="oee", name="OEE", category=KPICategory.PRODUCTIVITY,
formula="availability * performance * quality",
unit="%", target=85, warning_threshold=75, critical_threshold=65
),
KPIDefinition(
id="fpy", name="First Pass Yield", category=KPICategory.QUALITY,
formula="good_units / total_units * 100",
unit="%", target=98, warning_threshold=95, critical_threshold=90
),
KPIDefinition(
id="otd", name="On-Time Delivery", category=KPICategory.DELIVERY,
formula="on_time_orders / total_orders * 100",
unit="%", target=98, warning_threshold=95, critical_threshold=90
),
KPIDefinition(
id="trir", name="Total Recordable Incident Rate", category=KPICategory.SAFETY,
formula="incidents * 200000 / hours_worked",
unit="per 200k hrs", target=0.5, warning_threshold=1.0, critical_threshold=2.0,
higher_is_better=False
),
KPIDefinition(
id="productivity", name="Labor Productivity", category=KPICategory.PRODUCTIVITY,
formula="units_produced / labor_hours",
unit="units/hr", target=25, warning_threshold=20, critical_threshold=15
),
KPIDefinition(
id="scrap_rate", name="Scrap Rate", category=KPICategory.COST,
formula="scrap_cost / production_cost * 100",
unit="%", target=1.0, warning_threshold=2.0, critical_threshold=3.0,
higher_is_better=False
)
]
def calculate_kpi(kpi: KPIDefinition, data: dict):
"""Calculate KPI value from data"""
# Simple formula evaluation (in production, use safe eval)
try:
value = eval(kpi.formula, {"__builtins__": {}}, data)
# Determine status
if kpi.higher_is_better:
if value >= kpi.target:
status = "green"
elif value >= kpi.warning_threshold:
status = "yellow"
else:
status = "red"
else:
if value <= kpi.target:
status = "green"
elif value <= kpi.warning_threshold:
status = "yellow"
else:
status = "red"
return {
"kpi_id": kpi.id,
"name": kpi.name,
"value": round(value, 2),
"unit": kpi.unit,
"target": kpi.target,
"status": status,
"gap_to_target": round(value - kpi.target, 2)
}
except Exception as e:
return {"kpi_id": kpi.id, "error": str(e)}
2. Dashboard Layout Generator
def generate_dashboard_layout(kpis: List[KPIDefinition], layout_type: str = "standard"):
"""
Generate dashboard layout configuration
layout_type: 'standard', 'executive', 'operational', 'lean'
"""
if layout_type == "standard":
layout = {
"type": "grid",
"columns": 4,
"rows": 3,
"sections": [
{
"id": "header",
"row": 1, "col_span": 4,
"content": "title_and_period_selector"
},
{
"id": "summary_cards",
"row": 2, "col_span": 4,
"content": "kpi_summary_cards",
"kpis": [k.id for k in kpis[:6]]
},
{
"id": "trends",
"row": 3, "col": 1, "col_span": 2,
"content": "trend_charts"
},
{
"id": "details",
"row": 3, "col": 3, "col_span": 2,
"content": "detail_tables"
}
]
}
elif layout_type == "executive":
layout = {
"type": "single_page",
"sections": [
{"id": "headline_kpis", "position": "top", "height": "20%"},
{"id": "trend_summary", "position": "middle", "height": "50%"},
{"id": "action_items", "position": "bottom", "height": "30%"}
]
}
elif layout_type == "lean":
# Visual management board style
layout = {
"type": "sqdc", # Safety, Quality, Delivery, Cost
"columns": 4,
"sections": [
{"id": "safety", "col": 1, "category": "SAFETY"},
{"id": "quality", "col": 2, "category": "QUALITY"},
{"id": "delivery", "col": 3, "category": "DELIVERY"},
{"id": "cost", "col": 4, "category": "COST"}
],
"row_types": ["current_status", "trend_sparkline", "action_items"]
}
return layout
def generate_kpi_card_config(kpi: KPIDefinition):
"""Generate configuration for a KPI card widget"""
return {
"widget_type": "kpi_card",
"kpi_id": kpi.id,
"title": kpi.name,
"display": {
"value_format": f"{{value:.1f}}{kpi.unit}",
"show_target": True,
"show_trend": True,
"trend_periods": 7
},
"colors": {
"green": kpi.target,
"yellow": kpi.warning_threshold,
"red": kpi.critical_threshold
},
"gauge": kpi.id in ["oee", "fpy", "otd"] # Show gauge for percentage KPIs
}
3. Trend Analysis
def analyze_kpi_trends(historical_data: pd.DataFrame, kpi_id: str,
periods: int = 30):
"""
Analyze trends for a KPI
historical_data: DataFrame with ['date', 'kpi_id', 'value']
"""
kpi_data = historical_data[historical_data['kpi_id'] == kpi_id].copy()
kpi_data = kpi_data.sort_values('date').tail(periods)
if len(kpi_data) < 2:
return {"error": "Insufficient data for trend analysis"}
values = kpi_data['value'].values
dates = kpi_data['date'].values
# Calculate statistics
current = values[-1]
previous = values[-2]
change = current - previous
change_pct = (change / previous * 100) if previous != 0 else 0
# Moving averages
ma_7 = np.mean(values[-7:]) if len(values) >= 7 else np.mean(values)
ma_30 = np.mean(values[-30:]) if len(values) >= 30 else np.mean(values)
# Trend direction (linear regression)
x = np.arange(len(values))
slope, intercept = np.polyfit(x, values, 1)
if slope > 0.01:
trend_direction = "improving"
elif slope < -0.01:
trend_direction = "declining"
else:
trend_direction = "stable"
# Variability
std_dev = np.std(values)
cv = (std_dev / np.mean(values) * 100) if np.mean(values) != 0 else 0
return {