refine
This commit is contained in:
@@ -31,6 +31,7 @@ from .s24_coordinates import inp_in_coord
|
|||||||
from .s25_vertices import inp_in_vertex
|
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
|
||||||
|
|
||||||
_S = 'S'
|
_S = 'S'
|
||||||
_L = 'L'
|
_L = 'L'
|
||||||
@@ -64,6 +65,8 @@ _handler = {
|
|||||||
OPTIONS : (_S, _inp_in_option), # line, version
|
OPTIONS : (_S, _inp_in_option), # line, version
|
||||||
COORDINATES : (_L, inp_in_coord),
|
COORDINATES : (_L, inp_in_coord),
|
||||||
VERTICES : (_L, inp_in_vertex),
|
VERTICES : (_L, inp_in_vertex),
|
||||||
|
REGION : (_L, inp_in_region),
|
||||||
|
BOUND : (_L, inp_in_bound),
|
||||||
LABELS : (_L, inp_in_label),
|
LABELS : (_L, inp_in_label),
|
||||||
BACKDROP : (_S, inp_in_backdrop),
|
BACKDROP : (_S, inp_in_backdrop),
|
||||||
#END : 'END',
|
#END : 'END',
|
||||||
@@ -106,6 +109,8 @@ _level_4 = [
|
|||||||
ENERGY,
|
ENERGY,
|
||||||
REACTIONS,
|
REACTIONS,
|
||||||
VERTICES,
|
VERTICES,
|
||||||
|
REGION,
|
||||||
|
BOUND,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +161,7 @@ def _get_file_offset(inp: str) -> tuple[dict[str, list[int]], bool]:
|
|||||||
elif line != '' and line.startswith(';') == False:
|
elif line != '' and line.startswith(';') == False:
|
||||||
if current == DEMANDS:
|
if current == DEMANDS:
|
||||||
demand_outside = True
|
demand_outside = True
|
||||||
|
|
||||||
return (offset, demand_outside)
|
return (offset, demand_outside)
|
||||||
|
|
||||||
|
|
||||||
@@ -180,7 +185,7 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
|
|||||||
curve_type_desc_line = None
|
curve_type_desc_line = None
|
||||||
|
|
||||||
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:
|
||||||
@@ -250,11 +255,14 @@ 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 == BOUND:
|
||||||
|
tokens = line.split()
|
||||||
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:
|
||||||
sql_batch.add(handler(line, current_pattern not in variable_patterns))
|
sql_batch.add(handler(line, current_pattern not in variable_patterns))
|
||||||
|
elif s==BOUND:
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
sql_batch.add(handler(line))
|
sql_batch.add(handler(line))
|
||||||
|
|
||||||
@@ -310,12 +318,12 @@ def import_inp(project: str, cs: ChangeSet, version: str = '3') -> bool:
|
|||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
_print_time(f'Start writing temp file "{filename}"...')
|
_print_time(f'Start writing temp file "{filename}"...')
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w',encoding="GBK") as f:
|
||||||
f.write(str(cs.operations[0]['inp']))
|
f.write(str(cs.operations[0]['inp']))
|
||||||
_print_time(f'End writing temp file "{filename}"...')
|
_print_time(f'End writing temp file "{filename}"...')
|
||||||
|
|
||||||
result = read_inp(project, filename, version)
|
result = read_inp(project, filename, version)
|
||||||
|
|
||||||
os.remove(filename)
|
#os.remove(filename)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ def dump_inp(project: str, inp: str, version: str = '3'):
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
file = open(path, mode='w')
|
file = open(path, mode='w',encoding="UTF-8")
|
||||||
|
|
||||||
for name in section_name:
|
for name in section_name:
|
||||||
if name == TITLE:
|
if name == TITLE:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ _NODE = '_node'
|
|||||||
_LINK = '_link'
|
_LINK = '_link'
|
||||||
_CURVE = '_curve'
|
_CURVE = '_curve'
|
||||||
_PATTERN = '_pattern'
|
_PATTERN = '_pattern'
|
||||||
|
_REGION = '_region'
|
||||||
|
|
||||||
JUNCTION = 'junction'
|
JUNCTION = 'junction'
|
||||||
RESERVOIR = 'reservoir'
|
RESERVOIR = 'reservoir'
|
||||||
@@ -18,6 +19,8 @@ VALVE = 'valve'
|
|||||||
PATTERN = 'pattern'
|
PATTERN = 'pattern'
|
||||||
CURVE = 'curve'
|
CURVE = 'curve'
|
||||||
|
|
||||||
|
REGION = 'region'
|
||||||
|
|
||||||
|
|
||||||
def _get_from(name: str, id: str, base_type: str) -> Row | None:
|
def _get_from(name: str, id: str, base_type: str) -> Row | None:
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||||
@@ -70,6 +73,9 @@ def is_curve(name: str, id: str) -> bool:
|
|||||||
def is_pattern(name: str, id: str) -> bool:
|
def is_pattern(name: str, id: str) -> bool:
|
||||||
return _get_from(name, id, _PATTERN) != None
|
return _get_from(name, id, _PATTERN) != None
|
||||||
|
|
||||||
|
def is_region(name: str, id: str) -> bool:
|
||||||
|
return _get_from(name, id, _REGION) != None
|
||||||
|
|
||||||
|
|
||||||
def _get_all(name: str, base_type: str) -> list[str]:
|
def _get_all(name: str, base_type: str) -> list[str]:
|
||||||
ids : list[str] = []
|
ids : list[str] = []
|
||||||
@@ -95,6 +101,8 @@ def get_curves(name: str) -> list[str]:
|
|||||||
def get_patterns(name: str) -> list[str]:
|
def get_patterns(name: str) -> list[str]:
|
||||||
return _get_all(name, _PATTERN)
|
return _get_all(name, _PATTERN)
|
||||||
|
|
||||||
|
def get_regions(name: str) -> list[str]:
|
||||||
|
return _get_all(name, _REGION)
|
||||||
|
|
||||||
def get_node_links(name: str, id: str) -> list[str]:
|
def get_node_links(name: str, id: str) -> list[str]:
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||||
|
|||||||
@@ -81,3 +81,11 @@ def delete_region(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
if get_region(name, cs.operations[0]['id']) == {}:
|
if get_region(name, cs.operations[0]['id']) == {}:
|
||||||
return ChangeSet()
|
return ChangeSet()
|
||||||
return execute_command(name, _delete_region(name, cs))
|
return execute_command(name, _delete_region(name, cs))
|
||||||
|
|
||||||
|
def inp_in_region(line: str) -> str:
|
||||||
|
tokens = line.split()
|
||||||
|
return str(f"insert into _region (id, type) values ('{tokens[0]}', '{tokens[1]}');")
|
||||||
|
|
||||||
|
def inp_in_bound(line: str) -> str:
|
||||||
|
tokens = line.split()
|
||||||
|
return tokens[0]
|
||||||
@@ -63,6 +63,8 @@ REPORT = 'REPORT'
|
|||||||
OPTIONS = 'OPTIONS'
|
OPTIONS = 'OPTIONS'
|
||||||
COORDINATES = 'COORDINATES'
|
COORDINATES = 'COORDINATES'
|
||||||
VERTICES = 'VERTICES'
|
VERTICES = 'VERTICES'
|
||||||
|
REGION='REGION'
|
||||||
|
BOUND='BOUND'
|
||||||
LABELS = 'LABELS'
|
LABELS = 'LABELS'
|
||||||
BACKDROP = 'BACKDROP'
|
BACKDROP = 'BACKDROP'
|
||||||
END = 'END'
|
END = 'END'
|
||||||
@@ -72,4 +74,4 @@ section_name = [TITLE, JUNCTIONS, RESERVOIRS, TANKS, PIPES,
|
|||||||
PATTERNS, CURVES, CONTROLS, RULES, ENERGY,
|
PATTERNS, CURVES, CONTROLS, RULES, ENERGY,
|
||||||
EMITTERS, QUALITY, SOURCES, REACTIONS, MIXING,
|
EMITTERS, QUALITY, SOURCES, REACTIONS, MIXING,
|
||||||
TIMES, REPORT, OPTIONS, COORDINATES, VERTICES,
|
TIMES, REPORT, OPTIONS, COORDINATES, VERTICES,
|
||||||
LABELS, BACKDROP, END]
|
REGION, BOUND, LABELS, BACKDROP, END]
|
||||||
|
|||||||
Reference in New Issue
Block a user