From 6f0f8d02a80742ca13f0603c0bd51d50fa05ff44 Mon Sep 17 00:00:00 2001 From: dmy Date: Mon, 2 Mar 2026 22:49:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84EGM=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=A0=B8=E5=BF=83=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=8E=A8=E9=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将EGM计算逻辑从webview_app.py移到main.py中的run_egm函数 添加实时日志推送和计算结果回调机制 支持后台线程计算不阻塞前端 --- main.py | 49 +++- webui/src/components/ParameterForm.vue | 44 +++- webview_app.py | 323 ++++++++----------------- 3 files changed, 168 insertions(+), 248 deletions(-) diff --git a/main.py b/main.py index 38ac496..e751948 100644 --- a/main.py +++ b/main.py @@ -60,18 +60,12 @@ def read_parameter(toml_file_path): para.max_i = toml_optional["max_i"] -def egm(): - if len(sys.argv) < 2: - toml_file_path = r"D:/code/EGM/历史/平乾750kV.toml" - else: - toml_file_path = sys.argv[1] - if not os.path.exists(toml_file_path): - logger.info(f"无法找到数据文件{toml_file_path},程序退出。") - sys.exit(0) - logger.info(f"读取文件{toml_file_path}") - read_parameter(toml_file_path) - ######################################################### - # 以上是需要设置的参数 +def run_egm() -> dict: + """ + 执行 EGM 计算的核心函数,可被外部调用。 + 假设参数已通过 para 全局对象设置好。 + 返回计算结果字典。 + """ parameter_display(para) h_whole = para.h_arm[0] # 挂点高 string_g_len = para.string_g_len @@ -356,6 +350,37 @@ def egm(): f"不同相跳闸率是{np.array2string(np.mean(n_sf_phases,axis=1),precision=16)}次/(100km·a)" ) + return { + "success": True, + "message": "计算完成", + "data": { + "tripping_rate": f"{avr_n_sf:.16f} 次/(100km·a)", + "avr_n_sf": avr_n_sf, + "n_sf_phases": np.mean(n_sf_phases, axis=1).tolist(), + "parameters": { + "rated_voltage": para.rated_voltage, + "td": para.td, + "altitude": para.altitude, + "ground_angels": [a / math.pi * 180 for a in para.ground_angels], + "max_i": para.max_i + } + } + } + + +def egm(): + """命令行入口函数""" + if len(sys.argv) < 2: + toml_file_path = r"D:/code/EGM/历史/平乾750kV.toml" + else: + toml_file_path = sys.argv[1] + if not os.path.exists(toml_file_path): + logger.info(f"无法找到数据文件{toml_file_path},程序退出。") + sys.exit(0) + logger.info(f"读取文件{toml_file_path}") + read_parameter(toml_file_path) + run_egm() + def speed(): a = 0 diff --git a/webui/src/components/ParameterForm.vue b/webui/src/components/ParameterForm.vue index d145388..ee97bcf 100644 --- a/webui/src/components/ParameterForm.vue +++ b/webui/src/components/ParameterForm.vue @@ -317,7 +317,7 @@