source: trunk/Mars/datacenter/db/mcinfo.php@ 9969

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