[rules-users] sliding window problem

grules gshrestha at tmghealth.com
Tue Mar 11 14:39:54 EDT 2014


I think you have to follow the structure of accumulate function. Like
<result pattern> from accumulate( <source pattern>,
                                  init( <init code> ),
                                  action( <action code> ),
                                  reverse( <reverse code> ), (optional)
                                  result( <result expression> ) )

examples are:
when
    $order : Order()
    $total : Number( doubleValue > 100 )
             from accumulate( OrderItem( order == $order, $value : value ),
                              init( double total = 0; ),
                              action( total += $value; ),
                                     result( total ) )
then
    # apply discount to $order
end

As I understand from your code,

1.  Make List for Event class, because accumulate will loop through the elements of List<Event>

2.  Init (write action codes, i.e. initialize value so you will find how many time it got looped)

3.  Write code inside the block of action(//code here) and

4.  Update it in result block i.e. result(//update here);

Being said, follow the structure 1) init, 2) action, 3) result as above..




From: Sandhya Sree [via Drools] [mailto:ml-node+s46999n4028639h52 at n3.nabble.com]
Sent: Tuesday, March 11, 2014 1:51 PM
To: Gopu Shrestha
Subject: [rules-users] sliding window problem


i have a class called Event which has the following members { name, source, timestamp } with getters ,setters and constructor. i have a rule file which creates Event objects whenever a file is added / deleted in a particular folder. the rule file is as follows



rule "new file"

when

$p: RuleContext( $old : getOldContext().getContainedFiles(), $new :getNewContext().getContainedFiles())

RuleContext( $old != $new)

accumulate( $s : Object( this not memberOf $old ) from $new, $plus : collectList( $s ) )

events : Object() from $plus;

then

Event event = new Event("new file added",$p.getOldContext().getParent(),new Date());

end





rule " file deleted"

when

$p: RuleContext( $old : getOldContext().getContainedFiles(), $new:getNewContext().getContainedFiles())

RuleContext( $old != $new)

accumulate( $t : Object( this not memberOf $new ) from $old, $mins : collectList( $t ) )

events : Object() from $mins;

then

Event event = new Event("file deleted",$p.getOldContext().getParent(),new Date());

end

(do not confuse with RuleContext and other unknown identifiers.. they r just related with other classes in the project.. these two rules just works fine )..i need to use a sliding time window and create another event if the number of file additions are > 5 over the past 1 minute. my rule file is :



declare Event

@role( event )

end





rule "More than 5 additions"

when

Number(intValue > 5)

from    accumulate( $tick : Event ( name == "new file added" ) over window:time( 1m ),
        count( $tick ) ) )

then

    System.out.println("too many additions");

end

i have enabled stream mode processing too.. but it doesnt seem to work. what could be the problem?

_______________________________________________
rules-users mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4028639&i=0>
https://lists.jboss.org/mailman/listinfo/rules-users
________________________________
If you reply to this email, your message will be added to the discussion below:
http://drools.46999.n3.nabble.com/rules-users-sliding-window-problem-tp4028639.html
To start a new topic under Drools: User forum, email ml-node+s46999n47000h43 at n3.nabble.com<mailto:ml-node+s46999n47000h43 at n3.nabble.com>
To unsubscribe from Drools, click here<http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=46999&code=Z3NocmVzdGhhQHRtZ2hlYWx0aC5jb218NDY5OTl8LTQ5MTIwOTgwMg==>.
NAML<http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://drools.46999.n3.nabble.com/RE-rules-users-sliding-window-problem-tp4028640.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140311/6a7ec863/attachment-0001.html 


More information about the rules-users mailing list