Making WordPress.org

Changeset 13774

Timestamp:
06/04/2024 02:53:48 PM (8 weeks ago)
Author:
amieiro
Message:

Translation. Add the option to show statistics from the start date we want.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats-print.php

    r12114 r13774  
    33namespace WordPressdotorg\GlotPress\Customizations\CLI;
    44
     5
    56use WP_CLI;
    67use WP_CLI_Command;
     
    89class Stats_Print extends WP_CLI_Command  {
    910
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
    1031    public function __invoke( $args, $assoc_args ) {
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
    1143        $stats = new Stats();
    12         $stats( true );
     44        $stats( true );
    1345    }
    1446}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php

    r12798 r13774  
    1414
    1515use DateTime;
    16 use Exception;
    17 use GP;
    1816use GP_Locale;
    19 use GP_Locales;
    2017use WP_CLI;
    21 use WP_CLI_Command;
    2218use WP_Query;
    2319use WordPressdotorg\GlotPress\Routes\Plugin;
     
    163159     * Prints the Polyglots stats or stores them on a page.
    164160     *
    165      * @param bool $echo_the_values Whether it should print the info in the CLI or stores it on a page.
     161     * @param bool        $echo_the_values Whether it should print the info in the CLI or stores it on a page.
     162     * @param string|null $old_date        The date to compare the stats with. Format: 'Y-m-d'.
    166163     *
    167164     * @return void
    168165     */
    169     public function __invoke( bool $echo_the_values = false ) {
     166    public function __invoke( bool $echo_the_values = false {
    170167        global $wpdb;
    171168
     
    190187        $this->print_managers_stats();
    191188        $this->print_most_active_translators();
    192         $this->store_stats();
    193         $this->print_stats_comparison( gmdate( 'Y-m-d' ) );
     189        // Don't store the stats if we execute the command in the CLI, to avoid storing the same stats twice.
     190        if ( ! $echo_the_values ) {
     191            $this->store_stats();
     192        }
     193        $this->print_stats_comparison( gmdate( 'Y-m-d' ), $old_date );
    194194
    195195        $this->update_page();
     
    360360     *
    361361     * @param string $current_date The date for which we display the stats.
    362      * @param string $old_date The date to compare the stats with.
     362     * @param string $old_date The date to compare the stats with.
    363363     *
    364364     * @return void
     
    375375            return;
    376376        }
    377         if ( ! $this->echo_the_values ) {
    378             $this->stats_comparison = $this->create_gutenberg_heading( 'Summary for weekly stats' );
    379         } else {
    380             $this->print_wpcli_heading( 'Summary for weekly stats' );
     377
     378        $current_datetime = DateTime::createFromFormat( 'Y-m-d', $current_date );
     379        $old_datetime     = DateTime::createFromFormat( 'Y-m-d', $old_date );
     380        if ( ! $current_datetime || ! $old_datetime ) {
     381            return;
     382        }
     383        $interval        = $current_datetime->diff( $old_datetime );
     384        $days_difference = $interval->days;
     385
     386        if ( ! $this->echo_the_values ) {
     387            $this->stats_comparison = $this->create_gutenberg_heading( "Summary for the last $days_difference days" );
     388        } else {
     389            $this->print_wpcli_heading( "Summary for the last $days_difference days" );
    381390        }
    382391        $stats_diff = new \stdClass();
     
    395404        $code .= 'Requests: There are ' . $current_date_data->requests_unresolved . ' unresolved editor requests out of ' . $current_date_data->requests_total . ' (' . $this->prefix_num( $stats_diff->requests_unresolved ) . ') total and ' . $current_date_data->locale_requests_unresolved . ' unresolved locale requests out of ' . $current_date_data->locale_requests_total . ' (' . $this->prefix_num( $stats_diff->locale_requests_unresolved ) . ') total.' . PHP_EOL . PHP_EOL;
    396405
    397         $code .= 'Translators: There are ' . $current_date_data->translators_gtes . ' (' . $this->prefix_num( $stats_diff->translators_gtes ) . ') GTEs, ' . $current_date_data->translators_ptes . ' (' . $this->prefix_num( $stats_diff->translators_ptes ) . ') PTEs and ' . $current_date_data->translators_contributors . ' (' . $this->prefix_num( $stats_diff->translators_contributors ) . ') translation contributors.' . PHP_EOL;
    398         $code .= '(A wordpress.org account could have multiple roles over different locale)' . PHP_EOL . PHP_EOL;
    399 
    400         $code .= 'Site language: ' . $current_date_data->wp_translated_sites_pct . '% (' . $this->prefix_num( round( $stats_diff->wp_translated_sites_pct, 3 ) ) . '%) of WordPress sites are running a translated WordPress site. ' . PHP_EOL;
     406        $code .= 'Translators: There are ' . . ' (' . $this->prefix_num( $stats_diff->translators_contributors ) . ') translation contributors.' . PHP_EOL;
     407        $code .= '(A wordpress.org account could have multiple roles over different locale)' . PHP_EOL . PHP_EOL;
     408
     409        $code .= 'Site language: ' . $current_date_data->wp_translated_sites_pct . '% (' . $this->prefix_num( round( $stats_diff->wp_translated_sites_pct, 3 ) ) . '%) of WordPress sites are running a translated WordPress site. ' . PHP_EOL;
    401410        if ( ! $this->echo_the_values ) {
    402411            $this->stats_comparison .= $this->create_gutenberg_code( $code );
     
    421430     * Prefix numbers greater than zero with plus sign and plus_minus sign if number is zero.
    422431     *
    423      * @param int $num Number to be prefixed.
     432     * @param float $number          Number to be prefixed.
     433     * @param int   $number_decimals Number of decimals to be displayed.
    424434     *
    425435     * @return string Prefixed number
    426436     */
    427     private function prefix_num( $num ) {
    428         if ( 0 === $num ) {
     437    private function prefix_num( $num ) {
     438        if ( 0 === $num ) {
    429439            return '±0';
    430440        }
    431         return $num > 0 ? sprintf( '+%d', $num ) : $num;
     441        return $num;
    432442    }
    433443
Note: See TracChangeset for help on using the changeset viewer.