Add API get network link nodes

This commit is contained in:
DingZQ
2024-12-08 21:08:06 +08:00
parent 8b818185ff
commit de5ae4d1e5
2 changed files with 17 additions and 0 deletions

View File

@@ -1391,6 +1391,7 @@ async def fastapi_set_option_properties(network: str, req: Request) -> ChangeSet
async def fastapi_get_node_coord(network: str, node: str) -> dict[str, float] | None:
return get_node_coord(network, node)
# DingZQ, 2024-12-08, get all node coord
@app.get("/getnetworkcoords/")
async def fastapi_get_network_coords(network: str) -> list[str] | None:
coords = get_network_coords(network)
@@ -1399,6 +1400,12 @@ async def fastapi_get_network_coords(network: str) -> list[str] | None:
result.append(f"{node_id}:{coord['x']}:{coord['y']}")
return result
# DingZQ, 2024-12-08, get all links' start and end node
# link_id:node_id1:node_id2
@app.get("/getnetworklinknodes/")
async def fastapi_get_network_link_nodes(network: str) -> list[str] | None:
return get_network_link_nodes(network)
############################################################
# vertex 25.[VERTICES]
############################################################

View File

@@ -839,6 +839,16 @@ def get_network_coords(name: str) -> dict[str, dict[str, float]]:
result[node_id] = api.get_node_coord(name, node_id)
return result
# DingZQ, 2024-12-08, get all links' start and end node
# link_id:node_id1:node_id2
def get_network_link_nodes(name: str) -> list[str]:
links = api.get_links(name)
result = []
for link_id in links:
nodes = api.get_link_nodes(name, link_id)
result.append(f"{link_id}:{nodes[0]}:{nodes[1]}")
return result
############################################################
# vertex 25.[VERTICES]
############################################################