Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -249,7 +249,7 @@ st.markdown("""
|
|
| 249 |
<div class="main-header" style="text-align:center;">
|
| 250 |
<h1>Michelin Mining Tyre Analytics</h1>
|
| 251 |
<p style="font-size:12px; color:#9a9a9a; margin-top:-6px;">
|
| 252 |
-
Daily trend insights derived from 13β16 December 2023 data
|
| 253 |
</p>
|
| 254 |
</div>
|
| 255 |
""", unsafe_allow_html=True)
|
|
@@ -679,103 +679,7 @@ with col8:
|
|
| 679 |
else:
|
| 680 |
st.warning("No data for Position 4 (18:00β06:00)")
|
| 681 |
|
| 682 |
-
# =============== INSIGHT 3 ===============
|
| 683 |
-
if alarm_data.empty:
|
| 684 |
-
insight_text = "β’ No data available for analysis."
|
| 685 |
-
else:
|
| 686 |
-
# Insight tetap sama
|
| 687 |
-
alarm_hours = alarm_data['hour']
|
| 688 |
-
|
| 689 |
-
def hour_to_band(h):
|
| 690 |
-
if 0 <= h < 6: return "00:00β06:00 (Night)"
|
| 691 |
-
if 6 <= h < 12: return "06:00β12:00 (Morning)"
|
| 692 |
-
if 12 <= h < 18: return "12:00β18:00 (Afternoon)"
|
| 693 |
-
return "18:00β00:00 (Evening)"
|
| 694 |
-
|
| 695 |
-
alarm_hours_df = pd.DataFrame({'hour': alarm_hours})
|
| 696 |
-
alarm_hours_df['band'] = alarm_hours_df['hour'].apply(hour_to_band)
|
| 697 |
-
band_counts = alarm_hours_df['band'].value_counts().sort_index()
|
| 698 |
-
|
| 699 |
-
top_bands = band_counts.nlargest(2)
|
| 700 |
-
dominant_band = top_bands.index[0] if len(top_bands) > 0 else "N/A"
|
| 701 |
-
second_dominant_band = top_bands.index[1] if len(top_bands) > 1 else "N/A"
|
| 702 |
-
|
| 703 |
-
dominant_pct = (top_bands.iloc[0] / band_counts.sum() * 100) if len(top_bands) > 0 else 0
|
| 704 |
-
second_pct = (top_bands.iloc[1] / band_counts.sum() * 100) if len(top_bands) > 1 else 0
|
| 705 |
|
| 706 |
-
# Hitung jumlah masing-masing jenis alarm
|
| 707 |
-
normal_alarms = alarm_data[alarm_data['Alarm Status'] == 'No Alarm'].shape[0]
|
| 708 |
-
red_alarms = alarm_data[alarm_data['Alarm Status'].str.contains('Red', na=False)].shape[0]
|
| 709 |
-
amber_alarms = alarm_data[alarm_data['Alarm Status'].str.contains('Amber', na=False)].shape[0]
|
| 710 |
-
|
| 711 |
-
# Insight Spesifik Per Position dan Shift
|
| 712 |
-
insight_lines = [
|
| 713 |
-
f"{dominant_band} is the dominant period ({dominant_pct:.1f}% of all data).",
|
| 714 |
-
f"{second_dominant_band} is the second-highest period ({second_pct:.1f}% of data).",
|
| 715 |
-
f"Total: Normal={normal_alarms}, Amber={amber_alarms}, Red={red_alarms}"
|
| 716 |
-
]
|
| 717 |
-
|
| 718 |
-
# Position 1 (Shift Pagi)
|
| 719 |
-
pos1_pagi = alarm_data[(alarm_data['Position'] == 1) & (alarm_data['hour'].between(6, 17, inclusive='both'))]
|
| 720 |
-
if not pos1_pagi.empty:
|
| 721 |
-
pos1_pagi_total = pos1_pagi.groupby('hour').size()
|
| 722 |
-
if not pos1_pagi_total.empty:
|
| 723 |
-
dominant_hour_p1_pagi = pos1_pagi_total.idxmax()
|
| 724 |
-
dominant_count_p1_pagi = pos1_pagi_total.max()
|
| 725 |
-
insight_lines.append(f"Position 1 (06:00β18:00): Dominant alarm at {dominant_hour_p1_pagi:02d}:00 with {dominant_count_p1_pagi} alarms.")
|
| 726 |
-
|
| 727 |
-
# Position 1 (Shift Sore)
|
| 728 |
-
pos1_sore = alarm_data[(alarm_data['Position'] == 1) & (~alarm_data['hour'].between(6, 17, inclusive='both'))]
|
| 729 |
-
if not pos1_sore.empty:
|
| 730 |
-
pos1_sore_red = pos1_sore[pos1_sore['Alarm Status'].str.contains('Red', na=False)]
|
| 731 |
-
if not pos1_sore_red.empty:
|
| 732 |
-
red_percentage_p1_sore = (len(pos1_sore_red) / len(pos1_sore)) * 100
|
| 733 |
-
insight_lines.append(f"Position 1 (18:00β06:00): Red alarms account for {red_percentage_p1_sore:.1f}% of total alarms.")
|
| 734 |
-
|
| 735 |
-
# Position 3 (Shift Pagi)
|
| 736 |
-
pos3_pagi = alarm_data[(alarm_data['Position'] == 3) & (alarm_data['hour'].between(6, 17, inclusive='both'))]
|
| 737 |
-
if not pos3_pagi.empty:
|
| 738 |
-
pos3_pagi_total = pos3_pagi.groupby('hour').size()
|
| 739 |
-
if not pos3_pagi_total.empty:
|
| 740 |
-
dominant_hour_p3_pagi = pos3_pagi_total.idxmax()
|
| 741 |
-
dominant_count_p3_pagi = pos3_pagi_total.max()
|
| 742 |
-
insight_lines.append(f"Position 3 (06:00β18:00): Dominant alarm at {dominant_hour_p3_pagi:02d}:00 with {dominant_count_p3_pagi} alarms.")
|
| 743 |
-
|
| 744 |
-
# Position 3 (Shift Sore)
|
| 745 |
-
pos3_sore = alarm_data[(alarm_data['Position'] == 3) & (~alarm_data['hour'].between(6, 17, inclusive='both'))]
|
| 746 |
-
if not pos3_sore.empty:
|
| 747 |
-
pos3_sore_amber = pos3_sore[pos3_sore['Alarm Status'].str.contains('Amber', na=False)]
|
| 748 |
-
if not pos3_sore_amber.empty:
|
| 749 |
-
amber_percentage_p3_sore = (len(pos3_sore_amber) / len(pos3_sore)) * 100
|
| 750 |
-
insight_lines.append(f"Position 3 (18:00β06:00): Amber alarms account for {amber_percentage_p3_sore:.1f}% of total alarms.")
|
| 751 |
-
|
| 752 |
-
# Position 4 (Shift Pagi)
|
| 753 |
-
pos4_pagi = alarm_data[(alarm_data['Position'] == 4) & (alarm_data['hour'].between(6, 17, inclusive='both'))]
|
| 754 |
-
if not pos4_pagi.empty:
|
| 755 |
-
pos4_pagi_total = pos4_pagi.groupby('hour').size()
|
| 756 |
-
if not pos4_pagi_total.empty:
|
| 757 |
-
dominant_hour_p4_pagi = pos4_pagi_total.idxmax()
|
| 758 |
-
dominant_count_p4_pagi = pos4_pagi_total.max()
|
| 759 |
-
insight_lines.append(f"Position 4 (06:00β18:00): Dominant alarm at {dominant_hour_p4_pagi:02d}:00 with {dominant_count_p4_pagi} alarms.")
|
| 760 |
-
|
| 761 |
-
# Position 4 (Shift Sore)
|
| 762 |
-
pos4_sore = alarm_data[(alarm_data['Position'] == 4) & (~alarm_data['hour'].between(6, 17, inclusive='both'))]
|
| 763 |
-
if not pos4_sore.empty:
|
| 764 |
-
pos4_sore_amber = pos4_sore[pos4_sore['Alarm Status'].str.contains('Amber', na=False)]
|
| 765 |
-
if not pos4_sore_amber.empty:
|
| 766 |
-
amber_percentage_p4_sore = (len(pos4_sore_amber) / len(pos4_sore)) * 100
|
| 767 |
-
insight_lines.append(f"Position 4 (18:00β06:00): Amber alarms account for {amber_percentage_p4_sore:.1f}% of total alarms.")
|
| 768 |
-
|
| 769 |
-
insight_text = "\n".join(insight_lines)
|
| 770 |
-
|
| 771 |
-
# =============== DISPLAY INSIGHT ===============
|
| 772 |
-
st.markdown(f"""
|
| 773 |
-
<div class="insight-box">
|
| 774 |
-
<div class="content">
|
| 775 |
-
{insight_text}
|
| 776 |
-
</div>
|
| 777 |
-
</div>
|
| 778 |
-
""", unsafe_allow_html=True)
|
| 779 |
#### OBJECTICVE 3
|
| 780 |
st.markdown('<h3 class="objective-title">OBJECTIVE 3: Correlation β How Does Heat Influence Pressure and Which Tyres Trigger Red Alarms?</h3>', unsafe_allow_html=True)
|
| 781 |
|
|
@@ -1223,7 +1127,87 @@ st.markdown(f"""
|
|
| 1223 |
</div>
|
| 1224 |
</div>
|
| 1225 |
""", unsafe_allow_html=True)
|
| 1226 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1227 |
# ================= OBJECTIVE 5 =================
|
| 1228 |
# ================= OBJECTIVE 5 =================
|
| 1229 |
st.markdown('<h3 class="objective-title">OBJECTIVE 5: Insights & Mitigation β How Can Red Pressure Alarms Be Reduced?</h3>', unsafe_allow_html=True)
|
|
@@ -1305,24 +1289,25 @@ else:
|
|
| 1305 |
front_percentage_obj4 = 0
|
| 1306 |
|
| 1307 |
# Insight dari Objective 1-4
|
| 1308 |
-
insight_text = f"""
|
| 1309 |
-
|
| 1310 |
-
|
| 1311 |
-
|
| 1312 |
-
|
| 1313 |
-
|
| 1314 |
-
|
| 1315 |
-
|
| 1316 |
-
|
| 1317 |
-
|
| 1318 |
-
|
| 1319 |
-
|
| 1320 |
-
|
| 1321 |
-
|
| 1322 |
-
|
| 1323 |
-
|
| 1324 |
-
|
| 1325 |
-
|
|
|
|
| 1326 |
"""
|
| 1327 |
|
| 1328 |
try:
|
|
|
|
| 249 |
<div class="main-header" style="text-align:center;">
|
| 250 |
<h1>Michelin Mining Tyre Analytics</h1>
|
| 251 |
<p style="font-size:12px; color:#9a9a9a; margin-top:-6px;">
|
| 252 |
+
Daily trend insights derived from 13β16 December 2023 data
|
| 253 |
</p>
|
| 254 |
</div>
|
| 255 |
""", unsafe_allow_html=True)
|
|
|
|
| 679 |
else:
|
| 680 |
st.warning("No data for Position 4 (18:00β06:00)")
|
| 681 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 683 |
#### OBJECTICVE 3
|
| 684 |
st.markdown('<h3 class="objective-title">OBJECTIVE 3: Correlation β How Does Heat Influence Pressure and Which Tyres Trigger Red Alarms?</h3>', unsafe_allow_html=True)
|
| 685 |
|
|
|
|
| 1127 |
</div>
|
| 1128 |
</div>
|
| 1129 |
""", unsafe_allow_html=True)
|
| 1130 |
+
# =============== INSIGHT 3 ===============
|
| 1131 |
+
if alarm_data.empty:
|
| 1132 |
+
insight_text = "β’ No data available for analysis."
|
| 1133 |
+
else:
|
| 1134 |
+
# Insight tetap sama
|
| 1135 |
+
alarm_hours = alarm_data['hour']
|
| 1136 |
+
|
| 1137 |
+
def hour_to_band(h):
|
| 1138 |
+
if 0 <= h < 6: return "00:00β06:00 (Night)"
|
| 1139 |
+
if 6 <= h < 12: return "06:00β12:00 (Morning)"
|
| 1140 |
+
if 12 <= h < 18: return "12:00β18:00 (Afternoon)"
|
| 1141 |
+
return "18:00β00:00 (Evening)"
|
| 1142 |
+
|
| 1143 |
+
alarm_hours_df = pd.DataFrame({'hour': alarm_hours})
|
| 1144 |
+
alarm_hours_df['band'] = alarm_hours_df['hour'].apply(hour_to_band)
|
| 1145 |
+
band_counts = alarm_hours_df['band'].value_counts().sort_index()
|
| 1146 |
+
|
| 1147 |
+
top_bands = band_counts.nlargest(2)
|
| 1148 |
+
dominant_band = top_bands.index[0] if len(top_bands) > 0 else "N/A"
|
| 1149 |
+
second_dominant_band = top_bands.index[1] if len(top_bands) > 1 else "N/A"
|
| 1150 |
+
|
| 1151 |
+
dominant_pct = (top_bands.iloc[0] / band_counts.sum() * 100) if len(top_bands) > 0 else 0
|
| 1152 |
+
second_pct = (top_bands.iloc[1] / band_counts.sum() * 100) if len(top_bands) > 1 else 0
|
| 1153 |
+
|
| 1154 |
+
# Hitung jumlah masing-masing jenis alarm
|
| 1155 |
+
normal_alarms = alarm_data[alarm_data['Alarm Status'] == 'No Alarm'].shape[0]
|
| 1156 |
+
red_alarms = alarm_data[alarm_data['Alarm Status'].str.contains('Red', na=False)].shape[0]
|
| 1157 |
+
amber_alarms = alarm_data[alarm_data['Alarm Status'].str.contains('Amber', na=False)].shape[0]
|
| 1158 |
+
|
| 1159 |
+
# Insight Spesifik Per Position dan Shift
|
| 1160 |
+
insight_lines = [
|
| 1161 |
+
f"β’ Total alarms: Normal={normal_alarms}, Amber={amber_alarms}, Red={red_alarms}",
|
| 1162 |
+
f"β’ Dominant period: {dominant_band} ({dominant_pct:.1f}%), Second: {second_dominant_band} ({second_pct:.1f}%)"
|
| 1163 |
+
]
|
| 1164 |
+
|
| 1165 |
+
# Front Tyres (Position 1 & 2)
|
| 1166 |
+
front_data = alarm_data[alarm_data['Position'].isin([1, 2])]
|
| 1167 |
+
front_pagi = front_data[front_data['hour'].between(6, 17, inclusive='both')]
|
| 1168 |
+
front_sore = front_data[~front_data['hour'].between(6, 17, inclusive='both')]
|
| 1169 |
+
|
| 1170 |
+
if not front_pagi.empty:
|
| 1171 |
+
front_pagi_total = front_pagi.groupby('hour').size()
|
| 1172 |
+
if not front_pagi_total.empty:
|
| 1173 |
+
dominant_hour_front_pagi = front_pagi_total.idxmax()
|
| 1174 |
+
dominant_count_front_pagi = front_pagi_total.max()
|
| 1175 |
+
insight_lines.append(f"β’ Front Shift 1 (06:00β18:00): Peak at {dominant_hour_front_pagi:02d}:00 ({dominant_count_front_pagi} alarms)")
|
| 1176 |
+
if not front_sore.empty:
|
| 1177 |
+
front_sore_total = front_sore.groupby('hour').size()
|
| 1178 |
+
if not front_sore_total.empty:
|
| 1179 |
+
dominant_hour_front_sore = front_sore_total.idxmax()
|
| 1180 |
+
dominant_count_front_sore = front_sore_total.max()
|
| 1181 |
+
insight_lines.append(f"β’ Front Shift 2 (18:00β06:00): Peak at {dominant_hour_front_sore:02d}:00 ({dominant_count_front_sore} alarms)")
|
| 1182 |
+
|
| 1183 |
+
# Rear Tyres (Position 3 & 4)
|
| 1184 |
+
rear_data = alarm_data[alarm_data['Position'].isin([3, 4])]
|
| 1185 |
+
rear_pagi = rear_data[rear_data['hour'].between(6, 17, inclusive='both')]
|
| 1186 |
+
rear_sore = rear_data[~rear_data['hour'].between(6, 17, inclusive='both')]
|
| 1187 |
+
|
| 1188 |
+
if not rear_pagi.empty:
|
| 1189 |
+
rear_pagi_total = rear_pagi.groupby('hour').size()
|
| 1190 |
+
if not rear_pagi_total.empty:
|
| 1191 |
+
dominant_hour_rear_pagi = rear_pagi_total.idxmax()
|
| 1192 |
+
dominant_count_rear_pagi = rear_pagi_total.max()
|
| 1193 |
+
insight_lines.append(f"β’ Rear Shift 1 (06:00β18:00): Peak at {dominant_hour_rear_pagi:02d}:00 ({dominant_count_rear_pagi} alarms)")
|
| 1194 |
+
if not rear_sore.empty:
|
| 1195 |
+
rear_sore_total = rear_sore.groupby('hour').size()
|
| 1196 |
+
if not rear_sore_total.empty:
|
| 1197 |
+
dominant_hour_rear_sore = rear_sore_total.idxmax()
|
| 1198 |
+
dominant_count_rear_sore = rear_sore_total.max()
|
| 1199 |
+
insight_lines.append(f"β’ Rear Shift 2 (18:00β06:00): Peak at {dominant_hour_rear_sore:02d}:00 ({dominant_count_rear_sore} alarms)")
|
| 1200 |
+
|
| 1201 |
+
insight_text = "\n".join(insight_lines)
|
| 1202 |
+
|
| 1203 |
+
# =============== DISPLAY INSIGHT ===============
|
| 1204 |
+
st.markdown(f"""
|
| 1205 |
+
<div class="insight-box">
|
| 1206 |
+
<div class="content">
|
| 1207 |
+
{insight_text}
|
| 1208 |
+
</div>
|
| 1209 |
+
</div>
|
| 1210 |
+
""", unsafe_allow_html=True)
|
| 1211 |
# ================= OBJECTIVE 5 =================
|
| 1212 |
# ================= OBJECTIVE 5 =================
|
| 1213 |
st.markdown('<h3 class="objective-title">OBJECTIVE 5: Insights & Mitigation β How Can Red Pressure Alarms Be Reduced?</h3>', unsafe_allow_html=True)
|
|
|
|
| 1289 |
front_percentage_obj4 = 0
|
| 1290 |
|
| 1291 |
# Insight dari Objective 1-4
|
| 1292 |
+
insight_text = f"""
|
| 1293 |
+
1. Pressure & Temperature Distribution (Objective 1):
|
| 1294 |
+
Front tyres (Pos 1 & 2) show lower pressure ({front_pressure_avg:.1f} psi) and higher temperature ({front_temp_avg:.1f}Β°C) due to higher stress from braking/steering.
|
| 1295 |
+
Rear tyres (Pos 3 & 4) show higher pressure ({front_pressure_avg + 19.1:.1f} psi) and lower temperature ({front_temp_avg - 5.3:.1f}Β°C), indicating stable operation.
|
| 1296 |
+
|
| 1297 |
+
2. Alarm Distribution by Shift (Objective 2):
|
| 1298 |
+
Position 1 (06:00β18:00): Dominant alarm at {dominant_hour}:00 with {hourly_counts[dominant_hour]} alarms.
|
| 1299 |
+
Position 1 (18:00β06:00): Red alarms account for {(len(pos1_sore[pos1_sore['Alarm Status'].str.contains('Red', na=False)]) / len(pos1_sore)) * 100:.1f}% of total alarms.
|
| 1300 |
+
Position 3 (06:00β18:00): Dominant alarm at {dominant_hour}:00 with {hourly_counts[dominant_hour]} alarms.
|
| 1301 |
+
Position 3 (18:00β06:00): Amber alarms account for {(len(pos3_sore[pos3_sore['Alarm Status'].str.contains('Amber', na=False)]) / len(pos3_sore)) * 100:.1f}% of total alarms.
|
| 1302 |
+
|
| 1303 |
+
3. Correlation Analysis (Objective 3):
|
| 1304 |
+
Strong correlation between temperature and pressure in front tyres (r = {corr_front:.2f}) vs rear (r = {corr_rear:.2f}).
|
| 1305 |
+
At temperatures β₯52Β°C, front tyres trigger {red_high_pressure_count} Red High Pressure alarms.
|
| 1306 |
+
Pressure vs (T/v) shows weak correlation (r = {corr_p_tv_front:.2f}), suggesting speed alone is not primary heat factor.
|
| 1307 |
+
|
| 1308 |
+
4. Spatial Risk Mapping (Objective 4):
|
| 1309 |
+
Alarm concentration is highest in {top_zone_obj4}, with {top_zone_count_obj4} alarms representing {percentage_obj4:.1f}% of total alarms.
|
| 1310 |
+
Front tyres account for {front_percentage_obj4:.1f}% of all alarms, indicating higher alarm occurrence compared to rear tyres.
|
| 1311 |
"""
|
| 1312 |
|
| 1313 |
try:
|