Improve quickest streak ranking; misc bug-fixes

This commit is contained in:
Pragmatic Software 2015-05-23 02:27:08 -07:00
parent 22545d6249
commit 7a5a3a38f2
1 changed files with 18 additions and 17 deletions

View File

@ -99,21 +99,13 @@ sub print_correctstreak {
} }
sub sort_quickeststreak { sub sort_quickeststreak {
my $streak_a = $a->{lifetime_highest_quick_correct_streak} ? $a->{lifetime_highest_quick_correct_streak} : 1; my $streak_a = $a->{lifetime_highest_quick_correct_streak} ? $a->{lifetime_highest_quick_correct_streak} : -1000;
my $streak_b = $b->{lifetime_highest_quick_correct_streak} ? $b->{lifetime_highest_quick_correct_streak} : 1; my $streak_b = $b->{lifetime_highest_quick_correct_streak} ? $b->{lifetime_highest_quick_correct_streak} : -1000;
if ($rank_direction eq '+') { if ($rank_direction eq '+') {
if ($a->{lifetime_highest_quick_correct_streak} == $b->{lifetime_highest_quick_correct_streak}) { return $streak_b - $b->{lifetime_quickest_correct_streak} / $streak_b <=> $streak_a - $a->{lifetime_quickest_correct_streak} / $streak_a;
return $a->{lifetime_quickest_correct_streak} / $streak_a <=> $b->{lifetime_quickest_correct_streak} / $streak_b;
} else { } else {
return $a->{lifetime_quickest_correct_streak} / $streak_a <=> $b->{lifetime_quickest_correct_streak } / $streak_b; return $streak_a - $a->{lifetime_quickest_correct_streak} / $streak_a <=> $streak_b - $b->{lifetime_quickest_correct_streak} / $streak_b;
}
} else {
if ($b->{lifetime_highest_quick_correct_streak} == $a->{lifetime_highest_quick_correct_streak}) {
return $b->{lifetime_quickest_correct_streak} / $streak_b <=> $a->{lifetime_quickest_correct_streak} / $streak_a;
} else {
return $b->{lifetime_quickest_correct_streak} / $streak_b <=> $a->{lifetime_quickest_correct_streak } / $streak_a;
}
} }
} }
@ -213,21 +205,30 @@ if (lc $command eq 'rank') {
foreach my $player (@$players) { foreach my $player (@$players) {
next if $player->{nick} eq 'lern2play' and $opt ne 'lern2play'; next if $player->{nick} eq 'lern2play' and $opt ne 'lern2play';
next if $player->{nick} eq 'keep2play' and $opt ne 'keep2play'; next if $player->{nick} eq 'keep2play' and $opt ne 'keep2play';
$stats = $ranks{$key}->{print}->($player); $stats = $ranks{$key}->{print}->($player);
if (defined $stats) { if (defined $stats) {
my ($value) = $stats =~ /[^:]+:\s+(.*)/; my ($value) = $stats =~ /[^:]+:\s+(.*)/;
$rank++ if $value ne $last_value; $rank++ if $value ne $last_value;
$last_value = $value; $last_value = $value;
} else {
$rank++ if lc $player->{nick} eq $opt;
} }
last if lc $player->{nick} eq $opt; last if lc $player->{nick} eq $opt;
} }
if ($rank == 0) { if (not $rank) {
push @rankings, "$key: N/A"; push @rankings, "$ranks{key}->{title}: N/A";
} else {
if (not $stats) {
push @rankings, "$ranks{$key}->{title}: #$rank (N/A)";
} else { } else {
$stats =~ s/[^:]+:\s+//; $stats =~ s/[^:]+:\s+//;
push @rankings, "$ranks{$key}->{title}: #$rank ($stats)"; push @rankings, "$ranks{$key}->{title}: #$rank ($stats)";
} }
} }
}
if (lc $nick ne $opt) { if (lc $nick ne $opt) {
print "$player_nick->{nick}'s rankings: " print "$player_nick->{nick}'s rankings: "
@ -263,7 +264,7 @@ if (lc $command eq 'rank') {
} }
if (not scalar @ranking) { if (not scalar @ranking) {
if ($offset) { if ($offset > 1) {
print "No rankings available for $channel at offset #$offset.\n"; print "No rankings available for $channel at offset #$offset.\n";
} else { } else {
print "No rankings available for $channel yet.\n"; print "No rankings available for $channel yet.\n";