過去のイベントの操作

同じタイプの複数のイベントに対してテストを実行するルールを作成することができます。たとえば、一定期間に複数のイベント・インスタンスが発生したことをテストすることができます。

イベントのコレクションに対して、the number of および during などの時間演算子および集約演算子を使用します。

以下のルールは、過去 7 日間に少なくとも 3 回の購入が発生したかどうかをチェックします。このルールで処理される購入イベントは、返されるイベントの数には含まれません。このルールの条件は、4 番目のイベントを受信した時に true になります。

when a purchase event occurs
if
    the number of purchase events during the last period of 7 days is at least 3
then
    print "At least 3 purchases in a week";
警告: the last period of などの式は、時間 now を暗黙的に参照します。now が、when <event> occurs 節でイベントのタイム・スタンプを参照していない可能性があることに注意する必要があります。詳しくは、エージェントでのイベント処理を参照してください。

以下のルールは、すべての購入イベントの金額を計算します。合計金額は、このエージェントのイベントの時間境界線内にあるイベントについて計算されます。

when a purchase event occurs
if
    the total amount of all purchase events is more than 300
then
    print "Apply 10% discount on this purchase"; 
    set the loyalty status of 'the customer' to Gold; 

以下のルールは、指定された期間内に発生した同じタイプのイベントの中から、最後のイベントと以前のイベントを識別します。 definitions 部分で、このルールは、過去 20 分に発生したすべての zone enter イベントに対応する変数を定義しています。このイベント・グループ内の各イベントは、その後 previous zone enter イベントとして処理されます。 以前のイベントの後に、イベントのコレクション内にイベントが存在しないと、最新のイベントが識別されます。ルールはその後、現在のイベントの時間と以前のイベントの時間を表示します。

when a zone enter occurs , called LAST
definitions
    set 'recent zone enters' to all zone enters during the last period of 20 minutes ;
    set 'previous zone enter' to a zone enter in 'recent zone enters';
if
    there is no zone enter in 'recent zone enters'
        where this zone enter is after 'previous zone enter' ,
        and the zone id of the zone of 'previous zone enter' is "ZONE001"
then
    print "Current zone enter is: " + the timestamp of LAST ;
    print "Previous zone enter is: " + the timestamp of 'previous zone enter';