Closed TaurusYin closed 2 years ago
Yes paranthesis are supported and can be used to alter the order of operations as they do in Python and other languages.
Yes paranthesis are supported and can be used to alter the order of operations as they do in Python and other languages.
thanks for reply. Is there an example to use paranthesis? I tried the expression above but the order seems not correct.
Yes paranthesis are supported and can be used to alter the order of operations as they do in Python and other languages.
It looks like the privilege of the paranthesis does not work as I tried to use multiple paranthesis
Try 1 + (2 * 4)
vs (1 + 2) * 4
and you'll see a difference. There's a debug repl tool that you can use for testing this.
Details are here https://zerosteiner.github.io/rule-engine/debug_repl.html
Here's a demo:
PYTHONPATH=$(pwd)/lib python -m rule_engine.debug_repl --edit-console
edit the 'context' and 'thing' objects as necessary
>>> thing = {'mysql': {'cpu_usage': {'feature': 'spike'}, 'value': 90, 'active_session': {'feature': 'shift_up', 'value': 0}}}
>>> exit()
exiting the edit console...
rule > (mysql.cpu_usage.feature in ["spike", "shift_up", "trend_up"] or mysql.cpu_usage.value > 90) and (mysql.active_session.feature in ["shift_up", "trend_up"] or mysql.active_session.value > 16)
result:
True
rule > 1 + (2 * 4)
result:
Decimal('9.00')
rule > (1 + 2) * 4
result:
Decimal('12.00')
rule >
Excuse me, I would like to use "(" or ")" to control the privilege of this expression block. Will it support? (mysql.cpu_usage.feature in ["spike", "shift_up", "trend_up"] or mysql.cpu_usage.value > 90) and (mysql.active_session.feature in ["shift_up", "trend_up"] or mysql.active_session.value > 16)