summaryrefslogtreecommitdiff
path: root/web/graph.php
blob: d8996d01fb6c418bf6385069412f8e0b72afa679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
include("../externals/pchart/class/pDraw.class.php");
include("../externals/pchart/class/pImage.class.php");
include("../externals/pchart/class/pData.class.php");

include("funcs.inc.php");

$myData = new pData();

$db = new db();

$sql = "select * from (select sum(status=0) as success,sum(status=1) as failures,sum(status=2) as timeouts,count(*) as total,date(builddate) as day from results group by date(builddate) order by builddate desc limit 180) as foo order by day;";

$ret = $db->query($sql);
if ($ret == FALSE) {
  echo "Cannot retrieve statistics<br/>";
  bab_footer();
  exit;
}

$dates_data = array();
$success_data = array();
$failures_data = array();
$timeouts_data = array();
$total_data = array();

while($current = mysql_fetch_object($ret)) {
  array_push($dates_data, $current->day);
  array_push($success_data, $current->success * 100 / $current->total);
  array_push($failures_data, $current->failures * 100 / $current->total);
  array_push($timeouts_data, $current->timeouts * 100 / $current->total);
}

/* Add data in your dataset */
$myData->addPoints($success_data, "success %");
$myData->addPoints($failures_data, "failure %");
$myData->addPoints($timeouts_data, "timeout %");
$myData->setAxisName(0,"Percentage of builds");

$myData->addPoints($dates_data, "Labels");
$myData->setSerieDescription("Labels","Dates");
$myData->setAbscissa("Labels");

/* Create a pChart object and associate your dataset */
$myPicture = new pImage(1000,600,$myData);

/* Choose a nice font */
$myPicture->setFontProperties(array("FontName"=>"../externals/pchart/fonts/verdana.ttf","FontSize"=>8));

/* Define the boundaries of the graph area */
$myPicture->setGraphArea(70,50,950,500);

$myPicture->drawScale(array("LabelRotation" => 90, "LabelSkip" => 10));

$myPicture->drawLegend(20,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

$myPicture->drawLineChart();

$myPicture->Stroke();
?>