SHELLAPANDIANGANHUNGING commited on
Commit
5dd7d3e
·
verified ·
1 Parent(s): c77f565

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -725,7 +725,7 @@ st.markdown(f"""
725
  # """, unsafe_allow_html=True)
726
  st.markdown("""
727
  <h3 class="objective-title">OBJECTIVE 3: Alarm Frequency Analysis — When, Where, and Which Tyres Matter Most?</h3>
728
- <small>*Showing all alarm types: Normal (Green), Amber (Yellow), Red (Red)</small>
729
  """, unsafe_allow_html=True)
730
 
731
  # Filter semua data (termasuk alarm normal)
@@ -796,7 +796,7 @@ with col_b:
796
  )
797
  st.plotly_chart(fig_donut, use_container_width=True)
798
 
799
- # =============== COL A: Radial Charts (Count Alarm per Jam - Semua Jenis) ===============
800
  with col_a:
801
  st.markdown('<h5 style="text-align:center; margin-top: 0;">Alarm Count by Hour (Radial)</h5>', unsafe_allow_html=True)
802
 
@@ -814,31 +814,26 @@ with col_a:
814
  for i, pos in enumerate([1, 2, 3, 4], 1):
815
  pos_data = alarm_data[alarm_data['Position'] == pos].copy()
816
  if not pos_data.empty:
817
- # Kelompokkan jam dan alarm
818
- hourly_counts = pos_data.groupby(['hour', 'Alarm_Category']).size().unstack(fill_value=0)
819
-
820
- # Ambil total alarm per jam
821
- total_per_hour = hourly_counts.sum(axis=1).reindex(range(24), fill_value=0)
822
-
823
- # Warna berdasarkan jenis alarm dominan per jam
824
- dominant_alarm_per_hour = pos_data.groupby('hour')['Alarm_Category'].apply(
825
- lambda x: x.mode().iloc[0] if not x.empty else 'Normal'
826
  ).reindex(range(24), fill_value='Normal')
827
 
828
- # Map warna sesuai permintaan Anda
829
- color_map = {
830
- 'Normal': '#2E7D32', # Hijau
831
- 'Amber Alarm': '#FFC107', # Kuning
832
- 'Red Alarm': '#D32F2F' # Merah
833
- }
834
- colorscale = [color_map.get(cat, '#2E7D32') for cat in dominant_alarm_per_hour]
835
 
836
  # Sudut: jam 0 → 0° (atas), jam 6 → 90° (kanan), jam 12 → 180° (bawah), jam 18 → 270° (kiri)
837
  theta = [h * 15 for h in range(24)] # 24 jam * 15° = 360°
838
 
839
  fig_radial.add_trace(
840
  go.Barpolar(
841
- r=total_per_hour.values,
842
  theta=theta,
843
  name=f'Position {pos}',
844
  marker_color=colorscale,
@@ -856,7 +851,14 @@ with col_a:
856
  angularaxis=dict(
857
  direction="clockwise",
858
  period=24,
859
- rotation=90 # Jam 0 di atas
 
 
 
 
 
 
 
860
  )
861
  )
862
  )
@@ -906,7 +908,6 @@ st.markdown(f"""
906
  </div>
907
  </div>
908
  """, unsafe_allow_html=True)
909
-
910
  # ================= OBJECTIVE 3 =================
911
  st.markdown('<h3 class="objective-title">OBJECTIVE 4: Correlation — How Does Heat Influence Pressure and Which Tyres Trigger Red Alarms?</h3>', unsafe_allow_html=True)
912
 
 
725
  # """, unsafe_allow_html=True)
726
  st.markdown("""
727
  <h3 class="objective-title">OBJECTIVE 3: Alarm Frequency Analysis — When, Where, and Which Tyres Matter Most?</h3>
728
+ <small>*Showing all alarm types: Normal (Green), Abnormal (Red)</small>
729
  """, unsafe_allow_html=True)
730
 
731
  # Filter semua data (termasuk alarm normal)
 
796
  )
797
  st.plotly_chart(fig_donut, use_container_width=True)
798
 
799
+ # =============== COL A: Radial Charts (Count Alarm per Jam - 2 Warna: Normal vs Abnormal) ===============
800
  with col_a:
801
  st.markdown('<h5 style="text-align:center; margin-top: 0;">Alarm Count by Hour (Radial)</h5>', unsafe_allow_html=True)
802
 
 
814
  for i, pos in enumerate([1, 2, 3, 4], 1):
815
  pos_data = alarm_data[alarm_data['Position'] == pos].copy()
816
  if not pos_data.empty:
817
+ # Kelompokkan jam
818
+ hourly_counts = pos_data.groupby('hour').size().reindex(range(24), fill_value=0)
819
+
820
+ # Tentukan apakah jam tersebut "Normal" atau "Abnormal"
821
+ # Normal: hanya jika semua alarm di jam tersebut adalah "No Alarm"
822
+ # Abnormal: jika ada minimal satu "Amber" atau "Red"
823
+ hourly_status = pos_data.groupby('hour')['Alarm Status'].apply(
824
+ lambda x: 'Normal' if (x == 'No Alarm').all() else 'Abnormal'
 
825
  ).reindex(range(24), fill_value='Normal')
826
 
827
+ # Warna: Hijau untuk Normal, Merah untuk Abnormal
828
+ color_map = {'Normal': '#2E7D32', 'Abnormal': '#D32F2F'}
829
+ colorscale = [color_map.get(status, '#2E7D32') for status in hourly_status]
 
 
 
 
830
 
831
  # Sudut: jam 0 → 0° (atas), jam 6 → 90° (kanan), jam 12 → 180° (bawah), jam 18 → 270° (kiri)
832
  theta = [h * 15 for h in range(24)] # 24 jam * 15° = 360°
833
 
834
  fig_radial.add_trace(
835
  go.Barpolar(
836
+ r=hourly_counts.values,
837
  theta=theta,
838
  name=f'Position {pos}',
839
  marker_color=colorscale,
 
851
  angularaxis=dict(
852
  direction="clockwise",
853
  period=24,
854
+ rotation=90, # Jam 0 di atas
855
+ tickvals=[0, 90, 180, 270],
856
+ ticktext=["00:00", "06:00", "12:00", "18:00"],
857
+ tickfont=dict(size=12)
858
+ ),
859
+ radialaxis=dict(
860
+ visible=True,
861
+ range=[0, max(hourly_counts.max() * 1.1, 1)]
862
  )
863
  )
864
  )
 
908
  </div>
909
  </div>
910
  """, unsafe_allow_html=True)
 
911
  # ================= OBJECTIVE 3 =================
912
  st.markdown('<h3 class="objective-title">OBJECTIVE 4: Correlation — How Does Heat Influence Pressure and Which Tyres Trigger Red Alarms?</h3>', unsafe_allow_html=True)
913