SHELLAPANDIANGANHUNGING commited on
Commit
f35b1fa
·
verified ·
1 Parent(s): b438190

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -24
app.py CHANGED
@@ -486,7 +486,8 @@ st.markdown(f"""
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()
@@ -494,31 +495,34 @@ alarm_data = dff[dff['is_alarm'] == 1].copy()
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(
@@ -529,18 +533,18 @@ else:
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">
 
486
  </div>
487
  """, unsafe_allow_html=True)
488
  # ================= OBJECTIVE 2 =================
489
+ # ================= OBJECTIVE 2 =================
490
+ st.markdown('<h3 class="objective-title">OBJECTIVE 2: Hourly Alarm Trend Analysis — By Tyre Position</h3>', unsafe_allow_html=True)
491
 
492
  # Ambil data alarm
493
  alarm_data = dff[dff['is_alarm'] == 1].copy()
 
495
  if alarm_data.empty:
496
  st.warning("No alarm data to display.")
497
  else:
498
+ # Hitung jumlah alarm per jam dan per posisi
499
+ hourly_pos_counts = alarm_data.groupby(['hour', 'Position']).size().unstack(fill_value=0)
500
+
501
+ # Pastikan semua posisi (1,2,3,4) ada di kolom
502
+ for pos in [1, 2, 3, 4]:
503
+ if pos not in hourly_pos_counts.columns:
504
+ hourly_pos_counts[pos] = 0
505
+
506
+ # Urutkan kolom
507
+ hourly_pos_counts = hourly_pos_counts[[1, 2, 3, 4]]
508
 
509
+ # Gunakan warna sesuai Objective 1
510
+ color_map = {1: '#003DA5', 2: '#7FA6E8', 3: '#FFB300', 4: '#FFE082'}
511
 
512
  # Buat grafik trend
513
  fig = px.line(
514
+ hourly_pos_counts,
515
+ x=hourly_pos_counts.index,
516
+ y=[1, 2, 3, 4],
517
+ title="Hourly Alarm Count by Tyre Position",
518
+ labels={'value': 'Number of Alarms', 'variable': 'Tyre Position'},
519
+ template="plotly_white",
520
  line_shape='linear',
521
+ color_discrete_map=color_map
 
 
522
  )
523
 
524
+ # Ganti nama legend
525
+ fig.for_each_trace(lambda t: t.update(name=f'Position {int(t.name)}'))
 
 
 
 
 
 
526
 
527
  fig.update_layout(
528
  xaxis=dict(
 
533
  tickangle=45
534
  ),
535
  yaxis=dict(title="Number of Alarms"),
536
+ legend_title_text='Tyre Position',
537
  margin=dict(t=40, b=20, l=20, r=20)
538
  )
539
 
540
  st.plotly_chart(fig, use_container_width=True)
541
 
542
  # Insight singkat
543
+ total_by_pos = hourly_pos_counts.sum()
 
544
  insight_text = f"""
545
+ Position 1: {total_by_pos[1]} alarms | Position 2: {total_by_pos[2]} alarms
546
+ Position 3: {total_by_pos[3]} alarms | Position 4: {total_by_pos[4]} alarms
547
+ Peak alarm patterns vary by position — suggesting location-specific stress factors.
548
  """
549
  st.markdown(f"""
550
  <div class="insight-box">