Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -681,48 +681,7 @@ st.markdown(f"""
|
|
| 681 |
# hourly_alarm_melted,
|
| 682 |
# x='hour',
|
| 683 |
# y='Alarm Count',
|
| 684 |
-
# color='Position',
|
| 685 |
-
# color_discrete_map=color_map,
|
| 686 |
-
# title="Alarm Count (Amber & Red Only) per Hour by Tyre Position",
|
| 687 |
-
# labels={'Alarm Count': 'Number of Alarms', 'Position': 'Tyre Position'},
|
| 688 |
-
# line_shape='linear',
|
| 689 |
-
# template="plotly_white"
|
| 690 |
-
# )
|
| 691 |
-
|
| 692 |
-
# fig2.update_layout(
|
| 693 |
-
# xaxis=dict(
|
| 694 |
-
# title="Hour of Day",
|
| 695 |
-
# tickmode='array',
|
| 696 |
-
# tickvals=list(range(0, 24)),
|
| 697 |
-
# ticktext=[f"{h:02d}:00" for h in range(24)],
|
| 698 |
-
# tickangle=45
|
| 699 |
-
# ),
|
| 700 |
-
# yaxis=dict(title="Number of Alarms"),
|
| 701 |
-
# legend_title_text='Tyre Position',
|
| 702 |
-
# margin=dict(t=40, b=40, l=40, r=20),
|
| 703 |
-
# title_x=0.5
|
| 704 |
-
# )
|
| 705 |
-
|
| 706 |
-
# st.plotly_chart(fig2, use_container_width=True)
|
| 707 |
-
|
| 708 |
-
# # =============== INSIGHT ===============
|
| 709 |
-
# # Insight tetap bisa menampilkan perbandingan
|
| 710 |
-
# capture_by_pos = dff['Position'].value_counts().reindex([1,2,3,4], fill_value=0)
|
| 711 |
-
# alarm_by_pos = alarm_data['Position'].value_counts().reindex([1,2,3,4], fill_value=0)
|
| 712 |
-
|
| 713 |
-
# insight_text = f"""
|
| 714 |
-
# β’ Total data capture: Pos 1={capture_by_pos[1]}, 2={capture_by_pos[2]}, 3={capture_by_pos[3]}, 4={capture_by_pos[4]}
|
| 715 |
-
# β’ Total alarms (Amber/Red): Pos 1={alarm_by_pos[1]}, 2={alarm_by_pos[2]}, 3={alarm_by_pos[3]}, 4={alarm_by_pos[4]}
|
| 716 |
-
# β’ Alarm density varies significantly between positions β suggesting different operational stress levels.
|
| 717 |
-
# """
|
| 718 |
|
| 719 |
-
# st.markdown(f"""
|
| 720 |
-
# <div class="insight-box">
|
| 721 |
-
# <div class="content">
|
| 722 |
-
# {insight_text.strip()}
|
| 723 |
-
# </div>
|
| 724 |
-
# </div>
|
| 725 |
-
# "
|
| 726 |
st.markdown("""
|
| 727 |
<h3 class="objective-title">OBJECTIVE 2: Alarm Frequency Analysis β Shift-Based Radial Charts</h3>
|
| 728 |
<small>*Showing alarm types by shift: Normal (Green), Amber (Yellow), Red (Red)</small>
|
|
@@ -943,7 +902,7 @@ st.markdown(f"""
|
|
| 943 |
</div>
|
| 944 |
""", unsafe_allow_html=True)
|
| 945 |
# ================= OBJECTIVE 3 =================
|
| 946 |
-
st.markdown('<h3 class="objective-title">OBJECTIVE
|
| 947 |
|
| 948 |
# Prepare data
|
| 949 |
front_df = dff[dff['Position'].isin([1, 2])].copy()
|
|
@@ -952,7 +911,6 @@ rear_df = dff[dff['Position'].isin([3, 4])].copy()
|
|
| 952 |
col1, col2 = st.columns(2)
|
| 953 |
|
| 954 |
# =============== COL 1: Front β Temperature β Pressure (Scatter + Regression Area) ===============
|
| 955 |
-
# =============== COL 1: Front β Temperature β Pressure ===============
|
| 956 |
with col1:
|
| 957 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Front Tyres: Temperature β Pressure</h5>', unsafe_allow_html=True)
|
| 958 |
|
|
@@ -996,12 +954,31 @@ with col1:
|
|
| 996 |
marker=dict(size=6)
|
| 997 |
)
|
| 998 |
|
|
|
|
| 999 |
fig1.add_trace(go.Scatter(
|
| 1000 |
x=x_line.flatten(), y=y_line,
|
| 1001 |
mode='lines', name='Trend Line',
|
| 1002 |
line=dict(color='#1976D2', dash='dot', width=2)
|
| 1003 |
))
|
| 1004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
fig1.update_layout(
|
| 1006 |
margin=dict(t=40),
|
| 1007 |
annotations=[
|
|
@@ -1023,7 +1000,8 @@ with col1:
|
|
| 1023 |
borderwidth=1,
|
| 1024 |
itemclick=False,
|
| 1025 |
itemdoubleclick=False
|
| 1026 |
-
)
|
|
|
|
| 1027 |
)
|
| 1028 |
st.plotly_chart(fig1, use_container_width=True)
|
| 1029 |
else:
|
|
@@ -1031,9 +1009,7 @@ with col1:
|
|
| 1031 |
else:
|
| 1032 |
st.warning("No front tyre data.")
|
| 1033 |
|
| 1034 |
-
|
| 1035 |
# =============== COL 2: Front β Temperature / Speed (Boxplot) ===============
|
| 1036 |
-
# =============== COL 2: Front β Pressure vs (Temperature / Speed) ===============
|
| 1037 |
with col2:
|
| 1038 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Front Tyres: Pressure vs (Temperature / Speed)</h5>', unsafe_allow_html=True)
|
| 1039 |
|
|
@@ -1092,8 +1068,6 @@ with col2:
|
|
| 1092 |
|
| 1093 |
# =============== COL 3: Rear β Temperature β Pressure (Scatter + Regression Area) ===============
|
| 1094 |
col3, col4 = st.columns(2)
|
| 1095 |
-
# =============== COL 3: Rear β Temperature β Pressure ===============
|
| 1096 |
-
col3, col4 = st.columns(2)
|
| 1097 |
|
| 1098 |
with col3:
|
| 1099 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Rear Tyres: Temperature β Pressure</h5>', unsafe_allow_html=True)
|
|
@@ -1141,6 +1115,24 @@ with col3:
|
|
| 1141 |
line=dict(color='#1976D2', dash='dot', width=2)
|
| 1142 |
))
|
| 1143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1144 |
fig3.update_layout(
|
| 1145 |
margin=dict(t=40),
|
| 1146 |
annotations=[
|
|
@@ -1162,7 +1154,8 @@ with col3:
|
|
| 1162 |
borderwidth=1,
|
| 1163 |
itemclick=False,
|
| 1164 |
itemdoubleclick=False
|
| 1165 |
-
)
|
|
|
|
| 1166 |
)
|
| 1167 |
st.plotly_chart(fig3, use_container_width=True)
|
| 1168 |
else:
|
|
@@ -1170,7 +1163,6 @@ with col3:
|
|
| 1170 |
else:
|
| 1171 |
st.warning("No rear tyre data.")
|
| 1172 |
|
| 1173 |
-
|
| 1174 |
# =============== COL 4: Rear β Pressure vs (Temperature / Speed) ===============
|
| 1175 |
with col4:
|
| 1176 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Rear Tyres: Pressure vs (Temperature / Speed)</h5>', unsafe_allow_html=True)
|
|
@@ -1250,6 +1242,7 @@ st.markdown(f"""
|
|
| 1250 |
</div>
|
| 1251 |
</div>
|
| 1252 |
""", unsafe_allow_html=True)
|
|
|
|
| 1253 |
# ================= OBJECTIVE 5 =================
|
| 1254 |
st.markdown('<h3 class="objective-title">OBJECTIVE 5: Spatial Risk Mapping β Where Do Red Pressure Alarms Occur Most Frequently?</h3>', unsafe_allow_html=True)
|
| 1255 |
|
|
|
|
| 681 |
# hourly_alarm_melted,
|
| 682 |
# x='hour',
|
| 683 |
# y='Alarm Count',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 684 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
st.markdown("""
|
| 686 |
<h3 class="objective-title">OBJECTIVE 2: Alarm Frequency Analysis β Shift-Based Radial Charts</h3>
|
| 687 |
<small>*Showing alarm types by shift: Normal (Green), Amber (Yellow), Red (Red)</small>
|
|
|
|
| 902 |
</div>
|
| 903 |
""", unsafe_allow_html=True)
|
| 904 |
# ================= OBJECTIVE 3 =================
|
| 905 |
+
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)
|
| 906 |
|
| 907 |
# Prepare data
|
| 908 |
front_df = dff[dff['Position'].isin([1, 2])].copy()
|
|
|
|
| 911 |
col1, col2 = st.columns(2)
|
| 912 |
|
| 913 |
# =============== COL 1: Front β Temperature β Pressure (Scatter + Regression Area) ===============
|
|
|
|
| 914 |
with col1:
|
| 915 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Front Tyres: Temperature β Pressure</h5>', unsafe_allow_html=True)
|
| 916 |
|
|
|
|
| 954 |
marker=dict(size=6)
|
| 955 |
)
|
| 956 |
|
| 957 |
+
# Tambahkan garis regresi
|
| 958 |
fig1.add_trace(go.Scatter(
|
| 959 |
x=x_line.flatten(), y=y_line,
|
| 960 |
mode='lines', name='Trend Line',
|
| 961 |
line=dict(color='#1976D2', dash='dot', width=2)
|
| 962 |
))
|
| 963 |
|
| 964 |
+
# Tambahkan area confidence interval (soft background)
|
| 965 |
+
y_pred = model.predict(X)
|
| 966 |
+
residuals = y - y_pred
|
| 967 |
+
mse = np.mean(residuals**2)
|
| 968 |
+
std_error = np.sqrt(mse)
|
| 969 |
+
y_upper = y_line + 1.96 * std_error
|
| 970 |
+
y_lower = y_line - 1.96 * std_error
|
| 971 |
+
|
| 972 |
+
fig1.add_trace(go.Scatter(
|
| 973 |
+
x=np.concatenate([x_line.flatten(), x_line.flatten()[::-1]]),
|
| 974 |
+
y=np.concatenate([y_upper, y_lower[::-1]]),
|
| 975 |
+
fill='toself',
|
| 976 |
+
fillcolor='rgba(211, 47, 47, 0.1)', # Merah transparan
|
| 977 |
+
line=dict(color='rgba(255,255,255,0)'),
|
| 978 |
+
showlegend=False,
|
| 979 |
+
name='Confidence Interval'
|
| 980 |
+
))
|
| 981 |
+
|
| 982 |
fig1.update_layout(
|
| 983 |
margin=dict(t=40),
|
| 984 |
annotations=[
|
|
|
|
| 1000 |
borderwidth=1,
|
| 1001 |
itemclick=False,
|
| 1002 |
itemdoubleclick=False
|
| 1003 |
+
),
|
| 1004 |
+
showlegend=True
|
| 1005 |
)
|
| 1006 |
st.plotly_chart(fig1, use_container_width=True)
|
| 1007 |
else:
|
|
|
|
| 1009 |
else:
|
| 1010 |
st.warning("No front tyre data.")
|
| 1011 |
|
|
|
|
| 1012 |
# =============== COL 2: Front β Temperature / Speed (Boxplot) ===============
|
|
|
|
| 1013 |
with col2:
|
| 1014 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Front Tyres: Pressure vs (Temperature / Speed)</h5>', unsafe_allow_html=True)
|
| 1015 |
|
|
|
|
| 1068 |
|
| 1069 |
# =============== COL 3: Rear β Temperature β Pressure (Scatter + Regression Area) ===============
|
| 1070 |
col3, col4 = st.columns(2)
|
|
|
|
|
|
|
| 1071 |
|
| 1072 |
with col3:
|
| 1073 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Rear Tyres: Temperature β Pressure</h5>', unsafe_allow_html=True)
|
|
|
|
| 1115 |
line=dict(color='#1976D2', dash='dot', width=2)
|
| 1116 |
))
|
| 1117 |
|
| 1118 |
+
# Tambahkan area confidence interval (soft background)
|
| 1119 |
+
y_pred = model.predict(X)
|
| 1120 |
+
residuals = y - y_pred
|
| 1121 |
+
mse = np.mean(residuals**2)
|
| 1122 |
+
std_error = np.sqrt(mse)
|
| 1123 |
+
y_upper = y_line + 1.96 * std_error
|
| 1124 |
+
y_lower = y_line - 1.96 * std_error
|
| 1125 |
+
|
| 1126 |
+
fig3.add_trace(go.Scatter(
|
| 1127 |
+
x=np.concatenate([x_line.flatten(), x_line.flatten()[::-1]]),
|
| 1128 |
+
y=np.concatenate([y_upper, y_lower[::-1]]),
|
| 1129 |
+
fill='toself',
|
| 1130 |
+
fillcolor='rgba(211, 47, 47, 0.1)', # Merah transparan
|
| 1131 |
+
line=dict(color='rgba(255,255,255,0)'),
|
| 1132 |
+
showlegend=False,
|
| 1133 |
+
name='Confidence Interval'
|
| 1134 |
+
))
|
| 1135 |
+
|
| 1136 |
fig3.update_layout(
|
| 1137 |
margin=dict(t=40),
|
| 1138 |
annotations=[
|
|
|
|
| 1154 |
borderwidth=1,
|
| 1155 |
itemclick=False,
|
| 1156 |
itemdoubleclick=False
|
| 1157 |
+
),
|
| 1158 |
+
showlegend=True
|
| 1159 |
)
|
| 1160 |
st.plotly_chart(fig3, use_container_width=True)
|
| 1161 |
else:
|
|
|
|
| 1163 |
else:
|
| 1164 |
st.warning("No rear tyre data.")
|
| 1165 |
|
|
|
|
| 1166 |
# =============== COL 4: Rear β Pressure vs (Temperature / Speed) ===============
|
| 1167 |
with col4:
|
| 1168 |
st.markdown('<h5 style="text-align:center; margin-top: 0;">Rear Tyres: Pressure vs (Temperature / Speed)</h5>', unsafe_allow_html=True)
|
|
|
|
| 1242 |
</div>
|
| 1243 |
</div>
|
| 1244 |
""", unsafe_allow_html=True)
|
| 1245 |
+
|
| 1246 |
# ================= OBJECTIVE 5 =================
|
| 1247 |
st.markdown('<h3 class="objective-title">OBJECTIVE 5: Spatial Risk Mapping β Where Do Red Pressure Alarms Occur Most Frequently?</h3>', unsafe_allow_html=True)
|
| 1248 |
|