diff --git a/api/__init__.py b/api/__init__.py index 7eed155..8cb10eb 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -48,7 +48,7 @@ from .s4_tanks import get_tank_schema, add_tank, get_tank, set_tank from .batch_api import delete_tank_cascade from .s5_pipes import PIPE_STATUS_OPEN, PIPE_STATUS_CLOSED, PIPE_STATUS_CV -from .s5_pipes import get_pipe_schema, add_pipe, get_pipe, set_pipe +from .s5_pipes import get_pipe_schema, add_pipe, get_pipe, set_pipe, get_all_pipes from .batch_api import delete_pipe_cascade from .s6_pumps import get_pump_schema, add_pump, get_pump, set_pump diff --git a/api/s5_pipes.py b/api/s5_pipes.py index 2a1499a..7e726e8 100644 --- a/api/s5_pipes.py +++ b/api/s5_pipes.py @@ -33,6 +33,26 @@ def get_pipe(name: str, id: str) -> dict[str, Any]: d['status'] = str(p['status']) return d +# DingZQ, 2025-03-29 +def get_all_pipes(name: str) -> list[dict[str, Any]]: + p = try_read(name, f"select * from pipes") + if p == None: + return [] + + result = [] + for p in p: + d = {} + d['id'] = str(p['id']) + d['node1'] = str(p['node1']) + d['node2'] = str(p['node2']) + d['length'] = float(p['length']) + d['diameter'] = float(p['diameter']) + d['roughness'] = float(p['roughness']) + d['minor_loss'] = float(p['minor_loss']) + d['status'] = str(p['status']) + result.append(d) + + return result class Pipe(object): def __init__(self, input: dict[str, Any]) -> None: diff --git a/main.py b/main.py index 468c559..9b185b2 100644 --- a/main.py +++ b/main.py @@ -1018,6 +1018,11 @@ async def fastapi_set_pipe_status(network: str, pipe: str, status: str) -> Chang async def fastapi_get_pipe_properties(network: str, pipe: str) -> dict[str, Any]: return get_pipe(network, pipe) +# DingZQ, 2025-03-29 +@app.get('/getallpipeproperties/') +async def fastapi_get_all_pipe_properties(network: str) -> list[dict[str, Any]]: + return get_all_pipes(network) + @app.post("/setpipeproperties/",response_model=None) async def fastapi_set_pipe_properties(network: str, pipe: str, req: Request) -> ChangeSet: props = await req.json() diff --git a/tjnetwork.py b/tjnetwork.py index 045db3a..370e0cd 100644 --- a/tjnetwork.py +++ b/tjnetwork.py @@ -531,6 +531,10 @@ def get_pipe_schema(name: str) -> dict[str, dict[str, Any]]: def get_pipe(name: str, id: str) -> dict[str, Any]: return api.get_pipe(name, id) +# DingZQ, 2025-03-29 +def get_all_pipes(name: str) -> list[dict[str, Any]]: + return api.get_all_pipes(name) + def set_pipe(name: str, cs: ChangeSet) -> ChangeSet: return api.set_pipe(name, cs)