[rules-users] Does window:length work in Drools version 5.1.1 ?

Wolfgang Laun wolfgang.laun at gmail.com
Sun Oct 30 04:42:33 EDT 2011


There *may* be a problem in 5.1.1 due to using window:length on objects
produced
by "from" when these objects aren't facts.

Since you discard Tracker facts as soon as the 6th MMMBean arrives I
suggest that you calculate the sum when you add another Bean to the
Tracker, and store the sum in the Tracker, which needs to be updated anyway.

Also, I don't see the need for creating a Tracker in order to advance it to
level two; a simple update of the Tracker would work just as well.

Cheers
Wolfgang



On 28 October 2011 12:39, eskomk <esko.hujanen at ebsolut.fi> wrote:

> Drools-expert 5.1.1
>
> Does window:length work in Drools version 5.1.1 ?
>
> It seems that "over window:length( 5 )" in rule "PossibleFFF_launch_level1"
> does not work.
> It seems that it returns only the last MMMBean added in trackers in rules
> "PossibleFFF_Level1_update_tracker_count" and
> "PossibleFFF_Level2_update_tracker_count".
>
> The idea here is that trackers keep count of how many MMMBeans have entered
> the system, after incoming BBBBean with bbbEmpty == true have initiated the
> tracking (PossibleFFF).
> App domain specific operations are launched if there is no active counts
> (actCount) in a series of MMMBeans ("PossibleFFF_launch_level1" and
> "PossibleFFF_launch_level2").
> actCount is an integer but accumulate function sum apparently returns a
> floating point number, hence the check "doubleValue < 0.5".
> Rules "PossibleFFF_kill_tracker_with_bbb" and
> "PossibleFFF_kill_tracker_with_count" are to retract the trackers from
> memory, so ending the tracking.
> Rule "PossibleFFF_kill_tracker_with_bbb" kills this profileID's tracker if
> bbbEmpty == false.
> Rule "PossibleFFF_kill_tracker_with_count" kills tracker if count > 5,
> count
> indicating that no operations were launched ("PossibleFFF_launch_level1"
> and
> "PossibleFFF_launch_level2").
>
> Problem is, that the condition
>    $theSum : Number(doubleValue < 0.5) from accumulate(
>        // MMMBean( $actCount : activeCount) over window:length( 5 ) from
> $tracker.mdsBeanList,
>        MMMBean( $actCount : activeCount) over window:length( 5 ) from
> $tracker.getMdsBeanList(),
>        sum( $actCount ) )
> in rules
> "PossibleFFF_launch_level1" and "PossibleFFF_launch_level2"
> does not seem to work as expected.
> I expected that the sum would be calculated from field MMMBean.actCount
> over
> all MMMBean members of list $tracker.mdsBeanList.
> It seems that sum returns only the actCount of last MMMBean which was
> inserted in $tracker.mdsBeanList.
>
> Is there something wrong with the rules ?
>
> Rules are like these:
>
> // RULES -->
> rule "PossibleFFF" dialect "mvel"
>
> when
>    $bsb : BBBBean(bbbEmpty == true)
>    not FFFTracker(profileID == $bsb.profileID)
> then
>    FFFTracker $tracker = new FFFTracker();
>    $tracker.level = 1;
>    $tracker.count = 0;
>
>    $tracker.profileID = $bsb.profileID;
>    $tracker.location = $bsb.location;
>
>    retract($bsb);
>
>    $tracker.sensorBean = $bsb;
>
>    insert($tracker);
> end
>
>
> rule "PossibleFFF_Level1_update_tracker_count" dialect "mvel"
>
> when
>    $tracker : FFFTracker(level == 1)
>    $mds : MMMBean(profileID == $tracker.profileID, this after $tracker)
> then
>    drools.retract($mds);
>
>    $tracker.addMdsBean($mds);
>    $tracker.count = $tracker.count + 1;
>    drools.update($tracker);
> end
>
>
> rule "PossibleFFF_launch_level1" dialect "mvel"
>
> when
>    $tracker : FFFTracker(level == 1, count == 5, $prof : profileID)
>    $theSum : Number(doubleValue < 0.5) from accumulate(
>        // MMMBean( $actCount : activeCount) over window:length( 5 ) from
> $tracker.mdsBeanList,
>        MMMBean( $actCount : activeCount) over window:length( 5 ) from
> $tracker.getMdsBeanList(),
>        sum( $actCount ) )
> then
>    retract($tracker);
>
>    FFFTracker $tracker2 = new FFFTracker();
>    $tracker2.level = 2;
>
>    $tracker2.profileID = $tracker.profileID;
>    $tracker2.location = $tracker.location;
>    $tracker2.sensorBean = $tracker.sensorBean;
>    $tracker2.count = 0;
>
>    // Tracker2 is set to track further conditions
>    insert($tracker2);
>
>    // launch the app domain specific things
> end
>
> rule "PossibleFFF_Level2_update_tracker_count" dialect "mvel"
>
> when
>    $tracker : FFFTracker(level == 2)
>    $mds : MMMBean(profileID == $tracker.profileID, this after $tracker)
> then
>    drools.retract($mds);
>
>    $tracker.addMdsBean($mds);
>    $tracker.count = $tracker.count + 1;
>    drools.update($tracker);
> end
>
>
> rule "PossibleFFF_launch_level2" dialect "mvel"
>
> when
>    $tracker : FFFTracker(level == 2, count == 5, $prof : profileID)
>    $theSum : Number(doubleValue < 0.5) from accumulate(
>        // MMMBean( $actCount : activeCount, profileID == $prof) over
> window:length( 5 ) from $tracker.mdsBeanList,
>        MMMBean( $actCount : activeCount, profileID == $prof) over
> window:length( 5 ) from $tracker.getMdsBeanList(),
>        sum( $actCount ) )
> then
>    retract($tracker);
>
>    // launch the app domain specific things
> end
>
>
> rule "PossibleFFF_kill_tracker_with_bbb" dialect "mvel"
>
> when
>    $tracker : FFFTracker($prof : profileID, $loc : location)
>    $bsb : BBBBean(profileID == $prof, location == $loc, bbbEmpty == false,
> this after $tracker)
> then
>    retract($tracker);
> end
>
>
> rule "PossibleFFF_kill_tracker_with_count" dialect "mvel"
>
> when
>    $tracker : FFFTracker(count > 5, $prof : profileID)
> then
>    retract($tracker);
> end
> // <-- RULES
>
> BBBBean, MMMBean, FFFTracker are declared as events.
>
> class FFFTracker:
> public class FFFTracker extends Tracker
> {
>    private ArrayList<MMMMBean> mdsBeanList = new ArrayList<MMMMBean>();
>
>    public ArrayList<MMMBean> getMdsBeanList()
>    {
>        return mdsBeanList;
>    }
>
>    public void setMdsBeanList(ArrayList<MMMBean> pmdsbeanlist)
>    {
>        this.mdsBeanList = pmdsbeanlist;
>    }
>
>    public void addMdsBean(MMMBean pbean)
>    {
>        this.mdsBeanList.add(pbean);
>    }
> }
>
> class Tracker:
> public class Tracker
> {
>    private long profileID = 0;
>    private short location = 0;
>    private int level = 0;
>    private int count = 0;
>    private ASensorBean sensorBean = null; // AsensorBean is an abstract
> class from which BBBBean and MMMBean are derived
>
>    // getters and setters goes here
> }
>
> Best Regards,
> Esko
> ------
> Esko Hujanen
> www.ebsolut.fi
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Does-window-length-work-in-Drools-version-5-1-1-tp3460621p3460621.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111030/81bd1b7b/attachment.html 


More information about the rules-users mailing list