Add API to get major nodes and major pipes
This commit is contained in:
@@ -32,6 +32,7 @@ from .s0_base import is_curve
|
|||||||
from .s0_base import is_pattern
|
from .s0_base import is_pattern
|
||||||
from .s0_base import get_nodes, get_nodes_id_and_type, get_junctions, get_reservoirs, get_tanks, get_links, get_links_id_and_type, get_pipes, get_pumps, get_valves, get_curves, get_patterns
|
from .s0_base import get_nodes, get_nodes_id_and_type, get_junctions, get_reservoirs, get_tanks, get_links, get_links_id_and_type, get_pipes, get_pumps, get_valves, get_curves, get_patterns
|
||||||
from .s0_base import get_node_links, get_link_nodes
|
from .s0_base import get_node_links, get_link_nodes
|
||||||
|
from .s0_base import get_major_nodes, get_major_pipes
|
||||||
|
|
||||||
from .s1_title import get_title_schema, get_title, set_title
|
from .s1_title import get_title_schema, get_title, set_title
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,18 @@ def get_nodes_id_and_type(name: str) -> dict[str, str]:
|
|||||||
nodes_id_and_type[record['id']] = record['type']
|
nodes_id_and_type[record['id']] = record['type']
|
||||||
return nodes_id_and_type
|
return nodes_id_and_type
|
||||||
|
|
||||||
# DingZQ
|
# DingZQ 2024-12-31
|
||||||
|
def get_major_nodes(name: str) -> 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 > 800")
|
||||||
|
for record in cur:
|
||||||
|
major_nodes_set.add(record['node1'])
|
||||||
|
major_nodes_set.add(record['node2'])
|
||||||
|
|
||||||
|
return list(major_nodes_set)
|
||||||
|
|
||||||
|
# DingZQs
|
||||||
def get_junctions(name: str) -> list[str]:
|
def get_junctions(name: str) -> list[str]:
|
||||||
return _get_nodes_by_type(name, JUNCTION)
|
return _get_nodes_by_type(name, JUNCTION)
|
||||||
|
|
||||||
@@ -141,6 +152,16 @@ def get_links_id_and_type(name: str) -> dict[str, str]:
|
|||||||
links_id_and_type[record['id']] = record['type']
|
links_id_and_type[record['id']] = record['type']
|
||||||
return links_id_and_type
|
return links_id_and_type
|
||||||
|
|
||||||
|
# DingZQ 2024-12-31
|
||||||
|
# 获取直径大于800的管道
|
||||||
|
def get_major_pipes(name: str) -> 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 > 800 order by id")
|
||||||
|
for record in cur:
|
||||||
|
major_pipe_ids.append(record['id'])
|
||||||
|
return major_pipe_ids
|
||||||
|
|
||||||
# DingZQ
|
# DingZQ
|
||||||
def get_pipes(name: str) -> list[str]:
|
def get_pipes(name: str) -> list[str]:
|
||||||
return _get_links_by_type(name, PIPE)
|
return _get_links_by_type(name, PIPE)
|
||||||
|
|||||||
19
main.py
19
main.py
@@ -1403,12 +1403,29 @@ async def fastapi_get_network_coords(network: str) -> list[str] | None:
|
|||||||
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
|
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# DingZQ, 2024-12-08, get all links' start and end node
|
# DingZQ, 2024-12-31, get major node coord
|
||||||
|
# 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)
|
||||||
|
result = []
|
||||||
|
for node_id, coord in coords.items():
|
||||||
|
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
# DingZQ, 2024-12-08, get all links' start and end node
|
||||||
# link_id:link_type:node_id1:node_id2
|
# link_id:link_type:node_id1:node_id2
|
||||||
@app.get("/getnetworklinknodes/")
|
@app.get("/getnetworklinknodes/")
|
||||||
async def fastapi_get_network_link_nodes(network: str) -> list[str] | None:
|
async def fastapi_get_network_link_nodes(network: str) -> list[str] | None:
|
||||||
return get_network_link_nodes(network)
|
return get_network_link_nodes(network)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# vertex 25.[VERTICES]
|
# vertex 25.[VERTICES]
|
||||||
############################################################
|
############################################################
|
||||||
|
|||||||
22
tjnetwork.py
22
tjnetwork.py
@@ -844,6 +844,18 @@ def get_network_node_coords(name: str) -> dict[str, dict[str, float]]:
|
|||||||
result[node_id] = coord
|
result[node_id] = coord
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# DingZQ 2024-12-31
|
||||||
|
# id, x, y, type
|
||||||
|
def get_major_node_coords(name: str) -> dict[str, dict[str, float]]:
|
||||||
|
nodes_id_and_type = api.get_nodes_id_and_type(name)
|
||||||
|
major_node_ids = api.get_major_nodes(name)
|
||||||
|
result = {}
|
||||||
|
for node_id in major_node_ids:
|
||||||
|
coord = api.get_node_coord(name, node_id)
|
||||||
|
coord['type'] = nodes_id_and_type[node_id]
|
||||||
|
result[node_id] = coord
|
||||||
|
return result
|
||||||
|
|
||||||
# DingZQ, 2024-12-08, get all links' start and end node
|
# DingZQ, 2024-12-08, get all links' start and end node
|
||||||
# link_id:link_type:node_id1:node_id2
|
# link_id:link_type:node_id1:node_id2
|
||||||
def get_network_link_nodes(name: str) -> list[str]:
|
def get_network_link_nodes(name: str) -> list[str]:
|
||||||
@@ -854,6 +866,16 @@ def get_network_link_nodes(name: str) -> list[str]:
|
|||||||
result.append(f"{link_id}:{link_type}:{nodes[0]}:{nodes[1]}")
|
result.append(f"{link_id}:{link_type}:{nodes[0]}:{nodes[1]}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
result = []
|
||||||
|
for link_id in major_pipe_ids:
|
||||||
|
nodes = api.get_link_nodes(name, link_id)
|
||||||
|
result.append(f"{link_id}:pipe:{nodes[0]}:{nodes[1]}")
|
||||||
|
return result
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# vertex 25.[VERTICES]
|
# vertex 25.[VERTICES]
|
||||||
############################################################
|
############################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user