From d190f790bbcfc19fef05599f28e9147d73b5d1e2 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:11:20 +0800 Subject: [PATCH 01/14] Parse [ENERGY], only support inp out --- api/s15_energy.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/api/s15_energy.py b/api/s15_energy.py index 4884984..e9ef691 100644 --- a/api/s15_energy.py +++ b/api/s15_energy.py @@ -57,15 +57,15 @@ def set_energy(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_energy_cache(name, cs)) -def inp_in_energy(section: list[str]) -> ChangeSet: - cs = g_update_prefix | { 'type' : 'energy' } - for s in section: - line = s.upper().strip() - for key in get_energy_schema('').keys(): - if line.startswith(key): - value = line.removeprefix(key).strip() - cs |= { key : value } - return ChangeSet(cs) +# def inp_in_energy(section: list[str]) -> ChangeSet: +# cs = g_update_prefix | { 'type' : 'energy' } +# for s in section: +# line = s.upper().strip() +# for key in get_energy_schema('').keys(): +# if line.startswith(key): +# value = line.removeprefix(key).strip() +# cs |= { key : value } +# return ChangeSet(cs) def inp_out_energy(name: str) -> list[str]: From 3c9192b8d906e27a08f022e7a6ee08ec2efe48c0 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:21:17 +0800 Subject: [PATCH 02/14] Parse [EMITTERS] --- api/s16_emitters.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/api/s16_emitters.py b/api/s16_emitters.py index 42b2df1..ae3040f 100644 --- a/api/s16_emitters.py +++ b/api/s16_emitters.py @@ -57,3 +57,36 @@ def set_emitter_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_emitter(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_emitter_cache(name, cs)) + + +class InpEmitter: + def __init__(self, line: str) -> None: + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + self.junction = str(tokens[0]) + self.coefficient = float(tokens[1]) + + +def inp_in_emitter(section: list[str]) -> ChangeSet: + cs = ChangeSet() + for s in section: + # skip comment + if s.startswith(';'): + continue + obj = InpEmitter(s) + cs.append({'operation': API_UPDATE, 'type': 'emitter', 'junction': obj.junction, 'coefficient': obj.coefficient}) + return cs + + +def inp_out_emitter(name: str) -> list[str]: + lines = [] + objs = read_all(name, 'select * from emitters') + for obj in objs: + junction = obj['junction'] + coefficient = obj['coefficient'] + lines.append(f'{junction} {coefficient}') + return lines From 2002b1f24698d91f0c6fc2b0550cd0043fbc2db2 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:24:00 +0800 Subject: [PATCH 03/14] Parse [QUALITY] --- api/s17_quality.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/api/s17_quality.py b/api/s17_quality.py index acb18cd..b1063b7 100644 --- a/api/s17_quality.py +++ b/api/s17_quality.py @@ -57,3 +57,36 @@ def set_quality_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_quality(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_quality_cache(name, cs)) + + +class InpQuality: + def __init__(self, line: str) -> None: + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + self.node = str(tokens[0]) + self.quality = float(tokens[1]) + + +def inp_in_quality(section: list[str]) -> ChangeSet: + cs = ChangeSet() + for s in section: + # skip comment + if s.startswith(';'): + continue + obj = InpQuality(s) + cs.append({'operation': API_UPDATE, 'type': 'quality', 'node': obj.node, 'quality': obj.quality}) + return cs + + +def inp_out_quality(name: str) -> list[str]: + lines = [] + objs = read_all(name, 'select * from quality') + for obj in objs: + node = obj['node'] + quality = obj['quality'] + lines.append(f'{node} {quality}') + return lines From 2f8f7c49180ad21e02ff8b91a0398c0abfb43e63 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:36:41 +0800 Subject: [PATCH 04/14] Parse [SOURCES] --- api/s18_sources.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/api/s18_sources.py b/api/s18_sources.py index 2d489c0..d06a73a 100644 --- a/api/s18_sources.py +++ b/api/s18_sources.py @@ -98,3 +98,40 @@ def delete_source_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def delete_source(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, delete_source_cache(name, cs)) + + +class InpSource: + def __init__(self, line: str) -> None: + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + self.node = str(tokens[0]) + self.s_type = float(tokens[1]) + self.strength = float(tokens[2]) + self.pattern = str(tokens[3]) if num_without_desc >= 4 else None + + +def inp_in_source(section: list[str]) -> ChangeSet: + cs = ChangeSet() + for s in section: + # skip comment + if s.startswith(';'): + continue + obj = InpSource(s) + cs.append({'operation': API_ADD, 'type': 'source', 'node': obj.node, 's_type': obj.s_type, 'strength': obj.strength, 'pattern': obj.pattern}) + return cs + + +def inp_out_source(name: str) -> list[str]: + lines = [] + objs = read_all(name, 'select * from sources') + for obj in objs: + node = obj['node'] + s_type = obj['s_type'] + strength = obj['strength'] + pattern = obj['pattern'] if obj['pattern'] != None else '' + lines.append(f'{node} {s_type} {strength} {pattern}') + return lines From 1865d111df5249e4bcb41a0c51d8b6f24f485a91 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:37:49 +0800 Subject: [PATCH 05/14] Parse [REACTIONS], only support inp out --- api/s19_reactions.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/api/s19_reactions.py b/api/s19_reactions.py index be46b66..1222cc8 100644 --- a/api/s19_reactions.py +++ b/api/s19_reactions.py @@ -60,15 +60,15 @@ def set_reaction(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_reaction_cache(name, cs)) -def inp_in_reaction(section: list[str]) -> ChangeSet: - cs = g_update_prefix | { 'type' : 'reaction' } - for s in section: - line = s.upper().strip() - for key in get_reaction_schema('').keys(): - if line.startswith(key): - value = line.removeprefix(key).strip() - cs |= { key : value } - return ChangeSet(cs) +# def inp_in_reaction(section: list[str]) -> ChangeSet: +# cs = g_update_prefix | { 'type' : 'reaction' } +# for s in section: +# line = s.upper().strip() +# for key in get_reaction_schema('').keys(): +# if line.startswith(key): +# value = line.removeprefix(key).strip() +# cs |= { key : value } +# return ChangeSet(cs) def inp_out_reaction(name: str) -> list[str]: From e4023717a5e7f50b3095a739f0c6b096903c0e96 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:42:51 +0800 Subject: [PATCH 06/14] Fix source type --- api/s18_sources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/s18_sources.py b/api/s18_sources.py index d06a73a..42985a1 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 = float(tokens[1]) + self.s_type = str(tokens[1]) self.strength = float(tokens[2]) self.pattern = str(tokens[3]) if num_without_desc >= 4 else None From 4b1943ce25ec996d916c356663113967e04e35ba Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:43:06 +0800 Subject: [PATCH 07/14] Parse [MIXING] --- api/s20_mixing.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/api/s20_mixing.py b/api/s20_mixing.py index bf3eb06..2ad4fba 100644 --- a/api/s20_mixing.py +++ b/api/s20_mixing.py @@ -94,3 +94,38 @@ def delete_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def delete_mixing(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, delete_mixing_cache(name, cs)) + + +class InpMixing: + def __init__(self, line: str) -> None: + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + self.tank = str(tokens[0]) + self.model = str(tokens[1]) + self.value = float(tokens[3]) if num_without_desc >= 4 else None + + +def inp_in_mixing(section: list[str]) -> ChangeSet: + cs = ChangeSet() + for s in section: + # skip comment + if s.startswith(';'): + continue + obj = InpMixing(s) + cs.append({'operation': API_ADD, 'type': 'mixing', 'tank': obj.tank, 'model': obj.model, 'value': obj.value}) + return cs + + +def inp_out_mixing(name: str) -> list[str]: + lines = [] + objs = read_all(name, 'select * from mixing') + for obj in objs: + tank = obj['tank'] + model = obj['model'] + value = obj['value'] if obj['value'] != None else '' + lines.append(f'{tank} {model} {value}') + return lines From 7f691de6e78fd382bd5a14a803899b6338a73d55 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Mon, 14 Nov 2022 21:44:24 +0800 Subject: [PATCH 08/14] Fix coord typo --- api/s24_coordinates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/s24_coordinates.py b/api/s24_coordinates.py index e28b48f..409e693 100644 --- a/api/s24_coordinates.py +++ b/api/s24_coordinates.py @@ -22,7 +22,7 @@ def inp_in_coord(section: list[str]) -> dict[str, dict[str, float]]: return coords -def inp_out_junction(name: str) -> list[str]: +def inp_out_coord(name: str) -> list[str]: lines = [] objs = read_all(name, 'select * from coordinates') for obj in objs: From 4837d4ee45626c6968b64063ae342a44c103e498 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:32:40 +0800 Subject: [PATCH 09/14] Parse [ENERGY] --- api/s15_energy.py | 75 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/api/s15_energy.py b/api/s15_energy.py index e9ef691..a573416 100644 --- a/api/s15_energy.py +++ b/api/s15_energy.py @@ -57,27 +57,6 @@ def set_energy(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_energy_cache(name, cs)) -# def inp_in_energy(section: list[str]) -> ChangeSet: -# cs = g_update_prefix | { 'type' : 'energy' } -# for s in section: -# line = s.upper().strip() -# for key in get_energy_schema('').keys(): -# if line.startswith(key): -# value = line.removeprefix(key).strip() -# cs |= { key : value } -# return ChangeSet(cs) - - -def inp_out_energy(name: str) -> list[str]: - lines = [] - objs = read_all(name, f"select * from energy") - for obj in objs: - key = obj['key'] - value = obj['value'] - lines.append(f'{key} {value}') - return lines - - def get_pump_energy_schema(name: str) -> dict[str, dict[str, Any]]: return { 'pump' : {'type': 'str' , 'optional': False , 'readonly': True }, 'price' : {'type': 'float' , 'optional': True , 'readonly': False}, @@ -150,3 +129,57 @@ def set_pump_energy_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_pump_energy(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_pump_energy_cache(name, cs)) + + +def inp_in_energy(section: list[str]) -> ChangeSet: + cs = ChangeSet() + + for s in section: + tokens = s.strip().split() + + if tokens[0].upper() == 'PUMP': + pump = tokens[1] + key = tokens[2].lower() + value = tokens[3] + if key == 'price': + value = float(value) + cs.append(g_update_prefix | { 'type' : 'pump_energy', 'pump' : pump, key: value }) + + else: + line = s.upper().strip() + for key in get_energy_schema('').keys(): + if line.startswith(key): + value = line.removeprefix(key).strip() + cs.append(g_update_prefix | { 'type' : 'energy', key : value }) + + return cs + + +def inp_out_energy(name: str) -> list[str]: + lines = [] + + objs = read_all(name, f"select * from energy") + for obj in objs: + key = obj['key'] + value = obj['value'] + lines.append(f'{key} {value}') + + objs = read_all(name, f"select * from energy_pump_price") + for obj in objs: + pump = obj['pump'] + value = obj['price'] + lines.append(f'PUMP {pump} PRICE {value}') + + objs = read_all(name, f"select * from energy_pump_pattern") + for obj in objs: + pump = obj['pump'] + value = obj['pattern'] + lines.append(f'PUMP {pump} PATTERN {value}') + + objs = read_all(name, f"select * from energy_pump_effic") + for obj in objs: + pump = obj['pump'] + value = obj['effic'] + lines.append(f'PUMP {pump} EFFIC {value}') + + return lines From 6e84aef52a2454acf0d547bf95c63d273d70af8b Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:33:04 +0800 Subject: [PATCH 10/14] Parse [REACTIONS] --- api/s19_reactions.py | 78 ++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/api/s19_reactions.py b/api/s19_reactions.py index 1222cc8..7ef4b1c 100644 --- a/api/s19_reactions.py +++ b/api/s19_reactions.py @@ -60,27 +60,6 @@ def set_reaction(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_reaction_cache(name, cs)) -# def inp_in_reaction(section: list[str]) -> ChangeSet: -# cs = g_update_prefix | { 'type' : 'reaction' } -# for s in section: -# line = s.upper().strip() -# for key in get_reaction_schema('').keys(): -# if line.startswith(key): -# value = line.removeprefix(key).strip() -# cs |= { key : value } -# return ChangeSet(cs) - - -def inp_out_reaction(name: str) -> list[str]: - lines = [] - objs = read_all(name, f"select * from reactions") - for obj in objs: - key = obj['key'] - value = obj['value'] - lines.append(f'{key} {value}') - return lines - - def get_pipe_reaction_schema(name: str) -> dict[str, dict[str, Any]]: return { 'pipe' : {'type': 'str' , 'optional': False , 'readonly': True }, 'bulk' : {'type': 'float' , 'optional': True , 'readonly': False}, @@ -200,3 +179,60 @@ def set_tank_reaction_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_tank_reaction(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_tank_reaction_cache(name, cs)) + + +def inp_in_reaction(section: list[str]) -> ChangeSet: + cs = ChangeSet() + + for s in section: + tokens = s.strip().split() + token0 = tokens[0].upper() + if token0 == 'BULK' or token0 == 'WALL': + pipe = tokens[1] + key = token0.lower() + value = tokens[2] + cs.append(g_update_prefix | { 'type' : 'pipe_reaction', 'pipe' : pipe, key: value }) + + elif token0 == 'TANK': + tank = tokens[1] + value = tokens[2] + cs.append(g_update_prefix | { 'type' : 'pipe_reaction', 'tank' : tank, 'value': value }) + + else: + line = s.upper().strip() + for key in get_reaction_schema('').keys(): + if line.startswith(key): + value = line.removeprefix(key).strip() + cs.append(g_update_prefix | { 'type' : 'reaction', key : value }) + + return cs + + +def inp_out_reaction(name: str) -> list[str]: + lines = [] + + objs = read_all(name, f"select * from reactions") + for obj in objs: + key = obj['key'] + value = obj['value'] + lines.append(f'{key} {value}') + + objs = read_all(name, f"select * from reactions_pipe_bulk") + for obj in objs: + pipe = obj['pipe'] + bulk = obj['bulk'] + lines.append(f'BULK {pipe} {bulk}') + + objs = read_all(name, f"select * from reactions_pipe_wall") + for obj in objs: + pipe = obj['pipe'] + wall = obj['wall'] + lines.append(f'WALL {pipe} {wall}') + + objs = read_all(name, f"select * from reactions_tank") + for obj in objs: + tank = obj['tank'] + value = obj['value'] + lines.append(f'TANK {tank} {value}') + + return lines \ No newline at end of file From 2cd78ceaf06376c5cc9b8c810f4a9b8bc8e60c72 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:33:34 +0800 Subject: [PATCH 11/14] Parse [VERTICES] --- api/s25_vertices.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/api/s25_vertices.py b/api/s25_vertices.py index f9a5cc7..d6a73e8 100644 --- a/api/s25_vertices.py +++ b/api/s25_vertices.py @@ -78,3 +78,29 @@ def delete_vertex(name: str, cs: ChangeSet) -> ChangeSet: result.redo_cs |= g_delete_prefix result.undo_cs |= g_add_prefix return execute_command(name, result) + + +def inp_in_vertex(section: list[str]) -> ChangeSet: + vertices: dict[str, list[dict[str, float]]] = {} + + for s in section: + tokens = s.split() + if tokens[0] not in vertices: + vertices[tokens[0]] = [] + vertices[tokens[0]].append({'x': float(tokens[1]), 'y': float(tokens[2])}) + + cs = ChangeSet() + for link, coords in vertices.items(): + cs.append(g_add_prefix | {'type': 'vertex', 'link' : link, 'coords' : coords}) + return cs + + +def inp_out_vertex(name: str) -> list[str]: + lines = [] + objs = read_all(name, f"select * from vertices order by _order") + for obj in objs: + link = obj['link'] + x = obj['x'] + y = obj['y'] + lines.append(f"{link} {x} {y}") + return lines From b2d0a727d2f9393ff602492fab17c2fa53adf4df Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:33:49 +0800 Subject: [PATCH 12/14] Parse [LABELS] --- api/s26_labels.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/api/s26_labels.py b/api/s26_labels.py index af5d01d..8f3ea81 100644 --- a/api/s26_labels.py +++ b/api/s26_labels.py @@ -95,5 +95,38 @@ def delete_label_cache(name: str, cs: ChangeSet) -> SqlChangeSet: return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs) -def delete_label(name: str, cs: ChangeSet) -> ChangeSet: - return execute_command(name, delete_label_cache(name, cs)) +class InpLabel: + def __init__(self, line: str) -> None: + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + self.x = float(tokens[0]) + self.y = float(tokens[1]) + self.label = str(tokens[2]) + self.node = str(tokens[3]) if num >= 4 else None + + +def inp_in_label(section: list[str]) -> ChangeSet: + cs = ChangeSet() + for s in section: + # skip comment + if s.startswith(';'): + continue + obj = InpLabel(s) + cs.append({'operation': API_ADD, 'type': 'label', 'x': obj.x, 'y': obj.y, 'label': obj.label, 'node': obj.node}) + return cs + + +def inp_out_label(name: str) -> list[str]: + lines = [] + objs = read_all(name, 'select * from labels') + for obj in objs: + x = obj['x'] + y = obj['y'] + label = obj['label'] + node = obj['node'] if obj['node'] != None else '' + lines.append(f'{x} {y} {label} {node}') + return lines From b97d7954846f466f45273a32a93ce5390a851ac5 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:34:16 +0800 Subject: [PATCH 13/14] Parse [BACKDROP] --- api/s27_backdrop.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/s27_backdrop.py b/api/s27_backdrop.py index 84d4da6..6509da4 100644 --- a/api/s27_backdrop.py +++ b/api/s27_backdrop.py @@ -24,3 +24,19 @@ def set_backdrop_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, set_backdrop_cache(name, cs)) + + +class InpBackdrop: + def __init__(self, section) -> None: + self.value = '\n'.join(section) + + +def inp_in_backdrop(section: list[str]) -> ChangeSet: + obj = InpBackdrop(section) + cs = ChangeSet(g_update_prefix | {'type': 'backdrop', 'content' : obj.value}) + return cs + + +def inp_out_backdrop(name: str) -> list[str]: + obj = str(get_backdrop(name)['content']) + return obj.split('\n') \ No newline at end of file From 7a85867483e74678a92690271c06328e2869c181 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:47:14 +0800 Subject: [PATCH 14/14] Use operation prefix --- api/s10_status.py | 2 +- api/s11_patterns.py | 2 +- api/s12_curves.py | 2 +- api/s13_controls.py | 2 +- api/s14_rules.py | 2 +- api/s16_emitters.py | 2 +- api/s17_quality.py | 2 +- api/s18_sources.py | 2 +- api/s1_title.py | 2 +- api/s20_mixing.py | 2 +- api/s26_labels.py | 2 +- api/s2_junctions.py | 2 +- api/s3_reservoirs.py | 2 +- api/s4_tanks.py | 2 +- api/s5_pipes.py | 2 +- api/s6_pumps.py | 2 +- api/s7_valves.py | 2 +- api/s8_tags.py | 2 +- api/s9_demands.py | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/s10_status.py b/api/s10_status.py index 823b232..9db45bb 100644 --- a/api/s10_status.py +++ b/api/s10_status.py @@ -99,7 +99,7 @@ def inp_in_status(section: list[str]) -> ChangeSet: cs = ChangeSet() for link, values in objs.items(): - obj_cs = {'operation': API_UPDATE, 'type': 'status', 'link' : link, 'status': None, 'setting': None} + obj_cs : dict[str, Any] = g_update_prefix | {'type': 'status', 'link' : link, 'status': None, 'setting': None} for obj in values: if obj.is_status: obj_cs['status'] = obj.status diff --git a/api/s11_patterns.py b/api/s11_patterns.py index f53e3ab..72b1f5f 100644 --- a/api/s11_patterns.py +++ b/api/s11_patterns.py @@ -115,7 +115,7 @@ def inp_in_pattern(section: list[str]) -> ChangeSet: cs = ChangeSet() for id, factors in patterns.items(): - cs.append({'operation': API_ADD, 'type': 'pattern', 'id' : id, 'factors' : factors}) + cs.append(g_add_prefix | {'type': 'pattern', 'id' : id, 'factors' : factors}) return cs diff --git a/api/s12_curves.py b/api/s12_curves.py index e429061..9bd9c2c 100644 --- a/api/s12_curves.py +++ b/api/s12_curves.py @@ -148,7 +148,7 @@ def inp_in_curve(section: list[str]) -> ChangeSet: cs = ChangeSet() for id, coords in curves.items(): c_type = types[id] if id in types else CURVE_TYPE_PUMP - cs.append({'operation': API_ADD, 'type': 'curve', 'id' : id, 'c_type': c_type, 'coords' : coords}) + cs.append(g_add_prefix | {'type': 'curve', 'id' : id, 'c_type': c_type, 'coords' : coords}) return cs diff --git a/api/s13_controls.py b/api/s13_controls.py index 6173167..c8098da 100644 --- a/api/s13_controls.py +++ b/api/s13_controls.py @@ -33,7 +33,7 @@ class InpControl: def inp_in_control(section: list[str]) -> ChangeSet: obj = InpControl(section) - cs = ChangeSet({'operation' : API_UPDATE, 'type': 'control', 'control' : obj.control}) + cs = ChangeSet(g_update_prefix | {'type': 'control', 'control' : obj.control}) return cs diff --git a/api/s14_rules.py b/api/s14_rules.py index e5d1834..4db3ae3 100644 --- a/api/s14_rules.py +++ b/api/s14_rules.py @@ -33,7 +33,7 @@ class InpRule: def inp_in_rule(section: list[str]) -> ChangeSet: obj = InpRule(section) - cs = ChangeSet({'operation' : API_UPDATE, 'type': 'rule', 'rule' : obj.rule}) + cs = ChangeSet(g_update_prefix | {'type': 'rule', 'rule' : obj.rule}) return cs diff --git a/api/s16_emitters.py b/api/s16_emitters.py index ae3040f..2b0c25d 100644 --- a/api/s16_emitters.py +++ b/api/s16_emitters.py @@ -78,7 +78,7 @@ def inp_in_emitter(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpEmitter(s) - cs.append({'operation': API_UPDATE, 'type': 'emitter', 'junction': obj.junction, 'coefficient': obj.coefficient}) + cs.append(g_update_prefix | {'type': 'emitter', 'junction': obj.junction, 'coefficient': obj.coefficient}) return cs diff --git a/api/s17_quality.py b/api/s17_quality.py index b1063b7..d373c12 100644 --- a/api/s17_quality.py +++ b/api/s17_quality.py @@ -78,7 +78,7 @@ def inp_in_quality(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpQuality(s) - cs.append({'operation': API_UPDATE, 'type': 'quality', 'node': obj.node, 'quality': obj.quality}) + cs.append(g_update_prefix | {'type': 'quality', 'node': obj.node, 'quality': obj.quality}) return cs diff --git a/api/s18_sources.py b/api/s18_sources.py index 42985a1..07839eb 100644 --- a/api/s18_sources.py +++ b/api/s18_sources.py @@ -121,7 +121,7 @@ def inp_in_source(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpSource(s) - cs.append({'operation': API_ADD, 'type': 'source', 'node': obj.node, 's_type': obj.s_type, 'strength': obj.strength, 'pattern': obj.pattern}) + cs.append(g_add_prefix | {'type': 'source', 'node': obj.node, 's_type': obj.s_type, 'strength': obj.strength, 'pattern': obj.pattern}) return cs diff --git a/api/s1_title.py b/api/s1_title.py index 4a74810..b521860 100644 --- a/api/s1_title.py +++ b/api/s1_title.py @@ -34,7 +34,7 @@ class InpTitle: def inp_in_title(section: list[str]) -> ChangeSet: obj = InpTitle(section) - cs = ChangeSet({'operation' : API_ADD, 'type': 'title', 'value' : obj.value}) + cs = ChangeSet(g_update_prefix | {'type': 'title', 'value' : obj.value}) return cs diff --git a/api/s20_mixing.py b/api/s20_mixing.py index 2ad4fba..48986e1 100644 --- a/api/s20_mixing.py +++ b/api/s20_mixing.py @@ -116,7 +116,7 @@ def inp_in_mixing(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpMixing(s) - cs.append({'operation': API_ADD, 'type': 'mixing', 'tank': obj.tank, 'model': obj.model, 'value': obj.value}) + cs.append(g_add_prefix | {'type': 'mixing', 'tank': obj.tank, 'model': obj.model, 'value': obj.value}) return cs diff --git a/api/s26_labels.py b/api/s26_labels.py index 8f3ea81..5a0b782 100644 --- a/api/s26_labels.py +++ b/api/s26_labels.py @@ -116,7 +116,7 @@ def inp_in_label(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpLabel(s) - cs.append({'operation': API_ADD, 'type': 'label', 'x': obj.x, 'y': obj.y, 'label': obj.label, 'node': obj.node}) + cs.append(g_add_prefix | {'type': 'label', 'x': obj.x, 'y': obj.y, 'label': obj.label, 'node': obj.node}) return cs diff --git a/api/s2_junctions.py b/api/s2_junctions.py index 40a5bd7..c2275fe 100644 --- a/api/s2_junctions.py +++ b/api/s2_junctions.py @@ -142,7 +142,7 @@ def inp_in_junction(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpJunction(s) - cs.append({'operation': API_ADD, 'type': 'junction', 'id': obj.id, 'elevation': obj.elevation, 'demand': obj.demand, 'pattern': obj.pattern}) + cs.append(g_add_prefix | {'type': 'junction', 'id': obj.id, 'elevation': obj.elevation, 'demand': obj.demand, 'pattern': obj.pattern}) return cs diff --git a/api/s3_reservoirs.py b/api/s3_reservoirs.py index d8422f5..01715ec 100644 --- a/api/s3_reservoirs.py +++ b/api/s3_reservoirs.py @@ -137,7 +137,7 @@ def inp_in_reservoir(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpReservoir(s) - cs.append({'operation': API_ADD, 'type': 'reservoir', 'id': obj.id, 'head': obj.head, 'pattern': obj.pattern}) + cs.append(g_add_prefix | {'type': 'reservoir', 'id': obj.id, 'head': obj.head, 'pattern': obj.pattern}) return cs diff --git a/api/s4_tanks.py b/api/s4_tanks.py index 401b1ba..826aaf2 100644 --- a/api/s4_tanks.py +++ b/api/s4_tanks.py @@ -171,7 +171,7 @@ def inp_in_tank(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpTank(s) - cs.append({'operation': API_ADD, 'type': 'tank', 'id': obj.id, 'elevation': obj.elevation, 'init_level': obj.init_level, 'min_level': obj.min_level, 'max_level': obj.max_level, 'diameter': obj.diameter, 'min_vol': obj.min_vol, 'vol_curve': obj.vol_curve, 'overflow': obj.overflow}) + cs.append(g_add_prefix | {'type': 'tank', 'id': obj.id, 'elevation': obj.elevation, 'init_level': obj.init_level, 'min_level': obj.min_level, 'max_level': obj.max_level, 'diameter': obj.diameter, 'min_vol': obj.min_vol, 'vol_curve': obj.vol_curve, 'overflow': obj.overflow}) return cs diff --git a/api/s5_pipes.py b/api/s5_pipes.py index 8b7a482..32e6015 100644 --- a/api/s5_pipes.py +++ b/api/s5_pipes.py @@ -150,7 +150,7 @@ def inp_in_pipe(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpPipe(s) - cs.append({'operation': API_ADD, 'type': 'pipe', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'length': obj.length, 'diameter': obj.diameter, 'roughness': obj.roughness, 'minor_loss': obj.minor_loss, 'status': obj.status}) + cs.append(g_add_prefix | {'type': 'pipe', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'length': obj.length, 'diameter': obj.diameter, 'roughness': obj.roughness, 'minor_loss': obj.minor_loss, 'status': obj.status}) return cs diff --git a/api/s6_pumps.py b/api/s6_pumps.py index 04781d2..5a07be8 100644 --- a/api/s6_pumps.py +++ b/api/s6_pumps.py @@ -142,7 +142,7 @@ def inp_in_pump(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpPump(s) - cs.append({'operation': API_ADD, 'type': 'pump', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'power': obj.power, 'head': obj.head, 'speed': obj.speed, 'pattern': obj.pattern}) + cs.append(g_add_prefix | {'type': 'pump', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'power': obj.power, 'head': obj.head, 'speed': obj.speed, 'pattern': obj.pattern}) return cs diff --git a/api/s7_valves.py b/api/s7_valves.py index b9cbe22..42ffd92 100644 --- a/api/s7_valves.py +++ b/api/s7_valves.py @@ -147,7 +147,7 @@ def inp_in_valve(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpValve(s) - cs.append({'operation': API_ADD, 'type': 'valve', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'diameter': obj.diameter, 'v_type': obj.v_type, 'setting': obj.setting, 'minor_loss': obj.minor_loss}) + cs.append(g_add_prefix | {'type': 'valve', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'diameter': obj.diameter, 'v_type': obj.v_type, 'setting': obj.setting, 'minor_loss': obj.minor_loss}) return cs diff --git a/api/s8_tags.py b/api/s8_tags.py index bed1862..5d47fb3 100644 --- a/api/s8_tags.py +++ b/api/s8_tags.py @@ -99,7 +99,7 @@ def inp_in_tag(section: list[str]) -> ChangeSet: if s.startswith(';'): continue obj = InpTag(s) - cs.append({'operation': API_UPDATE, 'type': 'tag', 't_type': obj.t_type, 'id': obj.id, 'tag': obj.tag}) + cs.append(g_update_prefix | {'type': 'tag', 't_type': obj.t_type, 'id': obj.id, 'tag': obj.tag}) return cs diff --git a/api/s9_demands.py b/api/s9_demands.py index 13fc0d7..83593f7 100644 --- a/api/s9_demands.py +++ b/api/s9_demands.py @@ -113,7 +113,7 @@ def inp_in_demand(section: list[str]) -> ChangeSet: cs = ChangeSet() for junction, demands in objs.items(): - obj_cs = {'operation': API_UPDATE, 'type': 'demand', 'junction' : junction, 'demands' : []} + obj_cs : dict[str, Any] = g_update_prefix | {'type': 'demand', 'junction' : junction, 'demands' : []} for obj in demands: obj_cs['demands'].append({'demand': obj.demand, 'pattern' : obj.pattern, 'category': obj.category}) cs.append(obj_cs)