2 ////////////////////////////////////////////////////////////////////////////////
6 // Description: Produce a report or chart of the test statistics
7 // Author: Andrew@ClearSCM.com
8 // Created: Mon Apr 28 15:20:06 MST 2008
12 // (c) Copyright 2008, General Dynamics, all rights reserved.
14 // All rights reserved except as subject to DFARS 252.227-7014 of contract
15 // number CP02H8901N issued under prime contract N00039-04-C-2009.
17 // Warning: This document contains technical data whose export is restricted
18 // by the Arms Export Control Act (Title 22, U.S.C., Sec 2751, et seq.) or the
19 // Export Administration Act of 1979, as amended, Title, 50, U.S.C., App. 2401
20 // et seq. Violations of these export laws are subject to severe criminal
21 // penalties. Disseminate in accordance with provisions of DoD Directive
24 ////////////////////////////////////////////////////////////////////////////////
25 $script = basename ($_SERVER["PHP_SELF"]);
27 include_once "$_SERVER[DOCUMENT_ROOT]/php/Utils.php";
28 include_once "$_SERVER[DOCUMENT_ROOT]/php/RantestDB.php";
30 $start = $_REQUEST["start"];
31 $end = $_REQUEST["end"];
32 $user = $_REQUEST["user"];
34 $action = (empty ($_REQUEST["action"])) ? "Report" : $_REQUEST["action"];
35 $type = (empty ($_REQUEST["type"])) ? "All" : $_REQUEST["type"];
36 $sortBy = (empty ($_REQUEST["sortBy"])) ? "Date" : $_REQUEST["sortBy"];
37 $direction = (empty ($_REQUEST["direction"])) ? "descending" : $_REQUEST["direction"];
39 function getData ($start, $end) {
42 $data = getStatus ($start, $end);
45 if ($sortBy == "Passed") {
46 uasort ($data, "sortSuccess");
47 } elseif ($sortBy == "Failed") {
48 uasort ($data, "sortFailure");
49 } elseif ($sortBy == "Total") {
50 uasort ($data, "sortTotal");
52 uasort ($data, "sortDate");
58 function exportStats ($start, $end) {
59 $title = "Test Statistics from $start to $end";
60 $filename = "Test Statistics." . $start . "." . $end . ".csv";
62 header ("Content-Type: application/octect-stream");
63 header ("Content-Disposition: attachment; filename=\"$filename\"");
65 print exportCSV (getData ($start, $end), $title);
70 function createHeader () {
74 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
75 "http://www.w3.org/TR/html4/strict.dtd">
78 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
79 <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
80 <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
81 <title>Test Statistics from $start to $end></title>
88 <h1 align="center">Test Statistics from $start to $end</h1>
94 function CreatePage ($start, $end, $forEmail = false, $message = "") {
95 global $sortBy, $direction, $script;
97 $data = getData ($start, $end);
103 $direction = ($direction == "ascending") ? "descending" : "ascending";
104 $urlParms = "$script?start=$start&end=$end&action=$action&direction=$direction&sortBy";
106 if ($sortBy == "Passed") {
107 $passedDirection = ($direction == "ascending")
108 ? "<img src=/images/down.png align=absmiddle border=0>"
109 : "<img src=/images/up.png border=0>";
110 } elseif ($sortBy == "Failed") {
111 $failedDirection = ($direction == "ascending")
112 ? "<img src=/images/down.png border=0>"
113 : "<img src=/images/up.png align=absmiddle border=0>";
114 } elseif ($sortBy == "Total") {
115 $totalDirection = ($direction == "ascending")
116 ? "<img src=/images/down.png border=0>"
117 : "<img src=/images/up.png align=absmiddle border=0>";
119 $dateDirection = ($direction == "ascending")
120 ? "<img src=/images/down.png border=0>"
121 : "<img src=/images/up.png align=absmiddle border=0>";
124 if (isset ($message)) {
125 $page .= "<div align=center>$message</div>";
130 <table align=center width=60%>
137 <th class=clear align="left" colspan="2"><a href="$script?action=Export&start=$start&end=$end"><input type="submit" value="Export to CSV"></a> <a href="$script?action=Graph&start=$start&end=$end"><input type="submit" value="Graph"></a></th>
138 <th class=clear align="right" colspan="2"><form action="$script?action=Mail&start=$start&end=$end" method="post">
141 $page .= emailUsersDropdown ();
144 <input type="submit" value="Send"></form>
152 <th class=left><a href="$urlParms=Date">Date $dateDirection</a></th>
153 <th><a href="$urlParms=Passed">Total Passed $passedDirection</a></th>
154 <th><a href="$urlParms=Failed">Total Failed $failedDirection</a></th>
155 <th class=right><a href="$urlParms=Total">Total Run $totalDirection</a></th>
161 foreach ($data as $result) {
162 $reportDate = YMD2MDY ($result["Date"]);
163 $row_color = ($row_nbr++ % 2 == 0) ? " class=other" : " class=white";
167 <td align=center><a href="rantest.php?day=$reportDate">$reportDate</a></td>
168 <td align=right>$result[Success]</td>
169 <td align=right>$result[Failure]</td>
170 <td align=right>$result[Total]</td>
183 function displayReport ($start, $end, $message = "") {
184 print createHeader ($start, $end);
185 print createPage ($start, $end, false, $message);
190 function displayChart ($start, $end) {
191 global $testTypes, $type;
193 print createHeader ($start, $end);
199 <form action="TestStats.php">
200 Type: <select name="type" class="inputfield">
203 foreach ($testTypes as $t) {
205 print "<option>$t</option>";
207 print "<option selected=\"selected\">$t</option>";
214 <select name=start class=inputfield>
217 foreach ($days as $day) {
220 if ($day == $start) {
221 print " selected=selected";
224 print ">$day</option>\n";
229 <select name=end class=inputfield>
232 foreach ($days as $day) {
236 print " selected=selected";
239 print ">$day</option>\n";
244 <input type=submit name="action" value="Graph"> <a href="$script?action=Report&start=$start&end=$end"><input type="submit" value="Report"></a><br><br>
246 <img src="GraphStats.php?start=$start&end=$end&type=$type">
253 function mailTestStatsReport ($start, $end, $pnbr, $username) {
254 $subject = "Test Statistics from $start to $end";
255 $filename = "TestStats.$start-$end.csv";
256 $body = createPage ($start, $end, true);
257 $attachment = exportCSV (getData ($start, $end), $subject);
259 return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment);
262 if (MDY2YMD ($start) > MDY2YMD ($end)) {
263 Error ("<b>Start Date</b> must come before <b>End Date</b>");
271 displayChart ($start, $end);
275 exportStats ($start, $end);
279 list ($pnbr, $username) = explode (":", $user);
280 displayReport ($start, $end, mailTestStatsReport ($start, $end, $pnbr, $username));
284 displayReport ($start, $end);