Skip to content

Commit

Permalink
Fix standard deviation calculation and optionally use stats_standard_…
Browse files Browse the repository at this point in the history
…deviation function
  • Loading branch information
charlesverge committed Apr 8, 2016
1 parent 35a9b2b commit 79d53d2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions classes/headers/RollupHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}

Expand Down

0 comments on commit 79d53d2

Please sign in to comment.