diff --git a/api/s11_patterns.py b/api/s11_patterns.py index f354537..5393299 100644 --- a/api/s11_patterns.py +++ b/api/s11_patterns.py @@ -126,6 +126,28 @@ def inp_in_pattern(section: list[str]) -> ChangeSet: return cs +def inp_in_pattern_new(name: str, section: list[str]) -> None: + descs = {} + patterns: list[str] = [] + + count = len(section) + for i in range(0, count): + if section[i].startswith(';'): + # this is description + next = i + 1 + if next < count and section[next].startswith(';') == False: + next_tokens = section[next].split() + descs[next_tokens[0]] = section[i].removeprefix(';') + continue + + tokens = section[i].split() + if tokens[0] not in patterns: + patterns.append(tokens[0]) + write(name, f"insert into _pattern (id) values ('{tokens[0]}');") + for token in tokens[1:]: + write(name, f"insert into patterns (id, factor) values ('{tokens[0]}', {float(token)});") + + def inp_out_pattern(name: str) -> list[str]: lines = [] objs = read_all(name, f"select * from patterns order by _order") diff --git a/api/s12_curves.py b/api/s12_curves.py index 89235cd..1b30709 100644 --- a/api/s12_curves.py +++ b/api/s12_curves.py @@ -159,6 +159,32 @@ def inp_in_curve(section: list[str]) -> ChangeSet: return cs +def inp_in_curve_new(name: str, section: list[str]) -> None: + types = {} + descs = {} + curves: list[str] = [] + + count = len(section) + for i in range(0, count): + if section[i].startswith(';'): + # ;type: desc + type_plus_desc = section[i].removeprefix(';') + type_plus_desc_tokens = type_plus_desc.split(':') + 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().upper() + if len(type_plus_desc_tokens) > 1: + descs[next_tokens[0]] = type_plus_desc_tokens[1].strip() + continue + + tokens = section[i].split() + if tokens[0] not in curves: + curves.append(tokens[0]) + write(name, f"insert into _curve (id, type) values ('{tokens[0]}', '{types[tokens[0]]}');") + write(name, f"insert into curves (id, x, y) values ('{tokens[0]}', {float(tokens[1])}, {float(tokens[2])});") + + def inp_out_curve(name: str) -> list[str]: lines = [] types = read_all(name, f"select * from _curve") diff --git a/api/s13_controls.py b/api/s13_controls.py index 95832a3..c51c8e4 100644 --- a/api/s13_controls.py +++ b/api/s13_controls.py @@ -48,5 +48,10 @@ def inp_in_control(section: list[str]) -> ChangeSet: return ChangeSet() +def inp_in_control_new(name: str, section: list[str]) -> None: + for line in section: + write(name, f"\ninsert into controls (line) values ('{line}');") + + def inp_out_control(name: str) -> list[str]: return get_control(name)['controls'] diff --git a/api/s14_rules.py b/api/s14_rules.py index 714c78c..039ea01 100644 --- a/api/s14_rules.py +++ b/api/s14_rules.py @@ -44,5 +44,10 @@ def inp_in_rule(section: list[str]) -> ChangeSet: return ChangeSet() +def inp_in_rule_new(name: str, section: list[str]) -> None: + for line in section: + write(name, f"\ninsert into rules (line) values ('{line}');") + + def inp_out_rule(name: str) -> list[str]: return get_rule(name)['rules'] \ No newline at end of file diff --git a/api/s1_title.py b/api/s1_title.py index c650cc9..7dde6c3 100644 --- a/api/s1_title.py +++ b/api/s1_title.py @@ -40,6 +40,15 @@ def inp_in_title(section: list[str]) -> ChangeSet: return ChangeSet(g_update_prefix | {'type': 'title', 'value' : obj.value}) +def inp_in_title_new(name: str, section: list[str]) -> None: + if section == []: + return + + title = '\n'.join(section) + sql = f"update title set value = '{title}';" + write(name, sql) + + def inp_out_title(name: str) -> list[str]: obj = str(get_title(name)['value']) return obj.split('\n') diff --git a/api/s21_times.py b/api/s21_times.py index 4e74263..34372ed 100644 --- a/api/s21_times.py +++ b/api/s21_times.py @@ -97,6 +97,18 @@ def inp_in_time(section: list[str]) -> ChangeSet: return ChangeSet() +def inp_in_time_new(name: str, section: list[str]) -> None: + for s in section: + if s.startswith(';'): + continue + + line = s.upper().strip() + for key in get_time_schema('').keys(): + if line.startswith(key): + value = line.removeprefix(key).strip() + write(name, f"update times set value = '{value}' where key = '{key}';") + + def inp_out_time(name: str) -> list[str]: lines = [] objs = read_all(name, f"select * from times") diff --git a/api/s22_report.py b/api/s22_report.py index f396142..73aa7e0 100644 --- a/api/s22_report.py +++ b/api/s22_report.py @@ -22,6 +22,10 @@ def inp_in_report(section: list[str]) -> ChangeSet: return ChangeSet() +def inp_in_report_new(name: str, section: list[str]) -> None: + return + + def inp_out_report(name: str) -> list[str]: lines = [] objs = read_all(name, f"select * from report") diff --git a/api/s23_options.py b/api/s23_options.py index 01ec503..cb1fc5a 100644 --- a/api/s23_options.py +++ b/api/s23_options.py @@ -40,6 +40,18 @@ def inp_in_option(section: list[str]) -> ChangeSet: return result +def inp_in_option_new(name: str, section: list[str]) -> None: + result = inp_in_option(section) + for op in result.operations: + for key in op.keys(): + if key == 'operation' or key == 'type': + continue + if op['type'] == 'option': + write(name, f"update options set value = '{op[key]}' where key = '{key}';") + else: + write(name, f"update options_v3 set value = '{op[key]}' where key = '{key}';") + + def inp_out_option(name: str) -> list[str]: lines = [] objs = read_all(name, f"select * from options") diff --git a/api/s23_options_v3.py b/api/s23_options_v3.py index 65e2691..b31ff4c 100644 --- a/api/s23_options_v3.py +++ b/api/s23_options_v3.py @@ -44,7 +44,11 @@ def inp_in_option_v3(section: list[str]) -> ChangeSet: tokens = s.strip().split() key = tokens[0] if key in get_option_v3_schema('').keys(): - value = tokens[1] if len(tokens) >= 2 else '' + value = '' + if len(tokens) == 2: + value = tokens[1] + elif len(tokens) > 2: + value = ' '.join(tokens[1:]) cs_v3 |= { key : value } else: v2_lines.append(s.strip()) @@ -58,6 +62,18 @@ def inp_in_option_v3(section: list[str]) -> ChangeSet: return result +def inp_in_option_v3_new(name: str, section: list[str]) -> None: + result = inp_in_option_v3(section) + for op in result.operations: + for key in op.keys(): + if key == 'operation' or key == 'type': + continue + if op['type'] == 'option_v3': + write(name, f"update options_v3 set value = '{op[key]}' where key = '{key}';") + else: + write(name, f"update options set value = '{op[key]}' where key = '{key}';") + + def inp_out_option_v3(name: str) -> list[str]: lines = [] objs = read_all(name, f"select * from options_v3") diff --git a/api/s27_backdrop.py b/api/s27_backdrop.py index 030eb81..964e2d5 100644 --- a/api/s27_backdrop.py +++ b/api/s27_backdrop.py @@ -38,6 +38,15 @@ def inp_in_backdrop(section: list[str]) -> ChangeSet: return ChangeSet() +def inp_in_backdrop_new(name: str, section: list[str]) -> None: + if section == []: + return + + content = '\n'.join(section) + sql = f"update backdrop set content = '{content}';" + write(name, sql) + + def inp_out_backdrop(name: str) -> list[str]: obj = str(get_backdrop(name)['content']) return obj.split('\n') \ No newline at end of file diff --git a/api/sections.py b/api/sections.py index bd0c097..0a9ee75 100644 --- a/api/sections.py +++ b/api/sections.py @@ -34,9 +34,38 @@ s29_scada_device = 'scada_device' s30_scada_device_data = 'scada_device_data' s31_scada_element = 'scada_element' -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'] +TITLE = 'TITLE' +JUNCTIONS = 'JUNCTIONS' +RESERVOIRS = 'RESERVOIRS' +TANKS = 'TANKS' +PIPES = 'PIPES' +PUMPS = 'PUMPS' +VALVES = 'VALVES' +TAGS = 'TAGS' +DEMANDS = 'DEMANDS' +STATUS = 'STATUS' +PATTERNS = 'PATTERNS' +CURVES = 'CURVES' +CONTROLS = 'CONTROLS' +RULES = 'RULES' +ENERGY = 'ENERGY' +EMITTERS = 'EMITTERS' +QUALITY = 'QUALITY' +SOURCES = 'SOURCES' +REACTIONS = 'REACTIONS' +MIXING = 'MIXING' +TIMES = 'TIMES' +REPORT = 'REPORT' +OPTIONS = 'OPTIONS' +COORDINATES = 'COORDINATES' +VERTICES = 'VERTICES' +LABELS = 'LABELS' +BACKDROP = 'BACKDROP' +END = 'END' + +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]