window.avg
支援的國家/地區:
window.avg(numeric_values [, should_ignore_zero_values])
說明
傳回輸入值的平均值 (可以是整數或浮點數)。將選用的第二個引數設為 true,即可忽略零值。
參數資料類型
INT|FLOAT
傳回類型
FLOAT
程式碼範例
範例 1
這個範例顯示整數平均值。
// This rule sets the outcome $size_mode to the average
// file size in the 5 minute match window.
events:
$e.user.userid = $userid
match:
$userid over 5m
outcome:
$size_mode = window.avg($e.file.size) // yields 2.5 if the event file size values in the match window are 1, 2, 3 and 4
範例 2
這個範例顯示浮點數平均值。
events:
$e.user.userid = $userid
match:
$userid over 5m
outcome:
$size_mode = window.avg($e.file.size) // yields 1.75 if the event file size values in the match window are 1.1 and 2.4
範例 3
負數輸入平均值
events:
$e.user.userid = $userid
match:
$userid over 5m
outcome:
$size_mode = window.avg($e.file.size) // yields 0.6 if the event file size values in the match window are -1.1, 1.1, 0.0 and 2.4
範例 4
0 returns 0
events:
$e.user.userid = $userid
match:
$userid over 5m
outcome:
$size_mode = window.avg($e.file.size) // yields 0 if the event file size values in the match window is 0
範例 5
忽略 0 個值
events:
$e.user.userid = $userid
match:
$userid over 5m
outcome:
$size_mode = window.avg($e.file.size, true) // yields 394 if the event file size values in the match window are 0, 0, 0 and 394