More value heuristics
[contractdashboard.git] / graphs / displayAgencySuppliersGraph.php
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
<?php
include_once ("../lib/common.inc.php");
$agency = "AusAid";
$topX = 15;
$query = "SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 AND agencyName = '$agency'
GROUP BY lower(supplierName) ORDER BY val DESC limit $topX";
$result = mysql_query($query);
$suppliers = Array();
$values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
  $suppliers[] = ucsmart($row['supplierName']);
  $values[] = doubleval($row["val"]);
}
mysql_free_result($result);
 
$query = "SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 and agencyName = '$agency'
GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
if ($row['count'] > 0) {
  $suppliers[] = $row['count'] . " other suppliers";
  $values[] = doubleval($row[0]);
}
}
mysql_free_result($result);
 
// Width and height of the graph
$width = 800;
$height = 800;
// Create a graph instance
$graph = new PieGraph($width, $height);
$pieplot = new PiePlot($values);
$pieplot->SetCenter(400, 300);
$pieplot->SetGuideLines(true, false);
$pieplot->SetLegends($suppliers);
// Add the plot to the graph
$graph->Add($pieplot);
$graph->legend->SetPos(0.01, 0.97, 'left', 'bottom');
$graph->legend->SetColumns(2);
// Display the graph
$graph->Stroke();
?>