Allow to read EPANET3 pattern
This commit is contained in:
@@ -94,14 +94,22 @@ def delete_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
# [EPANET2][IN][OUT]
|
# [EPA2][IN][OUT]
|
||||||
# ;desc
|
# ;desc
|
||||||
# id mult1 mult2 .....
|
# id mult1 mult2 .....
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
|
# [EPA3][IN][OUT]
|
||||||
|
# id FIXED (interval)
|
||||||
|
# id factor1 factor2 ...
|
||||||
|
# id VARIABLE
|
||||||
|
# id time1 factor1 time2 factor2 ...
|
||||||
|
#--------------------------------------------------------------
|
||||||
def inp_in_pattern(section: list[str]) -> ChangeSet:
|
def inp_in_pattern(section: list[str]) -> ChangeSet:
|
||||||
descs = {}
|
descs = {}
|
||||||
patterns: dict[str, list[float]] = {}
|
patterns: dict[str, list[float]] = {}
|
||||||
|
|
||||||
|
variable_patterns: list[str] = []
|
||||||
|
|
||||||
count = len(section)
|
count = len(section)
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
if section[i].startswith(';'):
|
if section[i].startswith(';'):
|
||||||
@@ -113,10 +121,22 @@ def inp_in_pattern(section: list[str]) -> ChangeSet:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
tokens = section[i].split()
|
tokens = section[i].split()
|
||||||
|
|
||||||
|
# for EPA3, ignore time of variable pattern...
|
||||||
|
if tokens[1] == 'VARIABLE':
|
||||||
|
variable_patterns.append(tokens[0])
|
||||||
|
continue
|
||||||
|
elif tokens[1] == 'FIXED':
|
||||||
|
continue
|
||||||
|
|
||||||
if tokens[0] not in patterns:
|
if tokens[0] not in patterns:
|
||||||
patterns[tokens[0]] = []
|
patterns[tokens[0]] = []
|
||||||
for token in tokens[1:]:
|
if tokens[0] not in variable_patterns:
|
||||||
patterns[tokens[0]].append(float(token))
|
for token in tokens[1:]:
|
||||||
|
patterns[tokens[0]].append(float(token))
|
||||||
|
else:
|
||||||
|
for token in tokens[1::2]:
|
||||||
|
patterns[tokens[0]].append(float(token))
|
||||||
|
|
||||||
cs = ChangeSet()
|
cs = ChangeSet()
|
||||||
for id, factors in patterns.items():
|
for id, factors in patterns.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user