From 81b0ad0124847f083990d574dc8d20961ec6e713 Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期三, 01 四月 2026 14:12:55 +0800
Subject: [PATCH] feat(参数调节): 添加优化版挤出机参数调节页面
---
dashboard.py | 818 +++++++--------------------------------------------------
1 files changed, 111 insertions(+), 707 deletions(-)
diff --git a/dashboard.py b/dashboard.py
index 2850f76..d602522 100644
--- a/dashboard.py
+++ b/dashboard.py
@@ -1,10 +1,18 @@
import streamlit as st
-import plotly.express as px
-import pandas as pd
-from datetime import datetime, timedelta
-from app.services.data_query_service import DataQueryService
-from app.services.data_processing_service import DataProcessingService
-from app.services.extruder_service import ExtruderService
+from app.pages.sorting_dashboard import show_sorting_dashboard
+from app.pages.extruder_dashboard import show_extruder_dashboard
+from app.pages.main_process_dashboard import show_main_process_dashboard
+from app.pages.comprehensive_dashboard import show_comprehensive_dashboard
+from app.pages.metered_weight_dashboard import show_metered_weight_dashboard
+from app.pages.metered_weight_correlation import show_metered_weight_correlation
+from app.pages.metered_weight_regression import show_metered_weight_regression
+from app.pages.metered_weight_advanced import show_metered_weight_advanced
+from app.pages.metered_weight_deep_learning import show_metered_weight_deep_learning
+from app.pages.metered_weight_steady_state import show_metered_weight_steady_state
+from app.pages.metered_weight_prediction import show_metered_weight_prediction
+from app.pages.metered_weight_forecast import show_metered_weight_forecast
+from app.pages.extruder_parameter_adjustment import show_extruder_parameter_adjustment
+from app.pages.optimized_parameter_adjustment import show_optimized_parameter_adjustment
# 璁剧疆椤甸潰閰嶇疆
st.set_page_config(
@@ -13,722 +21,118 @@
layout="wide"
)
-# 宸︿晶鑿滃崟瀵艰埅
-st.sidebar.title("绯荤粺瀵艰埅")
-menu = st.sidebar.radio(
- "閫夋嫨鍒嗘瀽妯″潡",
- ["鍒嗘嫞纾呯Г", "鎸ゅ嚭鏈�"],
- index=0,
- key="main_menu"
+# 瀹氫箟椤甸潰
+sorting_page = st.Page(
+ show_sorting_dashboard,
+ title="鍒嗘嫞纾呯Г",
+ icon="鈿栵笍",
+ url_path="sorting"
)
-# 鍙充晶鍐呭鍖哄煙
-if menu == "鍒嗘嫞纾呯Г":
- # 鍒濆鍖栨湇鍔�
- query_service = DataQueryService()
- processing_service = DataProcessingService()
+extruder_page = st.Page(
+ show_extruder_dashboard,
+ title="鎸ゅ嚭鏈�",
+ icon="馃彮",
+ url_path="extruder"
+)
- # 椤甸潰鏍囬
- st.title("鍒嗘嫞纾呯Г鏁版嵁鍒嗘瀽")
+main_process_page = st.Page(
+ show_main_process_dashboard,
+ title="涓绘祦绋嬫帶鍒�",
+ icon="鈿欙笍",
+ url_path="main_process"
+)
- # 鏌ヨ鏉′欢鍖哄煙锛堣縼绉诲埌鍙充晶椤堕儴锛�
- st.subheader("鏌ヨ閰嶇疆")
- col1, col2, col3 = st.columns([2, 2, 1])
-
- with col1:
- start_date = st.date_input("寮�濮嬫棩鏈�", datetime.now() - timedelta(days=7), key="sorting_start_date")
-
- with col2:
- end_date = st.date_input("缁撴潫鏃ユ湡", datetime.now(), key="sorting_end_date")
-
- with col3:
- st.write("") # 鍗犱綅
- query_button = st.button("鏌ヨ鏁版嵁", key="sorting_query")
+comprehensive_page = st.Page(
+ show_comprehensive_dashboard,
+ title="鏉¢噸缁煎悎鍒嗘瀽",
+ icon="馃寪",
+ url_path="comprehensive"
+)
- # 杞崲涓篸atetime瀵硅薄锛堝寘鍚椂闂达級
- start_datetime = datetime.combine(start_date, datetime.min.time())
- end_datetime = datetime.combine(end_date, datetime.max.time())
+metered_weight_page = st.Page(
+ show_metered_weight_dashboard,
+ title="绫抽噸缁煎悎鍒嗘瀽",
+ icon="馃搹",
+ url_path="metered_weight"
+)
- # 鏌ヨ鎸夐挳澶勭悊
- if query_button:
- # 楠岃瘉鏃ユ湡鑼冨洿
- if start_datetime > end_datetime:
- st.error("寮�濮嬫棩鏈熶笉鑳芥櫄浜庣粨鏉熸棩鏈燂紒")
- else:
- # 鏄剧ず鍔犺浇鐘舵��
- with st.spinner("姝e湪鏌ヨ鏁版嵁..."):
- # 鏌ヨ鏁版嵁
- raw_data = query_service.get_sorting_scale_data(start_datetime, end_datetime)
-
- if raw_data is None or raw_data.empty:
- st.warning("鏈煡璇㈠埌鏁版嵁锛岃妫�鏌ユ棩鏈熻寖鍥存垨鏁版嵁搴撹繛鎺ワ紒")
- st.session_state['query_results'] = None
- else:
- # 娓呮礂鏁版嵁
- cleaned_data = processing_service.clean_data(raw_data)
-
- # 璁$畻缁熻淇℃伅
- stats = processing_service.calculate_statistics(cleaned_data)
-
- # 鍒嗘瀽鏋佸�肩偣
- extreme_analysis = processing_service.analyze_extreme_points(cleaned_data)
- extreme_points = extreme_analysis['extreme_points']
- phase_maxima = extreme_analysis['phase_maxima']
- overall_pass_rate = extreme_analysis['overall_pass_rate']
-
- # 缂撳瓨缁撴灉
- st.session_state['query_results'] = {
- 'cleaned_data': cleaned_data,
- 'stats': stats,
- 'extreme_points': extreme_points,
- 'phase_maxima': phase_maxima,
- 'overall_pass_rate': overall_pass_rate
- }
-
- # 鏄剧ず鏁版嵁姒傝
- st.subheader("鏁版嵁姒傝")
- col1, col2, col3, col4 = st.columns(4)
-
- with col1:
- st.metric("鎬昏褰曟暟", stats.get('total_records', 0))
-
- with col2:
- st.metric("骞冲潎鍚堟牸鏁�", round(stats.get('count_in_range', {}).get('mean', 0), 2))
-
- with col3:
- st.metric("鏁版嵁鏃堕棿鑼冨洿", f"{cleaned_data['time'].min()} 鑷� {cleaned_data['time'].max()}")
-
- with col4:
- st.metric("鏁翠綋鍚堟牸鐜�", f"{overall_pass_rate}%")
-
- # 鏄剧ず瓒嬪娍鍥�
- st.subheader("鏁版嵁瓒嬪娍鍥�")
- fig = px.line(
- cleaned_data,
- x='time',
- y=['count_under', 'count_in_range', 'count_over'],
- labels={
- 'time': '鏃堕棿',
- 'value': '鏁伴噺',
- 'variable': '鏁版嵁绫诲瀷'
- },
- title='鍒嗘嫞纾呯Г鏁版嵁瓒嬪娍',
- color_discrete_map={
- 'count_under': 'red',
- 'count_in_range': 'green',
- 'count_over': 'blue'
- }
- )
-
- # 鑷畾涔夊浘渚�
- fig.for_each_trace(lambda t: t.update(name={
- 'count_under': '浣庝簬鏍囧噯',
- 'count_in_range': '鍦ㄦ爣鍑嗚寖鍥村唴',
- 'count_over': '楂樹簬鏍囧噯'
- }[t.name]))
-
- # 閰嶇疆鍥捐〃缂╂斁鍔熻兘
- fig.update_layout(
- xaxis=dict(
- fixedrange=False
- ),
- yaxis=dict(
- fixedrange=False
- ),
- dragmode='zoom'
- )
-
- # 閰嶇疆鍥捐〃鍙傛暟
- config = {
- 'scrollZoom': True
- }
-
- # 鏄剧ず鍥捐〃
- st.plotly_chart(fig, use_container_width=True, config=config)
-
- # 鏄剧ず鏋佸�肩偣鍒嗘瀽
- st.subheader("鏋佸�肩偣鍒嗘瀽")
- if not extreme_points.empty:
- # 鍑嗗灞曠ず鏁版嵁
- display_df = extreme_points[['time', 'count_under', 'count_in_range', 'count_over', 'pass_rate']].copy()
-
- # 鏍煎紡鍖栨椂闂存埑
- display_df['time'] = display_df['time'].dt.strftime('%Y-%m-%d %H:%M:%S')
-
- # 淇敼鍒楀悕
- display_df.columns = ['鏃堕棿鎴�', '瓒呬笅闄愭暟鍊�', '鑼冨洿鍐呮暟鍊�', '瓒呬笂闄愭暟鍊�', '鍚堟牸鐜�(%)']
-
- # 鏄剧ず鏁版嵁琛ㄦ牸
- st.dataframe(display_df, use_container_width=True)
-
- # 鏄剧ず鏋佸�肩偣鏁伴噺
- st.info(f"鍏辫瘑鍒埌 {len(extreme_points)} 涓瀬鍊肩偣")
-
- # 娣诲姞瀵煎嚭鍔熻兘
- import csv
- import io
-
- # 鍒涘缓CSV鏁版嵁
- csv_buffer = io.StringIO()
- display_df.to_csv(csv_buffer, index=False, encoding='utf-8-sig')
- csv_data = csv_buffer.getvalue()
-
- # 娣诲姞涓嬭浇鎸夐挳
- st.download_button(
- label="涓嬭浇鏋佸�肩偣鍒嗘瀽缁撴灉",
- data=csv_data,
- file_name=f"鏋佸�肩偣鍒嗘瀽_{start_date}_{end_date}.csv",
- mime="text/csv"
- )
- else:
- st.warning("鏈瘑鍒埌鏋佸�肩偣")
-
-
- # 鏄剧ず閲嶉噺瓒嬪娍鍥�
- st.subheader("閲嶉噺瓒嬪娍鍥�")
- if 'weight' in cleaned_data.columns:
- # 鍒涘缓閲嶉噺瓒嬪娍鍥�
- import plotly.graph_objects as go
-
- # 鍒涘缓鍥捐〃
- weight_fig = go.Figure()
-
- # 妫�鏌ユ槸鍚﹀寘鍚槇鍊肩浉鍏冲瓧娈�
- has_thresholds = all(col in cleaned_data.columns for col in ['baseline_value', 'over_difference', 'under_difference'])
-
- # 璁$畻鍔ㄦ�侀槇鍊�
- if has_thresholds:
- # 澶嶅埗鏁版嵁浠ラ伩鍏嶄慨鏀瑰師濮嬫暟鎹�
- threshold_data = cleaned_data.copy()
-
- # 澶勭悊闆跺��
- for col in ['baseline_value', 'over_difference', 'under_difference']:
- threshold_data[col] = threshold_data[col].replace(0, pd.NA)
-
- # 鍚戝墠濉厖缂哄け鍊�
- threshold_data = threshold_data.ffill()
-
- # 璁$畻涓婁笅闄愰槇鍊�
- threshold_data['upper_threshold'] = threshold_data['over_difference']
- threshold_data['lower_threshold'] = threshold_data['under_difference']
-
- # 鏍囪瓒呭嚭闃堝�肩殑鐐�
- threshold_data['is_out_of_range'] = (threshold_data['weight'] > threshold_data['upper_threshold']) | (threshold_data['weight'] < threshold_data['lower_threshold'])
-
- # 娣诲姞鍩哄噯鍊肩嚎锛堝姩鎬侊級
- weight_fig.add_trace(go.Scatter(
- x=threshold_data['time'],
- y=threshold_data['baseline_value'],
- name='鍩哄噯鍊�',
- line=dict(color='green', width=2),
- opacity=0.7
- ))
-
- # 娣诲姞涓婇檺闃堝�肩嚎锛堝姩鎬侊級
- weight_fig.add_trace(go.Scatter(
- x=threshold_data['time'],
- y=threshold_data['upper_threshold'],
- name='涓婇檺闃堝��',
- line=dict(color='red', width=2),
- opacity=0.7
- ))
-
- # 娣诲姞涓嬮檺闃堝�肩嚎锛堝姩鎬侊級
- weight_fig.add_trace(go.Scatter(
- x=threshold_data['time'],
- y=threshold_data['lower_threshold'],
- name='涓嬮檺闃堝��',
- line=dict(color='orange', width=2),
- opacity=0.7
- ))
-
- # 鍒嗙姝e父鍜屽紓甯告暟鎹偣
- normal_data = threshold_data[~threshold_data['is_out_of_range']]
- out_of_range_data = threshold_data[threshold_data['is_out_of_range']]
-
- # 娣诲姞姝e父閲嶉噺鐐�
- weight_fig.add_trace(go.Scatter(
- x=normal_data['time'],
- y=normal_data['weight'],
- name='閲嶉噺 (姝e父)',
- opacity=0.8,
- mode='markers',
- marker=dict(
- size=4,
- color='blue',
- symbol='circle',
- line=dict(
- width=0,
- color='blue'
- )
- )
- ))
-
- # 娣诲姞寮傚父閲嶉噺鐐�
- if not out_of_range_data.empty:
- weight_fig.add_trace(go.Scatter(
- x=out_of_range_data['time'],
- y=out_of_range_data['weight'],
- name='閲嶉噺 (寮傚父)',
- opacity=0.8,
- mode='markers',
- marker=dict(
- size=4,
- color='red',
- symbol='triangle-up',
- line=dict(
- width=2,
- color='darkred'
- )
- )
- ))
- else:
- # 娌℃湁闃堝�兼暟鎹紝鍙樉绀洪噸閲忚秼鍔�
- weight_fig.add_trace(go.Scatter(
- x=cleaned_data['time'],
- y=cleaned_data['weight'],
- name='閲嶉噺',
- line=dict(color='blue', width=2),
- opacity=0.8
- ))
- st.warning("鏁版嵁涓笉鍖呭惈闃堝�肩浉鍏冲瓧娈碉紝鏃犳硶鏄剧ず闃堝�肩嚎鍜屽紓甯歌绀猴紒")
-
- # 閰嶇疆鍥捐〃甯冨眬
- weight_fig.update_layout(
- title='閲嶉噺闅忔椂闂村彉鍖栬秼鍔�',
- xaxis_title='鏃堕棿',
- yaxis_title='閲嶉噺',
- xaxis=dict(
- rangeslider=dict(
- visible=True
- ),
- type='date',
- fixedrange=False
- ),
- yaxis=dict(
- fixedrange=False
- ),
- legend=dict(
- orientation="h",
- yanchor="bottom",
- y=1.02,
- xanchor="right",
- x=1
- ),
- hovermode='x unified',
- height=600,
- dragmode='zoom',
- # 娣诲姞鑷畾涔夊伐鍏锋爮鎸夐挳
- updatemenus=[
- dict(
- type="buttons",
- direction="left",
- buttons=list([
- dict(
- args=["visible", [True, True, True, True, True]],
- label="鏄剧ず鍏ㄩ儴",
- method="restyle"
- ),
- dict(
- args=["visible", [False, False, False, True, True]],
- label="浠呮樉绀洪噸閲�",
- method="restyle"
- ),
- dict(
- args=["visible", [True, True, True, False, False]],
- label="浠呮樉绀洪槇鍊�",
- method="restyle"
- ),
- dict(
- args=["visible", [True, True, True, True, False]],
- label="鏄剧ず姝e父閲嶉噺",
- method="restyle"
- ),
- dict(
- args=["visible", [True, True, True, False, True]],
- label="鏄剧ず寮傚父閲嶉噺",
- method="restyle"
- )
- ]),
- pad={"r": 10, "t": 10},
- showactive=True,
- x=0.1,
- xanchor="left",
- y=1.1,
- yanchor="top"
- ),
- ]
- )
-
- # 閰嶇疆鍥捐〃鍙傛暟
- config = {
- 'scrollZoom': True,
- 'toImageButtonOptions': {
- 'format': 'png',
- 'filename': '閲嶉噺瓒嬪娍鍥�',
- 'height': 600,
- 'width': 1000,
- 'scale': 1
- }
- }
-
- # 鏄剧ず鍥捐〃
- st.plotly_chart(weight_fig, use_container_width=True, config=config)
-
-
- # 鏄剧ず鏁版嵁琛ㄦ牸
- st.subheader("鍘熷鏁版嵁")
- st.dataframe(cleaned_data, use_container_width=True)
-
- # 鏄剧ず璇︾粏缁熻淇℃伅
- if stats:
- st.subheader("璇︾粏缁熻淇℃伅")
- with st.expander("鏌ョ湅璇︾粏缁熻"):
- col_stats1, col_stats2, col_stats3 = st.columns(3)
-
- with col_stats1:
- st.write("**浣庝簬鏍囧噯**")
- st.write(f"骞冲潎鍊�: {round(stats['count_under']['mean'], 2)}")
- st.write(f"鎬诲拰: {stats['count_under']['sum']}")
- st.write(f"鏈�澶у��: {stats['count_under']['max']}")
- st.write(f"鏈�灏忓��: {stats['count_under']['min']}")
-
- with col_stats2:
- st.write("**鍦ㄦ爣鍑嗚寖鍥村唴**")
- st.write(f"骞冲潎鍊�: {round(stats['count_in_range']['mean'], 2)}")
- st.write(f"鎬诲拰: {stats['count_in_range']['sum']}")
- st.write(f"鏈�澶у��: {stats['count_in_range']['max']}")
- st.write(f"鏈�灏忓��: {stats['count_in_range']['min']}")
-
- with col_stats3:
- st.write("**楂樹簬鏍囧噯**")
- st.write(f"骞冲潎鍊�: {round(stats['count_over']['mean'], 2)}")
- st.write(f"鎬诲拰: {stats['count_over']['sum']}")
- st.write(f"鏈�澶у��: {stats['count_over']['max']}")
- st.write(f"鏈�灏忓��: {stats['count_over']['min']}")
+metered_weight_correlation_page = st.Page(
+ show_metered_weight_correlation,
+ title="绫抽噸鐩稿叧鎬у垎鏋�",
+ icon="馃搳",
+ url_path="metered_weight_correlation"
+)
- # 鏁版嵁搴撹繛鎺ョ姸鎬�
- st.sidebar.subheader("鏁版嵁搴撶姸鎬�")
- if 'query_service' in locals() and query_service.db.is_connected():
- st.sidebar.success("鏁版嵁搴撹繛鎺ユ甯�")
- else:
- st.sidebar.warning("鏁版嵁搴撴湭杩炴帴")
+metered_weight_regression_page = st.Page(
+ show_metered_weight_regression,
+ title="绫抽噸澶氬厓绾挎�у洖褰掑垎鏋�",
+ icon="馃搱",
+ url_path="metered_weight_regression"
+)
-elif menu == "鎸ゅ嚭鏈�":
- # 鍒濆鍖栨湇鍔�
- extruder_service = ExtruderService()
- processing_service = DataProcessingService()
+metered_weight_advanced_page = st.Page(
+ show_metered_weight_advanced,
+ title="绫抽噸楂樼骇棰勬祴鍒嗘瀽",
+ icon="馃",
+ url_path="metered_weight_advanced"
+)
- # 椤甸潰鏍囬
- st.title("鎸ゅ嚭鏈烘暟鎹垎鏋�")
+metered_weight_deep_learning_page = st.Page(
+ show_metered_weight_deep_learning,
+ title="绫抽噸娣卞害瀛︿範棰勬祴",
+ icon="馃",
+ url_path="metered_weight_deep_learning"
+)
- # 鏌ヨ鏉′欢鍖哄煙
- st.subheader("鏌ヨ閰嶇疆")
- col1, col2, col3 = st.columns([2, 2, 1])
-
- with col1:
- start_date = st.date_input("寮�濮嬫棩鏈�", datetime.now() - timedelta(days=7), key="extruder_start_date")
-
- with col2:
- end_date = st.date_input("缁撴潫鏃ユ湡", datetime.now(), key="extruder_end_date")
-
- with col3:
- st.write("") # 鍗犱綅
- query_button = st.button("鏌ヨ鏁版嵁", key="extruder_query")
+metered_weight_steady_state_page = st.Page(
+ show_metered_weight_steady_state,
+ title="绫抽噸绋虫�佽瘑鍒�",
+ icon="鈿栵笍",
+ url_path="metered_weight_steady_state"
+)
- # 杞崲涓篸atetime瀵硅薄锛堝寘鍚椂闂达級
- start_datetime = datetime.combine(start_date, datetime.min.time())
- end_datetime = datetime.combine(end_date, datetime.max.time())
+metered_weight_prediction_page = st.Page(
+ show_metered_weight_prediction,
+ title="绫抽噸缁熶竴棰勬祴",
+ icon="馃敭",
+ url_path="metered_weight_prediction"
+)
- # 鏌ヨ鎸夐挳澶勭悊
- if query_button:
- # 楠岃瘉鏃ユ湡鑼冨洿
- if start_datetime > end_datetime:
- st.error("寮�濮嬫棩鏈熶笉鑳芥櫄浜庣粨鏉熸棩鏈燂紒")
- else:
- # 鏄剧ず鍔犺浇鐘舵��
- with st.spinner("姝e湪鏌ヨ鏁版嵁..."):
- # 鏌ヨ鏁版嵁
- raw_data = extruder_service.get_extruder_data(start_datetime, end_datetime)
-
- if raw_data is None or raw_data.empty:
- st.warning("鏈煡璇㈠埌鏁版嵁锛岃妫�鏌ユ棩鏈熻寖鍥存垨鏁版嵁搴撹繛鎺ワ紒")
- st.session_state['extruder_results'] = None
- else:
- # 娓呮礂鏁版嵁
- cleaned_data = processing_service.clean_data(raw_data)
-
- # 妫�娴嬫崲鎵逛簨浠�
- batch_changes = extruder_service.detect_batch_changes(cleaned_data)
-
- # 鍒嗘瀽鍙傛暟瓒嬪娍
- # trends = extruder_service.analyze_parameter_trends(cleaned_data)
-
-
- # 缂撳瓨缁撴灉
- st.session_state['extruder_results'] = {
- 'cleaned_data': cleaned_data,
- 'batch_changes': batch_changes,
- # 'trends': trends,
- }
-
- # 鏄剧ず鏁版嵁姒傝
- st.subheader("鏁版嵁姒傝")
- col1, col2, col3, col4 = st.columns(4)
-
- with col1:
- st.metric("鎬昏褰曟暟", len(cleaned_data))
-
- with col2:
- st.metric("鎹㈡壒娆℃暟", len(batch_changes))
-
- with col3:
- st.metric("鏁版嵁鏃堕棿鑼冨洿", f"{cleaned_data['time'].min()} 鑷� {cleaned_data['time'].max()}")
-
- # 鏄剧ず鎹㈡壒鍒嗘瀽
- st.subheader("鎹㈡壒鍒嗘瀽")
- if not batch_changes.empty:
- # 鍑嗗灞曠ず鏁版嵁
- batch_display = batch_changes[['batch_id', 'compound_code', 'start_time', 'end_time', 'duration_minutes']].copy()
-
- # 鏍煎紡鍖栨椂闂�
- batch_display['start_time'] = batch_display['start_time'].dt.strftime('%Y-%m-%d %H:%M:%S')
- batch_display['end_time'] = batch_display['end_time'].dt.strftime('%Y-%m-%d %H:%M:%S')
-
- # 淇敼鍒楀悕
- batch_display.columns = ['鎵瑰彿', '鑳舵枡鍙�', '寮�濮嬫椂闂�', '缁撴潫鏃堕棿', '鎸佺画鏃堕暱(鍒嗛挓)']
- # 鏄剧ず鏁版嵁琛ㄦ牸
- st.dataframe(batch_display, use_container_width=True)
- else:
- st.warning("鏈娴嬪埌鎹㈡壒浜嬩欢")
-
- # 鏄剧ず鎹㈡枡鎿嶄綔鍙鍖栧浘琛�
- st.subheader("鎹㈡枡鎿嶄綔鍙鍖�")
- if not batch_changes.empty:
- # 鍒涘缓鎹㈡枡鎿嶄綔鍙鍖栧浘琛�
- import plotly.graph_objects as go
-
- # 鍑嗗鍥捐〃鏁版嵁
- fig = go.Figure()
-
- # 娣诲姞鍏抽敭鍙傛暟瓒嬪娍绾�
- fig.add_trace(go.Scatter(
- x=cleaned_data['time'],
- y=cleaned_data['screw_speed_actual'],
- name='瀹為檯杞��',
- line=dict(color='blue', width=2),
- opacity=0.8
- ))
-
- fig.add_trace(go.Scatter(
- x=cleaned_data['time'],
- y=cleaned_data['head_pressure'],
- name='鏈哄ご鍘嬪姏',
- line=dict(color='red', width=2),
- opacity=0.8,
- yaxis='y2'
- ))
-
- fig.add_trace(go.Scatter(
- x=cleaned_data['time'],
- y=cleaned_data['extruder_current'],
- name='鎸ゅ嚭鏈虹數娴�',
- line=dict(color='green', width=2),
- opacity=0.8,
- yaxis='y3'
- ))
-
- fig.add_trace(go.Scatter(
- x=cleaned_data['time'],
- y=cleaned_data['metered_weight'],
- name='绫抽噸',
- line=dict(color='orange', width=2),
- opacity=0.8,
- yaxis='y4'
- ))
-
- # 娣诲姞鎹㈡枡浜嬩欢鏍囪
- for i, row in batch_changes.iterrows():
- # 娣诲姞鍨傜洿绾�
- fig.add_shape(
- type="line",
- x0=row['start_time'],
- y0=0,
- x1=row['start_time'],
- y1=1,
- yref="paper",
- line=dict(
- color="purple",
- width=2,
- dash="dash"
- )
- )
-
- # 娣诲姞娉ㄩ噴
- fig.add_annotation(
- x=row['start_time'],
- y=1,
- yref='paper',
- text=f'鎹㈡枡: {row["compound_code"]}\n鎵瑰彿: {row["batch_id"]}',
- showarrow=True,
- arrowhead=1,
- ax=0,
- ay=-60
- )
-
- # 閰嶇疆鍥捐〃甯冨眬
- fig.update_layout(
- title='鎹㈡枡鎿嶄綔鍏抽敭鍙傛暟鍙樺寲瓒嬪娍',
- xaxis_title='鏃堕棿',
- xaxis=dict(
- rangeslider=dict(
- visible=True
- ),
- type='date'
- ),
- yaxis_title='瀹為檯杞�� (rpm)',
- yaxis2=dict(
- title='鏈哄ご鍘嬪姏 (MPa)',
- overlaying='y',
- side='right',
- position=0.85
- ),
- yaxis3=dict(
- title='鎸ゅ嚭鏈虹數娴� (A)',
- overlaying='y',
- side='right',
- position=0.92
- ),
- yaxis4=dict(
- title='绫抽噸 (kg)',
- overlaying='y',
- side='right',
- position=1
- ),
- legend=dict(
- orientation="h",
- yanchor="bottom",
- y=1.02,
- xanchor="right",
- x=1
- ),
- hovermode='x unified',
- height=700
- )
-
- # 鏄剧ず鍥捐〃
- st.plotly_chart(fig, use_container_width=True)
-
- # 娣诲姞鏁版嵁瀵煎嚭鍔熻兘
- import csv
- import io
- import pandas as pd
-
- # 鍑嗗瀵煎嚭鏁版嵁
- export_data = []
- for i, row in batch_changes.iterrows():
- # 鑾峰彇鎹㈡枡鍓嶅悗鐨勬暟鎹�
- before_change = cleaned_data[cleaned_data['time'] < row['start_time']].tail(5)
- after_change = cleaned_data[cleaned_data['time'] >= row['start_time']].head(5)
-
- # 娣诲姞鎹㈡枡浜嬩欢璁板綍
- export_data.append({
- 'event_type': '鎹㈡枡浜嬩欢',
- 'batch_id': row['batch_id'],
- 'compound_code': row['compound_code'],
- 'time': row['start_time'],
- 'screw_speed': '',
- 'head_pressure': '',
- 'extruder_current': '',
- 'metered_weight': ''
- })
-
- # 娣诲姞鎹㈡枡鍓嶆暟鎹�
- for _, before_row in before_change.iterrows():
- export_data.append({
- 'event_type': '鎹㈡枡鍓�',
- 'batch_id': row['batch_id'],
- 'compound_code': row['compound_code'],
- 'time': before_row['time'],
- 'screw_speed': before_row['screw_speed_actual'],
- 'head_pressure': before_row['head_pressure'],
- 'extruder_current': before_row['extruder_current'],
- 'metered_weight': before_row['metered_weight']
- })
-
- # 娣诲姞鎹㈡枡鍚庢暟鎹�
- for _, after_row in after_change.iterrows():
- export_data.append({
- 'event_type': '鎹㈡枡鍚�',
- 'batch_id': row['batch_id'],
- 'compound_code': row['compound_code'],
- 'time': after_row['time'],
- 'screw_speed': after_row['screw_speed_actual'],
- 'head_pressure': after_row['head_pressure'],
- 'extruder_current': after_row['extruder_current'],
- 'metered_weight': after_row['metered_weight']
- })
-
- # 杞崲涓篋ataFrame
- export_df = pd.DataFrame(export_data)
-
- # 鍒涘缓CSV鏁版嵁
- csv_buffer = io.StringIO()
- export_df.to_csv(csv_buffer, index=False, encoding='utf-8-sig')
- csv_data = csv_buffer.getvalue()
-
- # 娣诲姞涓嬭浇鎸夐挳
- st.download_button(
- label="涓嬭浇鎹㈡枡鎿嶄綔鍒嗘瀽鏁版嵁",
- data=csv_data,
- file_name=f"鎹㈡枡鎿嶄綔鍒嗘瀽_{start_date}_{end_date}.csv",
- mime="text/csv"
- )
- else:
- st.warning("鏈娴嬪埌鎹㈡壒浜嬩欢锛屾棤娉曠敓鎴愭崲鏂欐搷浣滃浘琛�")
-
- # 鏄剧ず鍘熷鏁版嵁
- st.subheader("鍘熷鏁版嵁")
- st.dataframe(cleaned_data, use_container_width=True)
+metered_weight_forecast_page = st.Page(
+ show_metered_weight_forecast,
+ title="绫抽噸棰勬祴鍒嗘瀽",
+ icon="馃搱",
+ url_path="metered_weight_forecast"
+)
- # 鏁版嵁搴撹繛鎺ョ姸鎬�
- st.sidebar.subheader("鏁版嵁搴撶姸鎬�")
- if 'extruder_service' in locals() and extruder_service.db.is_connected():
- st.sidebar.success("鏁版嵁搴撹繛鎺ユ甯�")
- else:
- st.sidebar.warning("鏁版嵁搴撴湭杩炴帴")
+extruder_parameter_adjustment_page = st.Page(
+ show_extruder_parameter_adjustment,
+ title="鎸ゅ嚭鏈哄弬鏁拌皟鑺�",
+ icon="鈿欙笍",
+ url_path="extruder_parameter_adjustment"
+)
-# 椤佃剼
-st.sidebar.markdown("---")
-st.sidebar.markdown("漏 2026 鏁版嵁鍒嗘瀽绯荤粺")
+optimized_parameter_adjustment_page = st.Page(
+ show_optimized_parameter_adjustment,
+ title="浼樺寲鐗堟尋鍑烘満鍙傛暟璋冭妭",
+ icon="馃殌",
+ url_path="optimized_parameter_adjustment"
+)
-# 缂撳瓨娓呯悊鏈哄埗
-def clear_cache():
- """娓呯悊浼氳瘽缂撳瓨锛屽綋鍒囨崲鑿滃崟鎴栨洿鏂版煡璇㈡潯浠舵椂璋冪敤"""
- if 'query_results' in st.session_state:
- del st.session_state['query_results']
- if 'extruder_results' in st.session_state:
- del st.session_state['extruder_results']
+# 渚ц竟鏍忛〉鑴氫俊鎭�
+def show_footer():
+ st.sidebar.markdown("---")
+ st.sidebar.markdown("漏 2026 鏁版嵁鍒嗘瀽绯荤粺")
-# 鍒濆鍖栦細璇濈姸鎬�
-if 'query_results' not in st.session_state:
- st.session_state['query_results'] = None
-if 'extruder_results' not in st.session_state:
- st.session_state['extruder_results'] = None
+# 瀵艰埅閰嶇疆
+pg = st.navigation({
+ "缁煎悎鍒嗘瀽": [comprehensive_page, metered_weight_page, metered_weight_correlation_page, metered_weight_regression_page, metered_weight_advanced_page, metered_weight_deep_learning_page, metered_weight_steady_state_page, metered_weight_prediction_page, metered_weight_forecast_page, extruder_parameter_adjustment_page, optimized_parameter_adjustment_page],
+ "鍒嗛」鍒嗘瀽": [sorting_page, extruder_page, main_process_page]
+})
-# 鐩戝惉鑿滃崟鍒囨崲锛屾竻鐞嗙紦瀛�
-if 'previous_menu' not in st.session_state:
- st.session_state['previous_menu'] = menu
-elif st.session_state['previous_menu'] != menu:
- clear_cache()
- st.session_state['previous_menu'] = menu
+# 杩愯瀵艰埅
+pg.run()
-# 鍏抽棴鏁版嵁搴撹繛鎺ワ紙褰撳簲鐢ㄧ粨鏉熸椂锛�
-def on_app_close():
- if 'query_service' in locals():
- query_service.close_connection()
- if 'extruder_service' in locals():
- extruder_service.close_connection()
-
-# 娉ㄥ唽搴旂敤鍏抽棴鍥炶皟
-st.session_state['app_close'] = on_app_close
\ No newline at end of file
+# 鏄剧ず椤佃剼
+show_footer()
--
Gitblit v1.9.3