0

I defined a class which acts as event to the rule engine

It has the following members 1. phone number 2. latitude 3. longitude

How do I formulate a rule wherein 1. The rule counts the number of distinct people in the same location 2. Same person if crossing the same location more than once during a 1 minute interval should be counted only as one and should not be duplicated

I made the below rule but it doesn't seem to be working

import locationbasedservices.LocationEvent;

declare LocationEvent
  @role(event)
  @expires(1m)
end

rule "footfallcount"
when
  LocationEvent ( $msisdn : msisdn )
  $footfallcnt : Number(intValue > 0)
    from accumulate( LocationEvent(latitude=="77.77", longitude=="77.77",
                                   age>31 && <40, arpu>40.00, gender=="MALE")
                       from entry-point LocationSvc,
  not ArrayList( size >= 2 )
    from collect( LocationEvent( msisdn == $msisdn )
                    from entry-point LocationSvc),
          count(1))
then
  System.out.println("Footfall: " + $footfallcnt);
end

Can someone help?

Regards Subbu

laune
  • 31,114
  • 3
  • 29
  • 42
subbu
  • 65
  • 6
  • This is a case where a custom accumulate operation with inline custom code is advisable. See the Drools documentation - it's really not very difficult. – laune Feb 18 '14 at 11:37
  • Can u provide me a sample rule so that it is bit easy for me to understand as I am very new to drools fusion and the doc is a bit confusing for me – subbu Feb 24 '14 at 08:50

1 Answers1

0

This is what I had in mind:

$m2e: Map( $size: size )
        from accumulate ( $le: LocationEvent ( latitude == "77.77", longitude == "77.77",
                                               age > 31 && < 40, arpu > 40.00,
                                               gender == "MALE", $msisdn : msisdn )
                                 over window:time( 1m ),
                          init( Map m2e = new HashMap(); ),
                          action( m2e.put( $msisdn, $le ); ),
                          result( m2e ) )

Note carefully what the Drools manual says in the section on accumulate: It is better practice to develop an accumulate function in Java code, implementing org.drools.core.runtime.rule.TypedAccumulateFunction and running this using simple syntax.

laune
  • 31,114
  • 3
  • 29
  • 42