SHELLAPANDIANGANHUNGING commited on
Commit
b580996
·
verified ·
1 Parent(s): c1b0250

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -13
app.py CHANGED
@@ -11,7 +11,7 @@ import base64
11
 
12
  # =================== CONFIG =====================
13
  st.set_page_config(
14
- page_title="Fatigue Analyzer - Advanced Fatigue Analytics",
15
  page_icon="🛡️", # Safety icon
16
  layout="wide",
17
  initial_sidebar_state="expanded"
@@ -1684,19 +1684,56 @@ with col_insights:
1684
  st.info(f"{critical_pct:.1f}% of alerts occur during critical hours. This is within acceptable range.")
1685
 
1686
  # 2. High-Speed Fatigue Analysis (Environmental Risk)
1687
- if col_speed and col_speed in df.columns:
1688
- high_speed_threshold = df[col_speed].quantile(0.75) if not df[col_speed].dropna().empty else 0 # Handle empty series
1689
- high_speed_fatigue = df[df[col_speed] >= high_speed_threshold] if high_speed_threshold > 0 else pd.DataFrame()
1690
- high_speed_pct = (len(high_speed_fatigue) / len(df)) * 100 if len(df) > 0 else 0
1691
-
1692
- st.markdown(f"**High-Speed Fatigue Risk (Speed > {high_speed_threshold:.0f} km/h)**")
1693
- st.metric("High-Speed Fatigue Events", f"{len(high_speed_fatigue)}", f"{high_speed_pct:.1f}% of total alerts")
1694
- if high_speed_pct > 20: # If more than 20% of alerts happen at high speed
1695
- st.warning(f"High risk: {high_speed_pct:.1f}% of fatigue alerts occur at high speeds. This increases accident severity potential.")
1696
- else:
1697
- st.info(f"{high_speed_pct:.1f}% of alerts occur at high speeds. This is within acceptable range.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1698
  else:
1699
- st.info("Speed data not available for High-Speed Fatigue Analysis.")
 
 
 
 
 
 
1700
 
1701
  # 3. Shift Pattern Analysis
1702
  if col_shift and col_shift in df.columns:
 
11
 
12
  # =================== CONFIG =====================
13
  st.set_page_config(
14
+ page_title="Fatigue Analyzer - Advanced Fatigue Anfalytics",
15
  page_icon="🛡️", # Safety icon
16
  layout="wide",
17
  initial_sidebar_state="expanded"
 
1684
  st.info(f"{critical_pct:.1f}% of alerts occur during critical hours. This is within acceptable range.")
1685
 
1686
  # 2. High-Speed Fatigue Analysis (Environmental Risk)
1687
+ if col_speed and col_speed in df.columns:
1688
+
1689
+ # --- Threshold FIX > 20 km/h ---
1690
+ high_speed_threshold = 20
1691
+
1692
+ # --- Filter High-Speed Fatigue ---
1693
+ high_speed_fatigue = df[df[col_speed] > high_speed_threshold]
1694
+
1695
+ # --- Persentase ---
1696
+ high_speed_pct = (len(high_speed_fatigue) / len(df) * 100) if len(df) > 0 else 0
1697
+
1698
+ # --- Judul ---
1699
+ st.markdown(f"### **High-Speed Fatigue Risk (Speed > {high_speed_threshold} km/h)**")
1700
+
1701
+ # --- Custom box merah ---
1702
+ st.markdown(
1703
+ f"""
1704
+ <div style="
1705
+ background-color:#d32f2f;
1706
+ padding:18px;
1707
+ border-radius:12px;
1708
+ color:white;
1709
+ font-size:22px;
1710
+ font-weight:600;
1711
+ text-align:center;
1712
+ margin-bottom:10px;
1713
+ ">
1714
+ High-Speed Fatigue Events: {len(high_speed_fatigue)}
1715
+ <div style="font-size:16px; font-weight:400; margin-top:4px;">
1716
+ {high_speed_pct:.1f}% of total alerts
1717
+ </div>
1718
+ </div>
1719
+ """,
1720
+ unsafe_allow_html=True
1721
+ )
1722
+
1723
+ # --- Risk message ---
1724
+ if high_speed_pct > 20:
1725
+ st.warning(
1726
+ f"High risk: {high_speed_pct:.1f}% of fatigue alerts occur at high speeds. "
1727
+ f"This increases accident severity potential."
1728
+ )
1729
  else:
1730
+ st.info(
1731
+ f"{high_speed_pct:.1f}% of alerts occur at high speeds. This is within acceptable range."
1732
+ )
1733
+
1734
+ else:
1735
+ st.info("Speed data not available for High-Speed Fatigue Analysis.")
1736
+
1737
 
1738
  # 3. Shift Pattern Analysis
1739
  if col_shift and col_shift in df.columns: