Second pass scan

This commit is contained in:
WQY\qiong
2023-03-09 23:24:41 +08:00
parent 55febbe163
commit e41abe362f
3 changed files with 71 additions and 0 deletions

View File

@@ -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')

View File

@@ -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')

View File

@@ -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')