diff options
Diffstat (limited to 'ui/include/classes/data/CHistFunctionData.php')
-rw-r--r-- | ui/include/classes/data/CHistFunctionData.php | 140 |
1 files changed, 98 insertions, 42 deletions
diff --git a/ui/include/classes/data/CHistFunctionData.php b/ui/include/classes/data/CHistFunctionData.php index 0f2a0355eea..bb420e7667e 100644 --- a/ui/include/classes/data/CHistFunctionData.php +++ b/ui/include/classes/data/CHistFunctionData.php @@ -44,6 +44,22 @@ final class CHistFunctionData { ['rules' => [['type' => 'query']]], ['rules' => [['type' => 'period', 'mode' => self::PERIOD_MODE_SEC_ONLY]]] ], + 'bucket_percentile' => [ + ['rules' => [['type' => 'query']]], + ['rules' => [['type' => 'period', 'mode' => self::PERIOD_MODE_SEC_ONLY]]], + ['rules' => [ + ['type' => 'regexp', 'pattern' => '/^((\d+(\.\d{0,4})?)|(\.\d{1,4}))$/'], + ['type' => 'number', 'min' => 0, 'max' => 100] + ]] + ], + 'bucket_rate_foreach' => [ + ['rules' => [['type' => 'query']]], + ['rules' => [['type' => 'period', 'mode' => self::PERIOD_MODE_SEC_ONLY]]], + ['rules' => [ + ['type' => 'regexp', 'pattern' => '/^\d+$/'], + ['type' => 'number', 'min' => 1] + ], 'required' => false] + ], 'change' => [ ['rules' => [['type' => 'query']]] ], @@ -167,6 +183,10 @@ final class CHistFunctionData { ['type' => 'number', 'min' => 0, 'max' => 100] ]] ], + 'rate' => [ + ['rules' => [['type' => 'query']]], + ['rules' => [['type' => 'period', 'mode' => self::PERIOD_MODE_SEC]]] + ], 'skewness' => [ ['rules' => [['type' => 'query']]], ['rules' => [['type' => 'period', 'mode' => self::PERIOD_MODE_DEFAULT]]] @@ -230,12 +250,70 @@ final class CHistFunctionData { ]; /** - * A subset of history functions for use in calculated item formulas only. + * Additional requirements for history function usage in expressions. + * + * @var array + */ + private const EXPRESSION_RULES = [ + 'avg_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]], + 'bucket_rate_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['histogram_quantile'], + 'parameters' => ['count' => 2], + 'position' => 1 + ]], + 'count_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]], + 'exists_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]], + 'last_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]], + 'max_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]], + 'min_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]], + 'sum_foreach' => [[ + 'type' => 'require_math_parent', + 'in' => ['avg', 'count', 'max', 'min', 'sum'], + 'parameters' => ['count' => 1], + 'position' => 0 + ]] + ]; + + /** + * A subset of aggregating history functions for use in calculated item formulas. * * @var array */ - private const CALCULATED_ONLY = [ + private const AGGREGATING = [ 'avg_foreach', + 'bucket_percentile', + 'bucket_rate_foreach', 'count_foreach', 'exists_foreach', 'item_count', @@ -259,6 +337,8 @@ final class CHistFunctionData { private const VALUE_TYPES = [ 'avg' => self::ITEM_VALUE_TYPES_NUM, 'avg_foreach' => self::ITEM_VALUE_TYPES_NUM, + 'bucket_percentile' => self::ITEM_VALUE_TYPES_NUM, + 'bucket_rate_foreach' => self::ITEM_VALUE_TYPES_NUM, 'change' => self::ITEM_VALUE_TYPES_ALL, 'count' => self::ITEM_VALUE_TYPES_ALL, 'count_foreach' => self::ITEM_VALUE_TYPES_ALL, @@ -284,6 +364,7 @@ final class CHistFunctionData { 'monoinc' => self::ITEM_VALUE_TYPES_NUM, 'nodata' => self::ITEM_VALUE_TYPES_ALL, 'percentile' => self::ITEM_VALUE_TYPES_NUM, + 'rate' => self::ITEM_VALUE_TYPES_NUM, 'skewness' => self::ITEM_VALUE_TYPES_NUM, 'stddevpop' => self::ITEM_VALUE_TYPES_NUM, 'stddevsamp' => self::ITEM_VALUE_TYPES_NUM, @@ -331,7 +412,7 @@ final class CHistFunctionData { return false; } - if (!$this->options['calculated'] && in_array($function, self::CALCULATED_ONLY, true)) { + if (!$this->options['calculated'] && in_array($function, self::AGGREGATING, true)) { return false; } @@ -348,20 +429,20 @@ final class CHistFunctionData { return self::PARAMETERS; } - return array_diff_key(self::PARAMETERS, array_flip(self::CALCULATED_ONLY)); + return array_diff_key(self::PARAMETERS, array_flip(self::AGGREGATING)); } /** - * Get known history functions along with supported item value types. + * Get additional requirements for history function usage in expressions. * * @return array */ - public function getValueTypes(): array { + public function getExpressionRules(): array { if ($this->options['calculated']) { - return self::VALUE_TYPES; + return self::EXPRESSION_RULES; } - return array_diff_key(self::VALUE_TYPES, array_flip(self::CALCULATED_ONLY)); + return array_diff_key(self::EXPRESSION_RULES, array_flip(self::AGGREGATING)); } /** @@ -373,45 +454,20 @@ final class CHistFunctionData { * * @return bool */ - public static function isAggregating(string $function): bool { - switch ($function) { - case 'avg_foreach': - case 'count_foreach': - case 'exists_foreach': - case 'item_count': - case 'last_foreach': - case 'max_foreach': - case 'min_foreach': - case 'sum_foreach': - return true; - - default: - return false; - } + public function isAggregating(string $function): bool { + return in_array($function, self::AGGREGATING); } /** - * Check if the result of aggregating function is further aggregatable. - * - * @static - * - * @param string $function + * Get known history functions along with supported item value types. * - * @return bool + * @return array */ - public static function isAggregatable(string $function): bool { - switch ($function) { - case 'avg_foreach': - case 'count_foreach': - case 'exists_foreach': - case 'last_foreach': - case 'max_foreach': - case 'min_foreach': - case 'sum_foreach': - return true; - - default: - return false; + public function getValueTypes(): array { + if ($this->options['calculated']) { + return self::VALUE_TYPES; } + + return array_diff_key(self::VALUE_TYPES, array_flip(self::AGGREGATING)); } } |