From 4f619c649f368404e9999d7ba2aa660384862c15 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 19:37:07 +0800 Subject: [PATCH 01/10] Fix title parser --- api/s1_title.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/s1_title.py b/api/s1_title.py index b521860..59962a0 100644 --- a/api/s1_title.py +++ b/api/s1_title.py @@ -33,9 +33,11 @@ class InpTitle: def inp_in_title(section: list[str]) -> ChangeSet: + if section == []: + return ChangeSet() + obj = InpTitle(section) - cs = ChangeSet(g_update_prefix | {'type': 'title', 'value' : obj.value}) - return cs + return ChangeSet(g_update_prefix | {'type': 'title', 'value' : obj.value}) def inp_out_title(name: str) -> list[str]: From 0acf2d98ed157bf7597470686753bf85215b4f69 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 19:37:23 +0800 Subject: [PATCH 02/10] Fix status parser --- api/s10_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/s10_status.py b/api/s10_status.py index 9db45bb..8b48305 100644 --- a/api/s10_status.py +++ b/api/s10_status.py @@ -77,7 +77,7 @@ class InpStatus: num_without_desc = (num - 1) if has_desc else num self.link = str(tokens[0]) - self.value = tokens[1] + self.value = tokens[1].upper() self.is_status = True if self.value == LINK_STATUS_OPEN or self.value == LINK_STATUS_CLOSED or self.value == LINK_STATUS_ACTIVE: self.status = str(self.value) From 0b5ce70966a91d2d0fa20ae91c1a24d5d1b1551c Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 19:42:39 +0800 Subject: [PATCH 03/10] Debug pattern & curve description --- api/s11_patterns.py | 2 ++ api/s12_curves.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/api/s11_patterns.py b/api/s11_patterns.py index 72b1f5f..9c3d4b7 100644 --- a/api/s11_patterns.py +++ b/api/s11_patterns.py @@ -116,6 +116,8 @@ def inp_in_pattern(section: list[str]) -> ChangeSet: cs = ChangeSet() for id, factors in patterns.items(): cs.append(g_add_prefix | {'type': 'pattern', 'id' : id, 'factors' : factors}) + + #print(descs) return cs diff --git a/api/s12_curves.py b/api/s12_curves.py index 9bd9c2c..98c1d29 100644 --- a/api/s12_curves.py +++ b/api/s12_curves.py @@ -149,6 +149,8 @@ def inp_in_curve(section: list[str]) -> ChangeSet: for id, coords in curves.items(): c_type = types[id] if id in types else CURVE_TYPE_PUMP cs.append(g_add_prefix | {'type': 'curve', 'id' : id, 'c_type': c_type, 'coords' : coords}) + + #print(descs) return cs From 1348c6626dfb3242fa377c1b377918b86665771a Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 20:10:32 +0800 Subject: [PATCH 04/10] Fix energy parser --- api/s15_energy.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/s15_energy.py b/api/s15_energy.py index a573416..70d50df 100644 --- a/api/s15_energy.py +++ b/api/s15_energy.py @@ -150,6 +150,11 @@ def inp_in_energy(section: list[str]) -> ChangeSet: for key in get_energy_schema('').keys(): if line.startswith(key): value = line.removeprefix(key).strip() + + # exception here + if line.startswith('GLOBAL EFFICIENCY'): + value = line.removeprefix('GLOBAL EFFICIENCY').strip() + cs.append(g_update_prefix | { 'type' : 'energy', key : value }) return cs From f59c6e4d523e971786c409014e03869d83def45a Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 20:11:27 +0800 Subject: [PATCH 05/10] Open report status --- script/sql/create/22.report.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/sql/create/22.report.sql b/script/sql/create/22.report.sql index 3065f75..40f1298 100644 --- a/script/sql/create/22.report.sql +++ b/script/sql/create/22.report.sql @@ -9,7 +9,7 @@ create table report insert into report (key, value) values ('PAGESIZE', '0') --, ('FILE', '') -, ('STATUS', 'NO') +, ('STATUS', 'FULL') , ('SUMMARY', 'YES') , ('MESSAGES', 'YES') , ('ENERY', 'YES') From 1193b656a4ba04261c8f874210e4f955495cbd1d Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 20:28:31 +0800 Subject: [PATCH 06/10] Support to dump change set --- api/operation.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/operation.py b/api/operation.py index 39d2f22..b2f6ca1 100644 --- a/api/operation.py +++ b/api/operation.py @@ -38,6 +38,10 @@ class ChangeSet: self.operations += cs.operations return self + def dump(self): + for op in self.operations: + print(op) + def compress(self): return self From 1c63ee0d49974e81ef990864bc371b0337730189 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 20:29:20 +0800 Subject: [PATCH 07/10] Guard coding for ";" line --- api/s15_energy.py | 3 +++ api/s19_reactions.py | 3 +++ api/s21_times.py | 3 +++ api/s23_options.py | 3 +++ api/s25_vertices.py | 3 +++ 5 files changed, 15 insertions(+) diff --git a/api/s15_energy.py b/api/s15_energy.py index 70d50df..aad2fd6 100644 --- a/api/s15_energy.py +++ b/api/s15_energy.py @@ -135,6 +135,9 @@ def inp_in_energy(section: list[str]) -> ChangeSet: cs = ChangeSet() for s in section: + if s.startswith(';'): + continue + tokens = s.strip().split() if tokens[0].upper() == 'PUMP': diff --git a/api/s19_reactions.py b/api/s19_reactions.py index 7ef4b1c..5f2be70 100644 --- a/api/s19_reactions.py +++ b/api/s19_reactions.py @@ -185,6 +185,9 @@ def inp_in_reaction(section: list[str]) -> ChangeSet: cs = ChangeSet() for s in section: + if s.startswith(';'): + continue + tokens = s.strip().split() token0 = tokens[0].upper() if token0 == 'BULK' or token0 == 'WALL': diff --git a/api/s21_times.py b/api/s21_times.py index 848ba9c..11cc6fc 100644 --- a/api/s21_times.py +++ b/api/s21_times.py @@ -70,6 +70,9 @@ def set_time(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_time(section: list[str]) -> ChangeSet: cs = g_update_prefix | { 'type' : 'time' } for s in section: + if s.startswith(';'): + continue + line = s.upper().strip() for key in get_time_schema('').keys(): if line.startswith(key): diff --git a/api/s23_options.py b/api/s23_options.py index 5d77569..329e419 100644 --- a/api/s23_options.py +++ b/api/s23_options.py @@ -108,6 +108,9 @@ def set_option(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_option(section: list[str]) -> ChangeSet: cs = g_update_prefix | { 'type' : 'option' } for s in section: + if s.startswith(';'): + continue + line = s.upper().strip() for key in get_option_schema('').keys(): if line.startswith(key): diff --git a/api/s25_vertices.py b/api/s25_vertices.py index d6a73e8..dac67e5 100644 --- a/api/s25_vertices.py +++ b/api/s25_vertices.py @@ -84,6 +84,9 @@ def inp_in_vertex(section: list[str]) -> ChangeSet: vertices: dict[str, list[dict[str, float]]] = {} for s in section: + if s.startswith(';'): + continue + tokens = s.split() if tokens[0] not in vertices: vertices[tokens[0]] = [] From 466903c90059297ba42b2e29b76825ab42ead8e8 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 20:46:45 +0800 Subject: [PATCH 08/10] Fix typo --- api/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/command.py b/api/command.py index 7c3dc27..71bcd4a 100644 --- a/api/command.py +++ b/api/command.py @@ -38,7 +38,7 @@ _s7_valve = 'valve' _s8_tag = 'tag' _s9_demand = 'demand' _s10_status = 'status' -_s11_pattern = 'patten' +_s11_pattern = 'pattern' _s12_curve = 'curve' _s13_control = 'control' _s14_rule = 'rule' From 1ee4a83d4cfa7e44eaa0577f3e6d8604eb7a4e3f Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 21:07:06 +0800 Subject: [PATCH 09/10] Upper key word --- api/s12_curves.py | 2 +- api/s18_sources.py | 2 +- api/s20_mixing.py | 2 +- api/s4_tanks.py | 2 +- api/s5_pipes.py | 2 +- api/s7_valves.py | 2 +- api/s8_tags.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/s12_curves.py b/api/s12_curves.py index 98c1d29..117278f 100644 --- a/api/s12_curves.py +++ b/api/s12_curves.py @@ -135,7 +135,7 @@ def inp_in_curve(section: list[str]) -> ChangeSet: next = i + 1 if next < count and section[next].startswith(';') == False: next_tokens = section[next].split() - types[next_tokens[0]] = type_plus_desc_tokens[0].strip() + types[next_tokens[0]] = type_plus_desc_tokens[0].strip().upper() if len(type_plus_desc_tokens) > 1: descs[next_tokens[0]] = type_plus_desc_tokens[1].strip() continue diff --git a/api/s18_sources.py b/api/s18_sources.py index 07839eb..43a82ce 100644 --- a/api/s18_sources.py +++ b/api/s18_sources.py @@ -109,7 +109,7 @@ class InpSource: num_without_desc = (num - 1) if has_desc else num self.node = str(tokens[0]) - self.s_type = str(tokens[1]) + self.s_type = str(tokens[1].upper()) self.strength = float(tokens[2]) self.pattern = str(tokens[3]) if num_without_desc >= 4 else None diff --git a/api/s20_mixing.py b/api/s20_mixing.py index 48986e1..6432571 100644 --- a/api/s20_mixing.py +++ b/api/s20_mixing.py @@ -105,7 +105,7 @@ class InpMixing: num_without_desc = (num - 1) if has_desc else num self.tank = str(tokens[0]) - self.model = str(tokens[1]) + self.model = str(tokens[1].upper()) self.value = float(tokens[3]) if num_without_desc >= 4 else None diff --git a/api/s4_tanks.py b/api/s4_tanks.py index 826aaf2..6662034 100644 --- a/api/s4_tanks.py +++ b/api/s4_tanks.py @@ -160,7 +160,7 @@ class InpTank: self.diameter = float(tokens[5]) self.min_vol = float(tokens[6]) self.vol_curve = str(tokens[7]) if num_without_desc >= 8 else None - self.overflow = str(tokens[8]) if num_without_desc >= 9 else None + self.overflow = str(tokens[8].upper()) if num_without_desc >= 9 else None self.desc = str(tokens[-1]) if has_desc else None diff --git a/api/s5_pipes.py b/api/s5_pipes.py index 32e6015..9e4bcf3 100644 --- a/api/s5_pipes.py +++ b/api/s5_pipes.py @@ -139,7 +139,7 @@ class InpPipe: self.roughness = float(tokens[5]) self.minor_loss = float(tokens[6]) # status is must-have, here fix input - self.status = str(tokens[7]) if num_without_desc >= 8 else PIPE_STATUS_OPEN + self.status = str(tokens[7].upper()) if num_without_desc >= 8 else PIPE_STATUS_OPEN self.desc = str(tokens[-1]) if has_desc else None diff --git a/api/s7_valves.py b/api/s7_valves.py index 42ffd92..659a7e4 100644 --- a/api/s7_valves.py +++ b/api/s7_valves.py @@ -134,7 +134,7 @@ class InpValve: self.node1 = str(tokens[1]) self.node2 = str(tokens[2]) self.diameter = float(tokens[3]) - self.v_type = str(tokens[4]) + self.v_type = str(tokens[4].upper()) self.setting = float(tokens[5]) self.minor_loss = float(tokens[6]) self.desc = str(tokens[-1]) if has_desc else None diff --git a/api/s8_tags.py b/api/s8_tags.py index 5d47fb3..a191eca 100644 --- a/api/s8_tags.py +++ b/api/s8_tags.py @@ -87,7 +87,7 @@ class InpTag: has_desc = tokens[-1].startswith(';') num_without_desc = (num - 1) if has_desc else num - self.t_type = str(tokens[0]) + self.t_type = str(tokens[0].upper()) self.id = str(tokens[1]) self.tag = str(tokens[2]) From 1e2f19e3c8f5d57150dffa5bd53f8a7f6d25f20d Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 18 Nov 2022 21:10:01 +0800 Subject: [PATCH 10/10] Finish inp reader --- api/api_parser.py | 395 ++++++++++++++++------------------------------ 1 file changed, 132 insertions(+), 263 deletions(-) diff --git a/api/api_parser.py b/api/api_parser.py index e8bcb91..edd4afb 100644 --- a/api/api_parser.py +++ b/api/api_parser.py @@ -28,17 +28,16 @@ from .s25_vertices import * from .s26_labels import * from .s27_backdrop import * from .s28_end import * +from .command import * - +section_name = ['TITLE', 'JUNCTIONS', 'RESERVOIRS', 'TANKS', 'PIPES', + 'PUMPS', 'VALVES', 'TAGS', 'DEMANDS', 'STATUS', + 'PATTERNS', 'CURVES', 'CONTROLS', 'RULES', 'ENERGY', + 'EMITTERS', 'QUALITY', 'SOURCES', 'REACTIONS', 'MIXING', + 'TIMES', 'REPORT', 'OPTIONS', 'COORDINATES', 'VERTICES', + 'LABELS', 'BACKDROP', 'END'] def parse_inp(inp: str) -> dict[str, list[str]]: - section_name = ['TITLE', 'JUNCTIONS', 'RESERVOIRS', 'TANKS', 'PIPES', - 'PUMPS', 'VALVES', 'TAGS', 'DEMANDS', 'STATUS', - 'PATTERNS', 'CURVES', 'CONTROLS', 'RULES', 'ENERGY', - 'EMITTERS', 'QUALITY', 'SOURCES', 'REACTIONS', 'MIXING', - 'TIMES', 'REPORT', 'OPTIONS', 'COORDINATES', 'VERTICES', - 'LABELS', 'BACKDROP', 'END'] - file: dict[str, list[str]] = {} for s in section_name: file[s] = [] @@ -48,7 +47,11 @@ def parse_inp(inp: str) -> dict[str, list[str]]: for line in open(inp): line = line.strip() if line == '': - section = '' + # skip empty line for control and rule + if section == 'CONTROLS' or section == 'RULES': + pass + else: + section = '' continue if line.startswith('['): @@ -67,259 +70,125 @@ def parse_inp(inp: str) -> dict[str, list[str]]: return file +def read_inp(project: str, inp: str): + file = parse_inp(inp) + + file_cs: dict[str, ChangeSet] = {} + for s in section_name: + file_cs[s] = ChangeSet() + + for name, section in file.items(): + if name == 'TITLE': + file_cs[name].merge(inp_in_title(section)) + + elif name == 'JUNCTIONS': # + coords + file_cs[name].merge(inp_in_junction(section)) + + elif name == 'RESERVOIRS': # + coords + file_cs[name].merge(inp_in_reservoir(section)) + + elif name == 'TANKS': # + coords + file_cs[name].merge(inp_in_tank(section)) + + elif name == 'PIPES': + file_cs[name].merge(inp_in_pipe(section)) + + elif name == 'PUMPS': + file_cs[name].merge(inp_in_pump(section)) + + elif name == 'VALVES': + file_cs[name].merge(inp_in_valve(section)) + + elif name == 'TAGS': + file_cs[name].merge(inp_in_tag(section)) + + elif name == 'DEMANDS': + file_cs[name].merge(inp_in_demand(section)) + + elif name == 'STATUS': + file_cs[name].merge(inp_in_status(section)) + + elif name == 'PATTERNS': + file_cs[name].merge(inp_in_pattern(section)) + + elif name == 'CURVES': + file_cs[name].merge(inp_in_curve(section)) + + elif name == 'CONTROLS': + file_cs[name].merge(inp_in_control(section)) + + elif name == 'RULES': + file_cs[name].merge(inp_in_rule(section)) + + elif name == 'ENERGY': + file_cs[name].merge(inp_in_energy(section)) + + elif name == 'EMITTERS': + file_cs[name].merge(inp_in_emitter(section)) + + elif name == 'QUALITY': + file_cs[name].merge(inp_in_quality(section)) + + elif name == 'SOURCES': + file_cs[name].merge(inp_in_source(section)) + + elif name == 'REACTIONS': + file_cs[name].merge(inp_in_reaction(section)) + + elif name == 'MIXING': + file_cs[name].merge(inp_in_mixing(section)) + + elif name == 'TIMES': + file_cs[name].merge(inp_in_time(section)) + + elif name == 'REPORT': + pass # ignore now, for simulation, always report all + + elif name == 'OPTIONS': + file_cs[name].merge(inp_in_option(section)) + + elif name == 'COORDINATES': + coords = inp_in_coord(section) + for s in ['JUNCTIONS', 'RESERVOIRS', 'TANKS']: + for node in file_cs[s].operations: + if node['id'] in coords: + coord = coords[node['id']] + node |= { 'x' : coord['x'], 'y' : coord['y'] } + else: + print(f"WARNING: [{s}] {node['id']} has no coordinate, set it at origin!") + node |= { 'x' : 0.0, 'y' : 0.0 } + + elif name == 'VERTICES': + file_cs[name].merge(inp_in_vertex(section)) + + elif name == 'LABELS': + file_cs[name].merge(inp_in_label(section)) + + elif name == 'BACKDROP': + file_cs[name].merge(inp_in_backdrop(section)) + + elif name == 'END': + pass # :) + + cs = ChangeSet() + cs.merge(file_cs['PATTERNS']) + cs.merge(file_cs['CURVES']) + for s in section_name: + if s == 'PATTERNS' or s == 'CURVES': + continue + cs.merge(file_cs[s]) + + if is_project_open(project): + close_project(project) + + if have_project(project): + delete_project(project) + + create_project(project) + open_project(project) + + execute_batch_command(project, cs) -def read_inp(name: str, inp: str): - if is_project_open(name): - close_project(name) - - if have_project(name): - delete_project(name) - - create_project(name) - open_project(name) - - section = '' - - file: dict[str, list[str]] = {} - - _1_title : str = '' - _2_junctions : dict[str, dict[str, Any]] = {} - _3_reservoirs : dict[str, dict[str, Any]] = {} - _4_tanks : dict[str, dict[str, Any]] = {} - _5_pipes : dict[str, dict[str, Any]] = {} - _6_pumps : dict[str, dict[str, Any]] = {} - _7_valves : dict[str, dict[str, Any]] = {} - _9_demands : dict[str, list[dict[str, Any]]] = {} - _10_status : dict[str, dict[str, Any]] = {} - _11_patterns : dict[str, list[float]] = {} - _12_curves : dict[str, list[dict[str, float]]] = {} - _16_emitters : dict[str, float] = {} - _21_times : dict[str, str] = {} - _22_options : dict[str, str] = {} - - for line in open(inp): - line = line.strip() - - if line.startswith(';') and not line.endswith(':'): - continue - if line.endswith(';'): - line = line.removesuffix(';') - - if line.startswith('[TITLE'): - section = 'title' - continue - if line.startswith('[JUNCTION'): - section = JUNCTION - continue - if line.startswith('[RESERVOIR'): - section = RESERVOIR - continue - if line.startswith('[TANK'): - section = TANK - continue - if line.startswith('[PIPE'): - section = PIPE - continue - if line.startswith('[PUMP'): - section = PUMP - continue - if line.startswith('[VALVE'): - section = VALVE - continue - if line.startswith('[DEMAND'): - section = 'demand' - continue - if line.startswith('[STATUS'): - section = 'status' - continue - if line.startswith('[PATTERN'): - section = PATTERN - continue - if line.startswith('[CURVE'): - section = CURVE - continue - if line.startswith('[EMITTER'): - section = 'emitter' - continue - if line.startswith('[TIME'): - section = 'time' - continue - if line.startswith('[OPTION'): - section = 'option' - continue - if line.startswith('[COORDINATE'): - section = 'coordinate' - continue - if line.startswith('['): - section = '' - continue - - tokens = [] - if section == 'time' or section == 'option': - tokens = line.upper().split() - else: - tokens = line.split() - tokens_len = len(tokens) - if tokens_len == 0: - continue - - if section == 'title': - if _1_title == '': - _1_title += '\n' - _1_title += line - continue - elif section == JUNCTION: - junction_demand = float(tokens[2]) if tokens_len >= 3 else None - junction_pattern = tokens[3] if tokens_len == 4 else None - _2_junctions[tokens[0]] = {'id': tokens[0], 'elevation': tokens[1], 'demand': junction_demand, 'pattern': junction_pattern} - continue - elif section == RESERVOIR: - reservoir_pattern = tokens[2] if tokens_len == 3 else None - _3_reservoirs[tokens[0]] = {'id': tokens[0], 'head': tokens[1], 'pattern': reservoir_pattern} - continue - elif section == TANK: - tank_vol_curve = tokens[7] if tokens_len >= 8 else None - tank_overflow = tokens[8].upper() if tokens_len == 9 else None - _4_tanks[tokens[0]] = {'id': tokens[0], 'elevation': tokens[1], 'init_level': tokens[2], 'min_level': tokens[3], 'max_level': tokens[4], 'diameter': tokens[5], 'min_vol': tokens[6], 'vol_curve': tank_vol_curve, 'overflow': tank_overflow} - continue - elif section == PIPE: - # status is must-have, here fix input - pipe_status = tokens[7].upper() if tokens_len == 8 else PIPE_STATUS_OPEN - _5_pipes[tokens[0]] = {'id': tokens[0], 'node1': tokens[1], 'node2': tokens[2], 'length': tokens[3], 'diameter': tokens[4], 'roughness': tokens[5], 'minor_loss': tokens[6], 'status': pipe_status} - continue - elif section == PUMP: - _6_pumps[tokens[0]] = {'id': tokens[0], 'node1': tokens[1], 'node2': tokens[2]} - for i in range(3, tokens_len, 2): - _6_pumps[tokens[0]] |= { tokens[i].lower(): tokens[i + 1] } - continue - elif section == VALVE: - _7_valves[tokens[0]] = {'id': tokens[0], 'node1': tokens[1], 'node2': tokens[2], 'diameter': tokens[3], 'v_type': tokens[4], 'setting': tokens[5], 'minor_loss': tokens[6]} - continue - elif section == 'demand': - demand_pattern = tokens[2] if tokens_len >= 3 else None - demand_category = tokens[3] if tokens_len == 4 else None - _9_demands[tokens[0]].append({'demand': tokens[1], 'pattern': demand_pattern, 'category': demand_category}) - continue - elif section == 'status': - if tokens[0] not in _10_status: - _10_status[tokens[0]] = {} - setting = None - try: - setting = float(tokens[1]) - except: - setting = None - if setting != None: - _10_status[tokens[0]]['setting'] = setting - else: - _10_status[tokens[0]]['status'] = tokens[1].upper() - continue - elif section == PATTERN: - if tokens[0] not in _11_patterns: - _11_patterns[tokens[0]] = [] - for i in range(1, tokens_len): - _11_patterns[tokens[0]].append(float(tokens[i])) - continue - elif section == CURVE: - if tokens[0] not in _12_curves: - _12_curves[tokens[0]] = [] - for i in range(1, tokens_len, 2): - _12_curves[tokens[0]].append({ 'x': float(tokens[i]), 'y': float(tokens[i + 1]) }) - continue - elif section == 'emitter': - _16_emitters[tokens[0]] = float(tokens[1]) - continue - elif section == 'time': - if tokens_len == 2: - _21_times[tokens[0]] = tokens[1] - elif tokens_len == 3: - _21_times[tokens[0] + ' ' + tokens[1]] = tokens[2] - elif tokens_len == 4: - _21_times[tokens[0] + ' ' + tokens[1]] = tokens[2] + ' ' + tokens[3] - continue - elif section == 'option': - if tokens[0] == 'HYDRAULICS' or tokens[0] == 'MAP': - continue - if tokens_len == 2: - _22_options[tokens[0]] = tokens[1] - elif tokens_len == 3: - if tokens[0] == 'UNBALANCED' or tokens[0] == 'QUALITY': - _22_options[tokens[0]] = tokens[1] + ' ' + tokens[2] - else: - _22_options[tokens[0] + ' ' + tokens[1]] = tokens[2] - continue - elif section == 'coordinate': - if tokens[0] in _2_junctions: - _2_junctions[tokens[0]] |= {'x': tokens[1], 'y': tokens[2]} - elif tokens[0] in _3_reservoirs: - _3_reservoirs[tokens[0]] |= {'x': tokens[1], 'y': tokens[2]} - elif tokens[0] in _4_tanks: - _4_tanks[tokens[0]] |= {'x': tokens[1], 'y': tokens[2]} - continue - - # title - set_title(name, ChangeSet({ 'value': _1_title })) - - # pattern - for key, value in _11_patterns.items(): - set_pattern(name, ChangeSet({'id': key, 'factors': value})) - - # curve - for key, value in _12_curves.items(): - set_curve(name, ChangeSet({'id': key, 'coords': value})) - - # junction - for value in _2_junctions.values(): - if 'x' not in value: - value['x'] = 0.0 - if 'y' not in value: - value['y'] = 0.0 - add_junction(name, ChangeSet(value)) - - # reservoir - for value in _3_reservoirs.values(): - if 'x' not in value: - value['x'] = 0.0 - if 'y' not in value: - value['y'] = 0.0 - add_reservoir(name, ChangeSet(value)) - - # tank - for value in _4_tanks.values(): - if 'x' not in value: - value['x'] = 0.0 - if 'y' not in value: - value['y'] = 0.0 - add_tank(name, ChangeSet(value)) - - # pipe - for value in _5_pipes.values(): - add_pipe(name, ChangeSet(value)) - - # pump - for value in _6_pumps.values(): - add_pump(name, ChangeSet(value)) - - # valve - for value in _7_valves.values(): - add_valve(name, ChangeSet(value)) - - # demand - for key, value in _9_demands.items(): - set_demand(name, ChangeSet({'junction': key, 'demands': value})) - - # status - for key, value in _10_status.items(): - set_status(name, ChangeSet({'link': key} | value)) - - # emitter - for key, value in _16_emitters.items(): - set_emitter(name, ChangeSet({'junction': key, 'coefficient': value})) - - # time - set_time(name, ChangeSet(_21_times)) - - # option - set_option(name, ChangeSet(_22_options)) - - close_project(name) +def dump_inp(name: str, inp: str): + pass