Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Fatigue Dashboard", layout="wide")
|
| 6 |
+
|
| 7 |
+
# Load Data
|
| 8 |
+
df = pd.read_excel("manual fatique.xlsx")
|
| 9 |
+
|
| 10 |
+
# Normalize timestamp
|
| 11 |
+
timestamp_col = [col for col in df.columns if "GMT" in col or "timestamp" in col.lower()][0]
|
| 12 |
+
df["Timestamp"] = pd.to_datetime(df[timestamp_col])
|
| 13 |
+
|
| 14 |
+
st.title("⛑️ Fatigue Monitoring Dashboard")
|
| 15 |
+
|
| 16 |
+
# Sidebar Filters
|
| 17 |
+
shift_filter = st.sidebar.multiselect("Filter Shift", df['Shift'].unique())
|
| 18 |
+
unit_filter = st.sidebar.multiselect("Filter Unit", df['Fleet Number'].unique())
|
| 19 |
+
|
| 20 |
+
filtered = df.copy()
|
| 21 |
+
if shift_filter:
|
| 22 |
+
filtered = filtered[filtered['Shift'].isin(shift_filter)]
|
| 23 |
+
if unit_filter:
|
| 24 |
+
filtered = filtered[filtered['Fleet Number'].isin(unit_filter)]
|
| 25 |
+
|
| 26 |
+
# KPI Metrics
|
| 27 |
+
col1, col2 = st.columns(2)
|
| 28 |
+
col1.metric("Total Fatigue Alerts", len(filtered))
|
| 29 |
+
col2.metric("Unique Operators", filtered['Operator Name'].nunique())
|
| 30 |
+
|
| 31 |
+
# Trend per day
|
| 32 |
+
trend = filtered.groupby(filtered["Timestamp"].dt.date).size().reset_index(name="Count")
|
| 33 |
+
fig = px.line(trend, x="Timestamp", y="Count", title="📈 Trend Fatigue Alerts Per Hari")
|
| 34 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 35 |
+
|
| 36 |
+
# Shift comparison
|
| 37 |
+
fig2 = px.bar(filtered, x="Shift", title="⚠️ Distribusi Alert per Shift", color="Shift")
|
| 38 |
+
st.plotly_chart(fig2, use_container_width=True)
|
| 39 |
+
|
| 40 |
+
# Top Units
|
| 41 |
+
unit = filtered.groupby("Fleet Number").size().reset_index(name="Count").sort_values("Count", ascending=False)
|
| 42 |
+
fig3 = px.bar(unit.head(10), x="Fleet Number", y="Count", title="🚛 Top 10 Unit dengan Alert Tertinggi")
|
| 43 |
+
st.plotly_chart(fig3, use_container_width=True)
|
| 44 |
+
|
| 45 |
+
# Heatmap jam kejadian
|
| 46 |
+
filtered['Hour'] = filtered['Timestamp'].dt.hour
|
| 47 |
+
hourly = filtered.groupby('Hour').size().reset_index(name="Count")
|
| 48 |
+
fig4 = px.bar(hourly, x='Hour', y='Count', title="🕒 Peak Hour Fatigue Alerts")
|
| 49 |
+
st.plotly_chart(fig4, use_container_width=True)
|
| 50 |
+
|
| 51 |
+
st.caption("Created for Safety Improvement & Predictive Behavior Monitoring")
|