Add rule api and test
This commit is contained in:
@@ -52,6 +52,8 @@ from .s12_curves import get_curve_schema, get_curve, set_curve
|
||||
|
||||
from .s13_controls import get_control_schema, get_control, set_control
|
||||
|
||||
from .s14_rules import get_rule_schema, get_rule, set_rule
|
||||
|
||||
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/s14_rules.py
Normal file
26
api/s14_rules.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from .operation import *
|
||||
|
||||
|
||||
def get_rule_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return { 'rule' : {'type': 'str' , 'optional': False , 'readonly': False} }
|
||||
|
||||
|
||||
def get_rule(name: str) -> dict[str, Any]:
|
||||
e = read(name, f"select * from rules")
|
||||
return { 'rule': e['rule'] }
|
||||
|
||||
|
||||
def set_rule_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
old = get_rule(name)
|
||||
|
||||
redo_sql = f"update rules set rule = '{cs.operations[0]['rule']}' where rule = '{old['rule']}';"
|
||||
undo_sql = f"update rules set rule = '{old['rule']}' where rule = '{cs.operations[0]['rule']}';"
|
||||
|
||||
redo_cs = g_update_prefix | { 'type': 'rule', 'rule': cs.operations[0]['rule'] }
|
||||
undo_cs = g_update_prefix | { 'type': 'rule', 'rule': old['rule'] }
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
|
||||
|
||||
def set_rule(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_rule_cache(name, cs))
|
||||
Reference in New Issue
Block a user