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

Ajay.Gautam at rbsgc.com Ajay.Gautam at rbsgc.com
Mon Nov 24 09:18:05 EST 2008


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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



********************************************************************
This message (including any attachments) is confidential and/or
privileged. It is to be used by the intended recipients only. If
you have received it by mistake please notify the sender by return
e-mail and delete this message from your system. Any unauthorized
use or dissemination of this message in whole or in part is
strictly prohibited. Please note that e-mails are inherently
insecure and susceptible to change. The Royal Bank of Scotland
Group, plc ("RBS") and its US subsidiaries, and affiliates and
subsidiary undertakings, including but not limited to, RBS plc New
York and Connecticut Branches, RBS Greenwich Capital Markets, Inc.,
ABN AMRO Bank N.V. New York and Chicago Branches and, ABN AMRO
Inc., Citizens Financial Group, Inc. and RBS Citizens, N.A., shall
not be liable for the improper or incomplete transmission of the
information contained in this communication or Attachment nor for
any delay in its receipt or damage to your system. RBS does not
guarantee that the integrity of this communication has been
maintained nor that this communication is free of viruses,
interceptions or interference. RBS and its subsidiaries and
affiliates do not guarantee the accuracy of any email or
attachment, that an email will be received or that RBS or its
affiliates and subsidiaries will respond to an email.

RBS makes no representations that any information contained in this
message (including any attachments) are appropriate for use in all
locations or that transactions, securities, products, instruments
or services discussed herein are available or appropriate for sale
or use in all jurisdictions, or by all investors or counterparties.
Those who utilize this information do so on their own initiative
and are responsible for compliance with applicable local laws or
regulations.********************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081124/08e16563/attachment.html 


More information about the rules-users mailing list