Add date for quickest/longest answer qstat

This commit is contained in:
Pragmatic Software 2015-05-23 06:24:22 -07:00
parent afad192b83
commit ae128442a8
2 changed files with 17 additions and 0 deletions

View File

@ -44,8 +44,10 @@ CREATE TABLE IF NOT EXISTS QStats (
highest_wrong_streak INTEGER DEFAULT 0,
hints INTEGER DEFAULT 0,
quickest_answer_time NUMERIC DEFAULT 0,
quickest_answer_date NUMERIC DEFAULT 0,
quickest_answer_nick TEXT COLLATE NOCASE DEFAULT NULL,
longest_answer_time NUMERIC DEFAULT 0,
longest_answer_date NUMERIC DEFAULT 0,
longest_answer_nick TEXT COLLATE NOCASE DEFAULT NULL,
average_answer_time NUMERIC DEFAULT 0
)
@ -74,6 +76,19 @@ sub end {
}
}
sub find_question {
my ($self, $id) = @_;
my $exists = eval {
my $sth = $self->{dbh}->prepare('SELECT 1 FROM QStats WHERE id = ?');
$sth->bind_param(1, $id);
$sth->execute();
return $sth->fetchrow_hashref();
};
print STDERR $@ if $@;
return $exists;
}
sub add_question {
my ($self, $id) = @_;

View File

@ -197,11 +197,13 @@ foreach my $answer (@valid_answers) {
if ($qdata->{quickest_answer_time} == 0 or $elapsed < $qdata->{quickest_answer_time}) {
$qdata->{quickest_answer_time} = $elapsed;
$qdata->{quickest_answer_date} = gettimeofday;
$qdata->{quickest_answer_nick} = $nick;
}
if ($elapsed > $qdata->{longest_answer_time}) {
$qdata->{longest_answer_time} = $elapsed;
$qdata->{longest_answer_date} = gettimeofday;
$qdata->{longest_answer_nick} = $nick;
}