From 79d53d2b2687b8fc946d87e66f0c542371cbcd99 Mon Sep 17 00:00:00 2001 From: Charles Verge Date: Thu, 7 Apr 2016 13:41:46 -0300 Subject: [PATCH] Fix standard deviation calculation and optionally use stats_standard_deviation function --- classes/headers/RollupHeader.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/classes/headers/RollupHeader.php b/classes/headers/RollupHeader.php index 4cf19aea..3b89ab1c 100644 --- a/classes/headers/RollupHeader.php +++ b/classes/headers/RollupHeader.php @@ -89,8 +89,14 @@ public static function beforeRender(&$report) { } $devs = array(); - foreach($real_values as $v) $devs[] = pow($v - $params['mean'], 2); - $params['stdev'] = sqrt(array_sum($devs) / (count($devs) - 1)); + if (empty($real_values)) { + $params['stdev'] = 0; + } else if (function_exists('stats_standard_deviation')) { + $params['stdev'] = stats_standard_deviation($real_values); + } else { + foreach($real_values as $v) $devs[] = pow($v - $params['mean'], 2); + $params['stdev'] = sqrt(array_sum($devs) / (count($devs))); + } } }