Add diameter to getmajornodes/getmajorpipes

This commit is contained in:
DingZQ
2025-01-01 10:19:12 +08:00
parent 51e3ae18bb
commit 9e7a4616b4
3 changed files with 12 additions and 12 deletions

View File

@@ -108,10 +108,10 @@ def get_nodes_id_and_type(name: str) -> dict[str, str]:
return nodes_id_and_type
# DingZQ 2024-12-31
def get_major_nodes(name: str) -> list[str]:
def get_major_nodes(name: str, diameter: int) -> list[str]:
major_nodes_set = set()
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(f"select node1, node2 from pipes where diameter > 0")
cur.execute(f"select node1, node2 from pipes where diameter > {diameter}")
for record in cur:
major_nodes_set.add(record['node1'])
major_nodes_set.add(record['node2'])
@@ -154,10 +154,10 @@ def get_links_id_and_type(name: str) -> dict[str, str]:
# DingZQ 2024-12-31
# 获取直径大于800的管道
def get_major_pipes(name: str) -> list[str]:
def get_major_pipes(name: str, diameter: int) -> list[str]:
major_pipe_ids: list[str] = []
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(f"select id from pipes where diameter > 0 order by id")
cur.execute(f"select id from pipes where diameter > {diameter} order by id")
for record in cur:
major_pipe_ids.append(record['id'])
return major_pipe_ids

View File

@@ -1407,8 +1407,8 @@ async def fastapi_get_network_coords(network: str) -> list[str] | None:
# id:type:x:y
# type: junction, reservoir, tank
@app.get("/getmajornodecoords/")
async def fastapi_get_major_node_coords(network: str) -> list[str] | None:
coords = get_major_node_coords(network)
async def fastapi_get_major_node_coords(network: str, diameter: int) -> list[str] | None:
coords = get_major_node_coords(network, diameter)
result = []
for node_id, coord in coords.items():
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
@@ -1423,8 +1423,8 @@ async def fastapi_get_network_link_nodes(network: str) -> list[str] | None:
# DingZQ 2024-12-31
# 获取直径大于800的管道
@app.get("/getmajorpipenodes/")
async def fastapi_get_major_pipe_nodes(network: str) -> list[str] | None:
return get_major_pipe_nodes(network)
async def fastapi_get_major_pipe_nodes(network: str, diameter: int) -> list[str] | None:
return get_major_pipe_nodes(network, diameter)
############################################################
# vertex 25.[VERTICES]

View File

@@ -846,9 +846,9 @@ def get_network_node_coords(name: str) -> dict[str, dict[str, float]]:
# DingZQ 2024-12-31
# id, x, y, type
def get_major_node_coords(name: str) -> dict[str, dict[str, float]]:
def get_major_node_coords(name: str, diameter: int) -> dict[str, dict[str, float]]:
nodes_id_and_type = api.get_nodes_id_and_type(name)
major_node_ids = api.get_major_nodes(name)
major_node_ids = api.get_major_nodes(name, diameter)
result = {}
for node_id in major_node_ids:
coord = api.get_node_coord(name, node_id)
@@ -868,8 +868,8 @@ def get_network_link_nodes(name: str) -> list[str]:
# DingZQ 2024-12-31
# link_id:pipe:node_id1:node_id2
def get_major_pipe_nodes(name: str) -> list[str]:
major_pipe_ids = api.get_major_pipes(name)
def get_major_pipe_nodes(name: str, diameter: int) -> list[str]:
major_pipe_ids = api.get_major_pipes(name, diameter)
result = []
for link_id in major_pipe_ids:
nodes = api.get_link_nodes(name, link_id)