Add API to get all pipes
This commit is contained in:
@@ -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 .batch_api import delete_tank_cascade
|
||||||
|
|
||||||
from .s5_pipes import PIPE_STATUS_OPEN, PIPE_STATUS_CLOSED, PIPE_STATUS_CV
|
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 .batch_api import delete_pipe_cascade
|
||||||
|
|
||||||
from .s6_pumps import get_pump_schema, add_pump, get_pump, set_pump
|
from .s6_pumps import get_pump_schema, add_pump, get_pump, set_pump
|
||||||
|
|||||||
@@ -33,6 +33,26 @@ def get_pipe(name: str, id: str) -> dict[str, Any]:
|
|||||||
d['status'] = str(p['status'])
|
d['status'] = str(p['status'])
|
||||||
return d
|
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):
|
class Pipe(object):
|
||||||
def __init__(self, input: dict[str, Any]) -> None:
|
def __init__(self, input: dict[str, Any]) -> None:
|
||||||
|
|||||||
5
main.py
5
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]:
|
async def fastapi_get_pipe_properties(network: str, pipe: str) -> dict[str, Any]:
|
||||||
return get_pipe(network, pipe)
|
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)
|
@app.post("/setpipeproperties/",response_model=None)
|
||||||
async def fastapi_set_pipe_properties(network: str, pipe: str, req: Request) -> ChangeSet:
|
async def fastapi_set_pipe_properties(network: str, pipe: str, req: Request) -> ChangeSet:
|
||||||
props = await req.json()
|
props = await req.json()
|
||||||
|
|||||||
@@ -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]:
|
def get_pipe(name: str, id: str) -> dict[str, Any]:
|
||||||
return api.get_pipe(name, id)
|
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:
|
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return api.set_pipe(name, cs)
|
return api.set_pipe(name, cs)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user