Permalink
Browse files

set_max & set_range reworked

  • Loading branch information...
1 parent 94e775e commit 8d6afc22a3fc1373ef484272720de303f02e2677 @barbie committed Jan 28, 2012
Showing with 44 additions and 38 deletions.
  1. +5 −0 Changes
  2. +2 −2 examples/example-settings.ini
  3. +37 −36 lib/CPAN/Testers/WWW/Statistics/Graphs.pm
View
@@ -1,10 +1,15 @@
Revision history for CPAN-Testers-WWW-Statistics
+0.96 current
+ - set_max & set_range reworked (Graph.pm)
+
0.95 26/01/2012
- removed NNTP code from cpanmail.cgi.
- added cpanmail.ini to cgi templates.
- don't overwrite basic files in case they have changed.
- added the ability to link basic files.
+ - changed date names
+ - leaderboard fixes.
0.94 21/08/2011
- revised banner logo image by Jon 'JJ' Allen.
@@ -74,7 +74,7 @@ LIST=<<HERE
199901-200412
200301-200712
200601-201012
-201001-201110
+201001-201201
HERE
[CPAN_RANGES]
@@ -83,7 +83,7 @@ LIST=<<HERE
199901-200412
200301-200712
200601-201012
-201001-201110
+201001-201201
HERE
@@ -318,49 +318,50 @@ sub _dec2hex {
sub _set_max {
my $max = shift;
- my ($limit,$max_limit) = (10,10000000);
-#print "max=$max\n";
-
- return $limit if($max <= $limit);
- while($limit < $max_limit) {
- if($max > $limit) {
- $limit *= 10;
- next;
- }
+ my $lmt = 10;
- my $inc10 = int($limit / 10);
- my $inc50 = int($limit / 20);
- for(my $inc = $inc10 ; $inc < $limit ; $inc += $inc50) {
- #print STDERR "\n# max=$max, limit=$limit, inc=$inc\n";
- return $inc if($max <= $inc);
- }
+ return $lmt if($max <= $lmt);
+
+ my $len = length("$max") - 1;
+ my $num = substr("$max",0,1);
+
+ if($max < 100_000) {
+ my $lmt1 = (10**$len) * $num;
+ my $lmt2 = ((10**$len) * $num) + ((1**($len-1)) * 5);
+ my $lmt3 = (10**$len) * ($num + 1);
- return $limit;
+ return $lmt1 if($max <= $lmt1);
+ return $lmt2 if($max <= $lmt2);
+ return $lmt3 if($max <= $lmt3);
}
- return $max_limit;
+ $num += ($num % 2) ? 1 : 2;
+
+ return (10**$len) * $num;
}
sub _set_range {
- my ($min,$max) = @_;
- my $step = 1;
-
- if($max < 10) { $step = 1 }
- elsif($max < 100) { $step = 10 }
- elsif($max < 500) { $step = 50 }
- elsif($max < 1000) { $step = 50 }
- elsif($max < 10000) { $step = 500 }
- elsif($max < 100000) { $step = 5000 }
- elsif($max < 1000000) { $step = 50000 }
- else { $step = 1000000 }
-
- my @r;
- for(my $r = $min; $r < ($max+$step); $r += $step) {
- my $x = $r < 1000000 ? $r < 1000 ? $r : ($r/1000) . 'k' : ($r/1000000) . 'm';
- push @r, $x;
- };
-#print "range=".(join('|',@r))."\n";
- return join('|',@r);
+ my $max = shift;
+ my $lmt = 10;
+
+ return $lmt if($max <= $lmt);
+
+ my $len = length("$max") - 1;
+ my $num = substr("$max",0,1);
+
+ if($max < 100_000) {
+ my $lmt1 = (10**$len) * $num;
+ my $lmt2 = ((10**$len) * $num) + ((1**($len-1)) * 5);
+ my $lmt3 = (10**$len) * ($num + 1);
+
+ return $lmt1 if($max <= $lmt1);
+ return $lmt2 if($max <= $lmt2);
+ return $lmt3 if($max <= $lmt3);
+ }
+
+ $num += ($num % 2) ? 1 : 2;
+
+ return (10**$len) * $num;
}
q('Will code for a nice Balti Lamb Tikka Bhuna');

0 comments on commit 8d6afc2

Please sign in to comment.