From 1d720c5b6c05f82f754ae7ec3c6f98d0961745a1 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 16 Mar 2023 00:15:34 +0800 Subject: [PATCH] Support inp in coord, vertex, label --- api/inp_in_new.py | 14 ++++++++------ api/s24_coordinates.py | 7 +++++++ api/s25_vertices.py | 8 ++++++++ api/s26_labels.py | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/api/inp_in_new.py b/api/inp_in_new.py index d98f727..13ff7bc 100644 --- a/api/inp_in_new.py +++ b/api/inp_in_new.py @@ -24,6 +24,9 @@ from .s20_mixing import inp_in_mixing_new from .s21_times import inp_in_time_new from .s22_report import inp_in_report_new from .s23_options import inp_in_option_new +from .s24_coordinates import inp_in_coord_new +from .s25_vertices import inp_in_vertex_new +from .s26_labels import inp_in_label_new from .s27_backdrop import inp_in_backdrop_new _S = 'S' @@ -53,9 +56,9 @@ _handler = { TIMES : (_S, inp_in_time_new), REPORT : (_S, inp_in_report_new), OPTIONS : (_S, inp_in_option_new), - COORDINATES : (_L, None), - VERTICES : (_L, None), - LABELS : (_L, None), + COORDINATES : (_L, inp_in_coord_new), + VERTICES : (_L, inp_in_vertex_new), + LABELS : (_L, inp_in_label_new), BACKDROP : (_S, inp_in_backdrop_new), #END : 'END', } @@ -188,13 +191,12 @@ def parse_file(project: str, inp: str) -> None: write(project, f"delete from demands where junction = '{junction}';") demand_junction = junction - if handler != None: - handler(project, line) + handler(project, line) f.seek(0) - if is_s and handler != None: + if is_s: handler(project, sections[s]) diff --git a/api/s24_coordinates.py b/api/s24_coordinates.py index aa30517..d802a2b 100644 --- a/api/s24_coordinates.py +++ b/api/s24_coordinates.py @@ -27,6 +27,13 @@ def inp_in_coord(section: list[str]) -> dict[str, dict[str, float]]: return coords +def inp_in_coord_new(name: str, line: str) -> None: + tokens = line.split() + node = tokens[0] + coord = f"'({tokens[1]}, {tokens[2]})'" + write(name, f"insert into coordinates (node, coord) values ('{node}', {coord});") + + def inp_out_coord(name: str) -> list[str]: lines = [] objs = read_all(name, 'select * from coordinates') diff --git a/api/s25_vertices.py b/api/s25_vertices.py index 932de52..2301817 100644 --- a/api/s25_vertices.py +++ b/api/s25_vertices.py @@ -98,6 +98,14 @@ def inp_in_vertex(section: list[str]) -> ChangeSet: return cs +def inp_in_vertex_new(name: str, line: str) -> None: + tokens = line.split() + link = tokens[0] + x = float(tokens[1]) + y = float(tokens[2]) + write(name, f"insert into vertices (link, x, y) values ('{link}', {x}, {y});") + + def inp_out_vertex(name: str) -> list[str]: lines = [] objs = read_all(name, f"select * from vertices order by _order") diff --git a/api/s26_labels.py b/api/s26_labels.py index 172f352..6e5f48c 100644 --- a/api/s26_labels.py +++ b/api/s26_labels.py @@ -124,6 +124,22 @@ def inp_in_label(section: list[str]) -> ChangeSet: return cs +def inp_in_label_new(name: str, line: str) -> None: + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + x = float(tokens[0]) + y = float(tokens[1]) + label = str(tokens[2]) + node = str(tokens[3]) if num >= 4 else None + node = f"'{node}'" if node != None else 'null' + + write(name, f"insert into labels (x, y, label, node) values ({x}, {y}, '{label}', {node});") + + def inp_out_label(name: str) -> list[str]: lines = [] objs = read_all(name, 'select * from labels')