Add API to get both nodes and links

This commit is contained in:
DingZQ
2025-01-27 21:39:20 +08:00
parent 97d1022460
commit 1193a4fe30

15
main.py
View File

@@ -1409,6 +1409,21 @@ async def fastapi_get_network_coords(network: str) -> list[str] | None:
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
return result
# DingZQ, 2025-01-27, get all node coord/links
# nodes: id:type:x:y
# links: id:type:node1:node2
# node type: junction, reservoir, tank
# link type: pipe, pump, valve
@app.get("/getnetworkgeometries/")
async def fastapi_get_network_geometries(network: str) -> dict[str, Any] | None:
coords = get_network_node_coords(network)
nodes = []
for node_id, coord in coords.items():
nodes.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
links = get_network_link_nodes(network)
return { 'nodes': nodes, 'links': links }
# DingZQ, 2024-12-31, get major node coord
# id:type:x:y
# type: junction, reservoir, tank