feat: 增强电缆数据校验和UI优化
This commit is contained in:
43
main.py
43
main.py
@@ -153,9 +153,48 @@ def load_data_from_excel(file_path):
|
||||
specs.append((section, capacity, resistance, cost, is_optional))
|
||||
|
||||
if specs:
|
||||
specs.sort(key=lambda x: x[1]) # 按载流量排序
|
||||
# --- 输入数据校验:单调性 ---
|
||||
for i in range(len(specs) - 1):
|
||||
curr_s = specs[i]
|
||||
next_s = specs[i + 1]
|
||||
|
||||
# 校验截面 (section)
|
||||
if curr_s[0] >= next_s[0]:
|
||||
raise ValueError(
|
||||
f"电缆数据校验失败:Excel中电缆顺序必须按截面从小到大排列。第{i+1}行({curr_s[0]}mm²) >= 第{i+2}行({next_s[0]}mm²)。"
|
||||
)
|
||||
|
||||
# 校验载流量 (capacity)
|
||||
if curr_s[1] >= next_s[1]:
|
||||
raise ValueError(
|
||||
f"电缆数据校验失败:Excel中电缆载流量必须严格递增。第{i+1}行({curr_s[1]}A) >= 第{i+2}行({next_s[1]}A)。"
|
||||
)
|
||||
|
||||
specs.sort(key=lambda x: x[1]) # 按载流量排序
|
||||
|
||||
# --- 输入数据校验 ---
|
||||
# 筛选出所有标记为 Optional='Y' 的电缆
|
||||
optional_cables = [s for s in specs if s[4]]
|
||||
|
||||
# 规则1: 最多只能有一条可选电缆
|
||||
if len(optional_cables) > 1:
|
||||
raise ValueError(
|
||||
f"电缆数据校验失败:检测到 {len(optional_cables)} 条可选电缆(Optional='Y')。系统限制最多只能指定 1 条可选电缆。"
|
||||
)
|
||||
|
||||
# 规则2: 如果存在可选电缆,它必须是所有电缆中截面最大的一条
|
||||
if len(optional_cables) == 1:
|
||||
opt_cable = optional_cables[0]
|
||||
# s[0] 是截面积
|
||||
max_section = max(s[0] for s in specs)
|
||||
if opt_cable[0] < max_section:
|
||||
raise ValueError(
|
||||
f"电缆数据校验失败:可选电缆 ({opt_cable[0]}mm²) 必须是所有电缆中截面最大的一条 (当前最大为 {max_section}mm²)。"
|
||||
)
|
||||
# --------------------
|
||||
|
||||
cable_specs = specs
|
||||
|
||||
|
||||
print(f"成功加载: {len(turbines)} 台风机, {len(substation)} 座升压站")
|
||||
if cable_specs:
|
||||
print(f"成功加载: {len(cable_specs)} 种电缆规格")
|
||||
|
||||
Reference in New Issue
Block a user