Add API to get all pipes

This commit is contained in:
DingZQ
2025-03-29 16:30:15 +08:00
parent 94773a59f8
commit 1dafaa6dcc
4 changed files with 30 additions and 1 deletions

View File

@@ -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

View File

@@ -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: