source: tags/Mars-V2.1.1/datacenter/db/runinfo-aio.php

Last change on this file was 8850, checked in by hoehne, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 12.6 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
4 {
5 $fromtable="RunData";
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 ";
18
19 if ($groups>0)
20 {
21 foreach ($checkgroup as $key => $element)
22 if ($element==-1)
23 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
24 //--------------------------------------------------
25 //$query0 .= " TIMEDIFF(fRunStop, fRunStart), ";
26 // Only available in MySQL>4.1.1
27 $query0 .= "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, " .
28 "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, " .
29 "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
30 //--------------------------------------------------
31 $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
32 $query0 .= " Min(fZenithDistance) as '" . $alias["Min(fZenithDistance)"] . "', ";
33 $query0 .= " Max(fZenithDistance) as '" . $alias["Max(fZenithDistance)"] . "', ";
34 $query0 .= " COUNT(*) as '# Runs' ";
35 }
36 else
37 {
38 if ($statusgroups>0)
39 {
40 foreach ($checkstatusgroup as $key => $element)
41 if ($element==-1)
42 $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
43// $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
44
45 $query0 .= " count(*) as '# Runs'";
46
47 }
48 else
49 {
50 $query0 .= " RunData.fRunNumber as 'Run#' ";
51
52 if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
53 {
54 $query0 .= ", CONCAT('<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
55 $query0 .= " as 'Links'";
56 }
57
58 foreach ($_GET as $key => $element)
59 if ($key!="fLinks" && $_GET[$key]=="On" && $key!="fTest")
60 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
61 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
62 }
63 }
64
65 $query0 .= " FROM RunData ";
66
67 $query0 .= " LEFT JOIN RunProcessStatus ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
68
69 foreach ($_GET as $key => $element)
70 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
71 $query0 .= GetJoin($fromtable,$key);
72
73 if ($_GET["fTest"]!="On")
74 {
75 if ($_GET["fSourceName"]!="On")
76 $query0 .= " LEFT JOIN Source ON Sequences.fSourceKEY=Source.fSourceKEY ";
77 $query0 .= " WHERE fTest='no'";
78 }
79
80 foreach ($checkwhere as $key => $element)
81 {
82 if (empty($element) || $element<=0)
83 continue;
84
85 if (strpos($query0, " WHERE ")==FALSE)
86 $query0 .= " WHERE ";
87 else
88 if ($element!=-1)
89 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
90 $query0 .= " AND ";
91
92 if ($element!=-1)
93 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
94 }
95
96 if (strpos($query0, " WHERE ")==FALSE)
97 $query0 .= " WHERE ";
98 else
99 $query0 .= " AND ";
100
101 $query0 .= StatusQuery("fCCFileAvail", $needs);
102 $query0 .= StatusQuery("fCaCoFileAvail", $needs);
103 $query0 .= StatusQuery("fCaCoFileFound", $needs);
104 $query0 .= StatusQuery("fRawFileAvail", $needs);
105 $query0 .= StatusQuery("fDataCheckDone", $needs);
106 $query0 .= StatusQuery("fTimingCorrection", $needs);
107
108 if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"]))
109 $query0 .= "RunData.fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
110
111 if ((!empty($_GET["fZDMin"]) || $_GET["fZDMin"]==0) && !empty($_GET["fZDMax"]))
112 $query0 .= "AND fZenithDistance BETWEEN " . $_GET["fZDMin"] . " AND " . $_GET["fZDMax"] . " ";
113
114/*
115 if (!empty($_GET["fDate"]))
116 $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
117*/
118
119 if (!empty($_GET["fSourceN"]))
120 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
121
122 if (!empty($_GET["fStartDate"]))
123 {
124 if (strpos(strrev($query0), " DNA ")!=0)
125 $query0 .= " AND ";
126
127 $startdate=substr($_GET["fStartDate"], 0, 10);
128 if ($startdate=="0000-00-00")
129 $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
130 else
131 $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
132 }
133
134 if (!empty($_GET["fStopDate"]))
135 {
136 if (strpos(strrev($query0), " DNA ")!=0)
137 $query0 .= " AND ";
138
139 $stopdate=substr($_GET["fStopDate"], 0, 10);
140 $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
141 }
142
143 if (!empty($_GET["fSequenceNo"]) || $_GET["fSequenceNo"]=="0")
144 {
145 if (strpos(strrev($query0), " DNA ")!=0)
146 $query0 .= " AND ";
147
148 $query0 .= " fSequenceFirst = '" . $_GET["fSequenceNo"] . "' ";
149 }
150
151
152 if ($groups>0)
153 {
154 $query0 .= " GROUP BY ";
155 $num = $groups;
156 foreach ($checkgroup as $key => $element)
157 if ($element==-1)
158 {
159 $query0 .= GetCheck($fromtable,$key);
160 if ($num-->1)
161 $query0 .= ", ";
162 }
163 }
164
165 if ($statusgroups>0)
166 {
167 $query0 .= " GROUP BY ";
168 $num = $statusgroups;
169 foreach ($checkstatusgroup as $key => $element)
170 if ($element==-1)
171 {
172 $query0 .= $alias[$key];
173 if ($num-->1)
174 $query0 .= ", ";
175 }
176 }
177
178 if (!empty($_GET["fSortBy"]))
179 {
180 $val=substr($_GET["fSortBy"], 0, -1);
181 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
182 if (substr($_GET["fSortBy"], -1)=="-")
183 $query0 .= "DESC";
184 }
185 else
186 $query0 .=" ORDER BY RunData.fRunNumber ASC";
187
188 if (empty($_GET["fNumStart"]))
189 $_GET["fNumStart"]=0;
190
191 if (empty($_GET["fSendTxt"]))
192 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
193
194 return $query0;
195 }
196
197 function InitGet($_GET)
198 {
199 // Find out whether it is the first call to the php script
200 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
201
202 if (empty($_GET["fNumResults"]))
203 $_GET["fNumResults"]="20";
204
205 if (empty($_GET["fTest"]))
206 $_GET["fTest"]=$first?"On":"";
207
208 if (empty($_GET["fNumEvents"]))
209 $_GET["fNumEvents"]=$first?"On":"";
210
211 if (empty($_GET["fRunStart"]))
212 $_GET["fRunStart"]=$first?"On":"";
213
214 if (empty($_GET["fZenithDistance"]))
215 $_GET["fZenithDistance"]=$first?"On":"";
216
217 if (empty($_GET["fRunTypeName"]))
218 $_GET["fRunTypeName"]=$first?"On":"";
219
220 if (empty($_GET["fSourceName"]))
221 $_GET["fSourceName"]=$first?"On":"";
222
223 if (empty($_GET["fMeanTriggerRate"]))
224 $_GET["fMeanTriggerRate"]=$first?"On":"";
225
226 if (empty($_GET["fExcludedFDAName"]))
227 $_GET["fExcludedFDAName"]=$first?"On":"";
228
229 if (empty($_GET["fSequenceNo"]))
230 $_GET["fSequenceNo"]="";
231
232 InitRunInfo($_GET, $first);
233 }
234
235 function PrintForm($_GET, $host, $user, $pw, $db)
236 {
237 printf("<center>\n");
238 printf("<form action=\"runinfo-aio.php\" METHOD=\"GET\">\n");
239
240 printf("<input id='sh' type='hidden' name='fShowHide' value='");
241 if (!empty($_GET["fShowHide"]))
242 printf("%s", $_GET["fShowHide"]);
243 else
244 printf("1000000000");
245 printf("'>\n");
246 printf("<img id='allbutton' src='minus.png' alt='-' onclick=\"showhide('all')\"> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp;\n");
247 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick=\"showhide('info');showhide('info2')\"> RunInfo \n");
248 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick=\"showhide('stat');showhide('fail')\"> StatusInfo \n");
249 printf("&nbsp;&nbsp;<img id='rangesbutton' src='plus.png' alt='+' onClick=\"showhide('ranges')\"> Ranges \n");
250
251 printf(" <div id='all' style='display:block'>");
252 PrintRunInfoMenu();
253 PrintRunInfo2Menu($host,$user,$pw,$db);
254 PrintRunStatMenu();
255 PrintFailMenu();
256 printf(" <div id='ranges' style='display:none'>");
257 PrintSequMenu($host,$user,$pw,$db);
258 PrintNightRangeMenu($host,$user,$pw,$db, "RunData");
259 printf("<p>");
260 PrintZdRangeMenu($host,$user,$pw,$db);
261 PrintRunRangeMenu($host,$user,$pw,$db);
262 printf(" <P>\n");
263 PrintSourceMenu($host,$user,$pw,$db);
264 PrintNumResPullDown();
265 printf("<p>");
266 printf("</div>");
267 printf("</div>");
268 printf(" <P>\n");
269
270 ini_set("mysql.trace_mode", "Off");
271 ini_set("display_errors", "Off");
272
273 PrintButtons("runinfo-aio.php");
274
275 printf("</form>\n");
276 printf("</center>\n");
277 printf("</td>\n");
278 printf("</tr>\n");
279 printf("<tr class='Block'>\n");
280 printf("<td>\n");
281 }
282
283 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
284 {
285 $db_id = mysql_connect($host, $user, $pw);
286 if ($db_id==FALSE)
287 {
288 printf("mysql_connect returned the following error: %s\n", mysql_error());
289 die("");
290 }
291 mysql_select_db($db);
292 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
293
294 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
295
296 $result0 = mysql_query($query0, $db_id);
297
298 if ($result0)
299 {
300 if ($html=="1" || $html=="2")
301 PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
302 else
303 PrintText($result0);
304
305 mysql_free_result($result0);
306 }
307 mysql_close($db_id);
308
309 PrintSubmittedQuery($query0, $html, $db, "");
310 }
311
312 include ("include.php");
313 include ("db.php");
314 include ("menu.php");
315 include ("magicdefs.php");
316
317 ini_set("display_errors", "On");
318 ini_set("mysql.trace_mode", "On");
319
320 if (!empty($_GET["fSendTxt"]))
321 {
322 header("Content-type: application/octet");
323 header("Content-Disposition: attachment; filename=query-result.txt");
324
325 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
326 }
327 else
328 {
329 if (empty($_GET["fPrintTable"]))
330 echo (file_get_contents("index-header.html"));
331
332 $environment = sizeof($_GET);
333
334 InitGet($_GET);
335 if (empty($_GET["fPrintTable"]))
336 PrintForm($_GET, $host, $user, $pw, $db);
337
338 if ($environment==0)
339 printf("No query submitted yet.<BR>");
340 else
341 {
342 if (empty($_GET["fPrintTable"]))
343 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
344 else
345 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
346 }
347
348 if (empty($_GET["fPrintTable"]))
349 echo (file_get_contents("index-footer.html"));
350 }
351
352 ini_set("display_errors", "Off");
353 ini_set("mysql.trace_mode", "Off");
354}
355?>
Note: See TracBrowser for help on using the repository browser.