Parse [RESERVOIRS]
This commit is contained in:
@@ -33,11 +33,11 @@ class InpTitle:
|
|||||||
|
|
||||||
|
|
||||||
def inp_in_title(section: list[str]) -> ChangeSet:
|
def inp_in_title(section: list[str]) -> ChangeSet:
|
||||||
title = InpTitle(section)
|
obj = InpTitle(section)
|
||||||
cs = ChangeSet({'operation' : API_ADD, 'type': 'title', 'value' : title.value})
|
cs = ChangeSet({'operation' : API_ADD, 'type': 'title', 'value' : obj.value})
|
||||||
return cs
|
return cs
|
||||||
|
|
||||||
|
|
||||||
def inp_out_title(name: str) -> list[str]:
|
def inp_out_title(name: str) -> list[str]:
|
||||||
title = str(get_title(name)['value'])
|
obj = str(get_title(name)['value'])
|
||||||
return title.split('\n')
|
return obj.split('\n')
|
||||||
|
|||||||
@@ -138,19 +138,19 @@ class InpJunction:
|
|||||||
def inp_in_junction(section: list[str]) -> ChangeSet:
|
def inp_in_junction(section: list[str]) -> ChangeSet:
|
||||||
cs = ChangeSet()
|
cs = ChangeSet()
|
||||||
for s in section:
|
for s in section:
|
||||||
junction = InpJunction(s)
|
obj = InpJunction(s)
|
||||||
cs.append({'operation': API_ADD, 'type': 'junction', 'id': junction.id, 'elevation': junction.elevation, 'demand': junction.demand, 'pattern': junction.pattern})
|
cs.append({'operation': API_ADD, 'type': 'junction', 'id': obj.id, 'elevation': obj.elevation, 'demand': obj.demand, 'pattern': obj.pattern})
|
||||||
return cs
|
return cs
|
||||||
|
|
||||||
|
|
||||||
def inp_out_junction(name: str) -> list[str]:
|
def inp_out_junction(name: str) -> list[str]:
|
||||||
lines = []
|
lines = []
|
||||||
junctions = read_all(name, 'select * from junctions')
|
objs = read_all(name, 'select * from junctions')
|
||||||
for j in junctions:
|
for obj in objs:
|
||||||
id = j['id']
|
id = obj['id']
|
||||||
elev = j['elevation']
|
elev = obj['elevation']
|
||||||
demand = j['demand'] if j['demand'] != None else ''
|
demand = obj['demand'] if obj['demand'] != None else ''
|
||||||
pattern = j['pattern'] if j['pattern'] != None else ''
|
pattern = obj['pattern'] if obj['pattern'] != None else ''
|
||||||
desc = ';'
|
desc = ';'
|
||||||
lines.append(f'{id} {elev} {demand} {pattern} {desc}')
|
lines.append(f'{id} {elev} {demand} {pattern} {desc}')
|
||||||
return lines
|
return lines
|
||||||
|
|||||||
@@ -114,3 +114,37 @@ def delete_reservoir_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
|||||||
|
|
||||||
def delete_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return execute_command(name, delete_reservoir_cache(name, cs))
|
return execute_command(name, delete_reservoir_cache(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
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 = float(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:
|
||||||
|
obj = InpReservoir(s)
|
||||||
|
cs.append({'operation': API_ADD, 'type': 'reservoir', 'id': obj.id, 'head': obj.head, 'pattern': obj.pattern})
|
||||||
|
return cs
|
||||||
|
|
||||||
|
|
||||||
|
def inp_out_junction(name: str) -> list[str]:
|
||||||
|
lines = []
|
||||||
|
objs = read_all(name, 'select * from junctions')
|
||||||
|
for obj in objs:
|
||||||
|
id = obj['id']
|
||||||
|
head = obj['head']
|
||||||
|
pattern = obj['pattern'] if obj['pattern'] != None else ''
|
||||||
|
desc = ';'
|
||||||
|
lines.append(f'{id} {head} {pattern} {desc}')
|
||||||
|
return lines
|
||||||
|
|||||||
Reference in New Issue
Block a user