Return type from getnetworkcoord
This commit is contained in:
@@ -29,7 +29,7 @@ from .s0_base import is_node, is_junction, is_reservoir, is_tank
|
||||
from .s0_base import is_link, is_pipe, is_pump, is_valve
|
||||
from .s0_base import is_curve
|
||||
from .s0_base import is_pattern
|
||||
from .s0_base import get_nodes, get_links, get_curves, get_patterns
|
||||
from .s0_base import get_nodes, get_junctions, get_reservoirs, get_tanks, get_links, get_pipes, get_pumps, get_valves, get_curves, get_patterns
|
||||
from .s0_base import get_node_links, get_link_nodes
|
||||
|
||||
from .s1_title import get_title_schema, get_title, set_title
|
||||
|
||||
@@ -103,18 +103,17 @@ def get_junctions(name: str) -> list[str]:
|
||||
return _get_nodes_by_type(name, JUNCTION)
|
||||
|
||||
# DingZQ
|
||||
def get_reservoir(name: str) -> list[str]:
|
||||
def get_reservoirs(name: str) -> list[str]:
|
||||
return _get_nodes_by_type(name, RESERVOIR)
|
||||
|
||||
# DingZQ
|
||||
def get_tank(name: str) -> list[str]:
|
||||
def get_tanks(name: str) -> list[str]:
|
||||
return _get_nodes_by_type(name, TANK)
|
||||
|
||||
# DingZQ
|
||||
def get_links(name: str) -> list[str]:
|
||||
return _get_all(name, _LINK)
|
||||
|
||||
|
||||
# DingZQ
|
||||
def _get_links_by_type(name: str, type: str) -> list[str]:
|
||||
ids : list[str] = []
|
||||
|
||||
4
main.py
4
main.py
@@ -1393,12 +1393,14 @@ async def fastapi_get_node_coord(network: str, node: str) -> dict[str, float] |
|
||||
return get_node_coord(network, node)
|
||||
|
||||
# DingZQ, 2024-12-08, get all node coord
|
||||
# id:type:x:y
|
||||
# type: junction, reservoir, tank
|
||||
@app.get("/getnetworkcoords/")
|
||||
async def fastapi_get_network_coords(network: str) -> list[str] | None:
|
||||
coords = get_network_coords(network)
|
||||
result = []
|
||||
for node_id, coord in coords.items():
|
||||
result.append(f"{node_id}:{coord['x']}:{coord['y']}")
|
||||
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
|
||||
return result
|
||||
|
||||
# DingZQ, 2024-12-08, get all links' start and end node
|
||||
|
||||
17
tjnetwork.py
17
tjnetwork.py
@@ -831,12 +831,25 @@ def get_node_coord(name: str, node_id: str) -> dict[str, float]:
|
||||
return api.get_node_coord(name, node_id)
|
||||
|
||||
# DingZQ, 2024-12-08, get all node coord
|
||||
# id, x, y
|
||||
# id, x, y, type
|
||||
def get_network_coords(name: str) -> dict[str, dict[str, float]]:
|
||||
node_ids = api.get_nodes(name)
|
||||
junctions = api.get_junctions(name)
|
||||
reservoirs = api.get_reservoirs(name)
|
||||
tanks = api.get_tanks(name)
|
||||
result = {}
|
||||
for node_id in node_ids:
|
||||
result[node_id] = api.get_node_coord(name, node_id)
|
||||
#result[node_id] = api.get_node_coord(name, node_id)
|
||||
coord = api.get_node_coord(name, node_id)
|
||||
if node_id in junctions:
|
||||
coord['type'] = 'junction'
|
||||
elif node_id in reservoirs:
|
||||
coord['type'] = 'reservoir'
|
||||
elif node_id in tanks:
|
||||
coord['type'] = 'tank'
|
||||
else:
|
||||
coord['type'] = 'node'
|
||||
result[node_id] = coord
|
||||
return result
|
||||
|
||||
# DingZQ, 2024-12-08, get all links' start and end node
|
||||
|
||||
Reference in New Issue
Block a user