Remove old inp in routine
This commit is contained in:
108
api/inp_in.py
108
api/inp_in.py
@@ -3,65 +3,65 @@ import os
|
||||
from .project import *
|
||||
from .database import ChangeSet, write
|
||||
from .sections import *
|
||||
from .s1_title import inp_in_title_new
|
||||
from .s2_junctions import inp_in_junction_new
|
||||
from .s3_reservoirs import inp_in_reservoir_new
|
||||
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 CURVE_TYPE_PUMP, inp_in_curve_new
|
||||
from .s13_controls import inp_in_control_new
|
||||
from .s14_rules import inp_in_rule_new
|
||||
from .s15_energy import inp_in_energy_new
|
||||
from .s16_emitters import inp_in_emitter_new
|
||||
from .s17_quality import inp_in_quality_new
|
||||
from .s18_sources import inp_in_source_new
|
||||
from .s19_reactions import inp_in_reaction_new
|
||||
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
|
||||
from .s1_title import inp_in_title
|
||||
from .s2_junctions import inp_in_junction
|
||||
from .s3_reservoirs import inp_in_reservoir
|
||||
from .s4_tanks import inp_in_tank
|
||||
from .s5_pipes import inp_in_pipe
|
||||
from .s6_pumps import inp_in_pump
|
||||
from .s7_valves import inp_in_valve
|
||||
from .s8_tags import inp_in_tag
|
||||
from .s9_demands import inp_in_demand
|
||||
from .s10_status import inp_in_status
|
||||
from .s11_patterns import inp_in_pattern
|
||||
from .s12_curves import CURVE_TYPE_PUMP, inp_in_curve
|
||||
from .s13_controls import inp_in_control
|
||||
from .s14_rules import inp_in_rule
|
||||
from .s15_energy import inp_in_energy
|
||||
from .s16_emitters import inp_in_emitter
|
||||
from .s17_quality import inp_in_quality
|
||||
from .s18_sources import inp_in_source
|
||||
from .s19_reactions import inp_in_reaction
|
||||
from .s20_mixing import inp_in_mixing
|
||||
from .s21_times import inp_in_time
|
||||
from .s22_report import inp_in_report
|
||||
from .s23_options import inp_in_option
|
||||
from .s24_coordinates import inp_in_coord
|
||||
from .s25_vertices import inp_in_vertex
|
||||
from .s26_labels import inp_in_label
|
||||
from .s27_backdrop import inp_in_backdrop
|
||||
|
||||
_S = 'S'
|
||||
_L = 'L'
|
||||
|
||||
_handler = {
|
||||
TITLE : (_S, inp_in_title_new),
|
||||
JUNCTIONS : (_L, inp_in_junction_new),
|
||||
RESERVOIRS : (_L, inp_in_reservoir_new),
|
||||
TANKS : (_L, inp_in_tank_new),
|
||||
PIPES : (_L, inp_in_pipe_new),
|
||||
PUMPS : (_L, inp_in_pump_new),
|
||||
VALVES : (_L, inp_in_valve_new),
|
||||
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),
|
||||
RULES : (_L, inp_in_rule_new),
|
||||
ENERGY : (_L, inp_in_energy_new),
|
||||
EMITTERS : (_L, inp_in_emitter_new),
|
||||
QUALITY : (_L, inp_in_quality_new),
|
||||
SOURCES : (_L, inp_in_source_new),
|
||||
REACTIONS : (_L, inp_in_reaction_new),
|
||||
MIXING : (_L, inp_in_mixing_new),
|
||||
TIMES : (_S, inp_in_time_new),
|
||||
REPORT : (_S, inp_in_report_new),
|
||||
OPTIONS : (_S, inp_in_option_new),
|
||||
COORDINATES : (_L, inp_in_coord_new),
|
||||
VERTICES : (_L, inp_in_vertex_new),
|
||||
LABELS : (_L, inp_in_label_new),
|
||||
BACKDROP : (_S, inp_in_backdrop_new),
|
||||
TITLE : (_S, inp_in_title),
|
||||
JUNCTIONS : (_L, inp_in_junction),
|
||||
RESERVOIRS : (_L, inp_in_reservoir),
|
||||
TANKS : (_L, inp_in_tank),
|
||||
PIPES : (_L, inp_in_pipe),
|
||||
PUMPS : (_L, inp_in_pump),
|
||||
VALVES : (_L, inp_in_valve),
|
||||
TAGS : (_L, inp_in_tag),
|
||||
DEMANDS : (_L, inp_in_demand),
|
||||
STATUS : (_L, inp_in_status),
|
||||
PATTERNS : (_L, inp_in_pattern),
|
||||
CURVES : (_L, inp_in_curve),
|
||||
CONTROLS : (_L, inp_in_control),
|
||||
RULES : (_L, inp_in_rule),
|
||||
ENERGY : (_L, inp_in_energy),
|
||||
EMITTERS : (_L, inp_in_emitter),
|
||||
QUALITY : (_L, inp_in_quality),
|
||||
SOURCES : (_L, inp_in_source),
|
||||
REACTIONS : (_L, inp_in_reaction),
|
||||
MIXING : (_L, inp_in_mixing),
|
||||
TIMES : (_S, inp_in_time),
|
||||
REPORT : (_S, inp_in_report),
|
||||
OPTIONS : (_S, inp_in_option),
|
||||
COORDINATES : (_L, inp_in_coord),
|
||||
VERTICES : (_L, inp_in_vertex),
|
||||
LABELS : (_L, inp_in_label),
|
||||
BACKDROP : (_S, inp_in_backdrop),
|
||||
#END : 'END',
|
||||
}
|
||||
|
||||
|
||||
@@ -72,48 +72,9 @@ def set_status(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA2][EPA3][IN][OUT]
|
||||
# link value
|
||||
#--------------------------------------------------------------
|
||||
class InpStatus:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.link = str(tokens[0])
|
||||
self.value = tokens[1].upper()
|
||||
self.is_status = True
|
||||
if self.value == LINK_STATUS_OPEN or self.value == LINK_STATUS_CLOSED or self.value == LINK_STATUS_ACTIVE:
|
||||
self.status = str(self.value)
|
||||
else:
|
||||
self.setting = float(self.value)
|
||||
self.is_status = False
|
||||
|
||||
|
||||
def inp_in_status(section: list[str]) -> ChangeSet:
|
||||
objs: dict[str, list[InpStatus]] = {}
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpStatus(s)
|
||||
if obj.link not in objs:
|
||||
objs[obj.link] = []
|
||||
objs[obj.link].append(obj)
|
||||
|
||||
cs = ChangeSet()
|
||||
for link, values in objs.items():
|
||||
obj_cs : dict[str, Any] = g_update_prefix | {'type': 'status', 'link' : link, 'status': None, 'setting': None}
|
||||
for obj in values:
|
||||
if obj.is_status:
|
||||
obj_cs['status'] = obj.status
|
||||
else:
|
||||
obj_cs['setting'] = obj.setting
|
||||
cs.append(obj_cs)
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_status_new(line: str) -> str:
|
||||
def inp_in_status(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -98,35 +98,9 @@ def delete_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# ;desc
|
||||
# id mult1 mult2 .....
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_pattern(section: list[str]) -> ChangeSet:
|
||||
descs = {}
|
||||
patterns: dict[str, list[float]] = {}
|
||||
|
||||
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[tokens[0]] = []
|
||||
for token in tokens[1:]:
|
||||
patterns[tokens[0]].append(float(token))
|
||||
|
||||
cs = ChangeSet()
|
||||
for id, factors in patterns.items():
|
||||
cs.append(g_add_prefix | {'type': 'pattern', 'id' : id, 'factors' : factors})
|
||||
|
||||
#print(descs)
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_pattern_new(line: str) -> str:
|
||||
def inp_in_pattern(line: str) -> str:
|
||||
tokens = line.split()
|
||||
sql = ''
|
||||
for token in tokens[1:]:
|
||||
|
||||
@@ -126,40 +126,9 @@ def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# ;type: desc
|
||||
# id x y
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_curve(section: list[str]) -> ChangeSet:
|
||||
types = {}
|
||||
descs = {}
|
||||
curves: dict[str, list[dict[str, float]]] = {}
|
||||
|
||||
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[tokens[0]] = []
|
||||
curves[tokens[0]].append({'x': float(tokens[1]), 'y': float(tokens[2])})
|
||||
|
||||
cs = ChangeSet()
|
||||
for id, coords in curves.items():
|
||||
c_type = types[id] if id in types else CURVE_TYPE_PUMP
|
||||
cs.append(g_add_prefix | {'type': 'curve', 'id' : id, 'c_type': c_type, 'coords' : coords})
|
||||
|
||||
#print(descs)
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_curve_new(line: str) -> str:
|
||||
def inp_in_curve(line: str) -> str:
|
||||
tokens = line.split()
|
||||
return f"insert into curves (id, x, y) values ('{tokens[0]}', {float(tokens[1])}, {float(tokens[2])});"
|
||||
|
||||
|
||||
@@ -42,13 +42,9 @@ def set_control(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# (0) (1) (2) (3) (4) (5) (6) (7)
|
||||
# todo...
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_control(section: list[str]) -> ChangeSet:
|
||||
if len(section) > 0:
|
||||
return ChangeSet(g_update_prefix | {'type': 'control', 'controls' : section})
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
def inp_in_control_new(line: str) -> str:
|
||||
def inp_in_control(line: str) -> str:
|
||||
return f"insert into controls (line) values ('{line}');"
|
||||
|
||||
|
||||
|
||||
@@ -38,13 +38,9 @@ def set_rule(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA2][EPA3]
|
||||
# TODO...
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_rule(section: list[str]) -> ChangeSet:
|
||||
if len(section) > 0:
|
||||
return ChangeSet(g_update_prefix | {'type': 'rule', 'rules' : section})
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
def inp_in_rule_new(line: str) -> str:
|
||||
def inp_in_rule(line: str) -> str:
|
||||
return f"insert into rules (line) values ('{line}');"
|
||||
|
||||
|
||||
|
||||
@@ -137,39 +137,9 @@ def set_pump_energy(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# PUMP id {PRICE/PATTERN/EFFIC} value
|
||||
# DEMAND CHARGE value
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_energy(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
for s in section:
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
|
||||
tokens = s.strip().split()
|
||||
|
||||
if tokens[0].upper() == 'PUMP':
|
||||
pump = tokens[1]
|
||||
key = tokens[2].lower()
|
||||
value = tokens[3]
|
||||
if key == 'price':
|
||||
value = float(value)
|
||||
cs.append(g_update_prefix | { 'type' : 'pump_energy', 'pump' : pump, key: value })
|
||||
|
||||
else:
|
||||
line = s.upper().strip()
|
||||
for key in get_energy_schema('').keys():
|
||||
if line.startswith(key):
|
||||
value = line.removeprefix(key).strip()
|
||||
|
||||
# exception here
|
||||
if line.startswith('GLOBAL EFFICIENCY'):
|
||||
value = line.removeprefix('GLOBAL EFFICIENCY').strip()
|
||||
|
||||
cs.append(g_update_prefix | { 'type' : 'energy', key : value })
|
||||
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_energy_new(line: str) -> str:
|
||||
def inp_in_energy(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
if tokens[0].upper() == 'PUMP':
|
||||
|
||||
@@ -66,30 +66,9 @@ def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA3][IN][OUT]
|
||||
# node Ke (exponent pattern)
|
||||
#--------------------------------------------------------------
|
||||
class InpEmitter:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.junction = str(tokens[0])
|
||||
self.coefficient = float(tokens[1])
|
||||
|
||||
|
||||
def inp_in_emitter(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpEmitter(s)
|
||||
cs.append(g_update_prefix | {'type': 'emitter', 'junction': obj.junction, 'coefficient': obj.coefficient})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_emitter_new(line: str) -> str:
|
||||
def inp_in_emitter(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -63,30 +63,9 @@ def set_quality(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA2][EPA3][IN][OUT]
|
||||
# node initqual
|
||||
#--------------------------------------------------------------
|
||||
class InpQuality:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.node = str(tokens[0])
|
||||
self.quality = float(tokens[1])
|
||||
|
||||
|
||||
def inp_in_quality(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpQuality(s)
|
||||
cs.append(g_update_prefix | {'type': 'quality', 'node': obj.node, 'quality': obj.quality})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_quality_new(line: str) -> str:
|
||||
def inp_in_quality(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -106,32 +106,9 @@ def delete_source(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA2][EPA3][IN][OUT]
|
||||
# node sourcetype quality (pattern)
|
||||
#--------------------------------------------------------------
|
||||
class InpSource:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.node = str(tokens[0])
|
||||
self.s_type = str(tokens[1].upper())
|
||||
self.strength = float(tokens[2])
|
||||
self.pattern = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
|
||||
|
||||
def inp_in_source(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpSource(s)
|
||||
cs.append(g_add_prefix | {'type': 'source', 'node': obj.node, 's_type': obj.s_type, 'strength': obj.strength, 'pattern': obj.pattern})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_source_new(line: str) -> str:
|
||||
def inp_in_source(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -192,37 +192,9 @@ def set_tank_reaction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# LIMITING POTENTIAL value
|
||||
# ROUGHNESS CORRELATION value
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_reaction(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
for s in section:
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
|
||||
tokens = s.strip().split()
|
||||
token0 = tokens[0].upper()
|
||||
if token0 == 'BULK' or token0 == 'WALL':
|
||||
pipe = tokens[1]
|
||||
key = token0.lower()
|
||||
value = tokens[2]
|
||||
cs.append(g_update_prefix | { 'type' : 'pipe_reaction', 'pipe' : pipe, key: value })
|
||||
|
||||
elif token0 == 'TANK':
|
||||
tank = tokens[1]
|
||||
value = tokens[2]
|
||||
cs.append(g_update_prefix | { 'type' : 'tank_reaction', 'tank' : tank, 'value': value })
|
||||
|
||||
else:
|
||||
line = s.upper().strip()
|
||||
for key in get_reaction_schema('').keys():
|
||||
if line.startswith(key):
|
||||
value = line.removeprefix(key).strip()
|
||||
cs.append(g_update_prefix | { 'type' : 'reaction', key : value })
|
||||
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_reaction_new(line: str) -> str:
|
||||
def inp_in_reaction(line: str) -> str:
|
||||
tokens = line.split()
|
||||
token0 = tokens[0].upper()
|
||||
if token0 == 'BULK' or token0 == 'WALL':
|
||||
|
||||
@@ -27,20 +27,7 @@ def set_title(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_title_cmd(name ,cs))
|
||||
|
||||
|
||||
class InpTitle:
|
||||
def __init__(self, section) -> None:
|
||||
self.value = '\n'.join(section)
|
||||
|
||||
|
||||
def inp_in_title(section: list[str]) -> ChangeSet:
|
||||
if section == []:
|
||||
return ChangeSet()
|
||||
|
||||
obj = InpTitle(section)
|
||||
return ChangeSet(g_update_prefix | {'type': 'title', 'value' : obj.value})
|
||||
|
||||
|
||||
def inp_in_title_new(section: list[str]) -> str:
|
||||
def inp_in_title(section: list[str]) -> str:
|
||||
if section == []:
|
||||
return ''
|
||||
|
||||
|
||||
@@ -101,31 +101,9 @@ def delete_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# TankID MixModel FractVolume
|
||||
# FractVolume if type == MIX2
|
||||
#--------------------------------------------------------------
|
||||
class InpMixing:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.tank = str(tokens[0])
|
||||
self.model = str(tokens[1].upper())
|
||||
self.value = float(tokens[3]) if num_without_desc >= 4 else None
|
||||
|
||||
|
||||
def inp_in_mixing(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpMixing(s)
|
||||
cs.append(g_add_prefix | {'type': 'mixing', 'tank': obj.tank, 'model': obj.model, 'value': obj.value})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_mixing_new(line: str) -> str:
|
||||
def inp_in_mixing(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -81,23 +81,9 @@ def set_time(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# START CLOCKTIME value (AM PM)
|
||||
# [EPA3] supports [EPA2] keyword
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_time(section: list[str]) -> ChangeSet:
|
||||
if len(section) > 0:
|
||||
cs = g_update_prefix | { 'type' : 'time' }
|
||||
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()
|
||||
cs |= { key : value }
|
||||
return ChangeSet(cs)
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
def inp_in_time_new(section: list[str]) -> str:
|
||||
def inp_in_time(section: list[str]) -> str:
|
||||
sql = ''
|
||||
for s in section:
|
||||
if s.startswith(';'):
|
||||
|
||||
@@ -18,11 +18,9 @@ from .database import *
|
||||
# [EPA3][NOT SUPPORT]
|
||||
# TRIALS {YES/NO}
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_report(section: list[str]) -> ChangeSet:
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
def inp_in_report_new(section: list[str]) -> str:
|
||||
def inp_in_report(section: list[str]) -> str:
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def set_option(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_batch_command(name, new_cs)
|
||||
|
||||
|
||||
def inp_in_option(section: list[str]) -> ChangeSet:
|
||||
def _inp_in_option(section: list[str]) -> ChangeSet:
|
||||
if len(section) <= 0:
|
||||
return ChangeSet()
|
||||
|
||||
@@ -41,9 +41,9 @@ def inp_in_option(section: list[str]) -> ChangeSet:
|
||||
return result
|
||||
|
||||
|
||||
def inp_in_option_new(section: list[str]) -> str:
|
||||
def inp_in_option(section: list[str]) -> str:
|
||||
sql = ''
|
||||
result = inp_in_option(section)
|
||||
result = _inp_in_option(section)
|
||||
for op in result.operations:
|
||||
for key in op.keys():
|
||||
if key == 'operation' or key == 'type':
|
||||
|
||||
@@ -16,18 +16,9 @@ def get_node_coord(name: str, id: str) -> dict[str, float]:
|
||||
# id x y
|
||||
#--------------------------------------------------------------
|
||||
# exception ! need merge to node change set !
|
||||
def inp_in_coord(section: list[str]) -> dict[str, dict[str, float]]:
|
||||
coords = {}
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
tokens = s.split()
|
||||
coords[tokens[0]] = { 'x': tokens[1], 'y': tokens[2] }
|
||||
return coords
|
||||
|
||||
|
||||
def inp_in_coord_new(line: str) -> str:
|
||||
def inp_in_coord(line: str) -> str:
|
||||
tokens = line.split()
|
||||
node = tokens[0]
|
||||
coord = f"'({tokens[1]}, {tokens[2]})'"
|
||||
|
||||
@@ -80,25 +80,9 @@ def delete_vertex(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# id x y
|
||||
# [EPA3][NOT SUPPORT]
|
||||
#--------------------------------------------------------------
|
||||
def inp_in_vertex(section: list[str]) -> ChangeSet:
|
||||
vertices: dict[str, list[dict[str, float]]] = {}
|
||||
|
||||
for s in section:
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
|
||||
tokens = s.split()
|
||||
if tokens[0] not in vertices:
|
||||
vertices[tokens[0]] = []
|
||||
vertices[tokens[0]].append({'x': float(tokens[1]), 'y': float(tokens[2])})
|
||||
|
||||
cs = ChangeSet()
|
||||
for link, coords in vertices.items():
|
||||
cs.append(g_add_prefix | {'type': 'vertex', 'link' : link, 'coords' : coords})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_vertex_new(line: str) -> str:
|
||||
def inp_in_vertex(line: str) -> str:
|
||||
tokens = line.split()
|
||||
link = tokens[0]
|
||||
x = float(tokens[1])
|
||||
|
||||
@@ -99,32 +99,7 @@ def delete_label(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_label_cmd(name, cs))
|
||||
|
||||
|
||||
class InpLabel:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.x = float(tokens[0])
|
||||
self.y = float(tokens[1])
|
||||
self.label = str(tokens[2])
|
||||
self.node = str(tokens[3]) if num >= 4 else None
|
||||
|
||||
|
||||
def inp_in_label(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpLabel(s)
|
||||
cs.append(g_add_prefix | {'type': 'label', 'x': obj.x, 'y': obj.y, 'label': obj.label, 'node': obj.node})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_label_new(line: str) -> str:
|
||||
def inp_in_label(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -26,19 +26,7 @@ def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_backdrop_cmd(name, cs))
|
||||
|
||||
|
||||
class InpBackdrop:
|
||||
def __init__(self, section) -> None:
|
||||
self.value = '\n'.join(section)
|
||||
|
||||
|
||||
def inp_in_backdrop(section: list[str]) -> ChangeSet:
|
||||
if len(section) > 0:
|
||||
obj = InpBackdrop(section)
|
||||
return ChangeSet(g_update_prefix | {'type': 'backdrop', 'content' : obj.value})
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
def inp_in_backdrop_new(section: list[str]) -> str:
|
||||
def inp_in_backdrop(section: list[str]) -> str:
|
||||
if section == []:
|
||||
return ''
|
||||
|
||||
|
||||
@@ -125,34 +125,9 @@ def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [OUT]
|
||||
# id elev. * * minpressure fullpressure
|
||||
#--------------------------------------------------------------
|
||||
class InpJunction:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.id = str(tokens[0])
|
||||
self.elevation = float(tokens[1])
|
||||
self.demand = float(tokens[2]) if num_without_desc >= 3 else None
|
||||
self.pattern = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
self.desc = str(tokens[-1]) if has_desc else None
|
||||
|
||||
|
||||
def inp_in_junction(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpJunction(s)
|
||||
cs.append(g_add_prefix | {'type': 'junction', 'id': obj.id, 'elevation': obj.elevation, 'demand': obj.demand, 'pattern': obj.pattern})
|
||||
cs.append(g_update_prefix | { 'type': 'demand', 'junction': obj.id, 'demands': [{'demand': obj.demand, 'pattern': obj.pattern, 'category': None}] })
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_junction_new(line: str, demand_outside: bool) -> str:
|
||||
def inp_in_junction(line: str, demand_outside: bool) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -120,32 +120,9 @@ def delete_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA2][EPA3][IN][OUT]
|
||||
# id elev (pattern) ;desc
|
||||
#--------------------------------------------------------------
|
||||
class InpReservoir:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.id = str(tokens[0])
|
||||
self.head = float(tokens[1])
|
||||
self.pattern = str(tokens[2]) if num_without_desc >= 3 else None
|
||||
self.desc = str(tokens[-1]) if has_desc else None
|
||||
|
||||
|
||||
def inp_in_reservoir(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpReservoir(s)
|
||||
cs.append(g_add_prefix | {'type': 'reservoir', 'id': obj.id, 'head': obj.head, 'pattern': obj.pattern})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_reservoir_new(line: str) -> str:
|
||||
def inp_in_reservoir(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -156,38 +156,9 @@ def delete_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA3]
|
||||
# id elev initlevel minlevel maxlevel diam minvol (vcurve)
|
||||
#--------------------------------------------------------------
|
||||
class InpTank:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.id = str(tokens[0])
|
||||
self.elevation = float(tokens[1])
|
||||
self.init_level = float(tokens[2])
|
||||
self.min_level = float(tokens[3])
|
||||
self.max_level = float(tokens[4])
|
||||
self.diameter = float(tokens[5])
|
||||
self.min_vol = float(tokens[6]) if num_without_desc >= 7 else 0.0
|
||||
self.vol_curve = str(tokens[7]) if num_without_desc >= 8 and tokens[7] != '*' else None
|
||||
self.overflow = str(tokens[8].upper()) if num_without_desc >= 9 else None
|
||||
self.desc = str(tokens[-1]) if has_desc else None
|
||||
|
||||
|
||||
def inp_in_tank(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpTank(s)
|
||||
cs.append(g_add_prefix | {'type': 'tank', 'id': obj.id, 'elevation': obj.elevation, 'init_level': obj.init_level, 'min_level': obj.min_level, 'max_level': obj.max_level, 'diameter': obj.diameter, 'min_vol': obj.min_vol, 'vol_curve': obj.vol_curve, 'overflow': obj.overflow})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_tank_new(line: str) -> str:
|
||||
def inp_in_tank(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -130,38 +130,9 @@ def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [OUT]
|
||||
# id node1 node2 length diam rcoeff lcoeff (status) ;desc
|
||||
#--------------------------------------------------------------
|
||||
class InpPipe:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.id = str(tokens[0])
|
||||
self.node1 = str(tokens[1])
|
||||
self.node2 = str(tokens[2])
|
||||
self.length = float(tokens[3])
|
||||
self.diameter = float(tokens[4])
|
||||
self.roughness = float(tokens[5])
|
||||
self.minor_loss = float(tokens[6])
|
||||
# status is must-have, here fix input
|
||||
self.status = str(tokens[7].upper()) if num_without_desc >= 8 else PIPE_STATUS_OPEN
|
||||
self.desc = str(tokens[-1]) if has_desc else None
|
||||
|
||||
|
||||
def inp_in_pipe(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpPipe(s)
|
||||
cs.append(g_add_prefix | {'type': 'pipe', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'length': obj.length, 'diameter': obj.diameter, 'roughness': obj.roughness, 'minor_loss': obj.minor_loss, 'status': obj.status})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_pipe_new(line: str) -> str:
|
||||
def inp_in_pipe(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -119,39 +119,9 @@ def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# id node1 node2 KEYWORD value {KEYWORD value ...} ;desc
|
||||
# where KEYWORD = [POWER,HEAD,PATTERN,SPEED]
|
||||
#--------------------------------------------------------------
|
||||
class InpPump:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.id = str(tokens[0])
|
||||
self.node1 = str(tokens[1])
|
||||
self.node2 = str(tokens[2])
|
||||
self.props = {}
|
||||
for i in range(3, num_without_desc, 2):
|
||||
self.props |= { tokens[i].lower(): tokens[i + 1] }
|
||||
self.power = float(self.props['power']) if 'power' in self.props else None
|
||||
self.head = str(self.props['head']) if 'head' in self.props else None
|
||||
self.speed = float(self.props['speed']) if 'speed' in self.props else None
|
||||
self.pattern = str(self.props['pattern']) if 'pattern' in self.props else None
|
||||
self.desc = str(tokens[-1]) if has_desc else None
|
||||
|
||||
|
||||
def inp_in_pump(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpPump(s)
|
||||
cs.append(g_add_prefix | {'type': 'pump', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'power': obj.power, 'head': obj.head, 'speed': obj.speed, 'pattern': obj.pattern})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_pump_new(line: str) -> str:
|
||||
def inp_in_pump(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -128,36 +128,9 @@ def delete_valve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# for GPV, setting is string = head curve id
|
||||
# [NOT SUPPORT] for PCV, add loss curve if present
|
||||
#--------------------------------------------------------------
|
||||
class InpValve:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.id = str(tokens[0])
|
||||
self.node1 = str(tokens[1])
|
||||
self.node2 = str(tokens[2])
|
||||
self.diameter = float(tokens[3])
|
||||
self.v_type = str(tokens[4].upper())
|
||||
self.setting = str(tokens[5])
|
||||
self.minor_loss = float(tokens[6])
|
||||
self.desc = str(tokens[-1]) if has_desc else None
|
||||
|
||||
|
||||
def inp_in_valve(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpValve(s)
|
||||
cs.append(g_add_prefix | {'type': 'valve', 'id': obj.id, 'node1': obj.node1, 'node2': obj.node2, 'diameter': obj.diameter, 'v_type': obj.v_type, 'setting': obj.setting, 'minor_loss': obj.minor_loss})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_valve_new(line: str) -> str:
|
||||
def inp_in_valve(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -79,31 +79,7 @@ def set_tag(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_tag_cmd(name, cs))
|
||||
|
||||
|
||||
class InpTag:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.t_type = str(tokens[0].upper())
|
||||
self.id = str(tokens[1])
|
||||
self.tag = str(tokens[2])
|
||||
|
||||
|
||||
def inp_in_tag(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpTag(s)
|
||||
cs.append(g_update_prefix | {'type': 'tag', 't_type': obj.t_type, 'id': obj.id, 'tag': obj.tag})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_tag_new(line: str) -> str:
|
||||
def inp_in_tag(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
@@ -63,41 +63,9 @@ def set_demand(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
# [EPA2][EPA3][IN][OUT]
|
||||
# node base_demand (pattern) ;category
|
||||
#--------------------------------------------------------------
|
||||
class InpDemand:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.junction = str(tokens[0])
|
||||
self.demand = float(tokens[1])
|
||||
self.pattern = str(tokens[2]) if num_without_desc >= 3 else None
|
||||
self.category = str(tokens[3]) if num_without_desc >= 4 else None
|
||||
|
||||
|
||||
def inp_in_demand(section: list[str]) -> ChangeSet:
|
||||
objs: dict[str, list[InpDemand]] = {}
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpDemand(s)
|
||||
if obj.junction not in objs:
|
||||
objs[obj.junction] = []
|
||||
objs[obj.junction].append(obj)
|
||||
|
||||
cs = ChangeSet()
|
||||
for junction, demands in objs.items():
|
||||
obj_cs : dict[str, Any] = g_update_prefix | {'type': 'demand', 'junction' : junction, 'demands' : []}
|
||||
for obj in demands:
|
||||
obj_cs['demands'].append({'demand': obj.demand, 'pattern' : obj.pattern, 'category': obj.category})
|
||||
cs.append(obj_cs)
|
||||
return cs
|
||||
|
||||
|
||||
def inp_in_demand_new(line: str) -> str:
|
||||
def inp_in_demand(line: str) -> str:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
|
||||
Reference in New Issue
Block a user