diff --git a/api/s2_junctions.py b/api/s2_junctions.py index 860da1a..d7b8489 100644 --- a/api/s2_junctions.py +++ b/api/s2_junctions.py @@ -152,6 +152,29 @@ def inp_in_junction(section: list[str]) -> ChangeSet: return cs +def inp_in_junction_new(name: str, line: str) -> None: + # skip comment + if line.startswith(';'): + return + + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + id = str(tokens[0]) + elevation = float(tokens[1]) + demand = float(tokens[2]) if num_without_desc >= 3 else None + pattern = str(tokens[3]) if num_without_desc >= 4 else None + pattern = f"'{pattern}'" if pattern != None else 'null' + desc = str(tokens[-1]) if has_desc else None + + write(name, f"insert into _node (id, type) values ('{id}', 'junction');") + write(name, f"insert into junctions (id, elevation) values ('{id}', {elevation});") + write(name, f"insert into demands (junction, demand, pattern) values ('{id}', {demand}, {pattern});") + + def inp_out_junction(name: str) -> list[str]: lines = [] objs = read_all(name, 'select * from junctions') diff --git a/api/s3_reservoirs.py b/api/s3_reservoirs.py index 3a9760a..53e988d 100644 --- a/api/s3_reservoirs.py +++ b/api/s3_reservoirs.py @@ -145,6 +145,27 @@ def inp_in_reservoir(section: list[str]) -> ChangeSet: return cs +def inp_in_reservoir_new(name: str, line: str) -> None: + # skip comment + if line.startswith(';'): + return + + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + id = str(tokens[0]) + head = float(tokens[1]) + pattern = str(tokens[2]) if num_without_desc >= 3 else None + pattern = f"'{pattern}'" if pattern != None else 'null' + desc = str(tokens[-1]) if has_desc else None + + write(name, f"insert into _node (id, type) values ('{id}', 'reservoir');") + write(name, f"\ninsert into reservoirs (id, head, pattern) values ('{id}', {head}, {pattern});") + + def inp_out_reservoir(name: str) -> list[str]: lines = [] objs = read_all(name, 'select * from reservoirs') diff --git a/api/s4_tanks.py b/api/s4_tanks.py index ad92d8f..766c336 100644 --- a/api/s4_tanks.py +++ b/api/s4_tanks.py @@ -187,6 +187,33 @@ def inp_in_tank(section: list[str]) -> ChangeSet: return cs +def inp_in_tank_new(name: str, line: str) -> None: + # skip comment + if line.startswith(';'): + return + + tokens = line.split() + + num = len(tokens) + has_desc = tokens[-1].startswith(';') + num_without_desc = (num - 1) if has_desc else num + + id = str(tokens[0]) + elevation = float(tokens[1]) + init_level = float(tokens[2]) + min_level = float(tokens[3]) + max_level = float(tokens[4]) + diameter = float(tokens[5]) + min_vol = float(tokens[6]) if num_without_desc >= 7 else 0.0 + vol_curve = str(tokens[7]) if num_without_desc >= 8 and tokens[7] != '*' else None + vol_curve = f"'{vol_curve}'" if vol_curve != None else 'null' + overflow = str(tokens[8].upper()) if num_without_desc >= 9 else None + overflow = f"'{overflow}'" if overflow != None else 'null' + desc = str(tokens[-1]) if has_desc else None + + write(name, f"insert into _node (id, type) values ('{id}', 'tank');") + write(name, f"insert into tanks (id, elevation, init_level, min_level, max_level, diameter, min_vol, vol_curve, overflow) values ('{id}', {elevation}, {init_level}, {min_level}, {max_level}, {diameter}, {min_vol}, {vol_curve}, {overflow});") + def inp_out_tank(name: str) -> list[str]: lines = [] objs = read_all(name, 'select * from tanks')