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

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;
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;
