Parse [MIXING]

This commit is contained in:
WQY\qiong
2022-11-14 21:43:06 +08:00
parent e4023717a5
commit 4b1943ce25

View File

@@ -94,3 +94,38 @@ def delete_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
def delete_mixing(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_mixing_cache(name, cs))
class InpMixing:
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.tank = str(tokens[0])
self.model = str(tokens[1])
self.value = float(tokens[3]) if num_without_desc >= 4 else None
def inp_in_mixing(section: list[str]) -> ChangeSet:
cs = ChangeSet()
for s in section:
# skip comment
if s.startswith(';'):
continue
obj = InpMixing(s)
cs.append({'operation': API_ADD, 'type': 'mixing', 'tank': obj.tank, 'model': obj.model, 'value': obj.value})
return cs
def inp_out_mixing(name: str) -> list[str]:
lines = []
objs = read_all(name, 'select * from mixing')
for obj in objs:
tank = obj['tank']
model = obj['model']
value = obj['value'] if obj['value'] != None else ''
lines.append(f'{tank} {model} {value}')
return lines