Parse [EMITTERS]
This commit is contained in:
@@ -57,3 +57,36 @@ def set_emitter_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
|||||||
|
|
||||||
def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return execute_command(name, set_emitter_cache(name, cs))
|
return execute_command(name, set_emitter_cache(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
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({'operation': API_UPDATE, 'type': 'emitter', 'junction': obj.junction, 'coefficient': obj.coefficient})
|
||||||
|
return cs
|
||||||
|
|
||||||
|
|
||||||
|
def inp_out_emitter(name: str) -> list[str]:
|
||||||
|
lines = []
|
||||||
|
objs = read_all(name, 'select * from emitters')
|
||||||
|
for obj in objs:
|
||||||
|
junction = obj['junction']
|
||||||
|
coefficient = obj['coefficient']
|
||||||
|
lines.append(f'{junction} {coefficient}')
|
||||||
|
return lines
|
||||||
|
|||||||
Reference in New Issue
Block a user