Changeset 13774
- Timestamp:
- 06/04/2024 02:53:48 PM (8 weeks ago)
- 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 3 3 namespace WordPressdotorg\GlotPress\Customizations\CLI; 4 4 5 5 6 use WP_CLI; 6 7 use WP_CLI_Command; … … 8 9 class Stats_Print extends WP_CLI_Command { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 10 31 public function __invoke( $args, $assoc_args ) { 32 33 34 35 36 37 38 39 40 41 42 11 43 $stats = new Stats(); 12 $stats( true );44 $stats( true ); 13 45 } 14 46 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php
r12798 r13774 14 14 15 15 use DateTime; 16 use Exception;17 use GP;18 16 use GP_Locale; 19 use GP_Locales;20 17 use WP_CLI; 21 use WP_CLI_Command;22 18 use WP_Query; 23 19 use WordPressdotorg\GlotPress\Routes\Plugin; … … 163 159 * Prints the Polyglots stats or stores them on a page. 164 160 * 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'. 166 163 * 167 164 * @return void 168 165 */ 169 public function __invoke( bool $echo_the_values = false ){166 public function __invoke( bool $echo_the_values = false { 170 167 global $wpdb; 171 168 … … 190 187 $this->print_managers_stats(); 191 188 $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 ); 194 194 195 195 $this->update_page(); … … 360 360 * 361 361 * @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. 363 363 * 364 364 * @return void … … 375 375 return; 376 376 } 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" ); 381 390 } 382 391 $stats_diff = new \stdClass(); … … 395 404 $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; 396 405 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; 401 410 if ( ! $this->echo_the_values ) { 402 411 $this->stats_comparison .= $this->create_gutenberg_code( $code ); … … 421 430 * Prefix numbers greater than zero with plus sign and plus_minus sign if number is zero. 422 431 * 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. 424 434 * 425 435 * @return string Prefixed number 426 436 */ 427 private function prefix_num( $num ) {428 if ( 0 === $num ) {437 private function prefix_num( $num ) { 438 if ( 0 === $num ) { 429 439 return '±0'; 430 440 } 431 return $num > 0 ? sprintf( '+%d', $num ) : $num;441 return $num; 432 442 } 433 443
Note: See TracChangeset
for help on using the changeset viewer.