From c813c3d6fbf1aa993940884844b7eb3cdf0971c9 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 3 Mar 2023 19:51:21 +0800 Subject: [PATCH] Implement option v3 in --- api/s23_options_v3.py | 148 ++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 86 deletions(-) diff --git a/api/s23_options_v3.py b/api/s23_options_v3.py index 390ca52..e1e9c50 100644 --- a/api/s23_options_v3.py +++ b/api/s23_options_v3.py @@ -53,36 +53,39 @@ OPTION_V3_QUALITY_UNITS_UGL = 'UG/L' def get_option_v3_schema(name: str) -> dict[str, dict[str, Any]]: - return { 'UNITS' : element_schema, - 'PRESSURE' : element_schema, - 'HEADLOSS' : element_schema, - 'QUALITY' : element_schema, - 'UNBALANCED' : element_schema, - 'PATTERN' : element_schema, - 'DEMAND MODEL' : element_schema, - 'DEMAND MULTIPLIER' : element_schema, - 'EMITTER EXPONENT' : element_schema, - 'VISCOSITY' : element_schema, - 'DIFFUSIVITY' : element_schema, - 'SPECIFIC GRAVITY' : element_schema, - 'TRIALS' : element_schema, - 'ACCURACY' : element_schema, - 'HEADERROR' : element_schema, - 'FLOWCHANGE' : element_schema, - 'MINIMUM PRESSURE' : element_schema, - 'REQUIRED PRESSURE' : element_schema, - 'PRESSURE EXPONENT' : element_schema, - 'TOLERANCE' : element_schema, - 'HTOL' : element_schema, - 'QTOL' : element_schema, - 'RQTOL' : element_schema, - 'CHECKFREQ' : element_schema, - 'MAXCHECK' : element_schema, - 'DAMPLIMIT' : element_schema } + return { 'FLOW_UNITS' : element_schema, + 'PRESSURE_UNITS' : element_schema, + 'HEADLOSS_MODEL' : element_schema, + 'SPECIFIC_GRAVITY' : element_schema, + 'SPECIFIC_VISCOSITY' : element_schema, + 'MAXIMUM_TRIALS' : element_schema, + 'HEAD_TOLERANCE' : element_schema, + 'FLOW_TOLERANCE' : element_schema, + 'FLOW_CHANGE_LIMIT' : element_schema, + 'RELATIVE_ACCURACY' : element_schema, + 'TIME_WEIGHT' : element_schema, + 'STEP_SIZING' : element_schema, + 'IF_UNBALANCED' : element_schema, + 'DEMAND_MODEL' : element_schema, + 'DEMAND_PATTERN' : element_schema, + 'DEMAND_MULTIPLIER' : element_schema, + 'MINIMUM_PRESSURE' : element_schema, + 'SERVICE_PRESSURE' : element_schema, + 'PRESSURE_EXPONENT' : element_schema, + 'LEAKAGE_MODEL' : element_schema, + 'LEAKAGE_COEFF1' : element_schema, + 'LEAKAGE_COEFF2' : element_schema, + 'EMITTER_EXPONENT' : element_schema, + 'QUALITY_MODEL' : element_schema, + 'QUALITY_NAME' : element_schema, + 'QUALITY_UNITS' : element_schema, + 'TRACE_NODE' : element_schema, + 'SPECIFIC_DIFFUSIVITY' : element_schema, + 'QUALITY_TOLERANCE' : element_schema } def get_option_v3(name: str) -> dict[str, Any]: - ts = read_all(name, f"select * from options") + ts = read_all(name, f"select * from options_v3") d = {} for e in ts: d[e['key']] = str(e['value']) @@ -102,22 +105,22 @@ def set_option_v3_cmd(name: str, cs: ChangeSet) -> DbChangeSet: old[key] = str(raw_old[key]) new[key] = str(new_dict[key]) - redo_cs = g_update_prefix | { 'type' : 'option' } + redo_cs = g_update_prefix | { 'type' : 'option_v3' } redo_sql = '' for key, value in new.items(): if redo_sql != '': redo_sql += '\n' - redo_sql += f"update options set value = '{value}' where key = '{key}';" + redo_sql += f"update options_v3 set value = '{value}' where key = '{key}';" redo_cs |= { key: value } - undo_cs = g_update_prefix | { 'type' : 'option' } + undo_cs = g_update_prefix | { 'type' : 'option_v3' } undo_sql = '' for key, value in old.items(): if undo_sql != '': undo_sql += '\n' - undo_sql += f"update options set value = '{value}' where key = '{key}';" + undo_sql += f"update options_v3 set value = '{value}' where key = '{key}';" undo_cs |= { key: value } return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs]) @@ -127,66 +130,39 @@ def set_option_v3(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_option_v3_cmd(name, cs)) -#-------------------------------------------------------------- -# [EPANET2][IN][OUT] -# UNITS CFS/GPM/MGD/IMGD/AFD/LPS/LPM/MLD/CMH/CMD/SI -# PRESSURE PSI/KPA/M -# HEADLOSS H-W/D-W/C-M -# QUALITY NONE/AGE/TRACE/CHEMICAL (TraceNode) -# UNBALANCED STOP/CONTINUE {Niter} -# PATTERN id -# DEMAND MODEL DDA/PDA -# DEMAND MULTIPLIER value -# EMITTER EXPONENT value -# VISCOSITY value -# DIFFUSIVITY value -# SPECIFIC GRAVITY value -# TRIALS value -# ACCURACY value# -# HEADERROR value -# FLOWCHANGE value -# MINIMUM PRESSURE value -# REQUIRED PRESSURE value -# PRESSURE EXPONENT value# -# TOLERANCE value -# HTOL value -# QTOL value -# RQTOL value -# CHECKFREQ value -# MAXCHECK value -# DAMPLIMIT value -# ---- Unsupported Options ----- -# HYDRAULICS USE/SAVE filename -# MAP filename -#-------------------------------------------------------------- -def inp_in_option_v3(section: list[str]) -> ChangeSet: - if len(section) > 0: - cs = g_update_prefix | { 'type' : 'option' } - for s in section: - if s.startswith(';'): - continue - - tokens = s.strip().split() - if tokens[0].upper() == 'PATTERN': # can not upper id - cs |= { 'PATTERN' : tokens[1] } - elif tokens[0].upper() == 'QUALITY': # can not upper trace node - value = tokens[1] - if len(tokens) > 2: - value += f' {tokens[2]}' - cs |= { 'QUALITY' : value } - else: - line = s.upper().strip() - for key in get_option_v3_schema('').keys(): - if line.startswith(key): - value = line.removeprefix(key).strip() - cs |= { key : value } - return ChangeSet(cs) +def _sync_to_v2() -> ChangeSet: return ChangeSet() +def inp_in_option_v3(section: list[str]) -> ChangeSet: + if len(section) <= 0: + return ChangeSet() + + cs = g_update_prefix | { 'type' : 'option_v3' } + v2_lines = [] + for s in section: + if s.startswith(';'): + continue + + tokens = s.strip().split() + key = tokens[0] + if key in get_option_v3_schema('').keys(): + value = tokens[1] if len(tokens) >= 2 else '' + cs |= { key : value } + else: + v2_lines.append(s.strip()) + + for line in v2_lines: + pass + + result = ChangeSet(cs) + result.merge(_sync_to_v2()) + return result + + def inp_out_option_v3(name: str) -> list[str]: lines = [] - objs = read_all(name, f"select * from options") + objs = read_all(name, f"select * from options_v3") for obj in objs: key = obj['key'] value = obj['value']