규칙의 공유 집계에서 값 가져오기
규칙에서 공유 집계 값을 사용하여 조건을 평가하고 결정합니다.
공유 집계의 값은 특정 시점 또는 특정 기간에 대해 액세스할 수 있으며 이를 규칙 논리에 사용할 수 있습니다. 예를 들어, 조건문 및 계산에서 공유 집계를 사용하여 조치의 코스 또는 이벤트 생성 여부를 판별할 수 있습니다.
집계에 대해 검색되는 각 값은 규칙에 사용된 시점 또는 기간에 따라 달라집니다. 시점 조회의 경우 값은 지정된 시점까지 발생한 이벤트를 포함한 지난 이벤트에서 계산됩니다. 시점을 지정하지 않으면 규칙 에이전트의 now 값을 사용합니다. 기간 조회의 경우 값은 지정된 기간 내에 발생한 이벤트에서 계산됩니다.
집계 조회의 값이 널일 수 있습니다. 예를 들어, 집계의 지평에 이벤트가 없는 경우입니다. 시간 인수가 널이면 현재 시간이 사용됩니다. 아래 예제에 정의된 것과 같은 단순 조건에서 집계 값이 널인 경우 규칙은 실행되지 않습니다.
if the purchase count of 'the customer' is more than 100
then
set the status of 'the customer' to EXCELLENT;
공유 집계의 시간 지점에서 값 가져오기
규칙에서는 다음 구조를 통해 값이 집계되는 시점을 지정할 수 있습니다.the <aggregate> at <time point>
다음 예제에서 규칙은 2015년 5월 15일에서 purchase count 속성의 집계 값을 참조합니다.if the purchase count of 'the customer' at the time of 5/15/2015 is less than 10
then print "The customer made" + the purchase count of 'the customer' + "purchases before 05/16/2015."
공유 집계의 기간에서 값 가져오기
규칙에서 다음 생성을 통해 값이 집계되는 기간을 지정할 수 있습니다.the <aggregate> over <time period>
집계 정의보다 규칙에서 기간을 지정하는 경우 서로 다른 기간에 동일한 속성 값을 집계하도록 규칙에서 집계 정의를 재사용할 수 있습니다. 집계의 비즈니스 모델 규정에서 이벤트를 사용할 수 있는 기간은 규칙에 정의된 최대 기간을 포함할 수 있을 정도가 되어야 합니다. 그렇지 않은 경우에는 조회에서 널을 리턴합니다.
다음 예제에서 세 개의 규칙은 다음과 같이 비즈니스 모델 규정에 정의된 purchase count의 동일한 집계된 속성을 참조합니다.
the purchase count of a customer is aggregated from purchase events,
where this customer comes from the customer of each purchase event
as the number of purchase events
available for 30 days.
첫 번째 규칙은 마지막 주 동안의 purchase count 속성을 참조합니다.
if the purchase count of 'the customer' over the last period of 1 week is less than 10
then print "The customer made" + the purchase count of 'the customer' + "purchases last week."
두 번째 규칙은 discount event의 달력 월 동안의 purchase count 속성을 참조합니다.
when a discount event occurs
definitions
set 'purchase month' to the calendar month of this discount event;
if the purchase count of 'the customer' over 'purchase month' is less than 10
then print "The customer made" + the purchase count of 'the customer' + "purchases last week."
세 번째 규칙은 purchase count 속성의 집계된 값을 비교합니다.
when a discount event occurs
definitions
set 'discount week' to the period between 1 week before this discount event and this discount event;
set 'recent large purchases' to the purchase count of 'the customer' over 'discount week';
set 'earlier large purchases' to the purchase count of 'the customer' over the period of 1 week before 'discount week';
if 'recent large purchases' is more than 'earlier large purchases'
then emit a new coupon;
grouped by 표현식이 있는 공유 집계에서 값 가져오기
공유 집계에는 grouped by 표현식이 포함될 수 있습니다.
the total price of a cart is aggregated from purchase events,
where this cart comes from the cart of each purchase event
as the total price of all purchase events
grouped by the city of each purchase event
available for 1 year.
이 집계에서 값을 조회하려면 grouped by 매개변수 즉, 각 purchase event의 city를 지정해야 합니다. 사용 가능한 구/군/시 목록이 비즈니스 모델 정의에 정의됩니다.
a city can be one of : London, Paris, Tokyo.
다음 규칙은 London에서 발생하는 purchase events의 집계 값을 조회합니다.
when a purchase event occurs
if the total price of the cart of this purchase event for London is at least 500
then
print "Expensive cart in London." ;
grouped by 매개변수의 유형이 비즈니스 모델 정의에서 정의되지 않으면, 기본적으로 유형은 문자열이며, the total price of the cart of this purchase event for "London" 규칙에서 이를 지정하기 위해 물음표를 사용해야 합니다.
다음 예제에서는 grouped by 표현식이 복합 표현식입니다.
the number of flights of a departure airport is aggregated from flight events,
where this departure airport comes from the departure airport of each flight event
as the number of flight events
grouped by the duration between the departure time of each flight event and the arrival time of each flight event in hours
available for 1 year.
다음 규칙은 기간이 2시간인 비행 이벤트의 집계 값을 조회합니다.
when a flight event occurs
if the number of flights of 'the departure airport' for 2 is more than 20
then print "More than 20 medium-haul flights from this airport." ;