<pre>
------ Stats ------
<?PHP

// Include the config
require_once('../include/config.inc.php');

$date date('Y-m-d'mktime(0,0,0,date('m'), date('d') -1date('Y')));

// counts
$sql "SELECT count(*) cnt FROM category WHERE _removed IS NULL";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$category_count $row['cnt'];
}

$sql "SELECT count(*) cnt FROM package WHERE _removed IS NULL";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$package_count $row['cnt'];
}

$sql "SELECT count(*) cnt FROM ebuild WHERE _removed IS NULL";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$ebuild_count $row['cnt'];
}

// deletions
$sql "SELECT count(*) cnt FROM category WHERE date_format(_removed, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$del_category $row['cnt'];
}

$sql "SELECT count(*) cnt FROM package WHERE date_format(_removed, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$del_package $row['cnt'];
}

$sql "SELECT count(*) cnt FROM ebuild WHERE date_format(_removed, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$del_ebuild $row['cnt'];
}

// additions
$sql "SELECT count(*) cnt FROM category WHERE date_format(_added, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$add_category $row['cnt'];
}

$sql "SELECT count(*) cnt FROM package WHERE date_format(_added, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$add_package $row['cnt'];
}

$sql "SELECT count(*) cnt FROM ebuild WHERE date_format(_added, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$add_ebuild $row['cnt'];
}

// comments
$sql "SELECT count(*) cnt FROM package_comment WHERE date_format(_added, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$add_comment $row['cnt'];
}

// screenshots
$sql "SELECT count(*) cnt FROM package_image WHERE date_format(_added, '%Y-%m-%d') = '{$date}' ";
$results mysql_query($sql) or die(mysql_error());
if(
$row mysql_fetch_assoc($results)){
    
$add_images $row['cnt'];
}


/**************
SQL
***************/

$sql "INSERT INTO stats SET 

category = '{$category_count}',
package = '{$package_count}',
ebuild = '{$ebuild_count}',
del_category = '{$del_category}',
del_package = '{$del_package}',
del_ebuild = '{$del_ebuild}',
add_category = '{$add_category}',
add_package = '{$add_package}',
add_ebuild = '{$add_ebuild}',
comments = '{$add_comment}',
images = '{$add_images}',
stats_date = '{$date}'

"
;
mysql_query($sql);

/***************
graphs
****************/

define ("TTF_DIR""/usr/share/fonts/corefonts/");

include (
"../include/jpgraph/jpgraph.php");
include (
"../include/jpgraph/jpgraph_bar.php");
include (
"../include/jpgraph/jpgraph_line.php");
include (
"../include/jpgraph/jpgraph_regstat.php");

// Some data
$months=$gDateLocale->GetShortMonth();
/* srand ((double) microtime() * 1000000);
for( $i=0; $i<25; ++$i) {
        $databary[]=rand(1,50);
        $databarx[]=$months[$i%12];
} */

$category_x = array();
$category_y = array();
$package_x = array();
$package_y = array();
$ebuild_x = array();
$ebuild_y = array();
$add_category_x = array();
$add_category_y = array();
$add_package_x = array();
$add_package_y = array();
$add_ebuild_x = array();
$add_ebuild_y = array();
$del_category_x = array();
$del_category_y = array();
$del_package_x = array();
$del_package_y = array();
$del_ebuild_x = array();
$del_ebuild_y = array();
$add_comment_x = array();
$add_comment_y = array();
$add_image_x = array();
$add_image_y = array();

$sql "SELECT * FROM `stats` ORDER BY stats_date";
$results mysql_query($sql) or die(mysql_error());
while(
$row mysql_fetch_assoc($results)){
    
$category_y[] = $row['category'];
    
$category_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$package_y[] = $row['package'];
    
$package_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$ebuild_y[] = $row['ebuild'];
    
$ebuild_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$add_category_y[] = $row['add_category'];
    
$add_category_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$add_package_y[] = $row['add_package'];
    
$add_package_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$add_ebuild_y[] = $row['add_ebuild'];
    
$add_ebuild_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$del_category_y[] = $row['del_category'];
    
$del_category_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$del_package_y[] = $row['del_package'];
    
$del_package_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$del_ebuild_y[] = $row['del_ebuild'];
    
$del_ebuild_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$add_comment_y[] = $row['comments'];
    
$add_comment_x[] = parse_date($row['stats_date'], 'd/m/Y');
    
    
$add_image_y[] = $row['images'];
    
$add_image_x[] = parse_date($row['stats_date'], 'd/m/Y');
}

writegraph('category.png''Total Categories'$category_x$category_y);
writegraph('package.png''Total Packages'$package_x$package_y);
writegraph('ebuild.png''Total Ebuilds'$ebuild_x$ebuild_y);

writegraph('category_add.png''Categories Added'$add_category_x$add_category_y);
writegraph('package_add.png''Packages Added'$add_package_x$add_package_y);
writegraph('ebuild_add.png''Ebuilds Added'$add_ebuild_x$add_ebuild_y);

writegraph('category_del.png''Categories Removed'$del_category_x$del_category_y);
writegraph('package_del.png''Packages Removed'$del_package_x$del_package_y);
writegraph('ebuild_del.png''Ebuilds Removed'$del_ebuild_x$del_ebuild_y);

writegraph('comments_add.png''Comments Added'$add_comment_x$add_comment_y);
writegraph('images_add.png''Images Added'$add_image_x$add_image_y);


function 
writegraph($file$title$xdata$ydata){

    
// New graph
    
$graph = new Graph(550,220,'auto');
    
    
// margins
    
$top 20;
    
$bottom 50;
    
$left 55;
    
$right 30;
    
$graph->SetMargin($left,$right,$top,$bottom);
    
$graph->SetMarginColor("#FFFFF9");
    
$graph->SetColor("#FFFFF9");
    
$graph->SetFrame(true,"#DCDCD7",2);

    
// Use a "text" X-scale
    
$min floor(min($ydata) -  max($ydata) * .03);
    if(
$min 10 || min($ydata) -  max($ydata) * .1 $min 0;
    
$max ceil(max($ydata) * 1.03);
    
$graph->SetScale("textlin"$min$max);

    
// Specify X-labels
    
$graph->xaxis->SetTickLabels($xdata);
    
$graph->xaxis->SetTextLabelInterval(ceil(count($xdata) / 5));
    
$graph->xaxis->HideTicks(truefalse);
    
$graph->xaxis->SetColor("#465273","#333333");
    
$graph->xaxis->SetFont(FF_FONT1,FS_NORMAL,8);
    
//$graph->xaxis->SetLabelAlign('center','top');
    //$graph->xaxis->SetLabelAngle(55);
    
    // Y - Axis
    
$graph->yaxis->SetColor("#465273","#333333");
    
$graph->yaxis->HideTicks(true,true);
    
$graph->yaxis->SetFont(FF_FONT1,FS_NORMAL,8);
    
$graph->yaxis->scale->SetGrace(5);
    
$graph->yaxis->title->SetColor("#333333");
    
$graph->yaxis->SetLabelAlign('right','bottom');

    
// Set title
    
$graph->title->Set($title);
    
$graph->title->SetFont(FF_FONT1,FS_NORMAL,8);
    
$graph->title->SetColor("#333333");

    
// Create the bar plot
    //$b1 = new BarPlot($ydata);
    //$graph->Add($b1);

    // cgreate the line plot
    
$p1 = new LinePlot($ydata);
    
$p1->SetColor("#B3BFD6");
    
$graph->Add($p1);
    
    
// Finally output the  image
    
$graph->Stroke('../htdocs/img/stats/'.$file);
    
    
    
    
/*
    $graph = new Graph(450,300,"auto");
    $graph->SetScale("intlin");

    $top = 20;
    $bottom = 50;
    $left = 55;
    $right = 30;
    $graph->SetMargin($left,$right,$top,$bottom);
    
    
    $graph->title->Set("New Ebuilds To Portage (Daily)");
    $graph->title->SetColor("#333333");
    $graph->title->SetFont(FF_ARIAL,FS_BOLD,8);
    $graph->SetMarginColor("#FFFFF9");
    $graph->SetColor("#FFFFF9");
    $graph->SetFrame(true,"#DCDCD7",2);

    //$graph->xaxis->SetTickLabels($datax1);
    $graph->xaxis->SetColor("#465273","#333333");
    $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
    $graph->xaxis->SetLabelAlign('center','top');
    $graph->xaxis->HideTicks(true,false);
    $graph->xaxis->SetLabelFormatCallback('getEbuildDate');
    $graph->xaxis->SetLabelAngle(55);

    $graph->yaxis->SetColor("#465273","#333333");
    $graph->yaxis->HideTicks(true,true);
    $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
    $graph->yaxis->scale->SetGrace(5);
    $graph->yaxis->title->SetColor("#333333");
    $graph->yaxis->SetLabelAlign('right','bottom');
    $graph->yaxis->title->SetFont(FF_ARIAL,FS_NORMAL,8);
    $graph->yaxis->title->Align('center');

    $p1 = new LinePlot($ebuildsy, $ebuildsx);
    $p1->SetColor("#B3BFD6");
    $p2 = getSlowCurve($ebuildsy, $ebuildsx);
    $p2->SetColor("#465273");
    $graph->Add($p1);
    $graph->Add($p2);
    $graph->Stroke("../img/ebuild-hist.png");
    */
    
    
}

?>
</pre>
<img src="/img/stats/category.png" /><br/>
<img src="/img/stats/package.png" /><br/>
<img src="/img/stats/ebuild.png" /><br/>
<img src="/img/stats/category_add.png" /><br/>
<img src="/img/stats/package_add.png" /><br/>
<img src="/img/stats/ebuild_add.png" /><br/>
<img src="/img/stats/category_del.png" /><br/>
<img src="/img/stats/package_del.png" /><br/>
<img src="/img/stats/ebuild_del.png" /><br/>
<img src="/img/stats/comments_add.png" /><br/>
<img src="/img/stats/images_add.png" />