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 החזרות 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