mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-22 11:59:43 +01:00
Add nick field to WrongAnswers; don't update average if > 10 mins elapsed since question asked
This commit is contained in:
parent
cd0486e525
commit
b79b835579
@ -57,6 +57,7 @@ SQL
|
||||
CREATE TABLE IF NOT EXISTS WrongAnswers (
|
||||
id INTEGER,
|
||||
answer TEXT NOT NULL COLLATE NOCASE,
|
||||
nick TEXT NOT NULL COLLATE NOCASE,
|
||||
count INTEGER DEFAULT 1
|
||||
)
|
||||
SQL
|
||||
@ -170,7 +171,7 @@ sub get_wrong_answers {
|
||||
}
|
||||
|
||||
sub add_wrong_answer {
|
||||
my ($self, $id, $answer) = @_;
|
||||
my ($self, $id, $answer, $nick) = @_;
|
||||
|
||||
$answer = lc $answer;
|
||||
$answer =~ s/^\s+|\s+$//g;
|
||||
@ -187,19 +188,21 @@ sub add_wrong_answer {
|
||||
|
||||
if (not $found_ans) {
|
||||
eval {
|
||||
my $sth = $self->{dbh}->prepare("INSERT INTO WrongAnswers (id, answer) VALUES (?, ?)");
|
||||
my $sth = $self->{dbh}->prepare("INSERT INTO WrongAnswers (id, answer, nick) VALUES (?, ?, ?)");
|
||||
$sth->bind_param(1, $id);
|
||||
$sth->bind_param(2, $answer);
|
||||
$sth->bind_param(3, $nick);
|
||||
$sth->execute();
|
||||
};
|
||||
print STDERR $@ if $@;
|
||||
} else {
|
||||
$found_ans->{count}++;
|
||||
eval {
|
||||
my $sth = $self->{dbh}->prepare("UPDATE WrongAnswers SET count = ? WHERE id = ? AND answer = ?");
|
||||
my $sth = $self->{dbh}->prepare("UPDATE WrongAnswers SET count = ?, nick = ? WHERE id = ? AND answer = ?");
|
||||
$sth->bind_param(1, $found_ans->{count});
|
||||
$sth->bind_param(2, $id);
|
||||
$sth->bind_param(3, $answer);
|
||||
$sth->bind_param(2, $nick);
|
||||
$sth->bind_param(3, $id);
|
||||
$sth->bind_param(4, $answer);
|
||||
$sth->execute();
|
||||
};
|
||||
print STDERR $@ if $@;
|
||||
|
@ -189,7 +189,7 @@ foreach my $answer (@valid_answers) {
|
||||
$qdata->{last_correct_time} = gettimeofday;
|
||||
$qdata->{last_correct_nick} = $nick;
|
||||
|
||||
if (gettimeofday - $qdata->{last_touched} < 60 * 5) {
|
||||
if (gettimeofday - $qdata->{last_asked} < 60 * 10) {
|
||||
$qdata->{average_answer_time} *= $qdata->{correct} - 1;
|
||||
$qdata->{average_answer_time} += $elapsed;
|
||||
$qdata->{average_answer_time} /= $qdata->{correct};
|
||||
@ -356,7 +356,7 @@ if ($qdata->{wrong_streak} > $qdata->{highest_wrong_streak}) {
|
||||
$qdata->{highest_wrong_streak} = $qdata->{wrong_streak};
|
||||
}
|
||||
|
||||
$qstats->add_wrong_answer($id, $lctext);
|
||||
$qstats->add_wrong_answer($id, $lctext, $nick);
|
||||
|
||||
my %streaks = (
|
||||
5 => "Guessing, are we, $nick?",
|
||||
|
Loading…
Reference in New Issue
Block a user