add amendments metric
[contractdashboard.git] / graphs / displayMethodCountGraph.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
include_once ("../lib/common.inc.php");
// Width and height of the graph
$width = 800;
$height = 300;
$query = "select procurementMethod, count(1) as count, value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
where $agencyQ $supplierQ childCN = 0 AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2009 group by procurementMethod,year,month order by procurementMethod,year,month";
$result = mysql_query($query);
$methods = Array("Direct","Open","Select");
$dates = Array();
$methodCountsP = Array();
$methodCounts = Array();
$maxValue = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  setlocale(LC_MONETARY, 'en_US');
  if ($row['value'] > $maxValue) $maxValue = $row['value'];
  $date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"];
  if (array_search($date,$dates) === false ) {
    $dates[$row["year"]*100 + $row["month"]] = $date;
    ksort($dates);
  }
  $methodCountsP[$row["procurementMethod"]][$date] = $row["count"];
 
}
foreach ($methods as $method) {
    foreach($dates as $date) {
        if ($methodCountsP[$method][$date] > 0) $methodCounts[$method][] = $methodCountsP[$method][$date];
        else $methodCounts[$method][] = 0;
    }
}
$dates = array_values($dates);
$totalRecords = array_sum_all($methodCounts);
mysql_free_result($result);
// Create a graph instance
$graph = new Graph($width, $height);
$graph->SetScale('datint');
$graph->SetMargin(95, 145, 45, 100);
// Setup a title for the graph
$graph->title->Set($agencyQ.$supplierQ);
$graph->SetUserFont("ttf-liberation/LiberationSans-Regular.ttf");
$graph->title->SetFont(FF_USERFONT, FS_NORMAL, 12);
// Setup font for axis
$graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 10);
$graph->xaxis->SetTickLabels($dates);
$graph->xaxis->SetLabelAngle(50);
$colors = Array ("orange","red","blue");
for ($i = 0; $i <= 2;$i++) {
   $lplot[$i] =   new LinePlot($methodCounts[$methods[$i]]);
   $lplot[$i]->SetLegend($methods[$i]);
   $lplot[$i]->SetFillColor($colors[$i]);
}
// Create the grouped bar plot
$alplot = new AccLinePlot($lplot);
// ...and add it to the graPH
$graph->Add($alplot);
$graph->Stroke();
 
 
function formatCallback($aVal) {
  global $totalRecords;
  return percent($aVal, $totalRecords) . "%";
}
$attributes = Array();
$attributeNames = Array(
  "Consultancies",
  "Confidentialities"
);
$query = "SELECT 'consultancy', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy='Yes' AND childCN = 0;";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_BOTH);
$attributes[0] = $row[1];
$query = "SELECT 'confidentiality', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract='Yes' OR confidentialityOutputs='Yes') AND childCN = 0;";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_BOTH);
$attributes[1] = $row[1];
mysql_free_result($result);
// Create a graph instance
$graph2 = new Graph($width, $height);
$graph2->SetScale('textlin',0,$totalRecords);
$graph2->Set90AndMargin(105, 45, 45, 45);
// Setup a title for the graph
$graph2->title->Set($agency);
$graph2->SetUserFont("ttf-liberation/LiberationSans-Regular.ttf");
$graph2->title->SetFont(FF_USERFONT, FS_NORMAL, 12);
// Setup font for axis
$graph2->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 10);
$graph2->xaxis->SetTickLabels($attributeNames);
$graph2->yaxis->hide();
$attb1plot = new BarPlot($attributes);
$attb1plot->value->Show();
$attb1plot->SetValuePos('top');
$attb1plot->value->SetFont(FF_USERFONT, FS_NORMAL, 12);
$attb1plot->value->SetAngle(45);
$attb1plot->value->SetFormatCallback("formatCallback");
$attb1plot->SetFillColor("orange");
// ...and add it to the graPH
$graph2->Add($attb1plot);
//-----------------------
// Create a multigraph
//----------------------
$mgraph = new MGraph();
$mgraph->SetMargin(2, 2, 2, 2);
$mgraph->Add($graph, 0, 0);
$mgraph->Add($graph2, 0, ($height) + 5);
$mgraph->Stroke();
?>