refactor: 移除全局参数对象并改为函数参数传递
This commit is contained in:
12
core.py
12
core.py
@@ -28,9 +28,6 @@ class Parameter:
|
||||
ac_or_dc: str # 交流或直流标识,"AC" 或 "DC",默认 "AC"
|
||||
|
||||
|
||||
para = Parameter()
|
||||
|
||||
|
||||
def rg_line_function_factory(_rg, ground_angel): # 返回一个地面捕雷线的直线方程
|
||||
y_d = _rg / math.cos(ground_angel) # y轴上的截距
|
||||
# 利用公式y-y0=k(x-x0) 得到直线公式
|
||||
@@ -188,9 +185,8 @@ def solve_circle_line_intersection(
|
||||
return [_x, _y]
|
||||
|
||||
|
||||
def min_i(string_len, u_ph):
|
||||
def min_i(string_len, u_ph, altitude: float = 0):
|
||||
# 海拔修正
|
||||
altitude = para.altitude
|
||||
if altitude > 1000:
|
||||
k_a = math.exp((altitude - 1000) / 8150) # 气隙海拔修正
|
||||
else:
|
||||
@@ -456,9 +452,9 @@ def tangent_line_k(line_x, line_y, center_x, center_y, radius, init_k=10.0):
|
||||
return np.array(k_candidate)[np.max(k_angle) == k_angle].tolist()[-1]
|
||||
|
||||
|
||||
def func_ng(td): # 地闪密度,通过雷暴日计算
|
||||
if para.ng > 0:
|
||||
r = para.ng
|
||||
def func_ng(td, ng: float = 0): # 地闪密度,通过雷暴日计算
|
||||
if ng > 0:
|
||||
r = ng
|
||||
else:
|
||||
r = 0.023 * (td**1.3)
|
||||
return r
|
||||
|
||||
@@ -30,7 +30,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"]
|
||||
@@ -55,6 +56,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 egm():
|
||||
@@ -66,7 +68,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)
|
||||
#########################################################
|
||||
# 以上是需要设置的参数
|
||||
parameter_display(para)
|
||||
@@ -93,7 +95,7 @@ def egm():
|
||||
phase_n = 1
|
||||
# 地闪密度 利用Q╱GDW 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
|
||||
for ground_angel in ground_angels:
|
||||
@@ -150,7 +152,7 @@ def egm():
|
||||
i_max = 0
|
||||
insulator_c_len = para.insulator_c_len
|
||||
# i_min = min_i(insulator_c_len, u_ph / 1.732)
|
||||
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)
|
||||
|
||||
10
main.py
10
main.py
@@ -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
|
||||
# 地闪密度 利用Q╱GDW 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)
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from loguru import logger
|
||||
project_root = Path(__file__).parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from core import para
|
||||
from core import Parameter
|
||||
from main import parameter_display, run_egm
|
||||
|
||||
|
||||
@@ -148,7 +148,8 @@ class EGMWebApp:
|
||||
advance_data = params.get('advance', {})
|
||||
optional_data = params.get('optional', {})
|
||||
|
||||
# 更新全局参数对象
|
||||
# 创建局部参数对象
|
||||
para = Parameter()
|
||||
para.h_g_sag = float(parameter_data.get('h_g_sag', 11.67))
|
||||
para.h_c_sag = float(parameter_data.get('h_c_sag', 14.43))
|
||||
para.td = int(parameter_data.get('td', 20))
|
||||
|
||||
Reference in New Issue
Block a user