source: trunk/www/dch/obs_summary.php@ 19921

Last change on this file since 19921 was 19741, checked in by Daniela Dorner, 5 years ago
added runid for list of runs
File size: 14.2 KB
Line 
1<?php
2
3 include("db.php");
4 require_once("class.Diff.php");
5
6 // ini_set("display_errors", "On");
7 // ini_set("mysql.trace_mode", "On");
8
9
10$db_id = mysql_connect($host, $user, $pw);
11if ($db_id==FALSE)
12{
13 printf("mysql_connect returned the following error: %s\n", mysql_error());
14 die("");
15}
16mysql_select_db($db);
17
18date_default_timezone_set('UTC');
19
20$date = isset($_GET["d"]) ? $_GET["d"] : date("Y-m-d");//'2016-02-16';
21$night = str_replace("-", "", $date);
22$legend = isset($_GET["nolegend"]) ? 0 : 1;
23
24// ====================================================================
25
26function fmt($date)
27{
28 $d = date_create_from_format("Y-m-d G:i:s", $date);
29 return "new Date(".$d->format("Y,n-1,j,G,i,s,0").")";
30 //return "new Date(".($d->getTimestamp()*1000).")";//format("Y,n-1,j,G,i,s,0").")";
31}
32
33// ====================================================================
34
35function QuerySchedule(&$data, &$html1, &$html2, &$query, $db_id, $table, $date)
36{
37$query = <<<EOT
38
39SELECT
40 fStart, fSourceName, fUser, fMeasurementTypeName
41FROM $table
42LEFT JOIN Source USING (fSourceKey)
43LEFT JOIN MeasurementType USING (fMeasurementTypeKey)
44WHERE fStart
45 BETWEEN ADDDATE('$date', INTERVAL +12 HOUR)
46 AND ADDDATE('$date', INTERVAL +36 HOUR)
47ORDER BY fStart
48
49EOT;
50
51$html1 = "";
52$array = array();
53
54$result = mysql_query($query, $db_id);
55if ($result)
56{
57 $html1 .= "<table>\n";
58
59 $n = 0;
60 while ($row = mysql_fetch_assoc($result))
61 {
62 $html1 .= " <tr>\n";
63 $html1 .= " <td>".$row["fStart"]."|</td>\n";
64 $html1 .= " <td>".$row["fMeasurementTypeName"]."</td>\n";
65 $html1 .= " <td>|".$row["fSourceName"]."</td>\n";
66 $html1 .= " <td>[".$row["fUser"]."]</td>\n";
67 $html1 .= " </tr>\n";
68
69 $array[$n++] = $row;
70 }
71 $html1 .= "</table>\n";
72
73 mysql_free_result($result);
74}
75else
76 $html1 = "[empty:".mysql_error()."]\n";
77
78// --------------------------------------------------------------------
79
80$html2 = "<table>\n";
81
82$suspend = false;
83$prev_data = array();
84
85for ($i=0; $i<$n-1; $i++)
86{
87 // Switch to "suspend-mode"
88 if ($array[$i]['fMeasurementTypeName']=='Suspend')
89 $suspend = true;
90
91 // If a resume is found, the data is replaced with the
92 // last data run with the resume-time as start time.
93 if ($array[$i]['fMeasurementTypeName']=='Resume')
94 {
95 // Sanity check: There is not much we can do
96 if (empty($prev_data) || !$suspend)
97 continue;
98
99 $prev_data['fStart'] = $array[$i]['fStart'];
100 $array[$i] = $prev_data;
101 $suspend = false;
102 }
103
104 // None data runs are not displayed
105 if ($array[$i]['fMeasurementTypeName']!='Data')
106 continue;
107
108 // If this is a data run keep that for use after a suspend/resume
109 $prev_data = $array[$i];
110
111 // If the system is suspended, don't display the runs
112 if ($suspend)
113 continue;
114
115 $data .= "[";
116 $data .= "'".$table."',";
117 $data .= "'".$array[$i]['fSourceName']."',";
118 $data .= fmt($array[$i]['fStart']).",";
119 // in case two resumes are scheduled without suspend inbetween, the stop of a later observations needs to be used
120 if ($array[$i+1]['fMeasurementTypeName']=='Resume' && !$suspend)
121 $data .= fmt($array[$i+2]['fStart']).",";
122 else
123 $data .= fmt($array[$i+1]['fStart']).",";
124 $data .= "],\n";
125
126 $html2 .= " <tr>";
127 $html2 .= " <td>".$array[$i]['fStart']."|</td>\n";
128 $html2 .= " <td>".$array[$i]["fSourceName"]."</td>\n";
129 // in case two resumes are scheduled without suspend inbetween, the stop of a later observations needs to be used
130 if ($array[$i+1]['fMeasurementTypeName']=='Resume' && !$suspend)
131 $html2 .= " <td>|".$array[$i+2]["fStart"]."|</td>\n";
132 else
133 $html2 .= " <td>|".$array[$i+1]["fStart"]."|</td>\n";
134 $html2 .= " </tr>\n";
135}
136
137$html2 .= "</table>\n";
138}
139
140// --------------------------------------------------------------------
141
142function QueryRunInfo(&$data, &$diff, &$html2, &$query2, $night, $db_id, $where)
143{
144$query2 = <<< EOT
145
146SELECT
147 fRunID,
148 fSourceName,
149 fRunStart,
150 fRunStop
151FROM RunInfo
152LEFT JOIN Source USING(fSourceKey)
153LEFT JOIN AnalysisResultsRunLP USING (fNight, fRunID)
154WHERE fNight=$night
155 AND NOT fRunStart='0000-00-00 00:00:00'
156 AND NOT fRunStop='0000-00-00 00:00:00'
157 AND fRunTypeKEY=1
158 $where
159ORDER BY fRunID
160
161EOT;
162
163// --------------------------------------------------------------------
164
165$array2 = array();
166
167$result2 = mysql_query($query2, $db_id);
168if ($result2)
169{
170 $html2 .= "<table>\n";
171
172 $n = 0;
173 while ($row = mysql_fetch_assoc($result2))
174 {
175 if (empty($row['fSourceName']))
176 continue;
177
178 $data .= "[";
179 $data .= "'RunInfo',";
180 $data .= "'".$row['fSourceName']."',";
181 $data .= fmt($row['fRunStart']).",";
182 $data .= fmt($row['fRunStop']).",";
183 $data .= "],\n";
184
185
186 $html2 .= " <tr>\n";
187 $html2 .= " <td>".$row["fRunStart"]." | </td>\n";
188 $html2 .= " <td>".$row["fSourceName"]."</td>\n";
189 $html2 .= " <td> | ".$row["fRunStop"]."</td>\n";
190 $html2 .= " </tr>\n";
191
192 $diff .= $row["fRunID"].": ";
193 $diff .= $row["fRunStart"]." | ";
194 $diff .= $row["fSourceName"]." | ";
195 $diff .= $row["fRunStop"]."\n";
196
197 $n++;
198 }
199 $html2 .= "</table>\n";
200
201 mysql_free_result($result2);
202}
203else
204 $html2 = "[empty:".mysql_error()."]\n";
205}
206
207// --------------------------------------------------------------------
208
209QuerySchedule($data, $html0a, $html0b, $query0, $db_id, "AutoSchedule", $date);
210QuerySchedule($data, $html1a, $html1b, $query1, $db_id, "Schedule", $date);
211
212// --------------------------------------------------------------------
213
214QueryRunInfo($dataA, $diffA, $html2, $query2, $night, $db_id, "");
215QueryRunInfo($dataB, $diffB, $html3, $query3, $night, $db_id, "AND NOT ISNULL(fNumExcEvts)");
216
217$data .= $dataA;
218
219$diff = "";
220if ($dataA!=$dataB)
221{
222 $diff = Diff::toTable(Diff::compare($diffA, $diffB));
223 $data .= str_replace("RunInfo", "QLA", $dataB);
224}
225
226// --------------------------------------------------------------------
227
228mysql_close($db_id);
229
230// --------------------------------------------------------------------
231
232$color = "false";
233if (empty($data))
234{
235 $data = "['No Schedule','',new Date(1970,1,1,19,0,0),new Date(1970,1,2,7,0,0)]";
236 $color = "'#eee'";
237}
238
239$querycol0 = colorize($query0);
240$querycol1 = colorize($query1);
241$querycol2 = colorize($query2);
242$querycol3 = colorize($query3);
243
244// --------------------------------------------------------------------
245
246echo <<<EOT
247
248<!DOCTYPE HTML>
249<html>
250<head>
251<script src="//code.jquery.com/jquery-2.2.1.min.js" integrity="sha256-gvQgAFzTH6trSrAWoH1iPo9Xc96QxSZ3feW6kem+O00=" crossorigin="anonymous"></script>
252<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" integrity="sha256-xNjb53/rY+WmG+4L6tTl9m6PpqknWZvRt0rO1SRnJzw=" crossorigin="anonymous"></script>
253
254<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
255
256<script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>
257<script type="text/javascript">
258
259 google.charts.load('current', {packages: ['timeline']});
260 google.charts.setOnLoadCallback(draw);
261
262 function draw()
263 {
264 $(document).keydown(function(e)
265 {
266 var offset = 0;
267 if (e.which == 38) offset = 7*24*3600*1000;
268 if (e.which == 40) offset = -7*24*3600*1000;
269 if (e.which == 39) offset = 1*24*3600*1000;
270 if (e.which == 37) offset = -1*24*3600*1000;
271 if (!offset)
272 return;
273
274 var d = $("#datepicker").datepicker("getDate");//.getTime();
275
276 var c = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())+offset);
277
278 window.location = "?d="+c.toISOString().split("T")[0];
279
280 //$("#datepicker").datepicker("setDate", date);
281 //$("#datepicker").trigger("select");
282
283 return false;
284 });
285
286 var dp = $("#datepicker").datepicker({
287 autoSize: true,
288 dateFormat: "yy-mm-dd",
289 selectOtherMonths: true,
290 /*showButtonPanel: true,*/
291 showWeek: true,
292 defaultDate: "$date",
293 inline: true,
294 changeMonth: true,
295 changeYear: true,
296 minDate: new Date(2011, 10, 15),
297 onSelect: function(date) { window.location = "?d="+date; }
298
299});
300
301 var data = new google.visualization.DataTable();
302 data.addColumn({ type: 'string', id: 'Role' });
303 data.addColumn({ type: 'string', id: 'Name' });
304 data.addColumn({ type: 'date', id: 'Start' });
305 data.addColumn({ type: 'date', id: 'End' });
306 data.addRows([$data]);
307
308 //var dateFormatter = new google.visualization.DateFormat({pattern: 'dd/MM/yyyy HH:mm'});
309 //dateFormatter.format(data, 2);
310 //dateFormatter.format(data, 3);
311
312 var options = {
313 hAxis: {format:'HH:mm', minorGridlines: {count:1}},
314 avoidOverlappingGridLines: false,
315 timeline: { singleColor: $color },
316 };
317
318 var chart = new google.visualization.Timeline(document.getElementById('chart_div'));
319 chart.draw(data, options);
320 //document.getElementById('print_chart').innerHTML = '<a href="' + chart.getImageURI() + '">Print</a>';
321 console.log("Google.chart.ready");
322 }
323</script>
324<style>
325dl {
326 //border: 3px double #ccc;
327 padding: 0.5em;
328 }
329 dt {
330 float: left;
331 clear: left;
332 width: 130px;
333 text-align: right;
334 font-weight: bold;
335 color: green;
336 }
337 dt:after {
338 content: ":";
339 }
340 dd {
341 margin: 0 0 0 140px;
342 padding: 0 0 1em 0;
343 }
344 code {
345 padding: 0 3px;
346 background-color: #eee; /* support: IE8 */;
347 background-color: rgba( 0, 0, 0, .1 );
348 border-radius: 3px;
349}
350.diff td{
351 vertical-align : top;
352 /*white-space : pre;
353 white-space : pre-wrap;*/
354 font-family : monospace;
355}
356.diff span{
357 margin-right: 2em;
358}
359
360/* .diff span:first-child{
361 margin-top:0;
362 }*/
363
364 .diffDeleted span{
365 border:1px solid rgb(255,192,192);
366 background:rgb(255,224,224);
367 } <
368
369 .diffInserted span{
370 border:1px solid rgb(192,255,192);
371 background:rgb(224,255,224);
372 }
373
374
375</style>
376
377<body>
378
379<p style="font-weight: bold;font-size:130%;">Date: <input type="text" id="datepicker" style="font-weight:normal;font-size:100%;" value="$date"></p>
380
381<div style='position:relative'>
382<!--<H3>$date</H3>-->
383<div id='chart_div' style="height:220px;width:99%;margin-left:0.5%;">Preparing chart... please stand by.</div>
384<div id='print_chart' style='position:absolute;top:10px;right:40px;'></div>
385</div>
386
387EOT;
388
389if ($legend)
390{
391echo <<<EOT
392
393<hr>
394
395<input type="button" onclick="$('#spoiler0').toggle(300);" value="Legend"/>
396<div id="spoiler0" style="display:none">
397 <dl>
398 <dt>AutoSchedule</dt>
399 <dd>(if available) The schedule from the AutoSchedule table as planned by the autoscheduler (<i>makeschedule</I>).</dd>
400 <dt>Schedule</dt>
401 <dd>The schedule as available in the Schedule table after the night.</dd>
402 <dt>RunInfo</dt>
403 <dd>The schedule as executed, taken from the RunInfo table. Only data runs are counted.</dd>
404 <dt>QLA</dt>
405 <dd>This row is only displayed if different from RunInfo. It shows all runs
406 which have been processed by the QLA already.
407 </dl>
408Note that the two schedules will never perfectly coincide with the runs taken
409because finite Measurements scheduled together with a source in one observation
410are counted to be part of the source. Also automatic calibration
411runs are obviously not accounted for in the schedule.
412
413<hr>
414
415<h3>Keyboard interaction</h3>
416
417<li><code>LEFT</code>: Move to the previous day.</li>
418<li><code>RIGHT</code>: Move to the next day.</li>
419<li><code>UP</code>: Move to the previous week.</li>
420<li><code>DOWN</code>: Move the next week.</li>
421
422<p>While the datepicker is open, the following key commands are available:</p>
423<ul>
424<li><code>PAGE UP</code>: Move to the previous month.</li>
425<li><code>PAGE DOWN</code>: Move to the next month.</li>
426<li><code>CTRL</code> + <code>PAGE UP</code>: Move to the previous year.</li>
427<li><code>CTRL</code> + <code>PAGE DOWN</code>: Move to the next year.</li>
428<li><code>CTRL</code> + <code>HOME</code>: Open the datepicker if closed.</li>
429<li><code>CTRL</code>/<code>COMMAND</code> + <code>HOME</code>: Move to the current month.</li>
430<li><code>CTRL</code>/<code>COMMAND</code> + <code>LEFT</code>: Move to the previous day.</li>
431<li><code>CTRL</code>/<code>COMMAND</code> + <code>RIGHT</code>: Move to the next day.</li>
432<li><code>CTRL</code>/<code>COMMAND</code> + <code>UP</code>: Move to the previous week.</li>
433<li><code>CTRL</code>/<code>COMMAND</code> + <code>DOWN</code>: Move the next week.</li>
434<li><code>ENTER</code>: Select the focused date.</li>
435<li><code>CTRL</code>/<code>COMMAND</code> + <code>END</code>: Close the datepicker and erase the date.</li>
436<li><code>ESCAPE</code>: Close the datepicker without selection.</li>
437</ul>
438
439</div>
440
441<hr>
442
443<input type="button" onclick="$('#spoiler1').show(300);$('#spoiler2').show(300);$('#spoiler3').show(300);$('#spoiler4').show(300);" value="Show all tables"/>
444<input type="button" onclick="$('#spoiler1').hide(300);$('#spoiler2').hide(300);$('#spoiler3').hide(300);$('#spoiler4').hide(300);" value="Hide all tables"/>
445
446<hr>
447
448<input type="button" onclick="$('#spoiler1').toggle(300);" value="Planned Schedule"/>
449<div id="spoiler1" style="display:none">
450$html0a
451<hr style='width:95%'>
452$html0b
453</div>
454
455<hr>
456
457<input type="button" onclick="$('#spoiler2').toggle(300);" value="Scheduled observations"/>
458<div id="spoiler2" style="display:none">
459$html1a
460<hr style='width:95%'>
461$html1b
462</div>
463
464<hr>
465
466<input type="button" onclick="$('#spoiler3').toggle(300);" value="Runs taken"/>
467<div id="spoiler3" style="display:none">
468$html2
469</div>
470
471<hr>
472
473<input type="button" onclick="$('#spoiler4').toggle(300);" value="Runs analysed"/>
474<div id="spoiler4" style="display:none">
475$html2
476</div>
477
478<hr>
479
480<input type="button" onclick="$('#spoiler5').toggle(300);" value="Diff taken/analysed"/>
481<div id="spoiler5" style="display:none">
482$diff
483</div>
484
485<hr>
486
487<input type="button" onclick="$('#spoiler6').toggle(300);" value="SQL query (Auto)Schedule"/>
488<div id="spoiler6" style="display:none">
489<pre>
490$querycol0
491<hr style='width:95%'>
492$querycol1
493</pre>
494</div>
495
496<hr>
497
498<input type="button" onclick="$('#spoiler7').toggle(300);" value="SQL query RunInfo"/>
499<div id="spoiler7" style="display:none">
500<pre>
501$querycol2
502<hr style='width:95%'>
503$querycol3
504</pre>
505</div>
506
507<hr>
508EOT;
509
510}
511
512echo <<<EOT
513
514</body>
515</html>
516EOT;
517
518?>
Note: See TracBrowser for help on using the repository browser.