Parse [CURVES]
This commit is contained in:
@@ -119,3 +119,50 @@ def delete_curve_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
|||||||
|
|
||||||
def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
return execute_command(name, delete_curve_cache(name, cs))
|
return execute_command(name, delete_curve_cache(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
def inp_in_curve(section: list[str]) -> ChangeSet:
|
||||||
|
types = {}
|
||||||
|
descs = {}
|
||||||
|
curves: dict[str, list[dict[str, float]]] = {}
|
||||||
|
|
||||||
|
count = len(section)
|
||||||
|
for i in range(0, count):
|
||||||
|
if section[i].startswith(';'):
|
||||||
|
# this is description
|
||||||
|
type_plus_desc = section[i].removeprefix(';')
|
||||||
|
type_plus_desc_tokens = type_plus_desc.split(':')
|
||||||
|
next = i + 1
|
||||||
|
if next < count and section[next].startswith(';') == False:
|
||||||
|
next_tokens = section[next].split()
|
||||||
|
types[next_tokens[0]] = type_plus_desc_tokens[0].strip()
|
||||||
|
if len(type_plus_desc_tokens) > 1:
|
||||||
|
descs[next_tokens[0]] = type_plus_desc_tokens[1].strip()
|
||||||
|
continue
|
||||||
|
|
||||||
|
tokens = section[i].split()
|
||||||
|
if tokens[0] not in curves:
|
||||||
|
curves[tokens[0]] = []
|
||||||
|
curves[tokens[0]].append({'x': float(tokens[1]), 'y': float(tokens[2])})
|
||||||
|
|
||||||
|
cs = ChangeSet()
|
||||||
|
for id, coords in curves.items():
|
||||||
|
c_type = types[id] if id in types else CURVE_TYPE_PUMP
|
||||||
|
cs.append({'operation': API_ADD, 'type': 'curve', 'id' : id, 'c_type': c_type, 'coords' : coords})
|
||||||
|
return cs
|
||||||
|
|
||||||
|
|
||||||
|
def inp_out_curve(name: str) -> list[str]:
|
||||||
|
lines = []
|
||||||
|
types = read_all(name, f"select * from _curve")
|
||||||
|
for type in types:
|
||||||
|
id = type['id']
|
||||||
|
# ;type: desc
|
||||||
|
lines.append(f";{type['type']}:")
|
||||||
|
objs = read_all(name, f"select * from curves where id = '{id}' order by _order")
|
||||||
|
for obj in objs:
|
||||||
|
id = obj['id']
|
||||||
|
x = obj['x']
|
||||||
|
y = obj['y']
|
||||||
|
lines.append(f'{id} {x} {y}')
|
||||||
|
return lines
|
||||||
|
|||||||
Reference in New Issue
Block a user