[rules-users] Question about length windows

Wolfgang Laun wolfgang.laun at gmail.com
Fri May 2 00:46:41 EDT 2014


A window:length is filled depending on the constraints but independent
of how old the participating facts are.

What you want to achieve can be done without windows:

   t2_1 : Tick( value < 102.352 )
   t1_1 : Tick( this before t2_1 , value >= 102.352 )
   not Tick( this before t2_1 && after t1_1 )

The last pattern ascertains that the preceding pair of facts is
adjacent. (The three timestamps should be different.)

You can also use rules based on an auxiliary fact maintaining state:
While value < 102.352, state is set to "below"; as soon as a
fact with value >= 102.352 matches state == "below", the
threshold is passed and state is set to "above"...

-W


On 02/05/2014, Demian Calcaprina <calcacuervo at gmail.com> wrote:
> Hi Guys, I have one question about how lenght windows will work.
>
> I have a rule like this. Basically, it is a "crosses" function, where the
> value of my object crosses a value.
>
> rule "mytest"
> dialect "mvel"
> when
> t2_1 : Tick( value < 102.352 ) over window:length (1)
> t1_1 : Tick( this before t2_1 , value >= 102.352 ) over window:length (2)
> then
> //DO SOMETHING
> end
>
> 23:51:32,150 INFO  [org.drools.core.audit.WorkingMemoryConsoleLogger]
> (Camel (camel-1) thread #2 - JmsConsumer[]) ACTIVATION FIRED rule:mytest
> activationId:berarrr_1 [0, 27, 26] declarations: t2_1=Tick [value=102.351,
> tickTime=Fri May 02 05:51:31 ART 2014](27); t1_1=Tick [value=102.352,
> tickTime=Fri May 02 05:51:12 ART 2014](26)
>
> 23:53:30,560 INFO  [org.drools.core.audit.WorkingMemoryConsoleLogger]
> (Camel (camel-1) thread #2 - JmsConsumer[]) ACTIVATION CREATED rule:mytest
> activationId:berarrr_1 [0, 146, 26] declarations: t2_1=Tick [value=102.349,
> tickTime=Fri May 02 05:53:30 ART 2014](146); t1_1=Tick [value=102.352,
> tickTime=Fri May 02 05:51:12 ART 2014](26)
>
> If you see, the first activation, the
> window:length(1), matched the object 27
> window:length(2), matched the object 26
>
> Then, after 2 minutes and some Ticks insertes in the WM
> window:length(1), matched the object 146
> but window:length(2), still matched the object 26
>
> I would expect, that, as object 26 was the first one to be inserted, then
> it is outside the window:length(2).
>
> Is my understanding correct? Am I making something wrong? I am using Drools
> 6.
>
> Thanks!
>
> Demian
>


More information about the rules-users mailing list