From 964e9af03362f6b3414430140c758aa53ad73cd1 Mon Sep 17 00:00:00 2001 From: wqy Date: Fri, 30 Sep 2022 20:15:25 +0800 Subject: [PATCH 1/2] Add more test about coord --- test_tjnetwork.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_tjnetwork.py b/test_tjnetwork.py index 7623f59..28c4abd 100644 --- a/test_tjnetwork.py +++ b/test_tjnetwork.py @@ -104,6 +104,12 @@ class TestApi: assert change_set.operations[0]['properties'] == ['demand'] assert get_junction(p, 'j0')['demand'] == 100.0 + assert get_junction(p, 'j0')['coord']['x'] == 0.0 + assert get_junction(p, 'j0')['coord']['y'] == 10.0 + change_set = set_junction(p, 'j0', {'coord': {'x': 100.0, 'y': 200.0}}) + assert get_junction(p, 'j0')['coord']['x'] == 100.0 + assert get_junction(p, 'j0')['coord']['y'] == 200.0 + # TODO: pattern change_set = add_junction(p, "j1", 0.0, 10.0, 20.0) From 85f27cf655a957f047d580985bf5ca7799726246 Mon Sep 17 00:00:00 2001 From: wqy Date: Fri, 30 Sep 2022 21:01:57 +0800 Subject: [PATCH 2/2] Expose node specific api --- api/__init__.py | 2 +- api/s24_coordinates.py | 3 ++- tjnetwork.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/__init__.py b/api/__init__.py index 543fa84..c93a287 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -33,4 +33,4 @@ from .s6_pumps import get_pump_schema, add_pump, get_pump, set_pump, delete_pump from .s7_valves import VALVES_TYPE_PRV, VALVES_TYPE_PSV, VALVES_TYPE_PBV, VALVES_TYPE_FCV, VALVES_TYPE_TCV, VALVES_TYPE_GPV from .s7_valves import get_valve_schema, add_valve, get_valve, set_valve, delete_valve -# from .s24_coordinates import get_node_coord, set_node_coord \ No newline at end of file +from .s24_coordinates import get_node_coord \ No newline at end of file diff --git a/api/s24_coordinates.py b/api/s24_coordinates.py index 0f5ed48..194eae2 100644 --- a/api/s24_coordinates.py +++ b/api/s24_coordinates.py @@ -20,7 +20,7 @@ def get_node_coord(name: str, id: str) -> dict[str, float] | None: coord = str(row['coord']) return _to_client_point(coord) - +''' def set_node_coord(name: str, node_type: str, id: str, x: float, y: float) -> ChangeSet: old = get_node_coord(name, id) if old == None: @@ -39,3 +39,4 @@ def set_node_coord(name: str, node_type: str, id: str, x: float, y: float) -> Ch change = ChangeSet() change.update(node_type, id, 'coord') return change +''' \ No newline at end of file diff --git a/tjnetwork.py b/tjnetwork.py index 23fe624..f9d7feb 100644 --- a/tjnetwork.py +++ b/tjnetwork.py @@ -136,6 +136,9 @@ def get_curves(name: str) -> list[str]: def get_patterns(name: str) -> list[str]: return api.get_patterns(name) +def get_node_links(name: str, node_id: str) -> list[str]: + return api.get_node_links(name, node_id) + ############################################################ # title 1.[TITLE] @@ -266,3 +269,11 @@ def set_valve(name: str, valve_id: str, properties: dict[str, Any]) -> ChangeSet def delete_valve(name: str, valve_id: str) -> ChangeSet: return api.delete_valve(name, valve_id) + + +############################################################ +# coord 24.[COORDINATES] +############################################################ + +def get_node_coord(name: str, node_id: str) -> dict[str, float] | None: + return api.get_node_coord(name, node_id)