Add diameter to getmajornodes/getmajorpipes
This commit is contained in:
@@ -108,10 +108,10 @@ def get_nodes_id_and_type(name: str) -> dict[str, str]:
|
|||||||
return nodes_id_and_type
|
return nodes_id_and_type
|
||||||
|
|
||||||
# DingZQ 2024-12-31
|
# 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()
|
major_nodes_set = set()
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
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:
|
for record in cur:
|
||||||
major_nodes_set.add(record['node1'])
|
major_nodes_set.add(record['node1'])
|
||||||
major_nodes_set.add(record['node2'])
|
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
|
# DingZQ 2024-12-31
|
||||||
# 获取直径大于800的管道
|
# 获取直径大于800的管道
|
||||||
def get_major_pipes(name: str) -> list[str]:
|
def get_major_pipes(name: str, diameter: int) -> list[str]:
|
||||||
major_pipe_ids: list[str] = []
|
major_pipe_ids: list[str] = []
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
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:
|
for record in cur:
|
||||||
major_pipe_ids.append(record['id'])
|
major_pipe_ids.append(record['id'])
|
||||||
return major_pipe_ids
|
return major_pipe_ids
|
||||||
|
|||||||
8
main.py
8
main.py
@@ -1407,8 +1407,8 @@ async def fastapi_get_network_coords(network: str) -> list[str] | None:
|
|||||||
# id:type:x:y
|
# id:type:x:y
|
||||||
# type: junction, reservoir, tank
|
# type: junction, reservoir, tank
|
||||||
@app.get("/getmajornodecoords/")
|
@app.get("/getmajornodecoords/")
|
||||||
async def fastapi_get_major_node_coords(network: str) -> list[str] | None:
|
async def fastapi_get_major_node_coords(network: str, diameter: int) -> list[str] | None:
|
||||||
coords = get_major_node_coords(network)
|
coords = get_major_node_coords(network, diameter)
|
||||||
result = []
|
result = []
|
||||||
for node_id, coord in coords.items():
|
for node_id, coord in coords.items():
|
||||||
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
|
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
|
# DingZQ 2024-12-31
|
||||||
# 获取直径大于800的管道
|
# 获取直径大于800的管道
|
||||||
@app.get("/getmajorpipenodes/")
|
@app.get("/getmajorpipenodes/")
|
||||||
async def fastapi_get_major_pipe_nodes(network: str) -> list[str] | None:
|
async def fastapi_get_major_pipe_nodes(network: str, diameter: int) -> list[str] | None:
|
||||||
return get_major_pipe_nodes(network)
|
return get_major_pipe_nodes(network, diameter)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# vertex 25.[VERTICES]
|
# vertex 25.[VERTICES]
|
||||||
|
|||||||
@@ -846,9 +846,9 @@ def get_network_node_coords(name: str) -> dict[str, dict[str, float]]:
|
|||||||
|
|
||||||
# DingZQ 2024-12-31
|
# DingZQ 2024-12-31
|
||||||
# id, x, y, type
|
# 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)
|
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 = {}
|
result = {}
|
||||||
for node_id in major_node_ids:
|
for node_id in major_node_ids:
|
||||||
coord = api.get_node_coord(name, node_id)
|
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
|
# DingZQ 2024-12-31
|
||||||
# link_id:pipe:node_id1:node_id2
|
# link_id:pipe:node_id1:node_id2
|
||||||
def get_major_pipe_nodes(name: str) -> list[str]:
|
def get_major_pipe_nodes(name: str, diameter: int) -> list[str]:
|
||||||
major_pipe_ids = api.get_major_pipes(name)
|
major_pipe_ids = api.get_major_pipes(name, diameter)
|
||||||
result = []
|
result = []
|
||||||
for link_id in major_pipe_ids:
|
for link_id in major_pipe_ids:
|
||||||
nodes = api.get_link_nodes(name, link_id)
|
nodes = api.get_link_nodes(name, link_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user