Index: /branches/eam_branches/ipp-20211108/ippMonitor/raw/czartool_labels.php
===================================================================
--- /branches/eam_branches/ipp-20211108/ippMonitor/raw/czartool_labels.php	(revision 42066)
+++ /branches/eam_branches/ipp-20211108/ippMonitor/raw/czartool_labels.php	(revision 42067)
@@ -376,4 +376,6 @@
 }
 
+# data quality timeseries
+echo getDataQuality($projectdb);
 # storage timeseries
 echo getSpaces($czardb);
@@ -1799,4 +1801,264 @@
     echo "<center>loading in $total_time seconds<br></center>";
 }
+
+
+###########################################################################
+#
+# Gets data quality status
+#
+###########################################################################
+function getDataQuality($db) {
+    // timer start
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $start = $time;
+
+    #Query for the needed data
+    $DQarray = array();
+
+    $sql = "SELECT subtime(dateobs,'10:00:00') as time,iq_fwhm_major,iq_fwhm_minor,zpt_obs,zpt_stdev,rawExp.filter,rawExp.exp_time,rawExp.comment FROM rawExp JOIN chipRun using (exp_id) JOIN camRun using (chip_id) JOIN camProcessedExp using (cam_id)";
+#    $sql.= " WHERE (rawExp.dateobs > utc_date() - INTERVAL 14 hour) and (rawExp.dateobs < utc_date() + INTERVAL 10 hour)";
+    $sql.= " WHERE (rawExp.dateobs > utc_date())";
+    $sql.= " AND exp_type = 'OBJECT' AND camRun.state like 'full' ORDER BY dateobs asc;";
+    if ($debug) {echo "$sql<br>";}
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    while ($qry->fetchInto($row)) {
+        $DQarray[] = $row;
+    }
+
+    #also find the median zeropoint
+    foreach($DQarray as $row) {
+        $zpt[]    = $row[3];
+    }
+
+    sort($zpt);
+    $count = sizeof($zpt);   // cache the count
+    $index = floor($count/2);  // cache the index
+    $zpt_med = $zpt[$index];
+
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">"; 
+    echo "  <div id=\"dq_div\" style=\"width:640; \"></div>";
+    echo "  <div class=\"overlay\" style=\"position: absolute; width: 400px; bottom: 60px; left: 85px;\">";
+    echo "  </div>";
+    echo "</div>";
+
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {packages: ['corechart']});";
+    echo "google.charts.setOnLoadCallback(drawChart);";
+    echo "function drawChart() {";
+    echo "  var data = new google.visualization.DataTable();";
+    echo "        data.addColumn('datetime', 'Time');";
+    echo "        data.addColumn('number', 'FWHM_maj');";
+    echo "        data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});";
+    echo "        data.addColumn('number', 'FWHM_min');";
+    echo "        data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});";
+    echo "        data.addColumn('number', 'seeing=1');";
+    echo "        data.addColumn('number', 'seeing=1.5');";
+    echo "   data.addRows([";
+
+    foreach($DQarray as $row) {
+        $tsp = explode(' ', $row[0]);
+        $dat = explode('-', $tsp[0]);
+        $tm = explode(':', $tsp[1]);
+        $timestamp = $row[0];
+        $fwhm_maj    = $row[1];
+        $fwhm_min = $row[2];
+
+        $tt_string1 = sprintf('time: %s\n FWHM_major: %s\n filter: %s\n exp_time: %s\n comment: %s', $timestamp, $fwhm_maj,$row[5],$row[6],$row[7]);
+        $tt_string2 = sprintf('time: %s\n FWHM_minor: %s\n filter: %s\n exp_time: %s\n comment: %s', $timestamp, $fwhm_min,$row[5],$row[6],$row[7]);
+#	new Date(Year, Month, Day, Hours, Minutes, Seconds, Milliseconds)
+       echo "[new Date($dat[0], $dat[1]-1, $dat[2], $tm[0], $tm[1]), $fwhm_maj,'$tt_string1',$fwhm_min,'$tt_string2',3.85,5.76],";
+    }
+   echo "  ]);";
+   echo "   var options = {";
+   echo "      chart: {";  
+   echo "               position: 'center', " ;
+   echo "              },";
+   echo "     title: 'FWHM overview during the last night',";
+   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
+   echo "     width: '100%',";
+   echo "     height: 400,";
+   echo "     legend: { position: 'top',";
+   echo "               alignment: 'center',";
+   echo "              },";
+   echo "     lineWidth: 2, ";
+   echo "     series: {";
+   echo "         0: { color: '#0000ff', lineWidth: 3 },      ";
+   echo "         1: { color: '#33a532', lineWidth: 3 },      ";
+   echo "         2: { color: 'red', lineWidth: 2 },      ";
+   echo "         3: { color: 'red', lineWidth: 2, lineDashStyle: [8, 4] },      ";
+   echo "              },";
+   echo "     hAxis: {  ";
+   echo "             title: 'Date/Time (HST)',";
+   echo "             format: 'HH:mm',";
+   echo "            gridlines: {count: -1},"; 
+   echo "     },";
+   echo "     vAxis: {  ";
+   echo "                  title: 'FWHM (pixels)',";
+   echo "     },";
+   echo "     chartArea: {left:80, top:50, right:20, bottom:50},";
+   echo "     fontSize: 12,";
+   echo "   };";
+   echo "   var chart = new google.visualization.LineChart(document.getElementById('dq_div'));";
+   echo "   chart.draw(data, options);";
+   echo " }";
+   echo "</script>";
+
+#   ---------------------------------------
+#   Also the zeropoint
+
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">"; 
+    echo "  <div id=\"dqzp_div\" style=\"width:640; \"></div>";
+    echo "  <div class=\"overlay\" style=\"position: absolute; width: 400px; bottom: 60px; left: 85px;\">";
+    echo "  </div>";
+    echo "</div>";
+
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {packages: ['corechart']});";
+    echo "google.charts.setOnLoadCallback(drawChart);";
+    echo "function drawChart() {";
+    echo "  var data = new google.visualization.DataTable();";
+    echo "        data.addColumn('datetime', 'Time');";
+    echo "        data.addColumn('number', 'zeropoint');";
+    echo "        data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});";
+    echo "        data.addColumn({id:'i0', type:'number', role:'interval'});";
+    echo "        data.addColumn({id:'i0', type:'number', role:'interval'});";
+    echo "   data.addRows([";
+    foreach($DQarray as $row) {
+        $tsp = explode(' ', $row[0]);
+        $dat = explode('-', $tsp[0]);
+        $tm = explode(':', $tsp[1]);
+        $timestamp = $row[0];
+        $zp    = $row[3];
+        $zp_stdev = $row[4];
+        $zp_low = $zp-$zp_stdev;
+        $zp_high = $zp+$zp_stdev;
+
+        $tt_string1 = sprintf('time: %s\n zeropoint: %s\n filter: %s\n exp_time: %s\n comment: %s', $timestamp, $zp,$row[5],$row[6],$row[7]);
+#	new Date(Year, Month, Day, Hours, Minutes, Seconds, Milliseconds)
+       echo "[new Date($dat[0], $dat[1]-1, $dat[2], $tm[0], $tm[1]), $zp,'$tt_string1', $zp_low, $zp_high],";
+    }
+
+   echo "  ]);";
+   echo "   var options = {";
+   echo "      chart: {";  
+   echo "               position: 'center', " ;
+   echo "              },";
+   echo "     title: 'Zeropoint overview during the last night',";
+   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
+   echo "     width: '100%',";
+   echo "     height: 400,";
+   echo "     legend: { position: 'top',";
+   echo "               alignment: 'center',";
+   echo "              },";
+   echo "     lineWidth: 2, ";
+   echo "     series: {";
+   echo "         0: { color: '#0000ff', lineWidth: 3 },      ";
+   echo "              },";
+   echo "     intervals: { 'style':'line' },  ";
+   echo "     hAxis: {  ";
+   echo "             title: 'Date/Time (HST)',";
+   echo "             format: 'HH:mm',";
+   echo "            gridlines: {count: -1},"; 
+   echo "     },";
+   echo "     vAxis: {  ";
+   echo "                  title: 'Zeropoint (mag)',";
+   echo "     },";
+   echo "     chartArea: {left:80, top:50, right:20, bottom:50},";
+   echo "     fontSize: 12,";
+   echo "   };";
+   echo "   var chart = new google.visualization.LineChart(document.getElementById('dqzp_div'));";
+   echo "   chart.draw(data, options);";
+   echo " }";
+   echo "</script>";
+
+#   ---------------------------------------
+#   And a fixed zoom in on the zeropoint to see details
+
+    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
+    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
+    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">"; 
+    echo "  <div id=\"dqzp_zoom_div\" style=\"width:640; \"></div>";
+    echo "  <div class=\"overlay\" style=\"position: absolute; width: 400px; bottom: 60px; left: 85px;\">";
+    echo "  </div>";
+    echo "</div>";
+
+    echo "<script type=\"text/javascript\">";
+    echo "google.charts.load('current', {packages: ['corechart']});";
+    echo "google.charts.setOnLoadCallback(drawChart);";
+    echo "function drawChart() {";
+    echo "  var data = new google.visualization.DataTable();";
+    echo "        data.addColumn('datetime', 'Time');";
+    echo "        data.addColumn('number', 'zeropoint');";
+    echo "        data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});";
+    echo "        data.addColumn({id:'i0', type:'number', role:'interval'});";
+    echo "        data.addColumn({id:'i0', type:'number', role:'interval'});";
+    echo "   data.addRows([";
+    foreach($DQarray as $row) {
+        $tsp = explode(' ', $row[0]);
+        $dat = explode('-', $tsp[0]);
+        $tm = explode(':', $tsp[1]);
+        $timestamp = $row[0];
+        $zp    = $row[3];
+        $zp_stdev = $row[4];
+        $zp_low = $zp-$zp_stdev;
+        $zp_high = $zp+$zp_stdev;
+
+        $tt_string1 = sprintf('time: %s\n zeropoint: %s\n filter: %s\n exp_time: %s\n comment: %s', $timestamp, $zp,$row[5],$row[6],$row[7]);
+#	new Date(Year, Month, Day, Hours, Minutes, Seconds, Milliseconds)
+       echo "[new Date($dat[0], $dat[1]-1, $dat[2], $tm[0], $tm[1]), $zp,'$tt_string1', $zp_low, $zp_high],";
+    }
+
+   echo "  ]);";
+   echo "   var options = {";
+   echo "      chart: {";  
+   echo "               position: 'center', " ;
+   echo "              },";
+   echo "     title: 'Zeropoint zoom-in during the last night',";
+   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
+   echo "     width: '100%',";
+   echo "     height: 400,";
+   echo "     legend: { position: 'top',";
+   echo "               alignment: 'center',";
+   echo "              },";
+   echo "     lineWidth: 2, ";
+   echo "     series: {";
+   echo "         0: { color: '#0000ff', lineWidth: 3 },      ";
+   echo "              },";
+   echo "     intervals: { 'style':'line' },  ";
+   echo "     hAxis: {  ";
+   echo "             title: 'Date/Time (HST)',";
+   echo "             format: 'HH:mm',";
+   echo "            gridlines: {count: -1},"; 
+   echo "     },";
+   echo "     vAxis: {  ";
+   echo "                  title: 'Zeropoint (mag)',";
+   echo "     viewWindow: {   min: $zpt_med-0.2, max: $zpt_med+0.2    },  ";
+   echo "     },";
+   echo "     chartArea: {left:80, top:50, right:20, bottom:50},";
+   echo "     fontSize: 12,";
+   echo "   };";
+   echo "   var chart = new google.visualization.LineChart(document.getElementById('dqzp_zoom_div'));";
+   echo "   chart.draw(data, options);";
+   echo " }";
+   echo "</script>";
+
+
+
+    $time = microtime();
+    $time = explode(' ', $time);
+    $time = $time[1] + $time[0];
+    $finish = $time;
+    $total_time = round(($finish - $start), 3);
+    $start= $finish;
+    echo "<center>loading plot in $total_time seconds<br></center>";
+}
+
 
 ###########################################################################
