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

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