diff --git a/api/s16_emitters.py b/api/s16_emitters.py index 42b2df1..ae3040f 100644 --- a/api/s16_emitters.py +++ b/api/s16_emitters.py @@ -57,3 +57,36 @@ def set_emitter_cache(name: str, cs: ChangeSet) -> SqlChangeSet: def set_emitter(name: str, cs: ChangeSet) -> ChangeSet: 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