foreach ( $this->inclusive as $func => $stats ) {
foreach ( $stats as $name => $value ) {
if ( $value instanceof RunningStat ) {
- $total = $value->m1 * $value->n;
+ $total = $value->getMean() * $value->getCount();
$percent = ( isset( $main[$name] ) && $main[$name] )
? 100 * $total / $main[$name]
: 0;
$this->inclusive[$func][$name] = [
'total' => $total,
'min' => $value->min,
- 'mean' => $value->m1,
+ 'mean' => $value->getMean(),
'max' => $value->max,
'variance' => $value->m2,
'percent' => $percent,
return function ( $a, $b ) use ( $key, $sub ) {
if ( isset( $a[$key] ) && isset( $b[$key] ) ) {
// Descending sort: larger values will be first in result.
- // Assumes all values are numeric.
// Values for 'main()' will not have sub keys
$valA = is_array( $a[$key] ) ? $a[$key][$sub] : $a[$key];
$valB = is_array( $b[$key] ) ? $b[$key][$sub] : $b[$key];
- return $valB - $valA;
+ return $valB <=> $valA;
} else {
// Sort datum with the key before those without
return isset( $a[$key] ) ? -1 : 1;