r57391 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57390‎ | r57391 | r57392 >
Date:19:06, 5 October 2009
Author:siebrand
Status:deferred
Tags:
Comment:
Add summary option to genetate a neat summary with counts and scores per continent category and a row with totals. Only available for a valid 'most' value.
Modified paths:
  • /trunk/extensions/Translate/scripts/groupStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/groupStatistics.php
@@ -89,6 +89,10 @@
9090 function heading() {
9191 echo '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;" width="100%"' . "\n";
9292 }
 93+
 94+ function summaryheading() {
 95+ echo "\n\n" . '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;"' . "\n";
 96+ }
9397 }
9498
9599 if ( isset( $options['help'] ) ) showUsage();
@@ -130,6 +134,8 @@
131135 --nol10n : do not add localised language name if I18ntags is installed.
132136 --continent : add a continent column. Only available when output is
133137 'wiki' or not specified.
 138+ --summary : add a summary with counts and scores per continent category
 139+ and totals. Only available for a valid 'most' value.
134140
135141 END;
136142 STDERR( $msg );
@@ -301,6 +307,12 @@
302308 unset($collection);
303309 }
304310
 311+// init summary array
 312+if( isset( $options['summary'] ) ) {
 313+ $summarise = true;
 314+ $summary = array();
 315+}
 316+
305317 foreach ( $languages as $code => $name ) {
306318 // Skip list
307319 if ( !isset( $options['most'] ) && in_array( $code, $skipLanguages ) ) {
@@ -378,6 +390,18 @@
379391 // Report a round numbers
380392 $score = number_format( $score, 0 );
381393
 394+ if( $summarise ) {
 395+ $continent = $mostSpokenLanguages[$code][2];
 396+ if( isset( $summary[$continent] ) ) {
 397+ $newcount = $summary[$continent][0] + 1;
 398+ $newscore = $summary[$continent][1] + $score;
 399+ } else {
 400+ $newcount = 1;
 401+ $newscore = $score;
 402+ }
 403+
 404+ $summary[$continent] = array( $newcount, $newscore );
 405+ }
382406 $out->element( $score );
383407 }
384408
@@ -390,5 +414,45 @@
391415 $out->blockend();
392416 }
393417
394 -# Finally output footer
395418 $out->footer();
 419+
 420+if( $reportScore && isset( $options['summary'] ) ) {
 421+ $out->summaryheading();
 422+
 423+ $out->blockstart();
 424+
 425+ $out->element( 'Continent', true );
 426+ $out->element( 'Count', true );
 427+ $out->element( 'Avg. score', true );
 428+
 429+ $out->blockend();
 430+
 431+ ksort( $summary );
 432+
 433+ $totals = array( 0, 0 );
 434+
 435+ foreach ( $summary as $key => $values ) {
 436+ $out->blockstart();
 437+
 438+ if( $key == 'multiple' ) {
 439+ $out->element( 'Multiple' );
 440+ } else {
 441+ $out->element( "{{int:timezoneregion-" . $key . "}}" );
 442+ }
 443+ $out->element( $values[0] );
 444+ $out->element( number_format( $values[1]/$values[0] ) );
 445+
 446+ $out->blockend();
 447+
 448+ $totals[0] += $values[0];
 449+ $totals[1] += $values[1];
 450+ }
 451+
 452+ $out->blockstart();
 453+ $out->element( 'Total' );
 454+ $out->element( $totals[0] );
 455+ $out->element( number_format( $totals[1]/$totals[0] ) );
 456+ $out->blockend();
 457+
 458+ $out->footer();
 459+}

Status & tagging log