refactor: 移除全局参数对象并改为函数参数传递

This commit is contained in:
dmy
2026-03-02 23:11:27 +08:00
parent 630598d498
commit bcaa4a5a9e
4 changed files with 19 additions and 18 deletions

10
main.py
View File

@@ -32,7 +32,8 @@ def parameter_display(para_dis: Parameter):
logger.info(f"雷暴日 d {para_dis.td}")
def read_parameter(toml_file_path):
def read_parameter(toml_file_path) -> Parameter:
para = Parameter()
with open(toml_file_path, "rb") as toml_fs:
toml_dict = tomli.load(toml_fs)
toml_parameter = toml_dict["parameter"]
@@ -58,6 +59,7 @@ def read_parameter(toml_file_path):
toml_optional = toml_dict["optional"]
para.voltage_n = toml_optional["voltage_n"] # 工作电压分成多少份来计算
para.max_i = toml_optional["max_i"]
return para
def run_egm(para: Parameter) -> dict:
@@ -88,7 +90,7 @@ def run_egm(para: Parameter) -> dict:
phase_n = 1
# 地闪密度 利用QGDW 11452-2015 架空输电线路防雷导则的公式 Ng=0.023*Td^(1.3) 20天雷暴日地闪密度为1.13
td = para.td
ng = func_ng(td)
ng = func_ng(td, para.ng)
avr_n_sf = 0 # 考虑电压的影响计算的跳闸率
ground_angels = para.ground_angels
# 初始化动画
@@ -152,7 +154,7 @@ def run_egm(para: Parameter) -> dict:
insulator_c_len = para.insulator_c_len
# i_min = min_i(insulator_c_len, u_ph / 1.732)
# TODO 需要考虑交、直流
i_min = min_i(insulator_c_len, u_ph)
i_min = min_i(insulator_c_len, u_ph, para.altitude)
_min_i = i_min # 尝试的最小电流
_max_i = para.max_i # 尝试的最大电流
# cad.draw(i_min, u_ph, rs_x, rs_y, rc_x, rc_y, rg_x, rg_y, rg_type, 2)
@@ -380,7 +382,7 @@ def egm():
logger.info(f"无法找到数据文件{toml_file_path},程序退出。")
sys.exit(0)
logger.info(f"读取文件{toml_file_path}")
read_parameter(toml_file_path)
para = read_parameter(toml_file_path)
run_egm(para)