source: trunk/www/dch/datataking_efficiency.php@ 18932

Last change on this file since 18932 was 18886, checked in by Daniela Dorner, 7 years ago
added (tool by Thomas to plot data taking efficiency)
File size: 10.3 KB
Line 
1<?php
2
3 include("db.php");
4
5 // ini_set("display_errors", "On");
6 // ini_set("mysql.trace_mode", "On");
7
8
9$db_id = mysql_connect($host, $user, $pw);
10if ($db_id==FALSE)
11{
12 printf("mysql_connect returned the following error: %s\n", mysql_error());
13 die("");
14}
15mysql_select_db($db);
16
17// --------------------------------------------------------------------
18
19 //0: night
20 //1: astronomical twilight range
21 //2: time when data was taken
22 //3: runtime all runs
23 //4: runtime data runs
24
25$query = <<<EOT
26
27SELECT
28 fNight AS '0',
29 TIME_TO_SEC(TIMEDIFF(fStopObservation, fStartObservation)) AS '1',
30 TIME_TO_SEC(TIMEDIFF(MAX(fRunStop),MIN(fRunStart))) AS '2',
31 SUM(IF (TIMEDIFF(fRunStop,fRunStart)<'00:30:00', TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)), 0)) AS '3',
32 SUM(IF (TIMEDIFF(fRunStop,fRunStart)<'00:30:00' AND fRunTypeKey=1, TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)), 0)) AS '4'
33FROM ObservationTimes
34LEFT JOIN RunInfo USING(fNight)
35WHERE fNight<DATE_FORMAT(DATE(NOW()), '%Y%m%d')
36GROUP BY fNight
37ORDER BY fNight
38
39EOT;
40
41// --------------------------------------------------------------------
42
43$var1 = "";
44$debug = "";
45$total = array();
46$total["All"] = array();
47
48$result = mysql_query($query, $db_id);
49if ($result)
50{
51 $counter = 0;
52 while ($row = mysql_fetch_assoc($result))
53 {
54 $counter++;
55 if (empty($row['1']))
56 continue;
57
58 $year = substr($row['0'], 0, 4);
59 $date = substr($row['0'], 0, 4)."-".substr($row['0'], 4, 2)."-".substr($row['0'], 6, 2);
60
61 //1: astronomical twilight range
62 //2: time when data was taken
63 //3: runtime all runs
64 //4: runtime data runs
65
66 $v1 = empty($row['1']) ? 0 : $row['1'];
67 $v2 = empty($row['2']) ? 0 : $row['2'];
68 $v3 = empty($row['3']) ? 0 : $row['3'];
69 $v4 = empty($row['4']) ? 0 : $row['4'];
70
71 if ($v3<0)
72 {
73 $v3 = 0;
74
75 $debug .= "[3]< 0 : ".print_r($row, true)."<br>";
76 }
77
78 if ($v2<0)
79 {
80 $v2 = 0;
81
82 $debug .= "[2]< 0 : ".print_r($row, true)."<br>";
83 }
84
85 if ($v4<0)
86 {
87 $v4 = 0;
88
89 $debug .= "[4]< 0 : ".print_r($row, true)."<br>";
90 }
91
92 // Last minus first run can easily be larger than astronomical twilight
93 if ($v2>$v1)
94 $v2 = $v1;
95
96 if ($v3>$v2)
97 {
98 $debug .= "[3]>[2]: ".print_r($row, true)."<br>";
99
100 $v3 = $v2;
101 }
102
103 if ($v4>$v3)
104 {
105 $debug .= "[4]>[3]: ".print_r($row, true)."<br>";
106
107 $v4 = $v3;
108 }
109
110 $v4 /= 3600;
111 $v3 /= 3600;
112 $v2 /= 3600;
113 $v1 /= 3600;
114
115 $val4 = $v4;
116 $val3 = $v3-$v4;
117 $val2 = $v2-$v3;
118 $val1 = $v1-$v2;
119
120 if (!isset($total[$year]))
121 $total[$year] = array();
122
123 $total["All"]["Twilight"] += $val1;
124 $total["All"]["First-to-last"] += $val2;
125 $total["All"]["All runs"] += $val3;
126 $total["All"]["Data runs"] += $val4;
127
128 $total[$year]["Twilight"] += $val1;
129 $total[$year]["First-to-last"] += $val2;
130 $total[$year]["All runs"] += $val3;
131 $total[$year]["Data runs"] += $val4;
132
133 $var1 .= "\n[";
134 $var1 .= "new Date('".$date."'),";
135 $var1 .= $val4.",";
136 $var1 .= $val3.",";
137 $var1 .= $val2.",";
138 $var1 .= $val1.",";
139 //$var1 .= "'lightgray', ";
140 $var1 .= "],";
141 }
142
143 mysql_free_result($result);
144}
145//else
146// $table0 = "[empty:".mysql_error()."]\n";
147
148
149// --------------------------------------------------------------------
150
151$var2 = "";
152foreach($total as $key => $val)
153{
154 $var2 .= "\n['".$key."',";
155 $var2 .= $total[$key]["Data runs"].",";
156 $var2 .= $total[$key]["All runs"].",";
157 $var2 .= $total[$key]["First-to-last"].",";
158 $var2 .= $total[$key]["Twilight"].",";
159 $var2 .= "],";
160}
161
162// --------------------------------------------------------------------
163
164$querycol = colorize($query);
165
166// --------------------------------------------------------------------
167
168echo <<<EOT
169
170<!DOCTYPE HTML>
171<html>
172<head>
173<script src="https://code.jquery.com/jquery-2.2.1.min.js" integrity="sha256-gvQgAFzTH6trSrAWoH1iPo9Xc96QxSZ3feW6kem+O00=" crossorigin="anonymous"></script>
174<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
175<script type="text/javascript">
176 google.charts.load('current', {packages: ['corechart', 'bar']});
177 google.charts.setOnLoadCallback(drawAxisTickColors);
178
179 function drawAxisTickColors()
180 {
181 var data1 = new google.visualization.DataTable();
182 data1.addColumn('date', 'Date');
183 data1.addColumn('number', 'Data runs');
184 data1.addColumn('number', 'All runs');
185 data1.addColumn('number', 'First-to-last');
186 data1.addColumn('number', 'Twilight');
187 data1.addRows([$var1]);
188
189 var data2 = new google.visualization.DataTable();
190 //data2.addColumn('date', 'Date');
191 data2.addColumn('string', 'Date');
192 data2.addColumn('number', 'Data runs');
193 data2.addColumn('number', 'All runs');
194 data2.addColumn('number', 'First-to-last');
195 data2.addColumn('number', 'Twilight');
196 data2.addRows([$var2]);
197
198 var options1 = {
199 title: "Datataking time",
200 //subtitle:
201 height: 400,
202 width:'90%',
203 hAxis: {
204 title: 'Date',
205 },
206 vAxis: {
207 title: 'Datataking time in hours',
208 minValue: 0,
209 gridlines: {count:-1}, minorGridlines: {count:1}
210 },
211 legend: { position: 'top', maxLines: 1 },
212 bar: { groupWidth: '100%' },
213 isStacked: true,
214 chartArea: {left:60,top:40,bottom:40,width:'90%'},
215 explorer: {keepInBound:true,actions:['dragToZoom','rightClickToReset']}
216 };
217
218 var options2 = {
219 title: "Datataking time",
220 //subtitle:
221 height: 400,
222 width:500,
223 hAxis: {
224 title: 'Year',
225 },
226 vAxis: {
227 title: 'Datataking time in hours',
228 minValue: 0,
229 gridlines: {count:-1}, minorGridlines: {count:1}
230 },
231 legend: { position: 'top', maxLines: 1 },
232 bar: { groupWidth: '90%' },
233 isStacked: true,
234 dataOpacity: 0.9,
235 chartArea: {left:60,top:40,bottom:40,width:'90%'},
236 explorer: {keepInBound:true,actions:['dragToZoom','rightClickToReset']}
237 };
238
239 var chart1 = new google.visualization.ColumnChart(document.getElementById('columnchart1_values'));
240 chart1.draw(data1, options1);
241 document.getElementById('print1_values').innerHTML = '<a href="' + chart1.getImageURI() + '">Print</a>';
242
243 var chart2 = new google.visualization.ColumnChart(document.getElementById('columnchart2_values'));
244 chart2.draw(data2, options2);
245 document.getElementById('print2_values').innerHTML = '<a href="' + chart2.getImageURI() + '">Print</a>';
246
247 options1.title = 'Data taking efficiency relative to astronomical twilight';
248 options1.isStacked = 'percent';
249 options1.vAxis.title = 'Data taking efficiency';
250
251 options2.title = 'Data taking efficiency relative to astronomical twilight';
252 options2.isStacked = 'percent';
253 options2.vAxis.title = 'Data taking efficiency';
254
255 var chart3 = new google.visualization.ColumnChart(document.getElementById('columnchart1_efficiency'));
256 chart3.draw(data1, options1);
257 document.getElementById('print1_efficiency').innerHTML = '<a href="' + chart3.getImageURI() + '">Print</a>';
258
259 var chart4 = new google.visualization.ColumnChart(document.getElementById('columnchart2_efficiency'));
260 chart4.draw(data2, options2);
261 document.getElementById('print2_efficiency').innerHTML = '<a href="' + chart4.getImageURI() + '">Print</a>';
262
263 console.log("Google.chart.ready");
264 }
265</script>
266<style>
267dl {
268 //border: 3px double #ccc;
269 padding: 0.5em;
270 }
271 dt {
272 float: left;
273 clear: left;
274 width: 130px;
275 text-align: right;
276 font-weight: bold;
277 color: green;
278 }
279 dt:after {
280 content: ":";
281 }
282 dd {
283 margin: 0 0 0 140px;
284 padding: 0 0 1em 0;
285 }
286</style>
287<body>
288
289<div style='position:relative'>
290<div id='columnchart1_values'>Preparing charts... this may take a moment.</div>
291<div id='print1_values' style='position:absolute;top:10px;right:40px;'></div>
292</div>
293
294<p>
295
296<div style='position:relative'>
297<div id='columnchart1_efficiency'></div>
298<div id='print1_efficiency' style='position:absolute;top:10px;right:40px;'></div>
299</div>
300
301<hr>
302
303<div style='position:relative'>
304<div id='columnchart2_values'></div>
305<div id='print2_values' style='position:absolute;top:10px;right:40px;'></div>
306</div>
307
308<p>
309
310<div style='position:relative'>
311<div id='columnchart2_efficiency'></div>
312<div id='print2_efficiency' style='position:absolute;top:10px;right:40px;'></div>
313</div>
314
315<hr>
316
317<input type="button" onclick="$('#spoiler0').toggle(300);" value="Legend"/>
318<div id="spoiler0" style="display:none">
319<dl>
320 <dt>Data runs</dt>
321 <dd>The sum of the data taking time of all data runs of the night with
322 less than 30min calculated as the difference between the time stamp
323 of closing and opening time of the run.</dd>
324
325 <dt>All runs</dt>
326 <dd>Same as <b>Onle data runs</b> but including all other run types such
327 as pedestal, drs calibration etc., which have a source name set. This
328 is usually the case if the telescope is tracking a source during the
329 run. This does not include times as repositioning times when the
330 no data acquisition was active.</dd>
331
332 <dt>First-to-last</dt>
333 <dd>This is the time difference between the end time of the last run of
334 the night and the start time of the first run of the night. This
335 corresponds roughly to the time the telescope is operated and is
336 a measure whether startup and shutdown was properly scheduled.</dd>
337
338 <dt>Twilight</dt>
339 <dd>This is the time of astronomical twilight which - in the ideal case -
340 corresponds to the maximum data taking time.</dd>
341 </dl>
342
343 On average 42% (10h) of a night is twilight. So a data taking efficiency
344 of 50% twlight means a total duty cycle of 21%.
345
346</div>
347
348<hr>
349
350<input type="button" onclick="$('#spoiler3').toggle(300);" value="SQL Query"/>
351<div id="spoiler3" style="display:none">
352<pre>
353$querycol
354</pre>
355</div>
356
357<hr>
358
359<input type="button" onclick="$('#spoiler4').toggle(300);" value="Warnings"/>
360<div id="spoiler4" style="display:none">
361$debug
362</div>
363
364</body>
365</html>
366EOT;
367
368?>
Note: See TracBrowser for help on using the repository browser.