Add API to get all node properties

This commit is contained in:
DingZQ
2025-03-29 17:08:31 +08:00
parent d1687b8464
commit 0431f4d82e
6 changed files with 91 additions and 3 deletions

View File

@@ -37,14 +37,14 @@ from .s0_base import get_major_nodes, get_major_pipes
from .s1_title import get_title_schema, get_title, set_title
from .s2_junctions import get_junction_schema, add_junction, get_junction, set_junction
from .s2_junctions import get_junction_schema, add_junction, get_junction, set_junction, get_all_junctions
from .batch_api import delete_junction_cascade
from .s3_reservoirs import get_reservoir_schema, add_reservoir, get_reservoir, set_reservoir
from .s3_reservoirs import get_reservoir_schema, add_reservoir, get_reservoir, set_reservoir, get_all_reservoirs
from .batch_api import delete_reservoir_cascade
from .s4_tanks import OVERFLOW_YES, OVERFLOW_NO
from .s4_tanks import get_tank_schema, add_tank, get_tank, set_tank
from .s4_tanks import get_tank_schema, add_tank, get_tank, set_tank, get_all_tanks
from .batch_api import delete_tank_cascade
from .s5_pipes import PIPE_STATUS_OPEN, PIPE_STATUS_CLOSED, PIPE_STATUS_CV

View File

@@ -24,6 +24,23 @@ def get_junction(name: str, id: str) -> dict[str, Any]:
d['links'] = get_node_links(name, id)
return d
# DingZQ, 2025-03-29
def get_all_junctions(name: str) -> list[dict[str, Any]]:
rows = read_all(name, f"select * from junctions")
if rows == None:
return []
result = []
for row in rows:
d = {}
d['id'] = str(row['id'])
d['x'] = float(row['x'])
d['y'] = float(row['y'])
d['elevation'] = float(row['elevation'])
d['links'] = get_node_links(name, row['id'])
result.append(d)
return result
class Junction(object):
def __init__(self, input: dict[str, Any]) -> None:

View File

@@ -26,6 +26,24 @@ def get_reservoir(name: str, id: str) -> dict[str, Any]:
d['links'] = get_node_links(name, id)
return d
# DingZQ, 2025-03-29
def get_all_reservoirs(name: str) -> list[dict[str, Any]]:
rows = read_all(name, f"select * from reservoirs")
if rows == None:
return []
result = []
for row in rows:
d = {}
d['id'] = str(row['id'])
d['x'] = float(row['x'])
d['y'] = float(row['y'])
d['head'] = float(row['head']) if row['head'] != None else None
d['pattern'] = str(row['pattern']) if row['pattern'] != None else None
d['links'] = get_node_links(name, row['id'])
result.append(d)
return result
class Reservoir(object):
def __init__(self, input: dict[str, Any]) -> None:

View File

@@ -42,6 +42,30 @@ def get_tank(name: str, id: str) -> dict[str, Any]:
d['links'] = get_node_links(name, id)
return d
# DingZQ, 2025-03-29
def get_all_tanks(name: str) -> list[dict[str, Any]]:
rows = read_all(name, f"select * from tanks")
if rows == None:
return []
result = []
for row in rows:
d = {}
d['id'] = str(row['id'])
d['x'] = float(row['x'])
d['y'] = float(row['y'])
d['elevation'] = float(row['elevation'])
d['init_level'] = float(row['init_level'])
d['min_level'] = float(row['min_level'])
d['max_level'] = float(row['max_level'])
d['diameter'] = float(row['diameter'])
d['min_vol'] = float(row['min_vol'])
d['vol_curve'] = str(row['vol_curve']) if row['vol_curve'] != None else None
d['overflow'] = str(row['overflow']) if row['overflow'] != None else None
d['links'] = get_node_links(name, row['id'])
result.append(d)
return result
class Tank(object):
def __init__(self, input: dict[str, Any]) -> None:

17
main.py
View File

@@ -649,6 +649,13 @@ async def fastapi_set_junction_pattern(network: str, junction: str, pattern: str
async def fastapi_get_junction_properties(network: str, junction: str) -> dict[str, Any]:
return get_junction(network, junction)
# DingZQ, 2025-03-29
@app.get("/getalljunctionproperties/")
async def fastapi_get_all_junction_properties(network: str) -> list[dict[str, Any]]:
return get_all_junctions(network)
@app.post("/setjunctionproperties/",response_model=None)
async def fastapi_set_junction_properties(network: str, junction: str, req: Request) -> ChangeSet:
props = await req.json()
@@ -738,6 +745,11 @@ async def fastapi_set_reservoir_y(network: str, reservoir: str, x: float, y: flo
async def fastapi_get_reservoir_properties(network: str, reservoir: str) -> dict[str, Any]:
return get_reservoir(network, reservoir)
# DingZQ, 2025-03-29
@app.get("/getallreservoirproperties/")
async def fastapi_get_all_reservoir_properties(network: str) -> list[dict[str, Any]]:
return get_all_reservoirs(network)
@app.post("/setreservoirproperties/",response_model=None)
async def fastapi_set_reservoir_properties(network: str, reservoir: str
, req: Request) -> ChangeSet:
@@ -900,6 +912,11 @@ async def fastapi_set_tank_coord(network: str, tank: str, x: float, y: float) ->
async def fastapi_get_tank_properties(network: str, tank: str) -> dict[str, Any]:
return get_tank(network, tank)
# DingZQ, 2025-03-29
@app.get("/getalltankproperties/")
async def fastapi_get_all_tank_properties(network: str) -> list[dict[str, Any]]:
return get_all_tanks(network)
@app.post("/settankproperties/",response_model=None)
async def fastapi_set_tank_properties(network: str, tank: str, req: Request) -> ChangeSet:
props = await req.json()

View File

@@ -468,6 +468,10 @@ def get_junction_schema(name: str) -> dict[str, dict[str, Any]]:
def get_junction(name: str, id: str) -> dict[str, Any]:
return api.get_junction(name, id)
# DingZQ, 2025-03-29
def get_all_junctions(name: str) -> list[dict[str, Any]]:
return api.get_all_junctions(name)
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
return api.set_junction(name, cs)
@@ -489,6 +493,10 @@ def get_reservoir_schema(name: str) -> dict[str, dict[str, Any]]:
def get_reservoir(name: str, id: str) -> dict[str, Any]:
return api.get_reservoir(name, id)
# DingZQ, 2025-03-29
def get_all_reservoirs(name: str) -> list[dict[str, Any]]:
return api.get_all_reservoirs(name)
def set_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
return api.set_reservoir(name, cs)
@@ -510,6 +518,10 @@ def get_tank_schema(name: str) -> dict[str, dict[str, Any]]:
def get_tank(name: str, id: str) -> dict[str, Any]:
return api.get_tank(name, id)
# DingZQ, 2025-03-29
def get_all_tanks(name: str) -> list[dict[str, Any]]:
return api.get_all_tanks(name)
def set_tank(name: str, cs: ChangeSet) -> ChangeSet:
return api.set_tank(name, cs)