Improve quickest-streak algorithm for setting new records

Use the following formula to set personal records for quickest-streak
relative to an existing personal current record.

(ranked_streak + ranked_streak) / ranked_answers > (current_streak + ranked_streak) / current_answers

E.g., given a current record of 8 correct answers in a row in 1 minute and
20 seconds, to beat that record you'd need: 6 answers in 40 seconds, 7 in
1 minute, 9 in 1 minute 40 seconds, 10 in 2 minutes, etc.
This commit is contained in:
Pragmatic Software 2015-05-22 04:03:39 -07:00
parent b0b74cd6ea
commit 04a308a59e
1 changed files with 15 additions and 11 deletions

View File

@ -214,21 +214,25 @@ foreach my $answer (@valid_answers) {
my $dont_print_streak = 0;
if (($player_data->{correct_streak} > $player_data->{highest_quick_correct_streak})
or ($player_data->{correct_streak} == $player_data->{highest_quick_correct_streak}
and (gettimeofday - $player_data->{correct_streak_timestamp} < $player_data->{quickest_correct_streak}))) {
my $t1 = $player_data->{lifetime_quickest_correct_streak} ? $player_data->{lifetime_quickest_correct_streak} : 32767;
my $t2 = gettimeofday - $player_data->{correct_streak_timestamp};
my $a1 = $player_data->{lifetime_highest_quick_correct_streak} ? $player_data->{lifetime_highest_quick_correct_streak} : 1;
my $a2 = $player_data->{correct_streak} ? $player_data->{correct_streak} : 1;
my $ratio1 = ($t1 + $t1) / $a1;
my $ratio2 = ($t2 + $t1) / $a2;
print STDERR "nick: $nick, t1 = $t1, t2 = $t2, a1 = $a1, a2 = $a2, ratio1 = $ratio1, ratio2 = $ratio2\n";
if ($ratio2 < $ratio1 and $player_data->{correct_streak} >= 3) {
$player_data->{highest_quick_correct_streak} = $player_data->{correct_streak};
$player_data->{quickest_correct_streak} = gettimeofday - $player_data->{correct_streak_timestamp};
if ($player_data->{highest_quick_correct_streak} > $player_data->{lifetime_highest_quick_correct_streak}) {
$player_data->{lifetime_highest_quick_correct_streak} = $player_data->{highest_quick_correct_streak};
$player_data->{lifetime_quickest_correct_streak} = $player_data->{quickest_correct_streak};
}
$player_data->{lifetime_highest_quick_correct_streak} = $player_data->{highest_quick_correct_streak};
$player_data->{lifetime_quickest_correct_streak} = $player_data->{quickest_correct_streak};
if ($player_data->{highest_quick_correct_streak} >= 3) {
print "$color{orange}$nick$color{cyan} just set a new personal quickest correct answer streak of $color{orange}$player_data->{highest_quick_correct_streak} $color{cyan}correct answers in $color{orange}", duration($player_data->{quickest_correct_streak}), "$color{cyan}!$color{reset}\n";
$dont_print_streak = 1;
}
print "$color{orange}$nick$color{cyan} just set a new personal quickest correct answer streak of $color{orange}$player_data->{highest_quick_correct_streak} $color{cyan}correct answers in $color{orange}", duration($player_data->{quickest_correct_streak}), "$color{cyan}!$color{reset}\n";
$dont_print_streak = 1;
}
unless ($dont_print_streak) {