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 @@