refine
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
|||||||
from .project import *
|
from .project import *
|
||||||
from .database import ChangeSet, write
|
from .database import ChangeSet, write
|
||||||
from .sections import *
|
from .sections import *
|
||||||
|
from .s0_base import get_region_type
|
||||||
from .s1_title import inp_in_title
|
from .s1_title import inp_in_title
|
||||||
from .s2_junctions import inp_in_junction
|
from .s2_junctions import inp_in_junction
|
||||||
from .s3_reservoirs import inp_in_reservoir
|
from .s3_reservoirs import inp_in_reservoir
|
||||||
@@ -32,6 +33,7 @@ from .s25_vertices import inp_in_vertex
|
|||||||
from .s26_labels import inp_in_label
|
from .s26_labels import inp_in_label
|
||||||
from .s27_backdrop import inp_in_backdrop
|
from .s27_backdrop import inp_in_backdrop
|
||||||
from .s32_region import inp_in_region,inp_in_bound
|
from .s32_region import inp_in_region,inp_in_bound
|
||||||
|
from .s32_region_util import from_postgis_polygon,to_postgis_polygon
|
||||||
|
|
||||||
_S = 'S'
|
_S = 'S'
|
||||||
_L = 'L'
|
_L = 'L'
|
||||||
@@ -113,7 +115,14 @@ _level_4 = [
|
|||||||
BOUND,
|
BOUND,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
map_regiontype={
|
||||||
|
# map the region types from desktop to server
|
||||||
|
'DISTRIBUTION':'WDA',
|
||||||
|
'DMA':'DMA',
|
||||||
|
'PMA':'PMA',
|
||||||
|
'VD':'VD',
|
||||||
|
'SA':'SA',
|
||||||
|
}
|
||||||
class SQLBatch:
|
class SQLBatch:
|
||||||
def __init__(self, project: str, count: int = 100) -> None:
|
def __init__(self, project: str, count: int = 100) -> None:
|
||||||
self.batch: list[str] = []
|
self.batch: list[str] = []
|
||||||
@@ -183,9 +192,11 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
|
|||||||
current_pattern = None
|
current_pattern = None
|
||||||
current_curve = None
|
current_curve = None
|
||||||
curve_type_desc_line = None
|
curve_type_desc_line = None
|
||||||
|
current_region =None
|
||||||
|
current_bound=[]
|
||||||
|
current_bound.clear()
|
||||||
|
region_list={}
|
||||||
sql_batch = SQLBatch(project)
|
sql_batch = SQLBatch(project)
|
||||||
print("aaa")
|
|
||||||
_print_time("Second scan...")
|
_print_time("Second scan...")
|
||||||
with open(inp) as f:
|
with open(inp) as f:
|
||||||
for s in levels:
|
for s in levels:
|
||||||
@@ -255,8 +266,23 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
|
|||||||
sql_batch.add(f"insert into _curve (id, type) values ('{tokens[0]}', '{type}');")
|
sql_batch.add(f"insert into _curve (id, type) values ('{tokens[0]}', '{type}');")
|
||||||
current_curve = tokens[0]
|
current_curve = tokens[0]
|
||||||
curve_type_desc_line = None
|
curve_type_desc_line = None
|
||||||
|
elif s== REGION:
|
||||||
|
tokens = line.split()
|
||||||
|
region_list[tokens[0]]=tokens[1]
|
||||||
elif s == BOUND:
|
elif s == BOUND:
|
||||||
tokens = line.split()
|
tokens = line.split()
|
||||||
|
if(tokens[0]!=current_region and len(current_bound)>0):
|
||||||
|
#insert the previous region after get all the vertex of the attatched geometry
|
||||||
|
current_bound.append(current_bound[0])
|
||||||
|
current_geometry=to_postgis_polygon(current_bound)
|
||||||
|
region_type=map_regiontype[region_list[tokens[0]]]
|
||||||
|
sql_batch.add(f"insert into region(id, boundary,r_type) values ('{current_region}', '{current_geometry}','{region_type}');")
|
||||||
|
#start the new region
|
||||||
|
current_bound.clear()
|
||||||
|
vertex_point=(float(tokens[1]),float(tokens[2]))
|
||||||
|
current_bound.append(vertex_point)
|
||||||
|
current_region=tokens[0]
|
||||||
|
|
||||||
if s == JUNCTIONS:
|
if s == JUNCTIONS:
|
||||||
sql_batch.add(handler(line, demand_outside))
|
sql_batch.add(handler(line, demand_outside))
|
||||||
elif s == PATTERNS:
|
elif s == PATTERNS:
|
||||||
@@ -273,7 +299,12 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
|
|||||||
sql_batch.add(handler(sections[s], version))
|
sql_batch.add(handler(sections[s], version))
|
||||||
else:
|
else:
|
||||||
sql_batch.add(handler(sections[s]))
|
sql_batch.add(handler(sections[s]))
|
||||||
|
#need to insert the last region into database
|
||||||
|
if len(current_bound)>0:
|
||||||
|
current_bound.append(current_bound[0])
|
||||||
|
current_geometry=to_postgis_polygon(current_bound)
|
||||||
|
region_type=map_regiontype[region_list[current_region]]
|
||||||
|
sql_batch.add(f"insert into region(id, boundary,r_type) values ('{current_region}', '{current_geometry}','{region_type}');")
|
||||||
sql_batch.flush()
|
sql_batch.flush()
|
||||||
|
|
||||||
end = _print_time(f'End reading file "{inp}"')
|
end = _print_time(f'End reading file "{inp}"')
|
||||||
|
|||||||
@@ -125,3 +125,8 @@ def get_link_nodes(name: str, id: str) -> list[str]:
|
|||||||
elif is_valve(name, id):
|
elif is_valve(name, id):
|
||||||
row = read(name, f"select node1, node2 from valves where id = '{id}'")
|
row = read(name, f"select node1, node2 from valves where id = '{id}'")
|
||||||
return [str(row['node1']), str(row['node2'])]
|
return [str(row['node1']), str(row['node2'])]
|
||||||
|
|
||||||
|
def get_region_type(name: str, id: str)->str:
|
||||||
|
if(is_region(name,id)):
|
||||||
|
type = read(name, f"select type from _region where id = '{id}'")
|
||||||
|
return type
|
||||||
Reference in New Issue
Block a user