Nested Collect probably

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Nested Collect probably

Chris B
I have a class

Employee
(name)

Certificates
(course, year, employee)

If the employees have CCNA & CCNP from the “same” year and then if they took “CCIE or J5SE in 2000”  or “J4WS in 2001 or 2002, or 2003”
The Action should be taken if there are more than 5 such employees.

The connection between Employee and Certificates is through Certificates.employee, but I can change it to a list of certificates in Employee also if needed.

I start with
$e: Employee()
Certificate (employee == $e, course == “CCNA”, $ccnaYear : year)
Certificate (employee == $e, course == “CCNP”, $ccnpYear : year)
//this will get the years for one employee..
//now we need to get all other employees from same year..
//but we still need to make sure all certificates are from the same employee.
ArrayList( size >= 2 ) from collect(Certificate (
((course == “CCNA”, year == $ccnaYear, $e_this:employee) && (course == “CCNP”, year == $ccnpYear, employee == $e_this))
&&
(
((course == “CCIE”, year == 2000, employee == $e_this) || (course == J5SE”, year == 2000, employee == $e_this))
||
((course == “J4WS”, year == 2001, employee == $e_this) || (course == “J4WS”, year == 2002, employee == $e_this) || (course == “J4WS”, year == 2003, employee == $e_this))
)
)

This is going crazy at this stage.
First problem, - I start with one employee, and try to get his years of CCNA and CCNP
Next I am collecting Certificates instead of Employees which I should be collecting and checking the length of the employees.

I think something like this will help me
http://blog.athico.com/2007/06/chained-from-accumulate-collect.html
But I am unable to convert it into my usecase.

Please help.
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Nested Collect probably

laune
Due to imprecise wording, this may or may not be what you want. The rule fires,
if there are 5 or more Employees, each of them with the property that
   - the employee has visited CCNA in year X
   - the employee has visited CCNP in year X
   - the employee has visited CCIE or J5SE in 2000 OR
     has visited J4WS in 2001 or 2002 or 2003 (OR both)

(There is no relation between the years X of different employees.)

rule findCombi
when
    accumulate(
    Certificate( course == "CCNA", $e: employee, $y: year )
    and
    Certificate( course == "CCNP", employee == $e, year == $y )
    and
    Certificate( employee == $e,
                 ((course == "CCIE" || == "J5SE" ) && year == 2000 )
                  ||
                  course == "J4WS" && year == 2001 || == 2002 || == 2003 );
    $es: collectSet( $e ); $es.size() >= 5 )
then
    System.out.println( "more than 5" );
end



On 26/05/2014, Chris B <[hidden email]> wrote:

> I have a class
>
> Employee
> (name)
>
> Certificates
> (course, year, employee)
>
> If the employees have CCNA & CCNP from the "same" year and then if they took
> "CCIE or J5SE in 2000"  or "J4WS in 2001 or 2002, or 2003"
> The Action should be taken if there are more than 5 such employees.
>
> The connection between Employee and Certificates is through
> Certificates.employee, but I can change it to a list of certificates in
> Employee also if needed.
>
> I start with
> $e: Employee()
> Certificate (employee == $e, course == "CCNA", $ccnaYear : year)
> Certificate (employee == $e, course == "CCNP", $ccnpYear : year)
> //this will get the years for one employee..
> //now we need to get all other employees from same year..
> //but we still need to make sure all certificates are from the same
> employee.
> ArrayList( size >= 2 ) from collect(Certificate (
> ((course == "CCNA", year == $ccnaYear, $e_this:employee) && (course ==
> "CCNP", year == $ccnpYear, employee == $e_this))
> &&
> (
> ((course == "CCIE", year == 2000, employee == $e_this) || (course == J5SE",
> year == 2000, employee == $e_this))
> ||
> ((course == "J4WS", year == 2001, employee == $e_this) || (course == "J4WS",
> year == 2002, employee == $e_this) || (course == "J4WS", year == 2003,
> employee == $e_this))
> )
> )
>
> This is going crazy at this stage.
> First problem, - I start with one employee, and try to get his years of CCNA
> and CCNP
> Next I am collecting Certificates instead of Employees which I should be
> collecting and checking the length of the employees.
>
> I think something like this will help me
> http://blog.athico.com/2007/06/chained-from-accumulate-collect.html
> But I am unable to convert it into my usecase.
>
> Please help.
> Thanks
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Nested-Collect-probably-tp4029681.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: Nested Collect probably

Chris B
This post was updated on .
In reply to this post by Chris B
Actually it is a event from an application usecase
Thanks for your reply and I think I am very close with your help.
This rule is giving error Line 99:5 mismatched input 'or' in rule "usecase-test"]

rule "usecase-test"
    when
    $e0 : Event ()
    ParsedValue(event == $e0, ruleId == "0", varName == "V0_1", $e0_V0_1_varStringValue : varStringValue)
    ParsedValue(event == $e0, ruleId == "0", varName == "V0_2", $e0_V0_2_varStringValue : varStringValue)
    accumulate(
    ParsedValue( ruleId == "0", varName == "V0_1",  varStringValue == $e0_V0_1_varStringValue, $e : event )
    and
    ParsedValue( event == $e, ruleId == "0", varName == "V0_2", varStringValue == $e0_V0_2_varStringValue )
    and
    (
    (
    ParsedValue( event == $e, ruleId == "1", varName == "V1_1", varStringValue == "X1_1")
    and
    ParsedValue( event == $e, ruleId == "1", varName == "V1_2", varStringValue == "X1_2")
    )
    or [<<Line 99]
    (
    ParsedValue( event == $e, ruleId == "2", varName == "V2_1", varStringValue == "X2_1")
    and
    ParsedValue( event == $e, ruleId == "2", varName == "V2_2", varStringValue == "X2_2")
    )
    );
    $es: collectSet( $e );
    $es.size() >= 5 )
   
        then
        System.out.println( "usecase-test" + $es.size());
end


The Event comes from application and is parsed for values.
The event from same application will have the same values for ruleId=0, varName-V0_1 and V0_2
So any event with same values for V0_1 and V0_2 is coming from same application.

The rule says if from same application
you have values which has this combination
ruleId == "1", varName == "V1_1", varStringValue == "X1_1"
ruleId == "1", varName == "V1_2", varStringValue == "X1_2"
or this combination
ruleId == "2", varName == "V2_1", varStringValue == "X2_1"
ruleId == "2", varName == "V2_2", varStringValue == "X2_2"
or this combination say
ruleId == "3", varName == "V3_1", varStringValue == "X3_1"
ruleId == "3", varName == "V3_2", varStringValue == "X3_2"
ruleId == "3", varName == "V3_3", varStringValue == "X3_3"

In pure english it is
First I have to identify if I am dealing with events from same application
This is by comparing (2) parsed values V0_1 and V0_2. If they are same across events .. then it having same source.
Next lets check for other conditions..
From Rule 1.. I want to check values of V1_1 and V1_2, if there is a issue
From Rule 2.. I want to check values of V2_1 and V2_2, if there is a issue

Now I do not want to raise exception as soon as condition is met.. since the problem can occur and can be ignored. But if it happens more than 5 times from the same source, then I want to raise an alert.
Reply | Threaded
Open this post in threaded view
|

Re: Nested Collect probably

Chris B
I tried a simpler version

rule "usecase2-test2"
    when
    $e0 : Event ()
    ParsedValue(event == $e0, ruleId == "0", varName == "V0_1", $e0_V0_1_varStringValue : varStringValue)
    ParsedValue(event == $e0, ruleId == "0", varName == "V0_2", $e0_V0_2_varStringValue : varStringValue)
    accumulate(
    ParsedValue( ruleId == "0", varName == "V0_1",  varStringValue == $e0_V0_1_varStringValue, $e:event )
    and
    ParsedValue( event == $e, ruleId == "0", varName == "V0_2", varStringValue == $e0_V0_2_varStringValue )
    and
    ParsedValue( event == $e, ruleId == "1", varName == "V1_1", varStringValue == "X1_1")
    and
    ParsedValue( event == $e, ruleId == "1", varName == "V1_2", varStringValue == "X1_2");
    $es: collectSet( $e );
    $es.size() >= 2 )
   
        then
        System.out.println( "usecase2" + $es.size());
end

but when I insert 2 events with same source (meaning same values with (ruleId == "0", varName == "V0_1") and (ruleId == "0", varName == "V0_2") and right values for rule1 variables
then also it works with one single event and never satisfies this condition.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Nested Collect probably

laune
In reply to this post by Chris B
It's not possible to use the conditional element "or" inside an
accumulate. (Reading up on the "or" CE should give you an idea why.)
And that's why I
used a boolean expression as a constraint within the third pattern.

-W

On 26/05/2014, Chris B <[hidden email]> wrote:

> Actually it is a event from an application usecaseThanks for your reply and
> I
> think I am very close with your help.This rule is giving error Line 99:5
> mismatched input 'or' in rule "usecase-test"]rule "usecase-test"    when
> $e0 : Event ()    ParsedValue(event == $e0, ruleId == "0", varName ==
> "V0_1", $e0_V0_1_varStringValue : varStringValue)    ParsedValue(event ==
> $e0, ruleId == "0", varName == "V0_2", $e0_V0_2_varStringValue :
> varStringValue)    accumulate(     ParsedValue( ruleId == "0", varName ==
> "V0_1",  varStringValue == $e0_V0_1_varStringValue, $e : event )     and
>
> ParsedValue( event == $e, ruleId == "0", varName == "V0_2", varStringValue
> == $e0_V0_2_varStringValue )     and     (     (     ParsedValue( event ==
> $e, ruleId == "1", varName == "V1_1", varStringValue == "X1_1")     and
>
> ParsedValue( event == $e, ruleId == "1", varName == "V1_2", varStringValue
> == "X1_2")     )     or *[<     (     ParsedValue( event == $e, ruleId ==
> "2", varName == "V2_1", varStringValue == "X2_1")     and
> ParsedValue(
> event == $e, ruleId == "2", varName == "V2_2", varStringValue == "X2_2")
>
> )    );    $es: collectSet( $e );     $es.size() >= 5 )     then
> System.out.println( "usecase-test" + $es.size());endThe Event comes from
> application and is parsed for values.The event from same application will
> have the same values for ruleId=0, varName-V0_1 and V0_2So any event with
> same values for V0_1 and V0_2 is coming from same application.The rule says
> if from same applicationyou have values which has this combinationruleId ==
> "1", varName == "V1_1", varStringValue == "X1_1"ruleId == "1", varName ==
> "V1_2", varStringValue == "X1_2"or this combinationruleId == "2", varName
> ==
> "V2_1", varStringValue == "X2_1"ruleId == "2", varName == "V2_2",
> varStringValue == "X2_2"or this combination sayruleId == "3", varName ==
> "V3_1", varStringValue == "X3_1"ruleId == "3", varName == "V3_2",
> varStringValue == "X3_2"ruleId == "3", varName == "V3_3", varStringValue ==
> "X3_3"In pure english it isFirst I have to identify if I am dealing with
> events from same applicationThis is by comparing (2) parsed values V0_1 and
> V0_2. If they are same across events .. then it having same source.Next
> lets
> check for other conditions..From Rule 1.. I want to check values of V1_1
> and
> V1_2, if there is a issueFrom Rule 2.. I want to check values of V2_1 and
> V2_2, if there is a issueNow I do not want to raise exception as soon as
> condition is met.. since the problem can occur and can be ignored. But if
> it
> happens more than 5 times from the same source, then I want to raise an
> alert.
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Nested-Collect-probably-tp4029681p4029703.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users