laune,
I've tried your proposed accumulate approach, the Result of
test1_FireAllRules() is:
-= 1 =-
$events avg duration = 2.0
----------FIRED----------
-= 2 =-
$events avg duration = 2.0
----------FIRED----------
-= 3 =-
$events avg duration = 7.0
----------FIRED----------
---test1 end---
Ok, it fires for each new inserted event (between fireAllRules calls) and
calculates avg for all events witn name "MyService".
But, as I wrote in first post, I need to fire a rule if last inserting event
duration 
greater than value which depends on average duration of all events from the
wm. Lets take $avg/10(/10 - take for convenience to show issue).
So I need to add pattern along with accumulate:
/    Number( $avg: doubleValue ) from accumulate( ServicePerformanceEvent(
$name: serviceName, $thisDuration: duration),
                     init( double sum = 0; double count = 0; )
                     action( if("MyService".equals($name)){
                                 sum += $thisDuration; 
                                 count++;})
                     result( count != 0 ? sum/count : 0 ) );
        
        $event : ServicePerformanceEvent(serviceName == "MyService", duration >
*/$avg/10/*);/
Result of test1_FireAllRules():
-= 1 =-
$event.duration = 2
$events avg duration = 2.0
----------FIRED----------
-= 2 =-
$event.duration = 2
$events avg duration = 2.0
----------FIRED----------
-= 3 =-
$event.duration = 12
$events avg duration = 7.0
----------FIRED----------
$event.duration = 2
$events avg duration = 7.0
----------FIRED----------
---test1 end---

As can see, it fires on both for newly inserted event and for old already
matched events/facts.
Ok, if rule analyzes all previous events/facts I decide to check previous
rule with test:
/       @Test
        public void test12_FireAllRules() throws RuleGeneratorException {
                System.out.println("-= 1 =-");
                ksession.insert(new ServicePerformanceEvent("MyService", 2));
                ksession.fireAllRules();

                System.out.println("-= 2 =-");
                ksession.insert(new ServicePerformanceEvent("AnotherService", 
10));
                ksession.fireAllRules();

                System.out.println("-= 3 =-");
                ksession.insert(new ServicePerformanceEvent("MyService", 12));
                ksession.fireAllRules();

*/              System.out.println("-= 4 =-");
                ksession.fireAllRules(); // call firing without inserting event 
after last
fire/*
                System.out.println("---test1 end---");
        }/
Result of test12_FireAllRules():
-= 1 =-
$event.duration = 2
$events avg duration = 2.0
----------FIRED----------
-= 2 =-
$event.duration = 2
$events avg duration = 2.0
----------FIRED----------
-= 3 =-
$event.duration = 12
$events avg duration = 7.0
----------FIRED----------
$event.duration = 2
$events avg duration = 7.0
----------FIRED----------
/-= 4 =-
---test1 end---/

And what I see, in case -3- the rule analyzed both new and old facts... 
but in case -4- the rule analyzed nothing! though, as in case -3-, there
were potentially matched old facts.
I completely don't understand such behavior...
Again, what I need for last test is:
-= 1 =-
$event.duration = 2
$events avg duration = 2.0
----------FIRED----------
-= 2 =-
-= 3 =-
/$event.duration = 12
$events avg duration = 7.0/
----------FIRED----------
-= 4 =-
---test1 end---



--
View this message in context: 
http://drools.46999.n3.nabble.com/CEP-accumulate-unclear-behavior-tp4027069p4027107.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to