Parse [JUNCTIONS]
This commit is contained in:
@@ -37,6 +37,7 @@ def inp_in_title(section: list[str]) -> ChangeSet:
|
|||||||
cs = ChangeSet({'operation' : API_ADD, 'type': 'title', 'value' : title.value})
|
cs = ChangeSet({'operation' : API_ADD, 'type': 'title', 'value' : title.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'])
|
title = str(get_title(name)['value'])
|
||||||
return title.split('\n')
|
return title.split('\n')
|
||||||
|
|||||||
@@ -118,3 +118,39 @@ def delete_junction_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
|||||||
|
|
||||||
def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return execute_command(name, delete_junction_cache(name, cs))
|
return execute_command(name, delete_junction_cache(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
junction = InpJunction(s)
|
||||||
|
cs.append({'operation': API_ADD, 'type': 'junction', 'id': junction.id, 'elevation': junction.elevation, 'demand': junction.demand, 'pattern': junction.pattern})
|
||||||
|
return cs
|
||||||
|
|
||||||
|
|
||||||
|
def inp_out_junction(name: str) -> list[str]:
|
||||||
|
lines = []
|
||||||
|
junctions = read_all(name, 'select * from junctions')
|
||||||
|
for j in junctions:
|
||||||
|
id = j['id']
|
||||||
|
elev = j['elevation']
|
||||||
|
demand = j['demand'] if j['demand'] != None else ''
|
||||||
|
pattern = j['pattern'] if j['pattern'] != None else ''
|
||||||
|
desc = ';'
|
||||||
|
lines.append(f'{id} {elev} {demand} {pattern} {desc}')
|
||||||
|
return lines
|
||||||
|
|||||||
Reference in New Issue
Block a user