Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -486,8 +486,72 @@ st.markdown(f"""
|
|
| 486 |
</div>
|
| 487 |
""", unsafe_allow_html=True)
|
| 488 |
# ================= OBJECTIVE 2 =================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
st.markdown("""
|
| 490 |
-
<h3 class="objective-title">OBJECTIVE
|
| 491 |
<small>*Showing only Red High Pressure Alarms</small>
|
| 492 |
""", unsafe_allow_html=True)
|
| 493 |
|
|
|
|
| 486 |
</div>
|
| 487 |
""", unsafe_allow_html=True)
|
| 488 |
# ================= OBJECTIVE 2 =================
|
| 489 |
+
st.markdown('<h3 class="objective-title">OBJECTIVE 2: Hourly Alarm Trend Analysis — When Do Alarms Peak?</h3>', unsafe_allow_html=True)
|
| 490 |
+
|
| 491 |
+
# Ambil data alarm
|
| 492 |
+
alarm_data = dff[dff['is_alarm'] == 1].copy()
|
| 493 |
+
|
| 494 |
+
if alarm_data.empty:
|
| 495 |
+
st.warning("No alarm data to display.")
|
| 496 |
+
else:
|
| 497 |
+
# Hitung jumlah alarm per jam
|
| 498 |
+
hourly_alarm_counts = alarm_data['hour'].value_counts().reindex(range(24), fill_value=0)
|
| 499 |
+
|
| 500 |
+
# Hitung rata-rata jumlah alarm per jam
|
| 501 |
+
avg_hourly_alarms = hourly_alarm_counts.mean() # rata-rata alarm per jam
|
| 502 |
+
|
| 503 |
+
# Buat grafik trend
|
| 504 |
+
fig = px.line(
|
| 505 |
+
x=hourly_alarm_counts.index,
|
| 506 |
+
y=hourly_alarm_counts.values,
|
| 507 |
+
markers=True,
|
| 508 |
+
line_shape='linear',
|
| 509 |
+
title=f"Hourly Alarm Trend Analysis (Avg: {avg_hourly_alarms:.2f} alarms/hour)",
|
| 510 |
+
labels={'x': 'Hour of Day', 'y': 'Number of Alarms'},
|
| 511 |
+
template="plotly_white"
|
| 512 |
+
)
|
| 513 |
+
|
| 514 |
+
# Tambahkan garis rata-rata
|
| 515 |
+
fig.add_hline(
|
| 516 |
+
y=avg_hourly_alarms,
|
| 517 |
+
line_dash="dash",
|
| 518 |
+
line_color="red",
|
| 519 |
+
annotation_text=f"Average: {avg_hourly_alarms:.2f}",
|
| 520 |
+
annotation_position="top right"
|
| 521 |
+
)
|
| 522 |
+
|
| 523 |
+
fig.update_layout(
|
| 524 |
+
xaxis=dict(
|
| 525 |
+
title="Hour of Day",
|
| 526 |
+
tickmode='array',
|
| 527 |
+
tickvals=list(range(0, 24)),
|
| 528 |
+
ticktext=[f"{h:02d}:00" for h in range(24)],
|
| 529 |
+
tickangle=45
|
| 530 |
+
),
|
| 531 |
+
yaxis=dict(title="Number of Alarms"),
|
| 532 |
+
margin=dict(t=40, b=20, l=20, r=20)
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 536 |
+
|
| 537 |
+
# Insight singkat
|
| 538 |
+
peak_hour = hourly_alarm_counts.idxmax()
|
| 539 |
+
peak_count = hourly_alarm_counts.max()
|
| 540 |
+
insight_text = f"""
|
| 541 |
+
• Peak alarm hour: {peak_hour:02d}:00 with {peak_count} alarms.
|
| 542 |
+
• Average alarms per hour: {avg_hourly_alarms:.2f}.
|
| 543 |
+
• Total alarms in period: {hourly_alarm_counts.sum()}.
|
| 544 |
+
"""
|
| 545 |
+
st.markdown(f"""
|
| 546 |
+
<div class="insight-box">
|
| 547 |
+
<div class="content">
|
| 548 |
+
{insight_text.strip()}
|
| 549 |
+
</div>
|
| 550 |
+
</div>
|
| 551 |
+
""", unsafe_allow_html=True)
|
| 552 |
+
# ================= OBJECTIVE 3 =================
|
| 553 |
st.markdown("""
|
| 554 |
+
<h3 class="objective-title">OBJECTIVE 3: Alarm Frequency Analysis — When, Where, and Which Tyres Matter Most?</h3>
|
| 555 |
<small>*Showing only Red High Pressure Alarms</small>
|
| 556 |
""", unsafe_allow_html=True)
|
| 557 |
|