File:  [Local Repository] / db / prgsrc / stats.pl
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Wed Nov 10 03:31:39 2004 UTC (19 years, 5 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Corrected off-by-one error in stats.pl

#!/usr/bin/perl
#
# Get statistics for the database in the form
# Date total_questions  distinct_questions
#
use DBI;
use CGI ':all';
use strict;

eval {require "dbdefs.pl";};
my $dbuser||="piataev";
my $dbname||="chgk";
my $dbpass||="";
my $dbhost||="localhost";


my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =
    gmtime(time);
$year += 1900;
$mon ++;
my @names=('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
$wday=$names[$wday];

printf "$wday %04d-%02d-%02d %02d:%02d:%02d GMT ", $year,$mon,$mday,$hour,$min,$sec;

my($dsn) = "DBI:mysql:database=$dbname;host=$dbhost";
my $dbh = DBI->connect($dsn, $dbuser, $dbpass) || die "Cannot connect\n";

my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions");
$sth->execute;
my $total=($sth->fetchrow)[0];
$sth->finish;
$sth= $dbh -> prepare("select distinct count(first) FROM equalto");
$sth -> execute;
my ($equal)=$sth->fetchrow;
$sth -> finish;

print " $total ",$total-$equal, "\n";

$dbh->disconnect;

exit 0;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>