source: tags/Mars-V0.10.1/datacenter/db/runinfo-aio.php

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