r57345 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57344‎ | r57345 | r57346 >
Date:21:01, 3 October 2009
Author:siebrand
Status:deferred
Tags:
Comment:
Implemented weighted scores
Modified paths:
  • /trunk/extensions/Translate/scripts/groupStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/groupStatistics.php
@@ -86,7 +86,7 @@
8787 $optionsWithArgs = array( 'groups', 'output', 'skiplanguages' );
8888 require( dirname( __FILE__ ) . '/cli.inc' );
8989
90 -class TranslateStatsOutput extends WikiStatsOutput {
 90+class TranslateStatsOutput extends wikiStatsOutput {
9191 function heading() {
9292 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";
9393 }
@@ -164,8 +164,13 @@
165165 }
166166
167167 $reportScore = false;
 168+// Check if score should be reported and prepare weights
168169 if ( isset( $options['most'] ) && isset( $localisedWeights[$options['most']] ) ) {
169170 $reportScore = true;
 171+ $weights = array();
 172+ foreach( $localisedWeights[$options['most']] as $weight ) {
 173+ $weights[] = $weight;
 174+ }
170175 }
171176
172177 // Get groups from input
@@ -213,16 +218,29 @@
214219 if( isset( $options['most'] ) && isset( $options['speakers'] ) ) {
215220 $out->element( 'Speakers', true );
216221 }
217 -/*if( $reportScore ) {
218 - $out->element( 'Score', true );
219 -}*/
 222+
 223+$totalWeight = 0;
 224+if( $reportScore ) {
 225+ foreach( $localisedWeights[$options['most']] as $weight ) {
 226+ $totalWeight += $weight;
 227+ }
 228+ $out->element( 'Score (' . $totalWeight . ')', true );
 229+}
 230+
220231 foreach ( $groups as $g ) {
221232 // Add unprocessed description of group as heading
222 - $out->element( $g->getLabel(), true );
223 - if ( isset( $options['fuzzy'] ) ) {
 233+ if( $reportScore ) {
 234+ $gid = $g->getId();
 235+ $heading = $g->getLabel() . " (" . $localisedWeights[$options['most']][$gid] . ")";
 236+ } else {
 237+ $heading = $g->getLabel();
 238+ }
 239+ $out->element( $heading, true );
 240+ if ( !$reportScore && isset( $options['fuzzy'] ) ) {
224241 $out->element( 'Fuzzy', true );
225242 }
226243 }
 244+
227245 $out->blockend();
228246
229247 $rows = array();
@@ -345,16 +363,29 @@
346364 }
347365
348366 // Fill the score field
349 - /*if( $reportScore ) {
350 - $weights = $localisedWeights[$options['most']];
351 - }*/
 367+ if( $reportScore ) {
 368+ // Keep count
 369+ $i = 0;
 370+ // Start with 0 points
 371+ $score = 0;
352372
 373+ foreach ( $columns as $fields ) {
 374+ list( $invert, $upper, $total ) = $fields;
 375+ // Weigh the score and add it to the current score
 376+ $score += ( $weights[$i] * $upper ) / $total;
 377+ $i++;
 378+ }
 379+
 380+ // Report a round numbers
 381+ $score = number_format( $score, 0 );
 382+
 383+ $out->element( $score );
 384+ }
 385+
353386 // Fill fields for groups
354387 foreach ( $columns as $fields ) {
355 - //var_dump( $fields, true );
356 - //exit(1);
357388 list( $invert, $upper, $total ) = $fields;
358 - $c = $out->formatPercent( $upper, $total, $invert, /* Decimals */ 2 );
 389+ $c = $out->formatPercent( $upper, $total, $invert );
359390 $out->element( $c );
360391 }
361392 $out->blockend();

Status & tagging log