0.40, 'query_ms' => 0.20, 'blocking_kb' => 0.20, 'autoload_kb' => 0.10, 'cron_per_day' => 0.10, ); /** * Add 'weight' (0-100) and 'weight_parts' to each owner. * * @param array $owners Owner summaries. * @return array */ public static function apply( array $owners ): array { $max = array(); foreach ( self::WEIGHTS as $dim => $w ) { $max[ $dim ] = 0.0; foreach ( $owners as $o ) { if ( self::is_baseline( $o ) || ! empty( $o['excluded'] ) ) { continue; // Core/unknown and a plugin filtered out of the run never set the scale. } $max[ $dim ] = max( $max[ $dim ], (float) ( $o[ $dim ] ?? 0 ) ); } } foreach ( $owners as $key => $o ) { $score = 0.0; $parts = array(); foreach ( self::WEIGHTS as $dim => $w ) { $norm = $max[ $dim ] > 0 && empty( $o['excluded'] ) ? min( 1.0, (float) ( $o[ $dim ] ?? 0 ) / $max[ $dim ] ) : 0.0; $parts[ $dim ] = round( $norm * $w * 100, 1 ); $score += $norm * $w; } $owners[ $key ]['weight'] = (int) round( $score * 100 ); $owners[ $key ]['weight_parts'] = $parts; } uasort( $owners, static function ( $a, $b ) { $c = self::group( $a ) <=> self::group( $b ); if ( 0 !== $c ) { return $c; // Plugins and themes first, then core/unknown, then a plugin filtered out of the run. } $c = $b['weight'] <=> $a['weight']; if ( 0 !== $c ) { return $c; } $c = ( $b['php_ms'] ?? 0 ) <=> ( $a['php_ms'] ?? 0 ); return 0 !== $c ? $c : strcmp( (string) ( $a['key'] ?? '' ), (string) ( $b['key'] ?? '' ) ); } ); $rank = 0; foreach ( $owners as $key => $o ) { $owners[ $key ]['rank'] = empty( $o['excluded'] ) ? ++$rank : 0; // 0: not ranked. } return $owners; } /** * Sort group: 0 plugins and themes, 1 core/unknown, 2 the plugin a "try without" run filtered out. * * @param array $o Owner summary. */ private static function group( array $o ): int { if ( ! empty( $o['excluded'] ) ) { return 2; } return self::is_baseline( $o ) ? 1 : 0; } /** * Core and unknown rows are shown for context, never ranked against plugins. * * @param array $o Owner summary. */ public static function is_baseline( array $o ): bool { return in_array( (string) ( $o['type'] ?? '' ), array( 'core', 'unknown' ), true ); } }