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, 6 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Corrected off-by-one error in stats.pl

    1: #!/usr/bin/perl
    2: #
    3: # Get statistics for the database in the form
    4: # Date total_questions  distinct_questions
    5: #
    6: use DBI;
    7: use CGI ':all';
    8: use strict;
    9: 
   10: eval {require "dbdefs.pl";};
   11: my $dbuser||="piataev";
   12: my $dbname||="chgk";
   13: my $dbpass||="";
   14: my $dbhost||="localhost";
   15: 
   16: 
   17: my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) =
   18:     gmtime(time);
   19: $year += 1900;
   20: $mon ++;
   21: my @names=('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
   22: $wday=$names[$wday];
   23: 
   24: printf "$wday %04d-%02d-%02d %02d:%02d:%02d GMT ", $year,$mon,$mday,$hour,$min,$sec;
   25: 
   26: my($dsn) = "DBI:mysql:database=$dbname;host=$dbhost";
   27: my $dbh = DBI->connect($dsn, $dbuser, $dbpass) || die "Cannot connect\n";
   28: 
   29: my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions");
   30: $sth->execute;
   31: my $total=($sth->fetchrow)[0];
   32: $sth->finish;
   33: $sth= $dbh -> prepare("select distinct count(first) FROM equalto");
   34: $sth -> execute;
   35: my ($equal)=$sth->fetchrow;
   36: $sth -> finish;
   37: 
   38: print " $total ",$total-$equal, "\n";
   39: 
   40: $dbh->disconnect;
   41: 
   42: exit 0;

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