Accept Merge Request #297: (wqy/region -> master)
Merge Request: Support to get link on boundary Created By: @王琼钰 Accepted By: @王琼钰 URL: https://tjwater.coding.net/p/tjwatercloud/d/TJWaterServer/git/merge/297?initial=true
This commit is contained in:
@@ -138,7 +138,7 @@ from .s31_scada_element import get_scada_element_schema, get_scada_element, set_
|
|||||||
from .s31_scada_element import get_all_scada_element_ids, get_all_scada_elements
|
from .s31_scada_element import get_all_scada_element_ids, get_all_scada_elements
|
||||||
from .clean_api import clean_scada_element
|
from .clean_api import clean_scada_element
|
||||||
|
|
||||||
from .s32_region_util import get_nodes_in_boundary, get_nodes_in_region, calculate_convex_hull, calculate_boundary, inflate_boundary, inflate_region
|
from .s32_region_util import get_nodes_in_boundary, get_nodes_in_region, get_links_on_region_boundary, calculate_convex_hull, calculate_boundary, inflate_boundary, inflate_region
|
||||||
from .s32_region import get_region_schema, get_region, set_region, add_region, delete_region
|
from .s32_region import get_region_schema, get_region, set_region, add_region, delete_region
|
||||||
|
|
||||||
from .s33_dma_cal import PARTITION_TYPE_RB, PARTITION_TYPE_KWAY
|
from .s33_dma_cal import PARTITION_TYPE_RB, PARTITION_TYPE_KWAY
|
||||||
|
|||||||
@@ -46,13 +46,62 @@ def get_nodes_in_boundary(name: str, boundary: list[tuple[float, float]]) -> lis
|
|||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
|
|
||||||
|
def _get_links_on_boundary(name: str, nodes: list[str]) -> list[str]:
|
||||||
|
links: list[str] = []
|
||||||
|
|
||||||
|
for node in nodes:
|
||||||
|
node_links = get_node_links(name, node)
|
||||||
|
for link in node_links:
|
||||||
|
if link in links:
|
||||||
|
continue
|
||||||
|
|
||||||
|
link_nodes = get_link_nodes(name, link)
|
||||||
|
if link_nodes[0] in nodes and link_nodes[1] not in nodes:
|
||||||
|
links.append(link)
|
||||||
|
elif link_nodes[0] not in nodes and link_nodes[1] in nodes:
|
||||||
|
links.append(link)
|
||||||
|
|
||||||
|
return links
|
||||||
|
|
||||||
|
|
||||||
|
# if region is general or wda => get_nodes_in_boundary
|
||||||
|
# if region is dma, sa or vd => get stored nodes in table
|
||||||
def get_nodes_in_region(name: str, region_id: str) -> list[str]:
|
def get_nodes_in_region(name: str, region_id: str) -> list[str]:
|
||||||
nodes: list[str] = []
|
nodes: list[str] = []
|
||||||
for row in read_all(name, f"select c.node from coordinates as c, region as r where ST_Intersects(c.coord, r.boundary) and r.id = '{region_id}'"):
|
|
||||||
nodes.append(row['node'])
|
row = try_read(name, f"select r_type from region where id = '{region_id}'")
|
||||||
|
if row == None:
|
||||||
|
return nodes
|
||||||
|
|
||||||
|
r_type = str(row['r_type'])
|
||||||
|
|
||||||
|
if r_type == 'DMA' or r_type == 'SA' or r_type == 'VD':
|
||||||
|
table = ''
|
||||||
|
if r_type == 'DMA':
|
||||||
|
table = 'region_dma'
|
||||||
|
elif r_type == 'SA':
|
||||||
|
table = 'region_sa'
|
||||||
|
elif r_type == 'VD':
|
||||||
|
table = 'region_vd'
|
||||||
|
|
||||||
|
if table != '':
|
||||||
|
row = try_read(name, f"select nodes from {table} where id = '{region_id}'")
|
||||||
|
if row != None:
|
||||||
|
nodes = eval(str(row['nodes']))
|
||||||
|
|
||||||
|
if nodes == []:
|
||||||
|
for row in read_all(name, f"select c.node from coordinates as c, region as r where ST_Intersects(c.coord, r.boundary) and r.id = '{region_id}'"):
|
||||||
|
nodes.append(row['node'])
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
|
|
||||||
|
def get_links_on_region_boundary(name: str, region_id: str) -> list[str]:
|
||||||
|
nodes = get_nodes_in_region(name, region_id)
|
||||||
|
print(nodes)
|
||||||
|
return _get_links_on_boundary(name, nodes)
|
||||||
|
|
||||||
|
|
||||||
def calculate_convex_hull(name: str, nodes: list[str]) -> list[tuple[float, float]]:
|
def calculate_convex_hull(name: str, nodes: list[str]) -> list[tuple[float, float]]:
|
||||||
write(name, f'delete from temp_node')
|
write(name, f'delete from temp_node')
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
|
|||||||
9
dev.py
9
dev.py
@@ -1,11 +1,10 @@
|
|||||||
from tjnetwork import *
|
from tjnetwork import *
|
||||||
|
|
||||||
p = 'dev'
|
p = 'dev'
|
||||||
read_inp(p, './inp/net3.inp', '3')
|
|
||||||
|
|
||||||
|
read_inp(p, f'./inp/net3.inp', '3')
|
||||||
open_project(p)
|
open_project(p)
|
||||||
|
|
||||||
sass = calculate_service_area(p)
|
add_region(p, ChangeSet({'id': 'r', 'boundary': [(24.614,13.087), (24.835,11.069), (26.144,10.747), (27.290,11.543), (25.726,12.987), (24.614,13.087)]}))
|
||||||
assert len(sass) == 25
|
links = get_links_on_region_boundary(p, 'r')
|
||||||
print(sass[0])
|
print(links)
|
||||||
print(sass[1])
|
|
||||||
@@ -5680,11 +5680,27 @@ class TestApi:
|
|||||||
boundary = calculate_boundary(p, vds[0]['nodes'])
|
boundary = calculate_boundary(p, vds[0]['nodes'])
|
||||||
boundary = inflate_boundary(p, boundary)
|
boundary = inflate_boundary(p, boundary)
|
||||||
|
|
||||||
add_region(p, ChangeSet({'id': 'r', 'boundary': boundary}))
|
add_region(p, ChangeSet({'id': 'r1', 'boundary': boundary}))
|
||||||
|
|
||||||
nodes = get_nodes_in_region(p, 'r')
|
nodes = get_nodes_in_region(p, 'r1')
|
||||||
assert nodes == ['10', '101', '103', '105', '107', '109', '111', '115', '117', '119', '120', '257', '259', '261', '263', 'Lake']
|
assert nodes == ['10', '101', '103', '105', '107', '109', '111', '115', '117', '119', '120', '257', '259', '261', '263', 'Lake']
|
||||||
|
|
||||||
|
add_district_metering_area(p, ChangeSet({'id': 'r2', 'boundary': boundary, 'nodes': ['10', '101', '103']}))
|
||||||
|
nodes = get_nodes_in_region(p, 'r2')
|
||||||
|
assert nodes == ['10', '101', '103']
|
||||||
|
|
||||||
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_links_on_boundary(self):
|
||||||
|
p = 'get_links_on_boundary'
|
||||||
|
read_inp(p, f'./inp/net3.inp', '3')
|
||||||
|
open_project(p)
|
||||||
|
|
||||||
|
add_region(p, ChangeSet({'id': 'r', 'boundary': [(24.614,13.087), (24.835,11.069), (26.144,10.747), (27.290,11.543), (25.726,12.987), (24.614,13.087)]}))
|
||||||
|
links = get_links_on_region_boundary(p, 'r')
|
||||||
|
assert links == ['183', '185', '229', '313', '315']
|
||||||
|
|
||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -984,16 +984,15 @@ def get_all_scada_elements(name: str) -> list[dict[str, Any]]:
|
|||||||
# general_region 32
|
# general_region 32
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
# pure geometry function, test point is in polygon
|
|
||||||
def get_nodes_in_boundary(name: str, boundary: list[tuple[float, float]]) -> list[str]:
|
def get_nodes_in_boundary(name: str, boundary: list[tuple[float, float]]) -> list[str]:
|
||||||
return api.get_nodes_in_boundary(name, boundary)
|
return api.get_nodes_in_boundary(name, boundary)
|
||||||
|
|
||||||
# if region is general or wda => get_nodes_in_boundary
|
|
||||||
# if region is dma, sa or vd => get stored nodes in table
|
|
||||||
# TODO: more test
|
|
||||||
def get_nodes_in_region(name: str, region_id: str) -> list[str]:
|
def get_nodes_in_region(name: str, region_id: str) -> list[str]:
|
||||||
return api.get_nodes_in_region(name, region_id)
|
return api.get_nodes_in_region(name, region_id)
|
||||||
|
|
||||||
|
def get_links_on_region_boundary(name: str, region_id: str) -> list[str]:
|
||||||
|
return api.get_links_on_region_boundary(name, region_id)
|
||||||
|
|
||||||
def calculate_convex_hull(name: str, nodes: list[str]) -> list[tuple[float, float]]:
|
def calculate_convex_hull(name: str, nodes: list[str]) -> list[tuple[float, float]]:
|
||||||
return api.calculate_convex_hull(name, nodes)
|
return api.calculate_convex_hull(name, nodes)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user