지난 이벤트에 대한 오퍼레이션

동일한 유형의 여러 이벤트에 대해 테스트를 실행하는 규칙을 쓸 수 있습니다. 예를 들어, 특정 기간 동안 여러 이벤트 인스턴스가 발생했음을 테스트할 수 있습니다.

이벤트의 콜렉션에 대해 시간 및 집계 연산자(예: the number of 및 during)를 사용합니다.

다음 규칙은 지난 7일 동안 최소한 세 번의 구매가 발생했는지 여부를 확인합니다. 이 규칙에서 처리되는 구매 이벤트는 리턴된 이벤트의 수에 포함되지 않습니다. 네 번째 이벤트를 수신할 때 규칙의 조건은 참이 됩니다.

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';