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

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