Clean and support v3 inp in

This commit is contained in:
Joey Wang
2023-03-22 13:00:16 +08:00
parent faec3cef73
commit 0db93b0637
3 changed files with 47 additions and 54 deletions

View File

@@ -13,8 +13,8 @@ from .s7_valves import inp_in_valve
from .s8_tags import inp_in_tag
from .s9_demands import inp_in_demand
from .s10_status import inp_in_status
from .s11_patterns import inp_in_pattern
from .s12_curves import CURVE_TYPE_PUMP, inp_in_curve
from .s11_patterns import pattern_v3_types, inp_in_pattern
from .s12_curves import curve_types, inp_in_curve
from .s13_controls import inp_in_control
from .s14_rules import inp_in_rule
from .s15_energy import inp_in_energy
@@ -35,9 +35,12 @@ from .s27_backdrop import inp_in_backdrop
_S = 'S'
_L = 'L'
def _inp_in_option(section: list[str], version: str = '3') -> str:
return inp_in_option_v3(section) if version == '3' else inp_in_option(section)
_handler = {
TITLE : (_S, inp_in_title),
JUNCTIONS : (_L, inp_in_junction),
JUNCTIONS : (_L, inp_in_junction), # line, demand_outside
RESERVOIRS : (_L, inp_in_reservoir),
TANKS : (_L, inp_in_tank),
PIPES : (_L, inp_in_pipe),
@@ -46,7 +49,7 @@ _handler = {
TAGS : (_L, inp_in_tag),
DEMANDS : (_L, inp_in_demand),
STATUS : (_L, inp_in_status),
PATTERNS : (_L, inp_in_pattern),
PATTERNS : (_L, inp_in_pattern), # line, fixed
CURVES : (_L, inp_in_curve),
CONTROLS : (_L, inp_in_control),
RULES : (_L, inp_in_rule),
@@ -58,7 +61,7 @@ _handler = {
MIXING : (_L, inp_in_mixing),
TIMES : (_S, inp_in_time),
REPORT : (_S, inp_in_report),
OPTIONS : (_S, inp_in_option),
OPTIONS : (_S, _inp_in_option), # line, version
COORDINATES : (_L, inp_in_coord),
VERTICES : (_L, inp_in_vertex),
LABELS : (_L, inp_in_label),
@@ -171,6 +174,7 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
if t[0] == _S:
sections[s] = []
variable_patterns = []
current_pattern = None
current_curve = None
curve_type_desc_line = None
@@ -209,22 +213,38 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
sections[s].append(line)
else:
if line.startswith(';'):
line = line.removeprefix(';')
if s == PATTERNS: # ;desc
pass
elif s == CURVES: # ;type: desc
curve_type_desc_line = line
if version != '3': #v2
line = line.removeprefix(';')
if s == PATTERNS: # ;desc
pass
elif s == CURVES: # ;type: desc
curve_type_desc_line = line
continue
if s == PATTERNS:
tokens = line.split()
if tokens[1].upper() in pattern_v3_types: #v3
sql_batch.add(f"insert into _pattern (id) values ('{tokens[0]}');")
current_pattern = tokens[0]
if tokens[1].upper() == 'VARIABLE':
variable_patterns.append(tokens[0])
continue
if current_pattern != tokens[0]:
sql_batch.add(f"insert into _pattern (id) values ('{tokens[0]}');")
current_pattern = tokens[0]
elif s == CURVES:
tokens = line.split()
if tokens[1].upper() in curve_types: #v3
sql_batch.add(f"insert into _curve (id, type) values ('{tokens[0]}', '{tokens[1].upper()}');")
current_curve = tokens[0]
continue
if current_curve != tokens[0]:
type = CURVE_TYPE_PUMP
type = curve_types[0]
if curve_type_desc_line != None:
type = curve_type_desc_line.split(':')[0].strip()
sql_batch.add(f"insert into _curve (id, type) values ('{tokens[0]}', '{type}');")
@@ -233,11 +253,10 @@ def parse_file(project: str, inp: str, version: str = '3') -> None:
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 == OPTIONS:
if version == '3':
sql_batch.add(inp_in_option_v3(line))
else:
sql_batch.add(inp_in_option(line))
sql_batch.add(handler(line, version))
else:
sql_batch.add(handler(line))