调整关阀分析算法输出结果

This commit is contained in:
2026-02-03 10:57:36 +08:00
parent 0755b1a61c
commit 6fe01aa248
2 changed files with 2 additions and 33 deletions

View File

@@ -1,13 +1,7 @@
from collections import defaultdict, deque
from typing import Any
from app.services.tjnetwork import (
get_link_properties,
get_link_type,
get_network_link_nodes,
is_link,
is_node,
)
from app.services.tjnetwork import get_network_link_nodes
VALVE_LINK_TYPE = "valve"
@@ -35,30 +29,6 @@ def valve_isolation_analysis(
target_elements = accident_elements
start_nodes = set()
accident_types = set()
for element in target_elements:
if is_node(network, element):
start_nodes.add(element)
accident_types.add("node")
elif is_link(network, element):
l_type = get_link_type(network, element)
accident_types.add(l_type)
link_props = get_link_properties(network, element)
node1 = link_props.get("node1")
node2 = link_props.get("node2")
if not node1 or not node2:
# 如果是批量处理,可以选择跳过错误或记录错误,这里暂时保持严谨抛出异常
raise ValueError(f"Accident link {element} missing node endpoints")
start_nodes.add(node1)
start_nodes.add(node2)
else:
raise ValueError(f"Accident element {element} not found")
# 如果有多种类型混合,简化返回类型描述
accident_type_str = (
list(accident_types)[0] if len(accident_types) == 1 else "mixed"
)
adjacency: dict[str, set[str]] = defaultdict(set)
valve_links: dict[str, tuple[str, str]] = {}
@@ -97,7 +67,6 @@ def valve_isolation_analysis(
result = {
"accident_elements": target_elements,
"accident_type": accident_type_str,
"affected_nodes": sorted(affected_nodes),
"must_close_valves": must_close_valves,
"optional_valves": optional_valves,

View File

@@ -16,6 +16,6 @@ if __name__ == "__main__":
"app.main:app",
host="0.0.0.0",
port=8000,
# workers=2, # 这里可以设置多进程
workers=2, # 这里可以设置多进程
loop="asyncio",
)