Skip to content

Commit

Permalink
Fix bug with Rollup header median calculation.
Browse files Browse the repository at this point in the history
jdorn committed Aug 2, 2017
1 parent 43adca0 commit a3663e6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion classes/headers/RollupHeader.php
Original file line number Diff line number Diff line change
@@ -80,7 +80,23 @@ public static function beforeRender(&$report) {
$params['count'] = count($real_values);
if($params['count']) {
$params['mean'] = $params['average'] = $params['sum'] / $params['count'];
$params['median'] = ($params['count']%2)? ($real_values[$params['count']/2-1] + $real_values[$params['count']/2])/2 : $real_values[floor($params['count']/2)];

// Median for odd number of rows
if($params['count']%2) {
$params['median'] = $real_values[floor($params['count']/2)];
}
// Median for even number of rows
else {
// If the 2 middle entries are numeric, average them
if(is_numeric($real_values[$params['count']/2-1]) && is_numeric($real_values[$params['count']/2])) {
$params['median'] = ($real_values[$params['count']/2-1] + $real_values[$params['count']/2])/2;
}
// If they are not numeric, pick one of the middle entries
else {
$params['median'] = $real_values[$params['count']/2-1];
}
}

$params['min'] = $real_values[0];
$params['max'] = $real_values[$params['count']-1];
}

0 comments on commit a3663e6

Please sign in to comment.