WordPress.org

Making WordPress.org


Ignore:
Timestamp:
11/22/2015 06:47:02 PM (5 years ago)
Author:
ocean90
Message:

Translate, Stats: Avoid a division by zero warning and use the same calculation for $percent_complete as on project pages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-stats-overview.php

    r2071 r2107  
    7474            }
    7575
    76             $translation_locale_statuses[ $locale_key ][ $set->path ] = floor( (float) $set->percent_complete );
     76            /*
     77             * > 50% round down, so that a project with all strings except 1 translated shows 99%, instead of 100%.
     78             * < 50% round up, so that a project with just a few strings shows 1%, instead of 0%.
     79             */
     80            $percent_complete = (float) $set->percent_complete;
     81            $percent_complete = ( $percent_complete > 50 ) ? floor( $percent_complete ) : ceil( $percent_complete );
     82            $translation_locale_statuses[ $locale_key ][ $set->path ] = $percent_complete;
     83
    7784            if ( ! isset( $translation_locale_statuses[ $locale_key ]['waiting'] ) ) {
    7885                $translation_locale_statuses[ $locale_key ]['waiting'] = 0;
     
    111118        foreach ( $translation_locale_statuses as $locale => $sets ) {
    112119            unset( $sets['waiting'] );
    113             $translation_locale_complete[ $locale ] = round( array_sum( $sets ) / count( $sets ), 3 );
     120            $sets_count = count( $sets );
     121            if ( $sets_count ) {
     122                $translation_locale_complete[ $locale ] = round( array_sum( $sets ) / $sets_count, 3 );
     123            } else {
     124                $translation_locale_complete[ $locale ] = 0;
     125            }
    114126        }
    115127        unset( $locale, $sets );
Note: See TracChangeset for help on using the changeset viewer.