Initial add of defaria.com
[clearscm.git] / defaria.com / GD / Rantest / GraphStats.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        GraphStats.php
5 // Revision:    1.2
6 // Description: Produce a graph showing number of tests passed/failed for a
7 //              date range.
8 // Author:      Andrew@ClearSCM.com
9 // Created:     Mon Apr 28 15:20:06 MST 2008
10 // Modified:    
11 // Language:    PHP
12 //
13 // (c) Copyright 2008, General Dynamics, all rights reserved.
14 //
15 // All rights reserved except as subject to DFARS 252.227-7014 of contract
16 // number CP02H8901N issued under prime contract N00039-04-C-2009.
17 //
18 // Warning: This document contains technical data whose export is restricted
19 // by the Arms Export Control Act (Title 22, U.S.C., Sec 2751, et seq.) or the
20 // Export Administration Act of 1979, as amended, Title, 50, U.S.C., App. 2401
21 // et seq. Violations of these export laws are subject to severe criminal
22 // penalties. Disseminate in accordance with provisions of DoD Directive
23 // 5230.25.
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26 $script = basename ($_SERVER["PHP_SELF"]);
27 $inc    = $_SERVER["DOCUMENT_ROOT"];
28
29 include_once "$inc/php/Utils.php";
30 include_once "$inc/php/RantestDB.php";
31
32 include_once ("$inc/pChart/pData.class");
33 include_once ("$inc/pChart/pChart.class");
34
35 $start  = $_REQUEST["start"];
36 $end    = $_REQUEST["end"];
37 $type   = $_REQUEST["type"];
38
39 $debug;
40
41 function mydebug ($msg) {
42   $debug = fopen ("/tmp/debug.log", "a");
43
44   fwrite ($debug, "$msg\n");
45 } // mydebug
46
47 // Sorting functions
48 function sortByDate ($a, $b) {
49   return strcmp ($a["Date"], $b["Date"]);
50 } // sortByDate
51
52 openDB ();
53
54 $data = getStatus ($start, $end, $type);
55
56 usort ($data, "sortByDate");
57
58 $fonts = "$inc/Fonts";
59
60 // Dataset definition 
61 $DataSet = new pData;
62
63 foreach ($data as $result) {
64   $reportDate = YMD2MDY ($result["Date"]);
65
66 //  mydebug ("$reportDate Success $result[Success] Failure $result[Failure]");
67
68   $DataSet->AddPoint ($result["Success"], "Passed",     $reportDate);
69   $DataSet->AddPoint ($result["Failure"], "Failed");
70 } // foreach
71
72 $DataSet->AddAllSeries ();
73 $DataSet->SetAbsciseLabelSerie ();
74
75 $DataSet->SetSerieName ("Passed", "Passed");
76 $DataSet->SetSerieName ("Failed", "Failed");
77
78 // Initialise the graph
79 $Test = new pChart (700, 280);
80 $Test->drawGraphAreaGradient (100, 150, 175, 100, TARGET_BACKGROUND);
81 $Test->setFontProperties ("$fonts/tahoma.ttf", 8);
82 $Test->setGraphArea (50, 30, 680, 200);
83 $Test->drawRoundedRectangle (5, 5, 695, 275, 5, 230, 230, 230);
84 $Test->drawGraphAreaGradient (162, 183, 202, 50);
85 $Test->drawScale ($DataSet->GetData (), $DataSet->GetDataDescription (), SCALE_ADDALL, 200, 200, 200, true, 70, 2, true);
86 $Test->drawGrid (4, true, 230, 230, 230, 50);
87
88 // Draw the 0 line
89 $Test->setFontProperties ("$fonts/tahoma.ttf", 6);
90 $Test->drawTreshold (0, 143, 55, 72, true, true);
91
92 // Draw the bar graph
93 $Test->drawStackedBarGraph ($DataSet->GetData (), $DataSet->GetDataDescription (), 75);
94
95 // Finish the graph
96 $Test->setFontProperties ("$fonts/tahoma.ttf",8);
97 $Test->drawLegend (610, 35, $DataSet->GetDataDescription (), 130, 180, 205);
98 $Test->setFontProperties ("$fonts/tahoma.ttf", 10);
99 $Test->drawTitle (50, 22, "Test Metrics ($type)", 255, 255, 255, 675);
100 $Test->Stroke ();