Add control api and test

This commit is contained in:
WQY\qiong
2022-10-29 19:04:42 +08:00
parent a04dcdd1ee
commit 44475cf005
5 changed files with 86 additions and 0 deletions

View File

@@ -50,6 +50,8 @@ from .s11_patterns import get_pattern_schema, get_pattern, set_pattern
from .s12_curves import get_curve_schema, get_curve, set_curve
from .s13_controls import get_control_schema, get_control, set_control
from .s16_emitters import get_emitter_schema, get_emitter, set_emitter
from .s21_times import TIME_STATISTIC_NONE, TIME_STATISTIC_AVERAGED, TIME_STATISTIC_MINIMUM, TIME_STATISTIC_MAXIMUM, TIME_STATISTIC_RANGE

26
api/s13_controls.py Normal file
View File

@@ -0,0 +1,26 @@
from .operation import *
def get_control_schema(name: str) -> dict[str, dict[str, Any]]:
return { 'control' : {'type': 'str' , 'optional': False , 'readonly': False} }
def get_control(name: str) -> dict[str, Any]:
e = read(name, f"select * from controls")
return { 'control': e['control'] }
def set_control_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
old = get_control(name)
redo_sql = f"update controls set control = '{cs.operations[0]['control']}' where control = '{old['control']}';"
undo_sql = f"update controls set control = '{old['control']}' where control = '{cs.operations[0]['control']}';"
redo_cs = g_update_prefix | { 'type': 'control', 'control': cs.operations[0]['control'] }
undo_cs = g_update_prefix | { 'type': 'control', 'control': old['control'] }
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
def set_control(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_control_cache(name, cs))