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

2011-10-31 Thread eskomk
Hi W,

Thank you, the sum in tracker approach worked fine.

Now I'll test if the update of tracker instead of creating level2 tracker is
enough for us ...

On the other hand, we are now considering moving from drools 5.1.1 to 5.2.0
or to 5.3.0.

br 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-tp3460621p3467949.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


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

2011-10-30 Thread Wolfgang Laun
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  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 ean 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 : ean(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

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

2011-10-28 Thread eskomk
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 ean 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 : ean(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 : ean(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

ean, MMMBean, FFFTracker are declared as events.

class FFFTracker:
public class FFFTracker extends Tracker
{
private ArrayList mdsBeanList = new ArrayList();

public ArrayList getMdsBeanList()
{
return mdsBeanList;
}

public void setMdsBeanLis