Making WordPress.org

Changeset 8045


Ignore:
Timestamp:
01/08/2019 06:50:03 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Stats: Ensure that the Usage stats add up to 100.00.

Sometimes due to rounding the sum of the usage stats end up at 100.01 or 99.99 which throw out the graphs.
Due to the rare occurences and generalness of these numbers, we'll fix this by adjusting one of the numbers slightly.

Fixes #3969.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php

    r6287 r8045  
    150150        }
    151151
     152        // Due to rounding issues, sometimes we'll end up with the total being .01 or .02 off 100
     153        // In these cases, we'll just alter the 'other' or final number slightly so everything adds up to 100.
     154        // This is ultimately needed for the stats graphs to display properly.
     155        if ( array_sum( $usage ) != 100.00 ) {
     156            $last_key = array_keys( $usage )[ count( $usage ) - 1 ];
     157            $usage[ $last_key ] -= array_sum( $usage ) - 100.00;
     158        }
     159
    152160        return $usage;
    153161    }
Note: See TracChangeset for help on using the changeset viewer.