[rules-users] Comparing multiple accumulations

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jul 14 12:26:59 EDT 2009


For simplicity's sake, I'll only consider the first example, where all
transactions with amount < 0 are also Type 1.

Let P be the sum of the positive values and N (<0) the sum of the
negative values over all transactions. Then
   $charges = P
   $adjustment = 29/336*N
   intValue = -P - N

The last CE would be true if
   -P - N > P + 29/336*N
   2P < -N(1+29/336)

Since P > |N| (in the first example), clearly this cannot be true.

-W


2009/7/14 Richard Sherman <rsherman315 at hotmail.com>:
> I'm really not on form today the real data does have negatives and thus my
> example should have been as follows
>
> Account :
>    accountBalanceInPence : 70000
>    transactions :
>      - transactionDate : 2009/07/10
>        amountInPence : 50000
>        transactionCode : charge
>      - transactionDate : 2009/07/12
>        amountInPence : -45000
>        transactionCode : Type 1
>
> and
>
> Account :
>    accountBalanceInPence : 70000
>    transactions :
>      - transactionDate : 2009/07/10
>        amountInPence : 50000
>        transactionCode : charge
>      - transactionDate : 2009/07/12
>        amountInPence : -45000
>        transactionCode : Type 1
>      - transactionDate : 2009/07/13
>        amountInPence : -5000
>        transactionCode : Type 2
>
>> Date: Tue, 14 Jul 2009 17:05:21 +0200
>> Subject: Re: [rules-users] Comparing multiple accumulations
>> From: wolfgang.laun at gmail.com
>> To: rules-users at lists.jboss.org
>>
>> The second accumulate has "amountInPence < 0" but the values in your
>> data are all positive. Therefore,...
>> -W
>>
>> 2009/7/14 Richard Sherman <rsherman315 at hotmail.com>:
>> > Thanks Wolfgang,
>> >
>> > Here's the extra information as requested.
>> > Firstly the When creating the email I was removing all references to
>> > rent
>> > and missed one hence RentTransaction should read Transaction. I've also
>> > noticed that the sum($value) in the third accumulation should read
>> > sum(-$value).
>> >
>> > Below is a typical set of Transactions that should cause a message to
>> > occur.
>> >
>> > Account :
>> >   accountBalanceInPence : 70000
>> >   transactions :
>> >     - transactionDate : 2009/07/10
>> >       amountInPence : 50000
>> >       transactionCode : charge
>> >     - transactionDate : 2009/07/12
>> >       amountInPence : 45000
>> >       transactionCode : Type 1
>> >
>> > Below is a similar set of Transactions that shouldn't cause a message to
>> > occur.
>> >
>> > Account :
>> >   accountBalanceInPence : 70000
>> >   transactions :
>> >     - transactionDate : 2009/07/10
>> >       amountInPence : 50000
>> >       transactionCode : charge
>> >     - transactionDate : 2009/07/12
>> >       amountInPence : 45000
>> >       transactionCode : Type 1
>> >     - transactionDate : 2009/07/13
>> >       amountInPence : 5000
>> >       transactionCode : Type 2
>> >
>> > Thanks
>> > Richard
>> >
>> >
>> >>From: wolfgang.laun at gmail.com
>> >>To: rules-users at lists.jboss.org
>> >>Date: Tue, 14 Jul 2009 12:43:40 +0200
>> >>Subject: Re: [rules-users] Comparing multiple accumulations
>> >>
>> >>You'll have to provide one full set of $acc.transaction values
>> >>(indicating class and relevant field values) where you think the rule
>> >>should fire, but doesnt, for people to be able to check what's going
>> >>on.
>> >>
>> >>Also, it is necessary to know how the types of Account.transactions
>> >>(List<???>), Transaction and RentTransaction are related.
>> >>
>> >>-W
>> >>
>> >>On 7/14/09, Richard Sherman <rsherman315 at hotmail.com> wrote:
>> >>> First I'm new to drools and secondly where I'm working we're using
>> >>> version
>> >>> 4.0.7.
>> >>>
>> >>> I have a list of accounts and each account contains a list of
>> >>> transactions.
>> >>> I wish to accumulate charge transactions and compare them to an
>> >>> accumulation
>> >>> of payment transactions for a given time period (such as the last
>> >>> month).
>> >>> And it gets slightly more awkward in that if a payment transaction is
>> >>> of
>> >>> a
>> >>> certain type it needs to be converted from a 4 weekly figure to a
>> >>> monthly
>> >>> figure ( using / 4 / 7 * 365 / 12). I've tried to use structures as
>> >>> follows
>> >>> but they are causing the then part of the rule never to fire.
>> >>>
>> >>> rule "Account in arrears"
>> >>>     salience 10
>> >>>     no-loop
>> >>>     when
>> >>>         $acc : Account( // balance between £500 and £1000
>> >>>             accountBalanceInPence >=  50000 &&
>> >>>             accountBalanceInPence <= 100000
>> >>>         )
>> >>>
>> >>>         $s  : MessageInfo( accountNumber == $acc.accountNumber )
>> >>>
>> >>>         Number($charges : intValue) from
>> >>>                     accumulate(
>> >>>                         (Transaction(
>> >>>                                transactionDate > oneMonthAgo &&
>> >>>                                amountInPence > 0 &&
>> >>>                                $value : amountInPence)
>> >>>                        from $acc.transactions),
>> >>>                         sum($value)
>> >>>                     )
>> >>>
>> >>>         Number($adjustment : intValue) from
>> >>>             accumulate(
>> >>>                 (Transaction(
>> >>>                            transactionDate > oneMonthAgo &&
>> >>>                            amountInPence < 0 &&
>> >>>                            transactionCode == "Type 1" &&
>> >>>                            $value : amountInPence)
>> >>>                        from $acc.transactions),
>> >>>                    sum(($value / 4 / 7 * 365 / 12) - $value)
>> >>>                )
>> >>>
>> >>>
>> >>>         Number( intValue > ($charges + $adjustment)) from
>> >>>                 accumulate(
>> >>>                     (RentTransaction
>> >>>                             (transactionDate > oneMonthAgo
>> >>>                             $value : amountInPence)
>> >>>                         from $acc.transactions),
>> >>>                     sum($value)
>> >>>                 )
>> >>>
>> >>>     then
>> >>>         $s.setMessage( "Account in arrears" );
>> >>>         update($s); // flag update
>> >>> end
>> >>>
>> >>> Thanks
>> >>> Richard
>> >>>
>> >>> ________________________________
>> >>> Beyond Hotmail - see what else you can do with Windows Live. Find out
>> >>> more.
>> >>> _______________________________________________
>> >>> rules-users mailing list
>> >>> rules-users at lists.jboss.org
>> >>> https://lists.jboss.org/mailman/listinfo/rules-users
>> > ________________________________
>> > View your Twitter and Flickr updates from one place – Learn more!
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> >
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
> ________________________________
> View your Twitter and Flickr updates from one place – Learn more!
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>




More information about the rules-users mailing list