source: branches/AddingGoogleTestEnvironment/datacenter/db/mcinfo.php

Last change on this file was 17386, checked in by tbretz, 11 years ago
Removed svn:executable property, these are no executables.
File size: 12.8 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits)
4 {
5 $fromtable="CeresInfo";
6
7 $groups = 0;
8 foreach ($checkgroup as $element)
9 if ($element==-1)
10 $groups++;
11
12 $statusgroups = 0;
13 foreach ($checkstatusgroup as $element)
14 if ($element==-1)
15 $statusgroups++;
16
17 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
18
19 if ($groups>0 || $statusgroups>0)
20 {
21 if ($groups>0)
22 {
23 foreach ($checkgroup as $key => $element)
24 if ($element==-1)
25 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
26 }
27
28 if ($statusgroups>0)
29 {
30 foreach ($checkstatusgroup as $key => $element)
31 if ($element==-1)
32 $query0 .= " IF( ISNULL(" . $key . "Status.fStartTime) "
33 ." AND ISNULL(" . $key . "Status.fStopTime) "
34 ." AND ISNULL(" . $key . "Status.fReturnCode), 'not done', "
35 //crashed
36 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
37 ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) > " . $key . "Status.fStartTime "
38 ." AND ISNULL(" . $key . "Status.fStopTime) "
39 ." AND ISNULL(" . $key . "Status.fReturnCode), 'crashed', "
40 //running
41 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
42 ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) < " . $key . "Status.fStartTime "
43 ." AND ISNULL(" . $key . "Status.fStopTime) "
44 ." AND ISNULL(" . $key . "Status.fReturnCode), 'running', "
45 //failed
46 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
47 ." AND NOT ISNULL(" . $key . "Status.fStopTime) "
48 ." AND NOT ISNULL(" . $key . "Status.fReturnCode), 'failed', "
49 //done or done and avail
50 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
51 ." AND NOT ISNULL(" . $key . "Status.fStopTime) "
52 ." AND ISNULL(" . $key . "Status.fReturnCode)"
53 ." AND ISNULL(" . $key . "Status.fAvailable), 'done', 'done and avail' "
54 ." ))))) AS '". $key . "', ";
55 }
56 $query0 .= " COUNT(*) as '# Files' ";
57 $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
58 $query0 .= ", SUM(fNumEvents*fNumReUseShowers) as '" . $alias["SUM(fNumEvents*fNumReUseShowers)"] . "' ";
59 }
60 else
61 {
62 $query0 .= " CONCAT(LPAD(" . $fromtable . ".fRunNumber,8, ' '),'.', ";
63 $query0 .= " RIGHT(LPAD(" . $fromtable . ".fFileNumber, 6, 0), 3)) as 'Run.File' ";
64
65 if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
66 {
67 $query0 .= ", CONCAT('<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
68 $query0 .= " as 'Links'";
69 }
70
71 foreach ($_GET as $key => $element)
72 if ($_GET[$key]=="On" && $key!="fTest" && $key!="fLinks")
73 if (!ereg("^f", $key))
74 {
75
76 $query0 .= ", IF (ISNULL(" . $key . "Status.fStartTime) AND ";
77 $query0 .= " ISNULL(" . $key . "Status.fStopTime) AND ";
78 $query0 .= " ISNULL(" . $key . "Status.fReturnCode), 'not done', ";
79
80 $query0 .= " IF (NOT ISNULL(" . $key . "Status.fStartTime) ";
81 $query0 .= " AND ISNULL(" . $key . "Status.fStopTime) ";
82 $query0 .= " AND ISNULL(" . $key . "Status.fReturnCode) ";
83 $query0 .= " AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) > " . $key . "Status.fStartTime, ";
84 $query0 .= " CONCAT('maybe crashed (started at ', " . $key . "Status.fStartTime, ')'), ";
85
86 $query0 .= " IF (NOT ISNULL(" . $key . "Status.fStartTime) ";
87 $query0 .= " AND ISNULL(" . $key . "Status.fStopTime) ";
88 $query0 .= " AND ISNULL(" . $key . "Status.fReturnCode) ";
89 $query0 .= " AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) < " . $key . "Status.fStartTime, ";
90 $query0 .= " CONCAT('running (started at ', " . $key . "Status.fStartTime, ')'), ";
91
92 $query0 .= " IF (NOT ISNULL(" . $key . "Status.fReturnCode), ";
93 $query0 .= " CONCAT('failed (', " . $key . "Status.fReturnCode, ', ', " . $key . "Status.fStopTime, ')'), ";
94 $query0 .= " CONCAT('done (', " . $key . "Status.fStopTime, ";
95 $query0 .= " ', ', TIMEDIFF(" . $key . "Status.fStopTime, " . $key . "Status.fStartTime), ')'))))) ";
96
97 $query0 .= " AS '" . $alias[$key] . "' ";
98 }
99 else
100 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
101 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
102 }
103
104 $query0 .= " FROM " . $fromtable;
105
106 $query0 .= " LEFT JOIN CorsikaInfo USING(fRunNumber,fFileNumber) ";
107
108 foreach ($_GET as $key => $element)
109 if ($_GET[$key]=="On" || $_GET[$key]!=0)
110 if (strpos($query0, GetJoin($fromtable,$key))==FALSE)
111 $query0 .= GetJoin($fromtable,$key);
112
113 foreach ($checkwhere as $key => $element)
114 {
115 if (empty($element) || $element<=0)
116 continue;
117
118 if (strpos($query0, " WHERE ")==FALSE)
119 $query0 .= " WHERE ";
120 else
121 if ($element!=-1)
122 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
123 $query0 .= " AND ";
124
125 if ($element!=-1)
126 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
127 }
128
129 if (strpos($query0, " WHERE ")==FALSE)
130 $query0 .= " WHERE";
131 else
132 $query0 .= " AND ";
133
134 $query0 .= StatusQuery("Corsika", $timelimits);
135 $query0 .= StatusQuery("Ceres", $timelimits);
136 $query0 .= StatusQuery("SequenceFile", $timelimits);
137 $query0 .= StatusQuery("Callisto", $timelimits);
138 $query0 .= StatusQuery("Star", $timelimits);
139
140 if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"]))
141 $query0 .= " " . $fromtable . ".fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
142
143
144 //remove WHERE or AND in the end of the query
145 $query0=preg_replace("/ WHERE\s+$/", " ", $query0);
146 $query0=preg_replace("/ AND\s+$/", " ", $query0);
147
148 if ($groups>0)
149 {
150 $query0 .= " GROUP BY ";
151 $num = $groups;
152 foreach ($checkgroup as $key => $element)
153 if ($element==-1)
154 {
155 $query0 .= GetCheck($fromtable,$key);
156 if ($num-->1)
157 $query0 .= ", ";
158 }
159 }
160
161 if ($statusgroups>0)
162 {
163 if (strpos($query0, " GROUP BY ")==FALSE)
164 $query0 .= " GROUP BY ";
165 else
166 $query0 .= ", ";
167 $num = $statusgroups;
168 foreach ($checkstatusgroup as $key => $element)
169 if ($element==-1)
170 {
171 $query0 .= $alias[$key];
172 if ($num-->1)
173 $query0 .= ", ";
174 }
175 }
176
177 if (!empty($_GET["fSortBy"]))
178 {
179 $val=substr($_GET["fSortBy"], 0, -1);
180 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
181 if (substr($_GET["fSortBy"], -1)=="-")
182 $query0 .= "DESC";
183 }
184 else
185 $query0 .=" ORDER BY " . $fromtable . ".fRunNumber ASC";
186
187 if (empty($_GET["fNumStart"]))
188 $_GET["fNumStart"]=0;
189
190 if (empty($_GET["fSendTxt"]))
191 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
192
193 return $query0;
194 }
195
196 function InitGet($_GET)
197 {
198 // Find out whether it is the first call to the php script
199 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
200
201 InitMCRunInfo($_GET, $first);
202 }
203
204 function PrintForm($_GET, $host, $user, $pw, $db)
205 {
206 printf("<center>\n");
207 printf("<form action=\"mcinfo.php\" METHOD=\"GET\">\n");
208
209 printf("<input id='sh' type='hidden' name='fShowHide' value='");
210 if (!empty($_GET["fShowHide"]))
211 printf("%s", $_GET["fShowHide"]);
212 else
213 printf("1000000010");
214 printf("'>\n");
215 printf("<img id='allbutton' src='minus.png' alt='-' onclick=\"showhide('all')\"> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp;\n");
216 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick=\"showhide('info');showhide('info2')\"> MCRunInfo \n");
217 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick=\"showhide('stat')\"> StatusInfo \n");
218 printf("&nbsp;&nbsp;<img id='rangesbutton' src='plus.png' alt='+' onClick=\"showhide('ranges')\"> Ranges \n");
219
220 printf(" <div id='all' style='display:block'>");
221 PrintMCRunInfoMenu($host,$user,$pw,$db);
222 PrintMCRunStatMenu();
223 printf(" <div id='ranges' style='display:none'>");
224 printf("<p>");
225 PrintMCRunRangeMenu($host,$user,$pw,$db);
226 printf("<p>");
227 printf("</div>");
228 printf("</div>");
229 printf(" <P>\n");
230
231 ini_set("mysql.trace_mode", "Off");
232 ini_set("display_errors", "Off");
233
234 PrintNumResPullDown();
235 PrintButtons("mcinfo.php");
236
237 printf("</form>\n");
238 printf("</center>\n");
239 printf("</td>\n");
240 printf("</tr>\n");
241 printf("<tr class='Block'>\n");
242 printf("<td>\n");
243 }
244
245 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits)
246 {
247 $db_id = mysql_connect($host, $user, $pw);
248 if ($db_id==FALSE)
249 {
250 printf("mysql_connect returned the following error: %s\n", mysql_error());
251 die("");
252 }
253 mysql_select_db($db);
254 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
255
256 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
257
258 $result0 = mysql_query($query0, $db_id);
259 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
260
261 if ($result0)
262 {
263 if ($html=="1" || $html=="2")
264 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
265 else
266 PrintText($result0);
267
268 mysql_free_result($result0);
269 mysql_free_result($result1);
270 }
271 mysql_close($db_id);
272
273 if ($html=="1")
274 PrintSubmittedQuery($query0, $db, "");
275 }
276
277 include ("include.php");
278 include ("db2.php");
279 include ("menu.php");
280 include ("mcdefs.php");
281
282 ini_set("display_errors", "On");
283 ini_set("mysql.trace_mode", "On");
284
285 if (!empty($_GET["fSendTxt"]))
286 {
287 header("Content-type: application/octet");
288 header("Content-Disposition: attachment; filename=query-result.txt");
289
290 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
291 }
292 else
293 {
294 if (empty($_GET["fPrintTable"]))
295 echo (file_get_contents("index-header-fact.html"));
296
297 $environment = sizeof($_GET);
298
299 InitGet($_GET);
300 if (empty($_GET["fPrintTable"]))
301 PrintForm($_GET, $host, $user, $pw, $db);
302
303 if ($environment==0)
304 printf("No query submitted yet.<BR>");
305 else
306 {
307 if (empty($_GET["fPrintTable"]))
308 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
309 else
310 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
311 }
312
313 if (empty($_GET["fPrintTable"]))
314 echo (file_get_contents("index-footer.html"));
315 }
316
317 ini_set("display_errors", "Off");
318 ini_set("mysql.trace_mode", "Off");
319}
320?>
Note: See TracBrowser for help on using the repository browser.