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 .s26_labels import inp_in_label
|
||||
from .s27_backdrop import inp_in_backdrop
|
||||
from .s32_region import inp_in_region,inp_in_bound
|
||||
|
||||
_S = 'S'
|
||||
_L = 'L'
|
||||
@@ -64,6 +65,8 @@ _handler = {
|
||||
OPTIONS : (_S, _inp_in_option), # line, version
|
||||
COORDINATES : (_L, inp_in_coord),
|
||||
VERTICES : (_L, inp_in_vertex),
|
||||
REGION : (_L, inp_in_region),
|
||||
BOUND : (_L, inp_in_bound),
|
||||
LABELS : (_L, inp_in_label),
|
||||
BACKDROP : (_S, inp_in_backdrop),
|
||||
#END : 'END',
|
||||
@@ -106,6 +109,8 @@ _level_4 = [
|
||||
ENERGY,
|
||||
REACTIONS,
|
||||
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:
|
||||
if current == DEMANDS:
|
||||
demand_outside = True
|
||||
|
||||
|
||||
return (offset, demand_outside)
|
||||
|
||||
|
||||
@@ -180,7 +185,7 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
|
||||
curve_type_desc_line = None
|
||||
|
||||
sql_batch = SQLBatch(project)
|
||||
|
||||
print("aaa")
|
||||
_print_time("Second scan...")
|
||||
with open(inp) as f:
|
||||
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}');")
|
||||
current_curve = tokens[0]
|
||||
curve_type_desc_line = None
|
||||
|
||||
elif s == BOUND:
|
||||
tokens = line.split()
|
||||
if s == JUNCTIONS:
|
||||
sql_batch.add(handler(line, demand_outside))
|
||||
elif s == PATTERNS:
|
||||
sql_batch.add(handler(line, current_pattern not in variable_patterns))
|
||||
elif s==BOUND:
|
||||
continue
|
||||
else:
|
||||
sql_batch.add(handler(line))
|
||||
|
||||
@@ -310,12 +318,12 @@ def import_inp(project: str, cs: ChangeSet, version: str = '3') -> bool:
|
||||
os.remove(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']))
|
||||
_print_time(f'End writing temp file "{filename}"...')
|
||||
|
||||
result = read_inp(project, filename, version)
|
||||
|
||||
os.remove(filename)
|
||||
#os.remove(filename)
|
||||
|
||||
return result
|
||||
|
||||
@@ -51,7 +51,7 @@ def dump_inp(project: str, inp: str, version: str = '3'):
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
|
||||
file = open(path, mode='w')
|
||||
file = open(path, mode='w',encoding="UTF-8")
|
||||
|
||||
for name in section_name:
|
||||
if name == TITLE:
|
||||
|
||||
@@ -7,6 +7,7 @@ _NODE = '_node'
|
||||
_LINK = '_link'
|
||||
_CURVE = '_curve'
|
||||
_PATTERN = '_pattern'
|
||||
_REGION = '_region'
|
||||
|
||||
JUNCTION = 'junction'
|
||||
RESERVOIR = 'reservoir'
|
||||
@@ -18,6 +19,8 @@ VALVE = 'valve'
|
||||
PATTERN = 'pattern'
|
||||
CURVE = 'curve'
|
||||
|
||||
REGION = 'region'
|
||||
|
||||
|
||||
def _get_from(name: str, id: str, base_type: str) -> Row | None:
|
||||
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:
|
||||
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]:
|
||||
ids : list[str] = []
|
||||
@@ -95,6 +101,8 @@ def get_curves(name: str) -> list[str]:
|
||||
def get_patterns(name: str) -> list[str]:
|
||||
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]:
|
||||
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']) == {}:
|
||||
return ChangeSet()
|
||||
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'
|
||||
COORDINATES = 'COORDINATES'
|
||||
VERTICES = 'VERTICES'
|
||||
REGION='REGION'
|
||||
BOUND='BOUND'
|
||||
LABELS = 'LABELS'
|
||||
BACKDROP = 'BACKDROP'
|
||||
END = 'END'
|
||||
@@ -72,4 +74,4 @@ section_name = [TITLE, JUNCTIONS, RESERVOIRS, TANKS, PIPES,
|
||||
PATTERNS, CURVES, CONTROLS, RULES, ENERGY,
|
||||
EMITTERS, QUALITY, SOURCES, REACTIONS, MIXING,
|
||||
TIMES, REPORT, OPTIONS, COORDINATES, VERTICES,
|
||||
LABELS, BACKDROP, END]
|
||||
REGION, BOUND, LABELS, BACKDROP, END]
|
||||
|
||||
Reference in New Issue
Block a user