Support to get link on boundary

This commit is contained in:
wqy
2023-07-21 18:40:27 +08:00
parent 4c6e257d1d
commit fb347ba03a
5 changed files with 77 additions and 14 deletions

View File

@@ -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 .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 .s33_dma_cal import PARTITION_TYPE_RB, PARTITION_TYPE_KWAY

View File

@@ -46,13 +46,62 @@ def get_nodes_in_boundary(name: str, boundary: list[tuple[float, float]]) -> lis
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]:
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
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]]:
write(name, f'delete from temp_node')
for node in nodes: