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

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