1

I need some advice on how to write a rule for the following case. First, here are my facts:

SessionClock($now : new Date(getCurrentTime()))

ClickEvent( $userId : userId, $productId : productId, $event : "FAVORITE" / "REMOVE_FAVORITE" )

Product($id : id, $endDate : endDate)

Purchase ( $userId : userId, $purchasedProducts : purchasedProducts )

where purchasedProducts is a List of:

PurchasedProduct( $id : id, $price : price)

Now I would like to send a notification everytime at a particular hour:

  1. Today is the endDate of a product and
  2. User has favorited but hasn't unfavorited the product (from ClickEvent) and
  3. User hasn't bought the product (from Purchase) and
  4. Include all such products in one notification (basically I need to collect products)

I appreciate any help on this.

Thanks in advance!

Hasan Can Saral
  • 2,950
  • 5
  • 43
  • 78
  • That's all a bit hazy. What is the format of the endDate, e.g., is it a Date with h:m:s=0:0:0, i.e. midnight? Are these ClickEvent facts kept since the beginning of Time? Do you want this per user or over all users? – laune Mar 13 '17 at 15:14
  • @laune `endDate` is a Java `Date` object, doesn't have to necessarily be midnight. `ClickEvent`s don't expire, at least not before `Product`s does. I am trying to achieve this per user. – Hasan Can Saral Mar 13 '17 at 15:56
  • I've proposed a solution "per user". The logic for determining the expiry date can/should be hidden in a function. – laune Mar 13 '17 at 16:21

1 Answers1

1

It may be a good idea to do this in steps

rule "interesting user/product"
when
  SessionClock( $now: time )
  Purchase( $uid: userId, $purchases: purchasedProducts )
  ClickEvent( userId == $uid, $pid: productId,
              event == "FAVORITE" )
  not ClickEvent( userId == $uid, productId == $pid,
                  event == "REMOVE_FAVORITE" )     
  Product( id == $pid, $endDate: endDate )
  eval( endDateIsToday( $now, $endDate ) )
then
end

rule "make Collection" extends "interesting user/product"
when
  not Collection( userId == $uid )
then
  insert( new Collection( $uid ) )
end

rule "fill Collection" extends "interesting user/product"
when
  $coll: Collection( userId == $uid, products not contains $pid )
then
  modify( $coll ){ addProduct( $pid ) }
end

A third rule, running with reduced salience, can do the notification.

Edit To clarify, endDateIsToday is a (DRL) function or static method. Collection is a class you need to define with a couple of fields: userId and set of product ids.

laune
  • 31,114
  • 3
  • 29
  • 42