Support inp in tag, demand, status
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from .project import *
|
||||
from .database import ChangeSet, write
|
||||
from .database import ChangeSet, write, try_read
|
||||
from .sections import *
|
||||
from .s1_title import inp_in_title_new
|
||||
from .s2_junctions import inp_in_junction_new
|
||||
@@ -8,6 +8,9 @@ from .s4_tanks import inp_in_tank_new
|
||||
from .s5_pipes import inp_in_pipe_new
|
||||
from .s6_pumps import inp_in_pump_new
|
||||
from .s7_valves import inp_in_valve_new
|
||||
from .s8_tags import inp_in_tag_new
|
||||
from .s9_demands import inp_in_demand_new
|
||||
from .s10_status import inp_in_status_new
|
||||
from .s11_patterns import inp_in_pattern_new
|
||||
from .s12_curves import inp_in_curve_new
|
||||
from .s13_controls import inp_in_control_new
|
||||
@@ -28,9 +31,9 @@ _handler = {
|
||||
PIPES : (_L, inp_in_pipe_new),
|
||||
PUMPS : (_L, inp_in_pump_new),
|
||||
VALVES : (_L, inp_in_valve_new),
|
||||
TAGS : (_L, None),
|
||||
DEMANDS : (_L, None),
|
||||
STATUS : (_L, None),
|
||||
TAGS : (_L, inp_in_tag_new),
|
||||
DEMANDS : (_L, inp_in_demand_new),
|
||||
STATUS : (_L, inp_in_status_new),
|
||||
PATTERNS : (_L, inp_in_pattern_new),
|
||||
CURVES : (_L, inp_in_curve_new),
|
||||
CONTROLS : (_L, inp_in_control_new),
|
||||
@@ -128,6 +131,7 @@ def parse_file(project: str, inp: str) -> None:
|
||||
|
||||
pattern_desc_line = None
|
||||
curve_type_desc_line = None
|
||||
demand_junction = None
|
||||
|
||||
with open(inp) as f:
|
||||
for s in levels:
|
||||
@@ -146,8 +150,10 @@ def parse_file(project: str, inp: str) -> None:
|
||||
break
|
||||
|
||||
line = line.strip()
|
||||
if line == '' or line.startswith('['):
|
||||
if line.startswith('['):
|
||||
break
|
||||
elif line == '':
|
||||
continue
|
||||
|
||||
if is_s:
|
||||
sections[s].append(line)
|
||||
@@ -171,6 +177,13 @@ def parse_file(project: str, inp: str) -> None:
|
||||
tokens = line.split()
|
||||
write(project, f"insert into _curve (id, type) values ('{tokens[0]}', '{type_and_desc[0].strip()}');")
|
||||
curve_type_desc_line = None
|
||||
elif s == DEMANDS:
|
||||
tokens = line.split()
|
||||
junction = str(tokens[0])
|
||||
if demand_junction != junction:
|
||||
if try_read(project, f"select * from demands where junction = '{junction}'") != None:
|
||||
write(project, f"delete from demands where junction = '{junction}';")
|
||||
demand_junction = junction
|
||||
|
||||
if handler != None:
|
||||
handler(project, line)
|
||||
|
||||
@@ -113,6 +113,21 @@ def inp_in_status(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_status_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
|
||||
|
||||
link = str(tokens[0])
|
||||
value = tokens[1].upper()
|
||||
if value == LINK_STATUS_OPEN or value == LINK_STATUS_CLOSED or value == LINK_STATUS_ACTIVE:
|
||||
write(name, f"insert into status (link, status, setting) values ('{link}', '{value}', null);")
|
||||
else:
|
||||
write(name, f"insert into status (link, status, setting) values ('{link}', null, {float(value)});")
|
||||
|
||||
|
||||
def inp_out_status(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from status')
|
||||
|
||||
@@ -103,6 +103,23 @@ def inp_in_tag(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_tag_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
|
||||
|
||||
t_type = str(tokens[0].upper())
|
||||
id = str(tokens[1])
|
||||
tag = str(tokens[2])
|
||||
|
||||
if t_type == TAG_TYPE_NODE:
|
||||
write(name, f"insert into tags_node (id, tag) values ('{id}', '{tag}');")
|
||||
elif t_type == TAG_TYPE_LINK:
|
||||
write(name, f"insert into tags_link (id, tag) values ('{id}', '{tag}');")
|
||||
|
||||
|
||||
def inp_out_tag(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from tags_node')
|
||||
|
||||
@@ -97,6 +97,23 @@ def inp_in_demand(section: list[str]) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_demand_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
|
||||
|
||||
junction = str(tokens[0])
|
||||
demand = float(tokens[1])
|
||||
pattern = str(tokens[2]) if num_without_desc >= 3 else None
|
||||
pattern = f"'{pattern}'" if pattern != None else 'null'
|
||||
category = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
category = f"'{category}'" if category != None else 'null'
|
||||
|
||||
write(name, f"\ninsert into demands (junction, demand, pattern, category) values ('{junction}', {demand}, {pattern}, {category});")
|
||||
|
||||
|
||||
def inp_out_demand(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, f"select * from demands order by _order")
|
||||
|
||||
Reference in New Issue
Block a user