Rules Engine Tutorial--Variable Tracking

 Functional Overview

    During the test of the rule package, if you want to know the execution of the variable in each rule and the change of the value of the variable in each rule, you can perform "debug trace" on the variable. In this way, the value assignments, changes, and results of variables in each rule and rule set can be recorded. This variable can be a variable in "Incoming Data", a variable in "Temporary Data", or a variable in "Memory Table".

 

Create a rule package named "Variable Tracking". The creation process is shown in the following figure:


 

 

 

 



 After the package is added, add rule sets and rules under the rule package. Right-click the rule package and select Add Rule Set. The adding process is as shown in the figure below:
 

 

 Continue to add new rules in the rule set " a is greater than 0 ", as shown in the figure below:

 



 

 

Go ahead and add new rules in the rule set " a is greater than 0 ", as shown in the following image:

 



 

 

 

Finally, add the rule "memory table assignment 1 " to the rule set " a is greater than 0 " , as shown in the following figure:



 



 

 

 

 

In this way, the rules of the rule set " a is greater than 0 " are added. Continue to add a rule set named " a is less than 0 " in the rule package, as shown in the following figure:

 



 

Then, to add three rules under this rule set, as shown in the following figure when completed:



 

 

After the rules are added, to add variables in the object library, the process of adding variables is shown in the following figure:



  

 

Then, there is also a calculation table (memory table) added to the object library. The adding process is shown in the following figure:

 

 



 

 

 

 

After the rules and variables are defined, specific rule logic should be added to the rules and rule sets.

 

First, the rule logic added in the rule set " a is greater than 0 ", as shown in the following figure:



 

 

 

 



 

 

Second, add rule logic to the rule "variable assignment 1 " under the rule set " a is greater than 0 ". After completion, as shown in the following figure:



 

 

Third, in the rule "auto-increment", let the variables b and c increment by 1. The specific rule logic is shown in the following figure:

 



 

 

Fourth, add rule logic in the rule "memory table assignment 1 " under the rule set " a is greater than 0 ". First, in the property window of the rule, modify the property settings of the rule:



 

In addition to assigning values ​​to each variable one by one, you can also use the memory table assignment wizard that comes with the rule configurator. Using wizards greatly reduces the time and steps involved in writing rules. The specific wizard steps are shown in the following figure:

 



 

 

 

Since the memory table is an empty table when it is first created, before assigning a value to the memory table, it is necessary to add an empty data to the memory. The steps are shown in the following figure:



 

After copying the " insert " method of the memory table, it is necessary to insert the method into the rule logic, as shown in the following figure:



 

 



 

 

 

 

In this way, the rule writing of the rule "memory table assignment 1 " is completed. The logic of the rule set " a is less than 0 " is as follows:



 

 

规则集“a小于0”完成之后,要给规则“变量赋值2”编写逻辑,如下图所示:

 



 

规则“变量赋值2”完成之后,我们在规则“自减”中,让变量bc自减1,具体的规则逻辑如下图所示:



 

变量自减之后,又要给内存表赋值了,在规则“内存表赋值2”中,实现的规则逻辑如下图所示:



 



 

在规则逻辑的编写完成之后,在就可以在对象库中设置需要跟踪的变量。过程如下图所示:

 



 

 

在“传入数据”中的变量添加了“调试跟踪”,在内存表的变量也可以跟踪其执行记录,如下图所示:

 



 

 

这样在规则包测试执行的时候,就可以记录已被“调试跟踪”的四个变量的值变化情况。

 

 

 

 

在规则包全部编写完成之后,就要对规则包进行保存、编译。点击“全部保存”会把所有的未保存的规则包,自动保存并编译。如下图所示:



 

 

点击之后,规则配置器的消息栏会有保存的消息记录,如下图:



 

 

 

规则包编写完成之后,可以添加测试数据进行规则包测试。在规则包测试过程中,就可以跟踪变量,记录变量的值变化情况。测试情况如下图所示:



 

 

点击了“执行到此”之后,就可以看到规则包测试结果和变量值变化。如下图所示:

 

上述的这种情况是执行了规则包进入了规则集“a大于0”的情况,下面再测试下规则集“a小于0 ”的情况。刷新测试数据,然后在规则包测试中输入“a=-3”,测试规则包执行结果,如下图所示:



 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326926770&siteId=291194637