Refine option to support batch command

This commit is contained in:
WQY\qiong
2023-03-08 22:56:29 +08:00
parent 3c3c29de90
commit 690e3aa09a
6 changed files with 35 additions and 19 deletions

View File

@@ -22,7 +22,7 @@ from .s19_reactions import set_reaction_cmd, set_pipe_reaction_cmd, set_tank_rea
from .s20_mixing import set_mixing_cmd, add_mixing_cmd, delete_mixing_cmd
from .s21_times import set_time_cmd
#from .s22_report import *
from .s23_options import set_option_cmd
from .s23_options_util import set_option_cmd, set_option_v3_cmd
#from .s24_coordinates import *
from .s25_vertices import set_vertex_cmd, add_vertex_cmd, delete_vertex_cmd
from .s26_labels import set_label_cmd, add_label_cmd, delete_label_cmd
@@ -89,6 +89,8 @@ def add_cmd(name: str, cs: ChangeSet) -> DbChangeSet | None:
return None
elif type == s23_option:
return None
elif type == s23_option_v3:
return None
elif type == s24_coordinate:
return None
elif type == s25_vertex:
@@ -164,6 +166,8 @@ def set_cmd(name: str, cs: ChangeSet) -> DbChangeSet | None:
return None
elif type == s23_option:
return set_option_cmd(name, cs)
elif type == s23_option_v3:
return set_option_v3_cmd(name, cs)
elif type == s24_coordinate: # do not support update here
return None
elif type == s25_vertex:
@@ -239,6 +243,8 @@ def del_cmd(name: str, cs: ChangeSet) -> DbChangeSet | None:
return None
elif type == s23_option:
return None
elif type == s23_option_v3:
return None
elif type == s24_coordinate:
return None
elif type == s25_vertex:

View File

@@ -23,6 +23,7 @@ from .s20_mixing import set_mixing, add_mixing, delete_mixing
from .s21_times import set_time
#from .s22_report import *
from .s23_options import set_option
from .s23_options_v3 import set_option_v3
#from .s24_coordinates import *
from .s25_vertices import set_vertex, add_vertex, delete_vertex
from .s26_labels import set_label, add_label, delete_label
@@ -89,6 +90,8 @@ def execute_add_command(name: str, cs: ChangeSet) -> ChangeSet:
return ChangeSet()
elif type == s23_option:
return ChangeSet()
elif type == s23_option_v3:
return ChangeSet()
elif type == s24_coordinate:
return ChangeSet()
elif type == s25_vertex:
@@ -164,6 +167,8 @@ def execute_update_command(name: str, cs: ChangeSet) -> ChangeSet:
return ChangeSet()
elif type == s23_option:
return set_option(name, cs)
elif type == s23_option_v3:
return set_option_v3(name, cs)
elif type == s24_coordinate: # do not support update here
return ChangeSet()
elif type == s25_vertex:
@@ -239,6 +244,8 @@ def execute_delete_command(name: str, cs: ChangeSet) -> ChangeSet:
return ChangeSet()
elif type == s23_option:
return ChangeSet()
elif type == s23_option_v3:
return ChangeSet()
elif type == s24_coordinate:
return ChangeSet()
elif type == s25_vertex:

View File

@@ -1,16 +1,12 @@
from .database import *
from .s23_options_util import get_option_schema, set_option_cmd, set_option_v3_cmd, generate_v3
from .s23_options_util import get_option_schema, generate_v3
from .batch_cmd import execute_batch_command
def set_option(name: str, cs: ChangeSet) -> ChangeSet:
v2_cmd = set_option_cmd(name, cs)
result = execute_command(name, v2_cmd)
v3 = generate_v3(ChangeSet(v2_cmd.redo_cs[0]))
v3_cmd = set_option_v3_cmd(name, v3)
result.merge(execute_command(name, v3_cmd))
return result
new_cs = cs
new_cs.merge(generate_v3(cs))
return execute_batch_command(name, new_cs)
def inp_in_option(section: list[str]) -> ChangeSet:

View File

@@ -140,6 +140,11 @@ def set_option_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
def set_option_only(name: str, cs: ChangeSet) -> ChangeSet:
v2_cmd = set_option_cmd(name, cs)
return execute_command(name, v2_cmd)
OPTION_V3_FLOW_UNITS_CFS = OPTION_UNITS_CFS
OPTION_V3_FLOW_UNITS_GPM = OPTION_UNITS_GPM
OPTION_V3_FLOW_UNITS_MGD = OPTION_UNITS_MGD
@@ -260,6 +265,11 @@ def set_option_v3_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
def set_option_v3_only(name: str, cs: ChangeSet) -> ChangeSet:
v3_cmd = set_option_v3_cmd(name, cs)
return execute_command(name, v3_cmd)
_key_map_23 = {
'UNITS' : 'FLOW_UNITS',
'PRESSURE' : 'PRESSURE_UNITS',

View File

@@ -1,16 +1,12 @@
from .database import *
from .s23_options_util import get_option_schema, get_option_v3_schema, set_option_v3_cmd, set_option_cmd, generate_v2, generate_v3
from .s23_options_util import get_option_schema, get_option_v3_schema, generate_v2, generate_v3
from .batch_cmd import execute_batch_command
def set_option_v3(name: str, cs: ChangeSet) -> ChangeSet:
v3_cmd = set_option_v3_cmd(name, cs)
result = execute_command(name, v3_cmd)
v2 = generate_v2(ChangeSet(v3_cmd.redo_cs[0]))
v2_cmd = set_option_cmd(name, v2)
result.merge(execute_command(name, v2_cmd))
return result
new_cs = cs
new_cs.merge(generate_v2(cs))
return execute_batch_command(name, new_cs)
def _parse_v2(v2_lines: list[str]) -> dict[str, str]:

View File

@@ -24,6 +24,7 @@ s20_mixing = 'mixing'
s21_time = 'time'
s22_report = 'report'
s23_option = 'option'
s23_option_v3 = 'option_v3'
s24_coordinate = 'coordinate'
s25_vertex = 'vertex'
s26_label = 'label'