cvs: pearweb /public_html package-stats-graph.php package-stats.php

From: Date: Tue, 28 May 2002 18:31:36 +0000
Subject: cvs: pearweb /public_html package-stats-graph.php package-stats.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4219@lists.php.net to get a copy of this message
richard Tue May 28 14:31:36 2002 EDT Modified files: /pearweb/public_html package-stats-graph.php package-stats.php Log: * ws Index: pearweb/public_html/package-stats-graph.php diff -u pearweb/public_html/package-stats-graph.php:1.1 pearweb/public_html/package-stats-graph.php:1.2 --- pearweb/public_html/package-stats-graph.php:1.1 Tue May 28 14:20:16 2002 +++ pearweb/public_html/package-stats-graph.php Tue May 28 14:31:36 2002 @@ -2,8 +2,8 @@ /** * Filename.......: package-stats-graph.php * Project........: Pearweb -* Last Modified..: $Date: 2002/05/28 18:20:16 $ -* CVS Revision...: $Revision: 1.1 $ +* Last Modified..: $Date: 2002/05/28 18:31:36 $ +* CVS Revision...: $Revision: 1.2 $ * * Use JPGraph library to display graphical * stats of downloads. @@ -15,71 +15,71 @@ * bar chart. */ - include ("../jpgraph/jpgraph.php"); - include ("../jpgraph/jpgraph_bar.php"); + include ("../jpgraph/jpgraph.php"); + include ("../jpgraph/jpgraph_bar.php"); /** * Determine the stats based on the supplied * package id (pid) and release id (rid). * Release id may be empty implying all releases. */ - for ($i=date('n'), $year=date('Y'); count(@$data_x) < 12; $i--) { - if ($i == 0) { - $i = 12; - $year--; - } - $data_x[$i] = date("M", mktime(0,0,0,$i,1,$year)); - $data_y[$i] = 0; - } - - $sql = sprintf("SELECT UNIX_TIMESTAMP(d.dl_when) AS date, COUNT(*) AS downloads - FROM packages p, downloads d - WHERE d.package = p.id - AND p.id = %s - %s - GROUP BY MONTH(d.dl_when) - ORDER BY YEAR(d.dl_when) DESC, MONTH(d.dl_when) DESC", - $_GET['pid'], - $release_clause = !empty($_GET['rid']) ? ' AND d.release = ' . $_GET['rid'] : ''); - - if ($result = $dbh->query($sql)) { - while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - $data_y[date('n', $row['date'])] = $row['downloads']; - } - } + for ($i=date('n'), $year=date('Y'); count(@$data_x) < 12; $i--) { + if ($i == 0) { + $i = 12; + $year--; + } + $data_x[$i] = date("M", mktime(0,0,0,$i,1,$year)); + $data_y[$i] = 0; + } + + $sql = sprintf("SELECT UNIX_TIMESTAMP(d.dl_when) AS date, COUNT(*) AS downloads + FROM packages p, downloads d + WHERE d.package = p.id + AND p.id = %s + %s + GROUP BY MONTH(d.dl_when) + ORDER BY YEAR(d.dl_when) DESC, MONTH(d.dl_when) DESC", + $_GET['pid'], + $release_clause = !empty($_GET['rid']) ? 'AND d.release = ' . $_GET['rid'] : ''); + + if ($result = $dbh->query($sql)) { + while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $data_y[date('n', $row['date'])] = $row['downloads']; + } + } - $data_x = array_reverse(array_values($data_x)); - $data_y = array_reverse(array_values($data_y)); + $data_x = array_reverse(array_values($data_x)); + $data_y = array_reverse(array_values($data_y)); /** * Go through setting up the graph */ - // Main graph object - $graph = new Graph(543,200,"jabba", 5); - $graph->img->SetMargin(40,20,30,30); - $graph->SetScale("textlin"); - $graph->SetMarginColor("#cccccc"); - - // Set up the title for the graph - $graph->title->Set("Download statistics for " . $dbh->getOne('SELECT name FROM packages WHERE id = ' . $_GET['pid'])); - $graph->title->SetColor("black"); - - // Show 0 label on Y-axis (default is not to show) - $graph->yscale->ticks->SupressZeroLabel(false); - - // Setup X-axis labels - $graph->xaxis->SetTickLabels($data_x); - - // Create the bar pot - $bplot = new BarPlot($data_y); - $bplot->SetWidth(0.6); - $bplot->SetFillGradient("white","#339900",GRAD_HOR); - //$bplot->setFillColor("#339900"); - - // Set color for the frame of each bar - $bplot->SetColor("black"); - $graph->Add($bplot); + // Main graph object + $graph = new Graph(543,200,"jabba", 5); + $graph->img->SetMargin(40,20,30,30); + $graph->SetScale("textlin"); + $graph->SetMarginColor("#cccccc"); + + // Set up the title for the graph + $graph->title->Set("Download statistics for " . $dbh->getOne('SELECT name FROM packages WHERE id = ' . $_GET['pid'])); + $graph->title->SetColor("black"); + + // Show 0 label on Y-axis (default is not to show) + $graph->yscale->ticks->SupressZeroLabel(false); + + // Setup X-axis labels + $graph->xaxis->SetTickLabels($data_x); + + // Create the bar pot + $bplot = new BarPlot($data_y); + $bplot->SetWidth(0.6); + $bplot->SetFillGradient("white","#339900",GRAD_HOR); + //$bplot->setFillColor("#339900"); + + // Set color for the frame of each bar + $bplot->SetColor("black"); + $graph->Add($bplot); - // Finally send the graph to the browser - $graph->Stroke(); + // Finally send the graph to the browser + $graph->Stroke(); ?> Index: pearweb/public_html/package-stats.php diff -u pearweb/public_html/package-stats.php:1.6 pearweb/public_html/package-stats.php:1.7 --- pearweb/public_html/package-stats.php:1.6 Tue May 28 14:20:16 2002 +++ pearweb/public_html/package-stats.php Tue May 28 14:31:36 2002 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Authors: Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ - $Id: package-stats.php,v 1.6 2002/05/28 18:20:16 richard Exp $ + $Id: package-stats.php,v 1.7 2002/05/28 18:31:36 richard Exp $ */ auth_require(); @@ -173,10 +173,10 @@ $bb->end(); - /** + /** * Print the graph */ - printf('<br /><img src="package-stats-graph.php?pid=%s&rid=%s" width="543" height="200" alt="">', $_GET['pid'], $_GET['rid']); + printf('<br /><img src="package-stats-graph.php?pid=%s&rid=%s" width="543" height="200" alt="">', $_GET['pid'], $_GET['rid']); } } else {

« previous php.pear.cvs (#4219) next »