Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +30 -30
src/streamlit_app.py
CHANGED
|
@@ -683,8 +683,8 @@ else:
|
|
| 683 |
# SUB-NAV PILLS (Menggunakan st.tabs bawaan dengan CSS Custom)
|
| 684 |
# ============================================================
|
| 685 |
tab_dashboard, tab_cycles = st.tabs([
|
| 686 |
-
"
|
| 687 |
-
"
|
| 688 |
])
|
| 689 |
|
| 690 |
# ============================================================
|
|
@@ -726,7 +726,7 @@ else:
|
|
| 726 |
db.execute("UPDATE cycles SET initial_thickness = ?, start_date = ? WHERE id = ?",
|
| 727 |
(thickness_actual, tgl_skrg.isoformat(), cycle_id))
|
| 728 |
db.commit()
|
| 729 |
-
st.success("
|
| 730 |
st.rerun()
|
| 731 |
with col_bulk:
|
| 732 |
with st.container(border=True):
|
|
@@ -772,9 +772,9 @@ else:
|
|
| 772 |
pass
|
| 773 |
|
| 774 |
if not col_tanggal or not col_suhu:
|
| 775 |
-
st.error("
|
| 776 |
else:
|
| 777 |
-
st.info("
|
| 778 |
st.dataframe(data_import.head(3), use_container_width=True)
|
| 779 |
|
| 780 |
if st.button("Konfirmasi & Simpan CSV", type="primary"):
|
|
@@ -798,7 +798,7 @@ else:
|
|
| 798 |
""", (cycle_id, log_date, raw_temp, cone_front, cone_back, thickness, lot_number))
|
| 799 |
count += 1
|
| 800 |
db.commit()
|
| 801 |
-
st.success(f"
|
| 802 |
st.rerun()
|
| 803 |
except Exception as e:
|
| 804 |
st.error(f"Gagal memproses file CSV: {e}")
|
|
@@ -836,10 +836,10 @@ else:
|
|
| 836 |
|
| 837 |
# Ringkasan Parameter Prediktif & Status Operasional
|
| 838 |
c1, c2, c3, c4 = st.columns(4)
|
| 839 |
-
c1.metric("
|
| 840 |
-
c2.metric("
|
| 841 |
-
c3.metric("
|
| 842 |
-
c4.metric("
|
| 843 |
|
| 844 |
# --- PLOTLY CHART (Estetika Minimalis & Editorial Replicate) ---
|
| 845 |
st.markdown('<div class="rep-chart-well">', unsafe_allow_html=True)
|
|
@@ -1053,25 +1053,25 @@ else:
|
|
| 1053 |
|
| 1054 |
if 'Tanggal' in df_excel.columns:
|
| 1055 |
cols_to_show.append('Tanggal')
|
| 1056 |
-
rename_dict['Tanggal'] = '
|
| 1057 |
if 'lot_number' in df_excel.columns:
|
| 1058 |
cols_to_show.append('lot_number')
|
| 1059 |
-
rename_dict['lot_number'] = '
|
| 1060 |
if 'cone_front' in df_excel.columns:
|
| 1061 |
cols_to_show.append('cone_front')
|
| 1062 |
-
rename_dict['cone_front'] = '
|
| 1063 |
if 'raw_temp' in df_excel.columns:
|
| 1064 |
cols_to_show.append('raw_temp')
|
| 1065 |
-
rename_dict['raw_temp'] = '
|
| 1066 |
if 'cone_back' in df_excel.columns:
|
| 1067 |
cols_to_show.append('cone_back')
|
| 1068 |
-
rename_dict['cone_back'] = '
|
| 1069 |
if 'thickness' in df_excel.columns:
|
| 1070 |
cols_to_show.append('thickness')
|
| 1071 |
-
rename_dict['thickness'] = '
|
| 1072 |
if 'thickness_pred' in df_excel.columns:
|
| 1073 |
cols_to_show.append('thickness_pred')
|
| 1074 |
-
rename_dict['thickness_pred'] = '
|
| 1075 |
|
| 1076 |
df_excel_subset = df_excel[cols_to_show].rename(columns=rename_dict)
|
| 1077 |
|
|
@@ -1081,13 +1081,13 @@ else:
|
|
| 1081 |
use_container_width=True,
|
| 1082 |
height=280,
|
| 1083 |
column_config={
|
| 1084 |
-
'
|
| 1085 |
-
'
|
| 1086 |
-
'
|
| 1087 |
-
'
|
| 1088 |
-
'
|
| 1089 |
}
|
| 1090 |
-
|
| 1091 |
st.markdown('<div style="height: 24px;"></div>', unsafe_allow_html=True)
|
| 1092 |
|
| 1093 |
# ============================================================
|
|
@@ -1146,7 +1146,7 @@ else:
|
|
| 1146 |
# Column 2: Bulk Import CSV
|
| 1147 |
with col_bulk:
|
| 1148 |
with st.container(border=True):
|
| 1149 |
-
st.markdown('<div style="font-size: 18px; font-weight: 700; margin-bottom: 8px; font-family: \'Bricolage Grotesque\'; color: #202020;">
|
| 1150 |
st.markdown('<p style="font-size: 13px; color: var(--text-charcoal); margin-bottom: 16px;">Unggah file CSV dengan kolom utama: <b>Tanggal</b> dan <b>Bodi Tengah (°C)</b>. Kolom pendukung seperti <i>Cone Depan (°C)</i>, <i>Cone Belakang (°C)</i>, <i>Ketebalan BTA (mm)</i>, dan <i>Lot Number</i> akan terdeteksi secara otomatis.</p>', unsafe_allow_html=True)
|
| 1151 |
|
| 1152 |
uploaded_file = st.file_uploader("Pilih file CSV dari komputer Anda", type="csv", key="int_uploader")
|
|
@@ -1189,9 +1189,9 @@ else:
|
|
| 1189 |
pass
|
| 1190 |
|
| 1191 |
if not col_tanggal or not col_suhu:
|
| 1192 |
-
st.error("
|
| 1193 |
else:
|
| 1194 |
-
st.info("
|
| 1195 |
st.dataframe(data_import.head(3), use_container_width=True)
|
| 1196 |
|
| 1197 |
if st.button("Konfirmasi & Simpan CSV", type="primary", key="int_confirm_btn"):
|
|
@@ -1239,7 +1239,7 @@ else:
|
|
| 1239 |
st.markdown(f'<p style="font-size: 13px; color: var(--text-charcoal); margin-bottom: 18px;">Saat ini Anda berada di dalam siklus aktif yang dimulai pada <b>{start_date_str}</b> dengan ketebalan awal BTA sebesar <b>{initial_thickness:.1f} mm</b>.</p>', unsafe_allow_html=True)
|
| 1240 |
st.markdown('<p style="font-size: 13px; color: var(--text-charcoal); margin-bottom: 24px;">Menutup siklus aktif akan mengarsipkan seluruh riwayat log harian saat ini, dan membuka form registrasi untuk mendata lining furnace BTA baru.</p>', unsafe_allow_html=True)
|
| 1241 |
|
| 1242 |
-
if st.button("
|
| 1243 |
db.execute("UPDATE cycles SET active = 0 WHERE active = 1")
|
| 1244 |
db.commit()
|
| 1245 |
st.success("Siklus aktif berhasil diarsipkan.")
|
|
@@ -1248,20 +1248,20 @@ else:
|
|
| 1248 |
# Column 2: Log Tabel Mentah Database
|
| 1249 |
with col_c2:
|
| 1250 |
with st.container(border=True):
|
| 1251 |
-
st.markdown('<div style="font-size: 18px; font-weight: 700; margin-bottom: 12px; font-family: \'Bricolage Grotesque\';">
|
| 1252 |
|
| 1253 |
# Tampilkan list siklus
|
| 1254 |
df_cycles = pd.read_sql_query("SELECT id, start_date, initial_thickness, active FROM cycles ORDER BY id DESC", db)
|
| 1255 |
if not df_cycles.empty:
|
| 1256 |
st.markdown('<div style="font-size: 13px; font-weight: 600; margin-bottom: 6px;">Daftar Siklus Tersimpan:</div>', unsafe_allow_html=True)
|
| 1257 |
df_cycles_styled = df_cycles.copy()
|
| 1258 |
-
df_cycles_styled['active'] = df_cycles_styled['active'].apply(lambda x: "
|
| 1259 |
st.dataframe(df_cycles_styled, use_container_width=True, height=140)
|
| 1260 |
|
| 1261 |
# View data log mentah
|
| 1262 |
if has_data:
|
| 1263 |
st.markdown('<div style="height: 12px;"></div>', unsafe_allow_html=True)
|
| 1264 |
-
with st.expander("
|
| 1265 |
st.dataframe(df_hist.tail(10), use_container_width=True)
|
| 1266 |
|
| 1267 |
|
|
|
|
| 683 |
# SUB-NAV PILLS (Menggunakan st.tabs bawaan dengan CSS Custom)
|
| 684 |
# ============================================================
|
| 685 |
tab_dashboard, tab_cycles = st.tabs([
|
| 686 |
+
"Dashboard & Input Terpadu",
|
| 687 |
+
"Manajemen Siklus BTA"
|
| 688 |
])
|
| 689 |
|
| 690 |
# ============================================================
|
|
|
|
| 726 |
db.execute("UPDATE cycles SET initial_thickness = ?, start_date = ? WHERE id = ?",
|
| 727 |
(thickness_actual, tgl_skrg.isoformat(), cycle_id))
|
| 728 |
db.commit()
|
| 729 |
+
st.success("Log perdana berhasil disimpan!")
|
| 730 |
st.rerun()
|
| 731 |
with col_bulk:
|
| 732 |
with st.container(border=True):
|
|
|
|
| 772 |
pass
|
| 773 |
|
| 774 |
if not col_tanggal or not col_suhu:
|
| 775 |
+
st.error("Kolom 'Tanggal' and 'Bodi Tengah (°C)' wajib ada di dalam file CSV.")
|
| 776 |
else:
|
| 777 |
+
st.info("Pratinjau Data (Semua Kolom):")
|
| 778 |
st.dataframe(data_import.head(3), use_container_width=True)
|
| 779 |
|
| 780 |
if st.button("Konfirmasi & Simpan CSV", type="primary"):
|
|
|
|
| 798 |
""", (cycle_id, log_date, raw_temp, cone_front, cone_back, thickness, lot_number))
|
| 799 |
count += 1
|
| 800 |
db.commit()
|
| 801 |
+
st.success(f"Berhasil mengimpor {count} baris data historis secara bulk!")
|
| 802 |
st.rerun()
|
| 803 |
except Exception as e:
|
| 804 |
st.error(f"Gagal memproses file CSV: {e}")
|
|
|
|
| 836 |
|
| 837 |
# Ringkasan Parameter Prediktif & Status Operasional
|
| 838 |
c1, c2, c3, c4 = st.columns(4)
|
| 839 |
+
c1.metric("Data Log Terakhir", latest_row['log_date'].strftime('%d %b %Y'))
|
| 840 |
+
c2.metric("Umur Operasi", f"{hari_ops} Hari")
|
| 841 |
+
c3.metric("Estimasi Ketebalan", f"{pred_mm:.1f} mm")
|
| 842 |
+
c4.metric("Estimasi Sisa Umur", f"{sisa_hari} Hari")
|
| 843 |
|
| 844 |
# --- PLOTLY CHART (Estetika Minimalis & Editorial Replicate) ---
|
| 845 |
st.markdown('<div class="rep-chart-well">', unsafe_allow_html=True)
|
|
|
|
| 1053 |
|
| 1054 |
if 'Tanggal' in df_excel.columns:
|
| 1055 |
cols_to_show.append('Tanggal')
|
| 1056 |
+
rename_dict['Tanggal'] = 'Tanggal'
|
| 1057 |
if 'lot_number' in df_excel.columns:
|
| 1058 |
cols_to_show.append('lot_number')
|
| 1059 |
+
rename_dict['lot_number'] = 'Lot Number'
|
| 1060 |
if 'cone_front' in df_excel.columns:
|
| 1061 |
cols_to_show.append('cone_front')
|
| 1062 |
+
rename_dict['cone_front'] = 'Suhu Cone Depan (°C)'
|
| 1063 |
if 'raw_temp' in df_excel.columns:
|
| 1064 |
cols_to_show.append('raw_temp')
|
| 1065 |
+
rename_dict['raw_temp'] = 'Suhu Body Tengah (°C)'
|
| 1066 |
if 'cone_back' in df_excel.columns:
|
| 1067 |
cols_to_show.append('cone_back')
|
| 1068 |
+
rename_dict['cone_back'] = 'Suhu Cone Belakang (°C)'
|
| 1069 |
if 'thickness' in df_excel.columns:
|
| 1070 |
cols_to_show.append('thickness')
|
| 1071 |
+
rename_dict['thickness'] = 'Tebal Aktual (mm)'
|
| 1072 |
if 'thickness_pred' in df_excel.columns:
|
| 1073 |
cols_to_show.append('thickness_pred')
|
| 1074 |
+
rename_dict['thickness_pred'] = 'Estimasi Tebal (mm)'
|
| 1075 |
|
| 1076 |
df_excel_subset = df_excel[cols_to_show].rename(columns=rename_dict)
|
| 1077 |
|
|
|
|
| 1081 |
use_container_width=True,
|
| 1082 |
height=280,
|
| 1083 |
column_config={
|
| 1084 |
+
'Tebal Aktual (mm)': st.column_config.NumberColumn(format="%.1f mm"),
|
| 1085 |
+
'Estimasi Tebal (mm)': st.column_config.NumberColumn(format="%.1f mm"),
|
| 1086 |
+
'Suhu Cone Depan (°C)': st.column_config.NumberColumn(format="%.0f °C"),
|
| 1087 |
+
'Suhu Body Tengah (°C)': st.column_config.NumberColumn(format="%.0f °C"),
|
| 1088 |
+
'Suhu Cone Belakang (°C)': st.column_config.NumberColumn(format="%.0f °C"),
|
| 1089 |
}
|
| 1090 |
+
|
| 1091 |
st.markdown('<div style="height: 24px;"></div>', unsafe_allow_html=True)
|
| 1092 |
|
| 1093 |
# ============================================================
|
|
|
|
| 1146 |
# Column 2: Bulk Import CSV
|
| 1147 |
with col_bulk:
|
| 1148 |
with st.container(border=True):
|
| 1149 |
+
st.markdown('<div style="font-size: 18px; font-weight: 700; margin-bottom: 8px; font-family: \'Bricolage Grotesque\'; color: #202020;">Bulk Import Data via CSV</div>', unsafe_allow_html=True)
|
| 1150 |
st.markdown('<p style="font-size: 13px; color: var(--text-charcoal); margin-bottom: 16px;">Unggah file CSV dengan kolom utama: <b>Tanggal</b> dan <b>Bodi Tengah (°C)</b>. Kolom pendukung seperti <i>Cone Depan (°C)</i>, <i>Cone Belakang (°C)</i>, <i>Ketebalan BTA (mm)</i>, dan <i>Lot Number</i> akan terdeteksi secara otomatis.</p>', unsafe_allow_html=True)
|
| 1151 |
|
| 1152 |
uploaded_file = st.file_uploader("Pilih file CSV dari komputer Anda", type="csv", key="int_uploader")
|
|
|
|
| 1189 |
pass
|
| 1190 |
|
| 1191 |
if not col_tanggal or not col_suhu:
|
| 1192 |
+
st.error("Kolom 'Tanggal' dan 'Bodi Tengah (°C)' wajib ada di dalam file CSV.")
|
| 1193 |
else:
|
| 1194 |
+
st.info("Pratinjau Data (Semua Kolom):")
|
| 1195 |
st.dataframe(data_import.head(3), use_container_width=True)
|
| 1196 |
|
| 1197 |
if st.button("Konfirmasi & Simpan CSV", type="primary", key="int_confirm_btn"):
|
|
|
|
| 1239 |
st.markdown(f'<p style="font-size: 13px; color: var(--text-charcoal); margin-bottom: 18px;">Saat ini Anda berada di dalam siklus aktif yang dimulai pada <b>{start_date_str}</b> dengan ketebalan awal BTA sebesar <b>{initial_thickness:.1f} mm</b>.</p>', unsafe_allow_html=True)
|
| 1240 |
st.markdown('<p style="font-size: 13px; color: var(--text-charcoal); margin-bottom: 24px;">Menutup siklus aktif akan mengarsipkan seluruh riwayat log harian saat ini, dan membuka form registrasi untuk mendata lining furnace BTA baru.</p>', unsafe_allow_html=True)
|
| 1241 |
|
| 1242 |
+
if st.button("Akhiri Siklus & Pasang BTA Baru"):
|
| 1243 |
db.execute("UPDATE cycles SET active = 0 WHERE active = 1")
|
| 1244 |
db.commit()
|
| 1245 |
st.success("Siklus aktif berhasil diarsipkan.")
|
|
|
|
| 1248 |
# Column 2: Log Tabel Mentah Database
|
| 1249 |
with col_c2:
|
| 1250 |
with st.container(border=True):
|
| 1251 |
+
st.markdown('<div style="font-size: 18px; font-weight: 700; margin-bottom: 12px; font-family: \'Bricolage Grotesque\';">Riwayat Siklus & Log Mentah</div>', unsafe_allow_html=True)
|
| 1252 |
|
| 1253 |
# Tampilkan list siklus
|
| 1254 |
df_cycles = pd.read_sql_query("SELECT id, start_date, initial_thickness, active FROM cycles ORDER BY id DESC", db)
|
| 1255 |
if not df_cycles.empty:
|
| 1256 |
st.markdown('<div style="font-size: 13px; font-weight: 600; margin-bottom: 6px;">Daftar Siklus Tersimpan:</div>', unsafe_allow_html=True)
|
| 1257 |
df_cycles_styled = df_cycles.copy()
|
| 1258 |
+
df_cycles_styled['active'] = df_cycles_styled['active'].apply(lambda x: "AKTIF" if x == 1 else "ARSIP")
|
| 1259 |
st.dataframe(df_cycles_styled, use_container_width=True, height=140)
|
| 1260 |
|
| 1261 |
# View data log mentah
|
| 1262 |
if has_data:
|
| 1263 |
st.markdown('<div style="height: 12px;"></div>', unsafe_allow_html=True)
|
| 1264 |
+
with st.expander("Lihat Log Tabel Mentah Harian (10 Baris Terakhir)"):
|
| 1265 |
st.dataframe(df_hist.tail(10), use_container_width=True)
|
| 1266 |
|
| 1267 |
|