[rules-users] 2 levels of sorting / distribution in Drools (Date + Proportionate)

Nimesh Muley nimeshm at mastek.com
Tue Nov 25 01:14:06 EST 2008


Hi,

Here is the solution that worked. I am not sure why exactly did it work :-(. The below solution is tampered little bit for the name changes etc. But the gist is the same. Hope it helps.

Had to consider already vested amount because that needs to be added to find the right proportion.

rule "LIFO And Proportionate"
dialect "java"
salience 101
      when
            $product : Product($productSeq : productSeq, vestedAmt > 0)
            $tranche : Tranche(productSeq == $productSeq, $maintrancheSeq : trancheSeq, $trancheValue : trancheValue > trancheVestedAmt, $trancheCreationDate : trancheCreationDt)

            not Tranche(claimProductSeq == $claimProductSeq, trancheSeq != $maintrancheSeq, trancheValue > trancheVestedAmt, trancheCreationDt > $trancheCreationDate )

            $totalTrancheAmount : Double () from accumulate ( Tranche(claimProductSeq == $claimProductSeq, $childtrancheValue : trancheValue > 0, trancheCreationDt == $trancheCreationDate), sum( $childtrancheValue ))

            $totalTrancheVestedAmount : Double () from accumulate ( Tranche(claimProductSeq == $claimProductSeq, trancheValue > 0, trancheCreationDt == $trancheCreationDate, $trancheVestedAmt : trancheVestedAmt), sum( $trancheVestedAmt ))
      then
            // Vesting should happen based on proportionate if the dates were matched otherwise based on which amount is greater.
            // Proportionate = $trancheValue / $ totalTrancheAmount
            vestTranche($product, $tranche, $totalTrancheAmount, $totalTrancheVestedAmount);
            update ($tranche);
            update ($product);
end

Thanks.
Regards,
- Nimesh

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Ajay.Gautam at rbsgc.com
Sent: Monday, November 24, 2008 7:48 PM
To: rules-users at lists.jboss.org
Subject: RE: [rules-users] 2 levels of sorting / distribution in Drools (Date + Proportionate)

The solution, if posted to the group, may help others avoid similar mistakes.
If possible, can you please post your solution?

Thanks

Aj



-----Original Message-----
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Nimesh Muley
Sent: Monday, November 24, 2008 8:19 AM
To: 'Rules Users List'
Subject: RE: [rules-users] 2 levels of sorting / distribution in Drools (Date + Proportionate)
Hi,

I have been able to solve this. Was an issue the way I had written my rule.

Thanks.
Regards,
- Nimesh

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Nimesh Muley
Sent: Monday, November 24, 2008 11:31 AM
To: 'Rules Users List'
Subject: RE: [rules-users] 2 levels of sorting / distribution in Drools (Date + Proportionate)

Hi,

Oops. A slight typo. The objects in the RHS were "$tranche" and "$product". I have modified in the mail below.

Regards,
- Nimesh

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Nimesh Muley
Sent: Monday, November 24, 2008 11:24 AM
To: 'Rules Users List'
Subject: [rules-users] 2 levels of sorting / distribution in Drools (Date + Proportionate)

Hi,

I have tried to implement 2 levels (nested) of sorting / distribution (Date and Proportionate) in Drools and failed :-(. I could not accomplish when the second level was 'proportionate'. Let me clear the terms before I give the example.

2 level --> The criteria chosen for the first level is same then only apply the second level criteria. In SQL terms it would be "order by date, avg price". The first level was Date.
Proportionate --> Proportionate means distribute the items / amount as proportion to what it contains.

The rule that is mentioned below did not work. There was no issue in implementing sequence number as second priority.

What happens is that the "$totalTrancheAmount" does not include the facts (Tranche objects) that were already matched or being matched. Basically the sum is always of the facts that are 'yet' to be matched.

Also what is needed is a fact understanding whether Tranche got selected as a "proportionate" one or only based on date. For this we can use if ($totalTrancheAmount > 0) condition on "then" side I suppose.

Is there any way of getting hold of all facts which taking sum of childTrancheValue?

rule "LIFO And Proportionate"
dialect "java"
salience 101
      when
            $product : Product($productSeq : productSeq, vestedAmt > 0)
            $tranche : Tranche(productSeq == $productSeq, $maintrancheSeq : trancheSeq, $trancheValue : trancheValue > trancheVestedAmt, $trancheCreationDate : trancheCreationDt)
            not Tranche(claimProductSeq == $claimProductSeq, trancheSeq != $maintrancheSeq, trancheValue > trancheVestedAmt, trancheCreationDt > $trancheCreationDate )
            and
            (
                  $totalTrancheAmount : Double () from accumulate ( Tranche($childtrancheValue : trancheValue, trancheCreationDt == $trancheCreationDate, trancheValue > trancheVestedAmt), sum( $childtrancheValue ))
                  or
                  eval(true)
            )
      then
            // Vesting should happen based on proportionate if the dates were matched otherwise based on which amount is greater.
            // Proportionate = $trancheValue / $ totalTrancheAmount
            vestTranche($product, $tranche);
            System.out.println("$totalTrancheAmount : " + $ totalTrancheAmount);
            update ($tranche);
            update ($product);
end
Thanks.
Regards,
- Nimesh



MASTEK LTD.
Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






MASTEK LTD.
Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






MASTEK LTD.
Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




MASTEK LTD.
Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081125/297a0d47/attachment.html 


More information about the rules-users mailing list