source: trunk/www/dch/obs_time.php@ 19598

Last change on this file since 19598 was 18885, checked in by Daniela Dorner, 8 years ago
added (tool by Thomas to plot observation time)
File size: 4.5 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
17date_default_timezone_set('UTC');
18
19$begin = isset($_GET["b"]) ? "AND fRunStart>'".$_GET["b"]."'" : "";
20$end = isset($_GET["e"]) ? "AND fRunStop<'".$_GET["e"]."'" : "";
21$limit = isset($_GET["l"]) ? 0+$_GET["l"] : 10;
22$hidden = isset($_GET["print"]) ? "*{visibility:hidden;}.print{position:fixed;left:0;top:0;}.print *{visibility:visible;}" : "";
23
24// ====================================================================
25
26$query = <<<EOT
27
28 SELECT
29 fSourceName AS 'Source' ,
30 SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600 AS 'Time'
31 FROM RunInfo
32 LEFT JOIN Source USING(fSourceKEY)
33 WHERE fRunTypeKEY=1 AND fSourceTypeKey=1 $begin $end
34 GROUP BY fSourceKEY
35 HAVING Time>=$limit
36 ORDER BY Time DESC
37
38EOT;
39
40$html = "";
41//$data = "['Source','Observation Time [h]'],\n";
42$data = "['Source','Observation Time [h]',{role:'annotation'}],\n";
43$var1 = "";
44$count = 0;
45$total = 0;
46
47$result = mysql_query($query, $db_id);
48if ($result)
49{
50 $html .= "<table>\n";
51
52 while ($row = mysql_fetch_assoc($result))
53 {
54 $html .= " <tr>";
55 $html .= " <td>".$row["Source"]."</td>\n";
56 $html .= " <td>|".$row["Time"]."</td>\n";
57 $html .= " </tr>\n";
58
59 $data .= "['".$row['Source']."',".$row['Time'].",'".number_format($row['Time'],0,'','')." h'],\n";
60 //$data .= "['".$row['Source']."',".$row['Time'].",'".$row['Source']."'],\n";
61 //$data .= "['',".$row['Time'].",'".$row['Source']."'],\n";
62
63 $total += $row['Time'];
64
65 $count++;
66 }
67 $html .= "</table>\n";
68
69 mysql_free_result($result);
70}
71else
72 $html = "[empty:".mysql_error()."]\n";
73
74// --------------------------------------------------------------------
75
76mysql_close($db_id);
77
78// --------------------------------------------------------------------
79
80if (isset($_GET['test']))
81{
82 print(json_encode($data/*, JSON_PRETTY_PRINT*/));
83 return;
84}
85
86// --------------------------------------------------------------------
87
88$querycol = $query;//colorize($query),
89
90// --------------------------------------------------------------------
91
92$height = $count*60;
93$width = $height*18/9;
94
95$total = number_format($total, 0, '', '');
96
97echo <<<EOT
98
99<!DOCTYPE HTML>
100<html>
101<head>
102<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
103<!--<script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>-->
104<script type="text/javascript" src="https://www.google.com/jsapi"></script>
105<script type="text/javascript">
106
107 google.load('visualization', 1, {packages: ['corechart', 'bar']});
108 google.setOnLoadCallback(drawAxisTickColors);
109
110 //google.charts.load('current', {packages: ['corechart', 'bar']});
111 //google.charts.setOnLoadCallback(drawAxisTickColors);
112
113 function drawAxisTickColors(data)
114 {
115 var data = google.visualization.arrayToDataTable(
116 [
117 $data
118 ]);
119
120 var options = {
121 width: $width,
122 height: $height,
123 legend: { position: 'top', maxLines: 1 },
124 bar: { groupWidth: '90%' },
125 dataOpacity: 0.9,
126 hAxis: {minValue: 0, gridlines: {count:-1}, minorGridlines: {count:1}},
127 };
128
129 var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
130 chart.draw(data, options);
131 document.getElementById('print_chart').innerHTML = '<a href="' + chart.getImageURI() + '">Print</a>';
132
133 console.log("Google.chart.ready");
134 }
135
136</script>
137<style>
138dl {
139 //border: 3px double #ccc;
140 padding: 0.5em;
141 }
142 dt {
143 float: left;
144 clear: left;
145 width: 130px;
146 text-align: right;
147 font-weight: bold;
148 color: green;
149 }
150 dt:after {
151 content: ":";
152 }
153 dd {
154 margin: 0 0 0 140px;
155 padding: 0 0 1em 0;
156 }
157 $hidden
158</style>
159
160<body>
161
162Total observation time: $total h (excluding sources with less than $limit h)
163<hr>
164
165<div style='position:relative'>
166<div id='chart_div' class="print">Preparing char... please stand by.</div>
167<div id='print_chart' style='position:absolute;top:10px;right:40px;'></div>
168</div>
169
170<hr>
171
172<input type="button" onclick="$('#spoiler1').toggle(300);" value="Table"/>
173<div id="spoiler1" style="display:none">
174$html
175</div>
176
177<hr>
178
179<input type="button" onclick="$('#spoiler2').toggle(300);" value="SQL query"/>
180<div id="spoiler2" style="display:none">
181<pre>
182$querycol
183</pre>
184</div>
185
186<hr>
187
188</body>
189</html>
190EOT;
191
192?>
Note: See TracBrowser for help on using the repository browser.