[jboss-jira] [JBoss JIRA] Created: (JBRULES-2823) Sliding window of length type does not accumulate/collect correctly with multiple objects in constraints

Mary Ellen Bench (JIRA) jira-events at lists.jboss.org
Wed Dec 8 11:17:31 EST 2010


Sliding window of length type does not accumulate/collect correctly with multiple objects in constraints
--------------------------------------------------------------------------------------------------------

                 Key: JBRULES-2823
                 URL: https://jira.jboss.org/browse/JBRULES-2823
             Project: Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: All
    Affects Versions: 5.1.1.FINAL
         Environment: Windows XP Java
            Reporter: Mary Ellen Bench
            Assignee: Mark Proctor


When using sliding windows and a constraint that filters by an input object, it does not properly create a window for each constraints, instead one window shared by both rules which leads to undesirable affects (ie a shared sliding window filtered down to less #s).  

Please also see the drools post:
http://drools-java-rules-engine.46999.n3.nabble.com/DROOLS-problem-with-sliding-windows-tt2039892.html

It is best to show the rule and output to explain it:

Background:
"I have been working with sliding windows, and they do not appear to work properly in DROOLS 5.1.1 or I am misunderstanding how they work.  My goal is to have the last X number of samples averaged or summed.  I've tried two mechanism, the accumulate/from, and the collect, and they both behave similarly wrong (or different than I expect), but this was much easier to follow so I've posted it for help. 

The way I have the code structured, I receive values for two nodes, 1 and 2 every second or two, which each contain random values.  After each value received I pass the CPUReportEvent and fire the rules.  The results are bizarre.  Sometimes it resets back to 1 count, sometimes it keeps the value to the previous one.  It seems to also fire both rules when really only one should've been triggered?  Can someone explain the results and how to adjust it to work for my specs? Thanks! 

I can't see into the accumulate function, so here's the collect function, but they perform identically. "





package com.sample 
  
import com.sample.DroolsTest.Message; 
import com.sample.DroolsInput; 
import com.sample.CPUReportEvent; 
import com.ComEntity; 
import java.util.Iterator 
import java.util.ArrayList 


declare CPUReportEvent 
  // declare a fact type as an event, default is 'fact' 
  @role( event ) 
end 

rule "collect with length window" 
no-loop true 
when 
    $comEntity : ComEntity() 
    $list : ArrayList ()  from collect( 
              CPUReportEvent(comEntity == $comEntity) 
                   over window:length(3) ) 
then 
    System.out.print("Entity " + $comEntity.getName() + " fired of count " + $list.size() + " value"); 
    
     Double sum = 0.0; 
     Double count = 0.0; 
     for(Iterator it = $list.iterator();it.hasNext();) { 
            CPUReportEvent report = (CPUReportEvent) it.next(); 
            System.out.print(" " + report.getAmount()); 
            sum = sum + report.getAmount(); 
            count = count + 1.0; 
     } 
    
    if (count > 0.0) 
    { 
        Double avg = (sum / count); 
        System.out.print(" - Sum " + sum + " avg " + avg + " count " + count); 
    } 
    
    System.out.println(); 
    
end 


RESULTS: 
Node1 : 7.0 
Entity Node2 fired of count 0 value 
Entity Node1 fired of count 1 value 7.0 - Sum 7.0 avg 7.0 count 1.0 
Node2 : 94.0 
Entity Node2 fired of count 1 value 94.0 - Sum 94.0 avg 94.0 count 1.0 
Node1 : 43.0 
Entity Node1 fired of count 2 value 7.0 43.0 - Sum 50.0 avg 25.0 count 2.0 
Node2 : 85.0 
Entity Node2 fired of count 2 value 94.0 85.0 - Sum 179.0 avg 89.5 count 2.0 
Entity Node1 fired of count 1 value 43.0 - Sum 43.0 avg 43.0 count 1.0 
Node1 : 88.0 
Entity Node2 fired of count 1 value 85.0 - Sum 85.0 avg 85.0 count 1.0 
Entity Node1 fired of count 2 value 43.0 88.0 - Sum 131.0 avg 65.5 count 2.0 
Node2 : 47.0 
Entity Node2 fired of count 2 value 85.0 47.0 - Sum 132.0 avg 66.0 count 2.0 
Entity Node1 fired of count 1 value 88.0 - Sum 88.0 avg 88.0 count 1.0 
Node1 : 39.0 
Entity Node2 fired of count 1 value 47.0 - Sum 47.0 avg 47.0 count 1.0 
Entity Node1 fired of count 2 value 88.0 39.0 - Sum 127.0 avg 63.5 count 2.0 
Node1 : 0.0 
Entity Node1 fired of count 2 value 39.0 0.0 - Sum 39.0 avg 19.5 count 2.0 


-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list