source: trunk/Mars/datacenter/db/fact_runinfo.php@ 12778

Last change on this file since 12778 was 12777, checked in by Daniela Dorner, 13 years ago
bugfix for display of columns, updated selection of default columns
  • Property svn:executable set to *
File size: 13.1 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
4 {
5 $fromtable="RunInfo";
6
7 $groups = 0;
8 foreach ($checkgroup as $element)
9 if ($element==-1)
10 $groups++;
11
12 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
13
14 if ($groups>0)
15 {
16 foreach ($checkgroup as $key => $element)
17 if ($element==-1)
18 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
19 //don't put a '#' at the beginning of the alias, else SortBy won't work anymore
20 $query0 .= " COUNT(*) as 'NumRuns', ";
21 $query0 .= " Round(Sum(TimeDiff(fRunStop,fRunStart))/60./60.,1) as 'Time [h]' ";
22 }
23 else
24 {
25 $query0 .= " Concat(fRunNumber,'_', LPAD(fFileNumber, 3, 0)) as 'Run' ";
26
27 foreach ($_GET as $key => $element)
28 if ($_GET[$key]=="On")
29 if ($key!="fComments")
30 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
31 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
32
33 if (!empty($_GET["fComments"]))
34 {
35 $query0 .= ", if (Count(fComment)>0, Concat('<a&ws;id=\'commentcell', fRunNUmber, fFileNumber, '\'&ws;href=\'run_comment.php?fRunNumber=',fRunNumber,'&fFileNumber=', fFileNumber, '\'&ws;onmouseover=\'get_comments(', fRunNumber, ',', fFileNumber, ')\'>', Count(fComment), '</a>'), ' ') ";
36 //$query0 .= ", if (Count(fComment)>0, Concat('<a&ws;href=\'run_comment.php?fRunNumber=',fRunNumber,'&fFileNumber=', fFileNumber, '\'&ws;onmouseover=\'bla\'>', Count(fComment), '</a>'), ' ') ";
37 $query0 .= " as 'Comments'";
38 }
39
40 }
41
42 $query0 .= " FROM " . $fromtable;
43
44 foreach ($_GET as $key => $element)
45 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
46 $query0 .= GetJoin($fromtable, $key);
47 $query0 .= " LEFT JOIN RunComments USING (fRunNumber, fFileNumber) ";
48
49 foreach ($checkwhere as $key => $element)
50 {
51 if (empty($element) || $element<=0)
52 continue;
53
54 if (strpos($query0, " WHERE ")==FALSE)
55 $query0 .= " WHERE ";
56 else
57 if ($element!=-1)
58 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
59 $query0 .= " AND ";
60
61 if ($element!=-1)
62 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
63 }
64
65 if (strpos($query0, " WHERE ")==FALSE)
66 $query0 .= " WHERE ";
67 else
68 $query0 .= " AND ";
69
70 if (!empty($_GET["fStartDate"]))
71 {
72 $startdate=substr($_GET["fStartDate"], 0, 10);
73 if ($startdate=="0000-00-00")
74 $query0 .=" fRunNumber >= " . $startdate . " ";
75 else
76 $query0 .= " fRunNumber >= " . $startdate . " - 1 ";
77 }
78
79 if (!empty($_GET["fStopDate"]))
80 {
81// if (strpos(strrev($query0), " DNA ")!=0)
82// $query0 .= " AND ";
83
84 $stopdate=substr($_GET["fStopDate"], 0, 10);
85 $query0 .= " AND fRunNumber <= " . $stopdate . " ";
86 }
87
88 if ($groups>0)
89 {
90 $query0 .= " GROUP BY ";
91 $num = $groups;
92 foreach ($checkgroup as $key => $element)
93 if ($element==-1)
94 {
95 $query0 .= GetCheck($fromtable, $key);
96 if ($num-->1)
97 $query0 .= ", ";
98 }
99 }
100 else
101 $query0 .= " GROUP BY fRunNumber, fFileNumber ";
102
103
104
105 if (!empty($_GET["fSortBy"]))
106 {
107 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
108 if (substr($_GET["fSortBy"], -1)=="-")
109 $query0 .= "DESC";
110 }
111 else
112 if ($groups==0)
113 $query0 .= " ORDER BY Run DESC";
114
115 if (empty($_GET["fNumStart"]))
116 $_GET["fNumStart"]=0;
117
118 if (empty($_GET["fSendTxt"]))
119 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
120
121 return $query0;
122 }
123
124 function InitGet($_GET)
125 {
126 // Find out whether it is the first call to the php script
127 $first = empty($_GET["fStartDate"]) && empty($_GET["fStopDate"]);
128
129 if (empty($_GET["fNumResults"]))
130 $_GET["fNumResults"]="20";
131
132 if (empty($_GET["fNumEvents"]))
133 $_GET["fNumEvents"]=$first?"Off":"";
134
135 if (empty($_GET["fComments"]))
136 $_GET["fComments"]=$first?"On":"";
137
138 if (empty($_GET["fNumPhysicsTrigger"]))
139 $_GET["fNumPhysicsTrigger"]=$first?"On":"";
140
141 if (empty($_GET["Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)"]))
142 $_GET["Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)"]=$first?"On":"";
143
144 if (empty($_GET["fNumPedestalTrigger"]))
145 $_GET["fNumPedestalTrigger"]=$first?"On":"";
146
147 if (empty($_GET["fNumELPTrigger"]))
148 $_GET["fNumELPTrigger"]=$first?"On":"";
149
150 if (empty($_GET["fNumTimeTrigger"]))
151 $_GET["fNumTimeTrigger"]=$first?"Off":"";
152
153 if (empty($_GET["fNumExt1Trigger"]))
154 $_GET["fNumExt1Trigger"]=$first?"Off":"";
155
156 if (empty($_GET["fNumExt2Trigger"]))
157 $_GET["fNumExt2Trigger"]=$first?"Off":"";
158
159 if (empty($_GET["fNumILPTrigger"]))
160 $_GET["fNumILPTrigger"]=$first?"Off":"";
161
162 if (empty($_GET["fNumOtherTrigger"]))
163 $_GET["fNumOtherTrigger"]=$first?"Off":"";
164
165 if (empty($_GET["TimeDiff(fRunStop,fRunStart)"]))
166 $_GET["TimeDiff(fRunStop,fRunStart)"]=$first?"On":"";
167
168 if (empty($_GET["fRunStart"]))
169 $_GET["fRunStart"]=$first?"On":"";
170
171 if (empty($_GET["fRunStop"]))
172 $_GET["fRunStop"]=$first?"Off":"";
173
174 if (empty($_GET["fROI"]))
175 $_GET["fROI"]=$first?"On":"";
176
177 if (empty($_GET["fROITimeMarker"]))
178 $_GET["fROITimeMarker"]=$first?"Off":"";
179
180 if (empty($_GET["fFitsFileErrors"]))
181 $_GET["fFitsFileErrors"]=$first?"Off":"";
182
183 if (empty($_GET["fHasDrsFile"]))
184 $_GET["fHasDrsFile"]=$first?"Off":"";
185
186 if (empty($_GET["fMd5sumRaw"]))
187 $_GET["fMd5sumRaw"]=$first?"Off":"";
188
189 if (empty($_GET["fMd5sumRawZip"]))
190 $_GET["fMd5sumRawZip"]=$first?"Off":"";
191
192 if (empty($_GET["fRunTypeName"]))
193 $_GET["fRunTypeName"]=$first?"On":"";
194
195 if (empty($_GET["fTriggerRateMedian"]))
196 $_GET["fTriggerRateMedian"]=$first?"Off":"";
197
198 if (empty($_GET["fThresholdMedian"]))
199 $_GET["fThresholdMedian"]=$first?"Off":"";
200
201 if (empty($_GET["fBiasVoltageMedian"]))
202 $_GET["fBiasVoltageMedian"]=$first?"Off":"";
203
204 if (empty($_GET["fRightAscension"]))
205 $_GET["fRightAscension"]=$first?"Off":"";
206
207 if (empty($_GET["fDeclination"]))
208 $_GET["fDeclination"]=$first?"Off":"";
209
210 }
211
212 function PrintForm($_GET, $host, $user, $pw, $db)
213 {
214 printf("<center>\n");
215 printf("<form action=\"fact_runinfo.php\" METHOD=\"GET\">\n");
216
217 // pull down boxes
218
219 printf(" <table>\n");
220 printf(" <tr><td>\n");
221 PrintPullDown($host, $user, $pw, $db, "RunType", "fRunTypeName", "fRunTypeKEY", "RunType");
222 printf(" </td></tr></table>\n");
223 printf(" <p>\n");
224
225 printf(" <table>\n");
226 printf(" <tr>\n");
227
228 CheckBox("fComments", "comments");
229 CheckBox("fRunStart", "start time");
230 CheckBox("fRunStop", "stop time");
231 CheckBox("TimeDiff(fRunStop,fRunStart)", "duration");
232 CheckBox("fROI", "roi");
233 CheckBox("fNumEvents", "#Evts");
234
235 printf(" </tr>\n");
236 printf(" <tr>\n");
237
238 CheckBox("Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)", "phys rate");
239 CheckBox("fNumPhysicsTrigger", "#Phys");
240 CheckBox("fNumPedestalTrigger", "#Ped");
241 CheckBox("fNumELPTrigger", "#ELP");
242 CheckBox("fNumTimeTrigger", "#Time");
243
244 printf(" </tr>\n");
245 printf(" <tr>\n");
246
247 CheckBox("fNumExt1Trigger", "#Ext1");
248 CheckBox("fNumExt2Trigger", "#Ext2");
249 CheckBox("fNumILPTrigger", "#ILP");
250 CheckBox("fNumOtherTrigger", "#Other");
251
252 printf(" </tr>\n");
253 printf(" <tr>\n");
254
255 CheckBox("fROITimeMarker", "roi-tm");
256 CheckBox("fFitsFileErrors", "file err");
257 CheckBox("fHasDrsFile", "num drs");
258 CheckBox("fMd5sumRaw", "md5");
259 CheckBox("fMd5sumRawZip", "md5(gz)");
260
261 printf(" </tr>\n");
262 printf(" <tr>\n");
263
264 CheckBox("fTriggerRateMedian", "mean rate");
265 CheckBox("fThresholdMedian", "mean threshold");
266 CheckBox("fBiasVoltageMedian", "mean voltage");
267 CheckBox("fRightAscension", "RA");
268 CheckBox("fDeclination", "Dec");
269
270 printf(" </tr>\n");
271 printf(" </table>\n");
272 printf(" <p>\n");
273
274 if (empty($_GET["fStartDate"]))
275 $timemin = GetMin("fRunNumber", "RunInfo", $host, $user, $pw, $db);
276 else
277 $timemin = $_GET["fStartDate"];
278
279 if (empty($_GET["fStopDate"]))
280 $timemax = GetMax("fRunnumber", "RunInfo", $host, $user, $pw, $db);
281 else
282 $timemax = $_GET["fStopDate"];
283
284 printf("Run&nbsp;(yyyymmdd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
285 printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
286
287 printf(" Results:\n");
288 printf(" <select name=\"fNumResults\">\n");
289
290 $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
291 foreach ($numres as $element)
292 {
293 if ($element==$_GET["fNumResults"])
294 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
295 else
296 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
297 }
298 printf(" </select>\n");
299 printf(" &nbsp;&nbsp;&nbsp;\n");
300
301 ini_set("mysql.trace_mode", "Off");
302 ini_set("display_errors", "Off");
303
304 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
305 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"fact_runinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
306 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
307 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
308 printf("</form>\n");
309 printf("</center>\n");
310 printf("</td>\n");
311 printf("</tr>\n");
312 printf("<tr class='Block'>\n");
313 printf("<td>\n");
314 }
315
316 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
317 {
318 $db_id = mysql_connect($host, $user, $pw);
319 if ($db_id==FALSE)
320 {
321 printf("mysql_connect returned the following error: %s\n", mysql_error());
322 die("");
323 }
324 mysql_select_db($db);
325 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
326
327
328 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup);
329
330 $result0 = mysql_query($query0, $db_id);
331 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
332
333 if ($result0)
334 {
335 if ($html=="1")
336 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
337 else
338 PrintText($result0);
339
340 mysql_free_result($result0);
341 mysql_free_result($result1);
342 }
343 mysql_close($db_id);
344
345 if ($html=="1")
346 PrintSubmittedQuery($query0, $db, "old");
347 }
348
349 include ("include.php");
350 include ("db.php");
351 include ("factdefs.php");
352
353 ini_set("display_errors", "On");
354 ini_set("mysql.trace_mode", "On");
355
356 if (!empty($_GET["fSendTxt"]))
357 {
358 header("Content-type: application/octet");
359 header("Content-Disposition: attachment; filename=query-result.txt");
360
361 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
362 }
363 else
364 {
365 echo (file_get_contents("index-header.html"));
366
367 $environment = sizeof($_GET);
368
369 InitGet($_GET);
370 PrintForm($_GET, $host, $user, $pw, $db);
371
372 if ($environment==0)
373 printf("No query submitted yet.<BR>");
374 else
375 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
376
377 echo (file_get_contents("index-footer.html"));
378 }
379
380 ini_set("display_errors", "Off");
381 ini_set("mysql.trace_mode", "Off");
382}
383?>
Note: See TracBrowser for help on using the repository browser.