mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-05-10 06:18 am

[dw-free] stats page miscalculates gender percentages

[commit: http://hg.dwscoalition.org/dw-free/rev/16cba21887f4]

http://bugs.dwscoalition.org/show_bug.cgi?id=1176

Calculate gender stat percentages across all four options.

Patch by [personal profile] kareila.

Files modified:
  • htdocs/stats.bml
--------------------------------------------------------------------------------
diff -r 21c6be8bb177 -r 16cba21887f4 htdocs/stats.bml
--- a/htdocs/stats.bml	Sun May 10 06:13:37 2009 +0000
+++ b/htdocs/stats.bml	Sun May 10 06:18:31 2009 +0000
@@ -61,16 +61,23 @@ body<=
  $ret .= "<h1>$ML{'.gender.header'}</h1>";
  $ret .= "<p>$ML{'.gender.desc'}</p><ul>";
  {
-     my $male = $stat{'gender'}->{'M'}+0;
-     my $female = $stat{'gender'}->{'F'}+0;
-     my $other = $stat{'gender'}->{'O'}+0;
-     my $tot = $male+$female+$other;
-     $tot ||= 1;
-     $ret .= "<li><b>$ML{'.gender.female'} </b> $female (" . sprintf("%0.1f", $female*100/($tot||1)) . "%)</li>";
-     $ret .= "<li><b>$ML{'.gender.male'} </b> $male (" . sprintf("%0.1f", $male*100/($tot||1)) . "%)</li>";
-     $ret .= "<li><b>$ML{'.gender.other'} </b> $other (" . sprintf("%0.1f", $other*100/($tot||1)) . "%)</li>";
+     my $male   = $stat{ gender }->{ M } + 0;
+     my $female = $stat{ gender }->{ F } + 0;
+     my $other  = $stat{ gender }->{ O } + 0;
+     my $unspec = $stat{ gender }->{ U } + 0;
+
+     my $tot = ($male + $female + $other + $unspec) || 1;
+
+     my $fpc = sprintf( "%0.1f", $female * 100 / $tot );
+     my $mpc = sprintf( "%0.1f", $male   * 100 / $tot );
+     my $opc = sprintf( "%0.1f", $other  * 100 / $tot );
+     my $upc = sprintf( "%0.1f", $unspec * 100 / $tot );
+
+     $ret .= "<li><b>$ML{'.gender.female'} </b> $female ($fpc%)</li>";
+     $ret .= "<li><b>$ML{'.gender.male'} </b> $male ($mpc%)</li>";
+     $ret .= "<li><b>$ML{'.gender.other'} </b> $other ($opc%)</li>";
+     $ret .= "<li><b>$ML{'.gender.unspecified'} </b> $unspec ($upc%)</li>";
  }
-     $ret .= "<li><b>$ML{'.gender.unspecified'} </b> " . ($stat{'gender'}->{'U'}+0) . "</li>";
      $ret .= "</ul>\n";
 
  LJ::run_hook('statspage', {
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org