Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1047,14 +1047,10 @@ with col_3d:
|
|
| 1047 |
st.markdown(insight_text, unsafe_allow_html=True)
|
| 1048 |
|
| 1049 |
|
| 1050 |
-
|
| 1051 |
-
####OBJECTIVE 4
|
| 1052 |
-
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1053 |
try:
|
| 1054 |
from wordcloud import WordCloud
|
| 1055 |
import matplotlib.pyplot as plt
|
| 1056 |
import plotly.express as px
|
| 1057 |
-
import numpy as np
|
| 1058 |
WORDCLOUD_AVAILABLE = True
|
| 1059 |
except ImportError:
|
| 1060 |
WORDCLOUD_AVAILABLE = False
|
|
@@ -1074,40 +1070,26 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1074 |
# 2 Kolom
|
| 1075 |
col1, col2 = st.columns(2)
|
| 1076 |
|
| 1077 |
-
# === PIE CHART: Semua temuan_kategori (
|
| 1078 |
with col1:
|
| 1079 |
if 'temuan_kategori' in df_all_kategori.columns:
|
| 1080 |
# Hitung jumlah per kategori
|
| 1081 |
category_counts = df_all_kategori['temuan_kategori'].value_counts()
|
| 1082 |
|
| 1083 |
if not category_counts.empty:
|
| 1084 |
-
# Buat warna
|
| 1085 |
colors = []
|
| 1086 |
for cat in category_counts.index:
|
| 1087 |
if cat == 'Positive':
|
| 1088 |
colors.append('#2E7D32') # Hijau
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1089 |
else:
|
| 1090 |
-
#
|
| 1091 |
-
idx = list(category_counts.index).index(cat)
|
| 1092 |
-
total_non_positive = len([c for c in category_counts.index if c != 'Positive'])
|
| 1093 |
-
|
| 1094 |
-
if total_non_positive > 1:
|
| 1095 |
-
step = idx / (total_non_positive - 1)
|
| 1096 |
-
else:
|
| 1097 |
-
step = 0
|
| 1098 |
-
|
| 1099 |
-
# Rentang merah pastel: dari #c62828 ke #ffebee
|
| 1100 |
-
r = int(198 + (255 - 198) * step)
|
| 1101 |
-
g = int(40 + (235 - 40) * step)
|
| 1102 |
-
b = int(40 + (238 - 40) * step)
|
| 1103 |
-
|
| 1104 |
-
# Pastikan nilai tidak melebihi 255
|
| 1105 |
-
r = min(255, max(0, r))
|
| 1106 |
-
g = min(255, max(0, g))
|
| 1107 |
-
b = min(255, max(0, b))
|
| 1108 |
-
|
| 1109 |
-
color_hex = f"#{r:02x}{g:02x}{b:02x}"
|
| 1110 |
-
colors.append(color_hex)
|
| 1111 |
|
| 1112 |
# Buat pie chart
|
| 1113 |
fig_pie = px.pie(
|
|
@@ -1148,7 +1130,7 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1148 |
|
| 1149 |
# Output kecil tapi tajam
|
| 1150 |
fig, ax = plt.subplots(figsize=(3, 2), dpi=200)
|
| 1151 |
-
ax.set_title("Unsafe Issues", fontsize=
|
| 1152 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 1153 |
ax.axis('off')
|
| 1154 |
plt.tight_layout()
|
|
@@ -1161,7 +1143,6 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1161 |
|
| 1162 |
else:
|
| 1163 |
st.info("WordCloud library not installed. Install `wordcloud` and `matplotlib` to enable this feature.")
|
| 1164 |
-
|
| 1165 |
# =================== 5. Matrix (Tetap Dipertahankan) ===================
|
| 1166 |
st.markdown("<h3 class='section-title'>OBJECTIVE 5 - Findings vs Lead Time: Which Divisions Move Slow?</h3>", unsafe_allow_html=True)
|
| 1167 |
|
|
|
|
| 1047 |
st.markdown(insight_text, unsafe_allow_html=True)
|
| 1048 |
|
| 1049 |
|
|
|
|
|
|
|
|
|
|
| 1050 |
try:
|
| 1051 |
from wordcloud import WordCloud
|
| 1052 |
import matplotlib.pyplot as plt
|
| 1053 |
import plotly.express as px
|
|
|
|
| 1054 |
WORDCLOUD_AVAILABLE = True
|
| 1055 |
except ImportError:
|
| 1056 |
WORDCLOUD_AVAILABLE = False
|
|
|
|
| 1070 |
# 2 Kolom
|
| 1071 |
col1, col2 = st.columns(2)
|
| 1072 |
|
| 1073 |
+
# === PIE CHART: Semua temuan_kategori (Warna Sesuai Kategori) ===
|
| 1074 |
with col1:
|
| 1075 |
if 'temuan_kategori' in df_all_kategori.columns:
|
| 1076 |
# Hitung jumlah per kategori
|
| 1077 |
category_counts = df_all_kategori['temuan_kategori'].value_counts()
|
| 1078 |
|
| 1079 |
if not category_counts.empty:
|
| 1080 |
+
# Buat warna sesuai kategori
|
| 1081 |
colors = []
|
| 1082 |
for cat in category_counts.index:
|
| 1083 |
if cat == 'Positive':
|
| 1084 |
colors.append('#2E7D32') # Hijau
|
| 1085 |
+
elif cat == 'Unsafe Condition':
|
| 1086 |
+
colors.append('#EF5350') # Merah Muda
|
| 1087 |
+
elif cat == 'Unsafe Action':
|
| 1088 |
+
colors.append('#F48FB1') # Pink
|
| 1089 |
+
elif cat == 'Near Miss':
|
| 1090 |
+
colors.append('#BDBDBD') # Abu-abu
|
| 1091 |
else:
|
| 1092 |
+
colors.append('#9E9E9E') # Default abu-abu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1093 |
|
| 1094 |
# Buat pie chart
|
| 1095 |
fig_pie = px.pie(
|
|
|
|
| 1130 |
|
| 1131 |
# Output kecil tapi tajam
|
| 1132 |
fig, ax = plt.subplots(figsize=(3, 2), dpi=200)
|
| 1133 |
+
ax.set_title("Unsafe Issues", fontsize=10)
|
| 1134 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 1135 |
ax.axis('off')
|
| 1136 |
plt.tight_layout()
|
|
|
|
| 1143 |
|
| 1144 |
else:
|
| 1145 |
st.info("WordCloud library not installed. Install `wordcloud` and `matplotlib` to enable this feature.")
|
|
|
|
| 1146 |
# =================== 5. Matrix (Tetap Dipertahankan) ===================
|
| 1147 |
st.markdown("<h3 class='section-title'>OBJECTIVE 5 - Findings vs Lead Time: Which Divisions Move Slow?</h3>", unsafe_allow_html=True)
|
| 1148 |
|