Parse [QUALITY]
This commit is contained in:
@@ -57,3 +57,36 @@ def set_quality_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
|||||||
|
|
||||||
def set_quality(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_quality(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return execute_command(name, set_quality_cache(name, cs))
|
return execute_command(name, set_quality_cache(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
class InpQuality:
|
||||||
|
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.node = str(tokens[0])
|
||||||
|
self.quality = float(tokens[1])
|
||||||
|
|
||||||
|
|
||||||
|
def inp_in_quality(section: list[str]) -> ChangeSet:
|
||||||
|
cs = ChangeSet()
|
||||||
|
for s in section:
|
||||||
|
# skip comment
|
||||||
|
if s.startswith(';'):
|
||||||
|
continue
|
||||||
|
obj = InpQuality(s)
|
||||||
|
cs.append({'operation': API_UPDATE, 'type': 'quality', 'node': obj.node, 'quality': obj.quality})
|
||||||
|
return cs
|
||||||
|
|
||||||
|
|
||||||
|
def inp_out_quality(name: str) -> list[str]:
|
||||||
|
lines = []
|
||||||
|
objs = read_all(name, 'select * from quality')
|
||||||
|
for obj in objs:
|
||||||
|
node = obj['node']
|
||||||
|
quality = obj['quality']
|
||||||
|
lines.append(f'{node} {quality}')
|
||||||
|
return lines
|
||||||
|
|||||||
Reference in New Issue
Block a user