サンプルレート

以下でサポートされています。
optimization.sample_rate(byteOrString, rateNumerator, rateDenominator)

説明

この関数は、あるイベントを含めるかどうかを、決定論的なサンプリングの方法に基づいて判断します。次の結果を返します。

  • true: 入力値の割合(rateNumerator / rateDenominator に相当)。イベントをサンプルに含める必要があることを示します。
  • false: イベントをサンプルに含める必要がないことを示します。

この関数は、イベントのサブセットのみを処理する最適化シナリオで役立ちます。次と同等です。

hash.fingerprint2011(byteOrString) % rateDenominator < rateNumerator

パラメータのデータ型

  • byteOrString: BYTE または STRING のいずれかに評価される式。
  • rateNumerator: 'INT'
  • rateDenominator: 'INT'

戻り値の型

BOOL

コードサンプル

events:
    $e.metadata.event_type = "NETWORK_CONNECTION"
    $asset_id = $e.principal.asset.asset_id
    optimization.sample_rate($e.metadata.id, 1, 5) // Only 1 out of every 5 events

  match:
    $asset_id over 1h

  outcome:
    $event_count = count_distinct($e.metadata.id)
  // estimate the usage by multiplying by the inverse of the sample rate
    $usage_past_hour = sum(5.0 * $e.network.sent_bytes)

 condition:
  // Requiring a certain number of events after sampling avoids bias (e.g. a
  // device with just 1 connection will still show up 20% of the time and
  // if we multiply that traffic by 5, we'll get an incorrect estimate)
  $e and ($usage_past_hour > 1000000000) and $event_count >= 100