[rules-users] [Drools Fusion] Can't detect 2 occurrences with sliding window

Xavier Coulon xcoulon at gmail.com
Thu May 27 09:25:48 EDT 2010


Hello again,

I'm back on my problem and a colleague of mime suggested me the following
rule instead :

# declare events
declare Operation
    @role(event)
    @timestamp(date)
end

rule "overActivity"
dialect "mvel"
    when
        #condition : 2 operation in less than 1 minute
       * $operation1 : Operation($ipAddress1 : ipAddress) **
            from entry-point "OperationStream"
        $operation2 : Operation(this != $operation1, ipAddress ==
$ipAddress1,
            this after[ 0s,30s ] $operation1) from entry-point
"OperationStream"*
    then
        #actions
        System.out.println("over-active user " + $ipAddress1 );
end


It works, and the main difference is the use of *after[]* instead of *
window:time()*
Is it because the window:time() was used outside of an *accumulate()*function ?
I'd just like to understand this.
If anyone can take a few minutes to answer, thank you in advance

Best regards,

Xavier



On Wed, May 19, 2010 at 10:08 AM, Xavier Coulon <xcoulon at gmail.com> wrote:

>
> Hello Wolfgang,
>
> sorry, I wasn't available yesterday.
> I just followed your instructions:
>
> Here's my test method now :
>
> @SuppressWarnings("unchecked")
>    @Test
>    public void testActivity() throws IOException, ParseException,
>            InterruptedException {
>        // parse the log file
>        Resource logFile = new ClassPathResource(
>                 "activity/activity18h20-18h30-extract.log");
>         // converter and inject tracks in the session,
>        List<String> logLines = FileUtils.readLines(logFile.getFile(),
> "UTF-8");
>         LOGGER.info("loading events");
>        // load events from stream
>         Operation previousOperation = null;
>         for (String logLine : logLines) {
>            Operation operation = LineConverterUtil.getOperation(logLine);
>             Assert.assertFalse("Current operation equals() previous one",
>                    operation.equals(previousOperation));
>            Assert.assertFalse("Current operation == previous one",
>                    operation == previousOperation);
>             previousOperation = operation;
>             LOGGER.debug("Moving clock from "
>                    + (new Date(clock.getCurrentTime())).toString() + " to "
>                    + operation.getDate());
>            clock.advanceTime(operation.getDate().getTime()
>                    - clock.getCurrentTime(), TimeUnit.MILLISECONDS);
>            // clock.advanceTime(10, TimeUnit.SECONDS);
>             LOGGER.debug("Inserting " + operation);
>            FactHandle operationHandle = entryPoint.insert(operation);
>            LOGGER.debug("Insertion done: " +
> operationHandle.toExternalForm());
>
>        }
>         session.fireAllRules();
>
>        LOGGER.info("done with events");
>        // check...
>        Assert.assertTrue("Rule not fired...", listener
>                .isRuleFired("overActivity"));
>    }
>
> And the logs in the console :
>
> Console> 2010-05-19 09:57:06|INFO
> ||DroolsRulesTestCase.testActivity|loading
> events
> Console> 2010-05-19 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Moving
> clock from Thu Jan 01 01:00:00 CET 1970 to Fri Apr 30 18:26:47 CEST 2010
> Console> 2010-05-19
> 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
> [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1, hostname=server1,
> ipAddress=1.2.3.4, operation=null, requestSize=0, responseSize=0]
> Console> 2010-05-19 09:57:06|WARN
> ||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [event
> fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1,
> hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
> responseSize=0]]
> Console> 2010-05-19
> 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
> fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1,
> hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
> responseSize=0]]
> Console> 2010-05-19 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Moving
> clock from Fri Apr 30 18:26:47 CEST 2010 to Fri Apr 30 18:27:11 CEST 2010
> Console> 2010-05-19
> 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
> [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164, hostname=server1,
> ipAddress=1.2.3.4, operation=CONSULTATION, requestSize=1299,
> responseSize=895]
> Console> 2010-05-19 09:57:06|WARN
> ||TrackingWorkingMemoryEventListener.objectRetracted|Object retracted:
> [event fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010,
> executionTime=1, hostname=server1, ipAddress=1.2.3.4, operation=null,
> requestSize=0, responseSize=0]]
> Console> 2010-05-19 09:57:06|WARN
> ||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [event
> fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164,
> hostname=server1, ipAddress=1.2.3.4, operation=CONSULTATION,
> requestSize=1299, responseSize=895]]
> Console> 2010-05-19
> 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
> fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164,
> hostname=server1, ipAddress=1.2.3.4, operation=CONSULTATION,
> requestSize=1299, responseSize=895]]
> Console> 2010-05-19 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Moving
> clock from Fri Apr 30 18:27:11 CEST 2010 to Fri Apr 30 18:28:47 CEST 2010
> Console> 2010-05-19
> 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
> [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1, hostname=server1,
> ipAddress=1.2.3.4, operation=null, requestSize=0, responseSize=0]
> Console> 2010-05-19 09:57:06|WARN
> ||TrackingWorkingMemoryEventListener.objectRetracted|Object retracted:
> [event fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010,
> executionTime=164, hostname=server1, ipAddress=1.2.3.4,
> operation=CONSULTATION, requestSize=1299, responseSize=895]]
> Console> 2010-05-19 09:57:06|WARN
> ||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [event
> fid:3:3:Operation [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1,
> hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
> responseSize=0]]
> Console> 2010-05-19
> 09:57:06|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
> fid:3:3:Operation [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1,
> hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
> responseSize=0]]
> Console> 2010-05-19 09:57:06|INFO ||DroolsRulesTestCase.testActivity|done
> with events
>
>
> Strangely, the first operation is retracted when the second one is
> inserted,
> yet, they are not equals()...
>
> /Xavier
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Fusion-Can-t-detect-2-occurrences-with-sliding-window-tp823141p828505.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Xavier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100527/1097c76a/attachment.html 


More information about the rules-users mailing list