IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 27, 2019, 11:39:38 AM (7 years ago)
Author:
eugene
Message:

merge changes from trunk (mostly Ohana & ippMonitor improvements, some work on ippTools)

Location:
branches/eam_branches/ipp-20191011
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011

  • branches/eam_branches/ipp-20191011/ippMonitor

  • branches/eam_branches/ipp-20191011/ippMonitor/raw/czartool_labels.php

    r40883 r41170  
    214214echo "<td style=height:200px;width:400px;text-align:top;\">";
    215215
    216 #echo "<br>";
     216/////////////////////////////////////////
     217// timer begin for status and links
     218/////////////////////////////////////////
     219$time = microtime();
     220$time = explode(' ', $time);
     221$time = $time[1] + $time[0];
     222$start = $time;
    217223
    218224// status table at top
    219225$nsStatus = getNightlyScienceStatus($czardb, $proj);
    220226$plotTypeLink = ($plotType == "linear") ? "log" : "linear";
    221 $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
     227$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel .
     228        "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
     229
    222230echo "<br>";
    223231echo $table;
    224 
    225 createTableTitle("Status and links", 3);
     232createTableTitle("Status and links", 2);
    226233echo "<tr>\n";
    227 echo "<tr><td>Time of last update</td><td>$lastUpdateTime</td></tr>";
    228 echo "<tr><td>ippMonitor SVN version</td><td>"; include 'version.php'; echo "</td></tr>";
    229 echo "<tr><td>Current nightly science status</td><td>$nsStatus</td></tr>";
    230 echo "<tr><td>Postage stamp server status</td><td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\"><font color=\"blue\">here</font></a></td></tr>";
    231 echo "<tr><td>Documentation</td><td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\"><font color=\"blue\">here</font></a></td></tr>";
    232 echo "<tr><td>Cluster load</td><td><a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&hc=6&c=IPP%2520Production\"><font color=\"blue\">here</font></a> <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=cpu_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\"><font color=\"blue\">cpu_report</font></a> <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=mem_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\"><font color=\"blue\">mem_report</font></a></td></tr>";
    233 echo "<tr><td>IPP metrics</td><td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\"><font color=\"blue\">here</font></a></td></tr>";
    234 echo "<tr><td>Czar log pages</td><td><a href=\"https://confluence.ipp.ifa.hawaii.edu/pages/viewrecentblogposts.action?key=IPPCZAR\"><font color=\"blue\">here</font></a></td></tr>";
    235 echo "<tr><td>Exposure summary</td><td><a href=\"czartool_exposures.php?pass=$pass&proj=$proj\"><font color=\"blue\">here</font></a></td></tr>";
    236 echo "<tr><td>Confluence</td><td><a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IPPCZAR/IPP-Czaring+Home\"><font color=\"blue\">here</font></a></td></tr>";
    237 echo "<tr><td>JIRA</td><td><a href=\"https://jira.ipp.ifa.hawaii.edu/secure/Dashboard.jspa\"><font color=\"blue\">here</font></a></td></tr>";
     234echo "<tr><td>Time of last update</td>
     235          <td>$lastUpdateTime</td></tr>";
     236echo "<tr><td>ippMonitor SVN version</td>
     237          <td>"; include 'version.php'; echo "</td></tr>";
     238echo "<tr><td>Current nightly science status</td>
     239          <td>$nsStatus</td></tr>";
     240echo "<tr><td>Postage stamp server status</td>
     241          <td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\" target=new><font color=\"blue\">here</font></a></td></tr>";
     242echo "<tr><td>Documentation</td>
     243          <td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\" target=new><font color=\"blue\">here</font></a></td></tr>";
     244echo "<tr><td>Cluster load</td>
     245          <td><a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&hc=6&c=IPP%2520Production\">
     246              <font color=\"blue\">here</font></a>
     247              <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=cpu_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\">
     248              <font color=\"blue\">cpu_report</font></a>
     249              <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?m=mem_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\">
     250              <font color=\"blue\">mem_report</font></a></td></tr>";
     251echo "<tr><td>IPP metrics</td>
     252          <td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\"><font color=\"blue\" target=new>here</font></a></td></tr>";
     253echo "<tr><td>Czar log pages</td>
     254          <td><a href=\"https://confluence.ipp.ifa.hawaii.edu/pages/viewrecentblogposts.action?key=IPPCZAR\" target=new><font color=\"blue\">here</font></a></td></tr>";
     255echo "<tr><td>Exposure summary</td>
     256          <td><a href=\"czartool_exposures.php?pass=$pass&proj=$proj\"><font color=\"blue\">here</font></a></td></tr>";
     257echo "<tr><td>Confluence</td>
     258          <td><a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IPPCZAR/IPP-Czaring+Home\" target=new><font color=\"blue\">here</font></a></td></tr>";
     259echo "<tr><td>JIRA</td>
     260          <td><a href=\"https://jira.ipp.ifa.hawaii.edu/secure/Dashboard.jspa\" target=new><font color=\"blue\">here</font></a></td></tr>";
     261echo "<tr><td>data store</td>
     262          <td><a href=\"https://svn.ifa.hawaii.edu/\" target=new><font color=\"blue\">here</font></a></td></tr>";
    238263
    239264$plotTypeLink = ($plotType == "linear") ? "log" : "linear";
    240 $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&mode=" . $selectedMode . "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
    241 
    242 echo "</table>\n";
    243 
    244 echo "<br>";
    245 
    246        createLabelsTable($pass,
    247          $proj,
    248          $czardb,
    249          $selectedMode,
    250          $labels,
    251          $distLabelsExist,
    252          $pubLabelsExist,
    253          $stages,
    254          "new",
    255          $selectedLabel,
    256          $selectedStage,
    257          $plotType);
    258 
    259       if ($selectedMode == "update") {echo "<br>"; createPStampDataTable();}
    260       echo "<br>";
    261 
    262       # XXX EAM : 2017.09.17 : debugging slowness
    263       createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType); echo "<br>";
    264       createSummitDataTable($projectdb); echo "<br>"; // this is slow because of the join between summitExp and rawExp
    265       createChunkDataTable($projectdb); echo "<br>";
    266       createDatesTable($czardb, $proj); echo "<br>";
    267 
    268       echo $table;
    269       echo "<tr>";
    270       createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\">here</a>)", 2);
    271 
    272       echo "<tr>";
    273       createTableColumnHeader("Database");
    274       createTableColumnHeader("Status (sec behind master)");
    275       showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $DBNAME_GPC1);
    276       showReplicationsStatus($REPL_HOST_GPC1, $REPL_USER_GPC1, $REPL_PASSWORD_GPC1, $REPL_DBNAME_GPC1);
    277       showReplicationsStatus($REPL_HOST_GPC1_SECONDARY, $REPL_USER_GPC1_SECONDARY, $REPL_PASSWORD_GPC1_SECONDARY, $REPL_DBNAME_GPC1_SECONDARY);
    278 
    279       echo "<tr>";
    280 
    281       showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $DBNAME_NEBULOUS);
    282       showReplicationsStatus($REPL_HOST_NEBULOUS, $REPL_USER_NEBULOUS, $REPL_PASSWORD_NEBULOUS, $REPL_DBNAME_NEBULOUS);
    283       showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
    284       showReplicationsStatus($REPL_HOST_DATASTORE_SECONDARY, $REPL_USER_DATASTORE_SECONDARY, $REPL_PASSWORD_DATASTORE_SECONDARY, $REPL_DBNAME_DATASTORE_SECONDARY);
    285 
    286 #     some mysql replication slaves to add when they are returned to service
    287 #     showReplicationsStatus($REPL_HOST_PSTAMP, $REPL_USER_PSTAMP, $REPL_PASSWORD_PSTAMP, $REPL_DBNAME_PSTAMP);
    288 #     showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
    289       echo "</table>";
    290 
    291       echo $table;
    292       echo "<tr>";
    293       createTableTitle("Critical machine status", 2);
    294 
    295       echo "<tr>";
    296       createTableColumnHeader("Hostname");
    297       createTableColumnHeader("Status");
    298       showPingStatus($HOST_GATEWAY, $DBNAME_GATEWAY);
    299       showPingStatus($HOST_GATEWAY_SECONDARY, $DBNAME_GATEWAY_SECONDARY);
    300 
    301 #      showPingStatus($HOST_APACHE1, $DBNAME_APACHE1);
    302       showPingStatus($HOST_APACHE2, $DBNAME_APACHE2);
    303       showPingStatus($HOST_APACHE3, $DBNAME_APACHE3);
    304       showPingStatus($HOST_APACHE4, $DBNAME_APACHE4);
    305       showPingStatus($HOST_APACHE5, $DBNAME_APACHE5);
    306       showPingStatus($HOST_APACHE6, $DBNAME_APACHE6);
    307       showPingStatus($HOST_APACHE7, $DBNAME_APACHE7);
    308       showPingStatus($HOST_PROXY, $DBNAME_PROXY);
    309       showPingStatus($HOST_SVN, $DBNAME_SVN);
    310       showPingStatus($HOST_CONFLUENCE, $DBNAME_CONFLUENCE);
    311 
    312       echo "</table>";
    313 
    314 echo "</table>";
     265$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&mode=" . $selectedMode .
     266        "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
     267
     268// timer finished
     269echo "<tr><th colspan=4>";
     270$time = microtime();
     271$time = explode(' ', $time);
     272$time = $time[1] + $time[0];
     273$finish = $time;
     274$total_time = round(($finish - $start), 3);
     275echo "loading in $total_time seconds.";
     276echo "</th></tr>";
     277echo "</table><br>";
     278
     279createLabelsTable($pass, $proj, $czardb, $selectedMode, $labels,
     280  $distLabelsExist, $pubLabelsExist, $stages, "new", $selectedLabel,
     281  $selectedStage, $plotType);
     282if ($selectedMode == "update") {echo "<br>"; createPStampDataTable();}
     283
     284# XXX EAM : 2017.09.17 : debugging slowness
     285# CCL : 2019.11.09 : debugging slowness
     286//createSummitDataTable($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
     287createSummitDataTable2($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
     288
     289createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType);
     290// this was the major slowness part due to large table in czardb
     291
     292createChunkDataTable($projectdb);  // this is another part for slowness during nightly processing
     293
     294createDatesTable($czardb, $proj);
     295
     296/////////////////////////////////////////
     297// timer begin for Database status
     298/////////////////////////////////////////
     299$time = microtime();
     300$time = explode(' ', $time);
     301$time = $time[1] + $time[0];
     302$start = $time;
     303
     304// status table at top
     305  echo $table;
     306  echo "<tr>";
     307  createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\">here</a>)", 2);
     308 
     309  echo "<tr>";
     310  createTableColumnHeader("Database");
     311  createTableColumnHeader("Status (sec behind master)");
     312  showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $DBNAME_GPC1);
     313  showReplicationsStatus($REPL_HOST_GPC1, $REPL_USER_GPC1, $REPL_PASSWORD_GPC1, $REPL_DBNAME_GPC1);
     314  showReplicationsStatus($REPL_HOST_GPC1_SECONDARY, $REPL_USER_GPC1_SECONDARY, $REPL_PASSWORD_GPC1_SECONDARY, $REPL_DBNAME_GPC1_SECONDARY);
     315 
     316  echo "<tr>";
     317  showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $DBNAME_NEBULOUS);
     318  showReplicationsStatus($REPL_HOST_NEBULOUS, $REPL_USER_NEBULOUS, $REPL_PASSWORD_NEBULOUS, $REPL_DBNAME_NEBULOUS);
     319  showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
     320  showReplicationsStatus($REPL_HOST_DATASTORE_SECONDARY, $REPL_USER_DATASTORE_SECONDARY, $REPL_PASSWORD_DATASTORE_SECONDARY, $REPL_DBNAME_DATASTORE_SECONDARY);
     321 
     322//  some mysql replication slaves to add when they are returned to service
     323//  showReplicationsStatus($REPL_HOST_PSTAMP, $REPL_USER_PSTAMP, $REPL_PASSWORD_PSTAMP, $REPL_DBNAME_PSTAMP);
     324//  showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
     325
     326// timer finished
     327echo "<tr><th colspan=2>";
     328$time = microtime();
     329$time = explode(' ', $time);
     330$time = $time[1] + $time[0];
     331$finish = $time;
     332$total_time = round(($finish - $start), 3);
     333echo "loading in $total_time seconds.";
     334echo "</th></tr>";
     335echo "</table><br>";
     336
     337/////////////////////////////////////////
     338// timer begin for critical machines
     339/////////////////////////////////////////
     340$time = microtime();
     341$time = explode(' ', $time);
     342$time = $time[1] + $time[0];
     343$start = $time;
     344
     345// status table at top
     346  $PingStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">DOWN</font>";
     347  echo $table;
     348  echo "<tr>";
     349  createTableTitle("Critical machine status", 3);
     350
     351  echo "<tr>";
     352  createTableColumnHeader("Hostname");
     353  createTableColumnHeader("Status");
     354  createTableColumnHeader("Loading time");
     355  showPingStatus($HOST_GATEWAY, $DBNAME_GATEWAY);
     356  showPingStatus($HOST_GATEWAY_SECONDARY, $DBNAME_GATEWAY_SECONDARY);
     357  showPingStatus($HOST_APACHE1, $DBNAME_APACHE1);
     358  showPingStatus($HOST_APACHE2, $DBNAME_APACHE2);
     359  showPingStatus($HOST_APACHE3, $DBNAME_APACHE3);
     360  showPingStatus($HOST_APACHE4, $DBNAME_APACHE4);
     361  showPingStatus($HOST_APACHE5, $DBNAME_APACHE5);
     362  showPingStatus($HOST_APACHE6, $DBNAME_APACHE6);
     363  showPingStatus($HOST_APACHE7, $DBNAME_APACHE7);
     364  showPingStatus($HOST_APACHE8, $DBNAME_APACHE8);
     365//     echo "<td>ippc70 (apache node) <td> $PingStatus <td> 0 seconds ";  // comment out if ippc70 is back
     366  showPingStatus($HOST_PROXY, $DBNAME_PROXY);
     367  showPingStatus($HOST_SVN, $DBNAME_SVN);
     368  showPingStatus($HOST_CONFLUENCE, $DBNAME_CONFLUENCE);
     369
     370// timer finished
     371echo "<tr><th colspan=3>";
     372$time = microtime();
     373$time = explode(' ', $time);
     374$time = $time[1] + $time[0];
     375$finish = $time;
     376$total_time = round(($finish - $start), 3);
     377echo "loading in $total_time seconds.";
     378echo "</th></tr>";
     379echo "</table><br>";
     380   
     381
    315382menu_end();
    316383
     384
     385#############################################################################
     386#############################  Functions Below  #############################
     387#############################################################################
    317388
    318389###########################################################################
     
    361432}
    362433
    363 ###########################################################################
    364 #
    365 # Creates a table of summitExp against rawExp
    366 #
    367 ###########################################################################
    368 function createSummitDataTable($projectdb) {
    369 
    370     $date = date("Y-m-d");
    371     $sql = "SELECT DISTINCT exp_type FROM summitExp WHERE dateobs > '$date'";
    372 
    373     $qry = $projectdb->query($sql);
    374     if (dberror($qry)) {
    375         echo "<b>error reading newExp table</b><br>\n";
    376         echo "<br><small><b> table query : $sql </b></small><br>\n";
    377         menu_end();
    378     }
    379 
    380     // set up the table
    381     global $table;
    382     echo $table;
    383     echo "<tr>";
    384     createTableTitle("Status of last night's data", 4);
    385     echo "<tr>";
    386     createTableColumnHeader("Exposure type");
    387     createTableColumnHeader("At summit");
    388     createTableColumnHeader("Registered at MHPCC");
    389     createTableColumnHeader("At summit (Dropped)");
    390 
    391     $msg = "No science images taken since $date";
    392 
    393     // list the results
    394     while ($qry->fetchInto($expType)) {
    395 
    396         $sql = "SELECT COUNT(*) FROM summitExp left join pzDownloadExp using (summit_id) WHERE dateobs > '$date' AND exp_type = '$expType[0]' and (state != 'drop' or state is null) and fault != 1042";
    397 #       $sql = "SELECT COUNT(*) FROM summitExp WHERE dateobs > '$date' AND exp_type = '$expType[0]'";
    398         $qry2 = $projectdb->query($sql);
    399         $qry2->fetchInto($summit);
    400 
    401 
    402         $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name WHERE summitExp.dateobs > '$date' AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
    403         $qry2 = $projectdb->query($sql);
    404         $qry2->fetchInto($mhpcc);
    405 
    406         $sql = "SELECT COUNT(*) FROM summitExp join pzDownloadExp using (summit_id) WHERE dateobs > '$date' AND exp_type = '$expType[0]' and state = 'drop'";
    407         $qry2 = $projectdb->query($sql);
    408         $qry2->fetchInto($dropped);
    409 
    410 
    411         #Query with 30 minutes delay to check during the night if any exposures are missing.
    412         $datehour = gmdate("Y-m-d H:i:s");
    413         $sql = "SELECT COUNT(*) FROM summitExp left join pzDownloadExp using (summit_id) WHERE dateobs > '$date' AND dateobs <= date_sub('$datehour', interval 30 minute) AND exp_type = '$expType[0]' and (state != 'drop' or state is null) and fault != 1042";
    414         $qry2 = $projectdb->query($sql);
    415         $qry2->fetchInto($summitdelay);
    416 
    417         $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name WHERE summitExp.dateobs > '$date' AND summitExp.dateobs <= date_sub('$datehour', interval 30 minute) AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
    418         $qry2 = $projectdb->query($sql);
    419         $qry2->fetchInto($mhpccdelay);
    420 
    421         echo "<tr>";
    422 
    423         $DLdiff = $summit[0] - $mhpcc[0];
    424         if ($DLdiff == 0) $error = 0;
    425         else $error = 1;
    426 
    427         $delayDLdiff = $summitdelay[0] - $mhpccdelay[0];
    428         if ($delayDLdiff == 0) $errordelay = 0;
    429         else $errordelay = 1;
    430 
    431         echo "<td>$expType[0]</td>";
    432         echo "<td>$summit[0]</td>";
    433         #createFormattedTableCell("", "", $mhpcc[0], $error, 0);
    434         if ($delayDLdiff==0) {
    435            createFormattedTableCell("", "", $mhpcc[0], $error, 0);
    436         } else {
    437            $DLStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">$mhpcc[0] ($delayDLdiff)</font>";
    438            echo "<td>$DLStatus</td>";
    439         }
    440 
    441         echo "<td>$dropped[0]</td>";
    442 
    443         echo "</tr>";
    444     }
    445 
    446     echo "</table>\n";
    447 
    448 }
    449434
    450435###########################################################################
     
    455440function createChunkDataTable($projectdb) {
    456441
     442    // timer start
     443    $time = microtime();
     444    $time = explode(' ', $time);
     445    $time = $time[1] + $time[0];
     446    $start = $time;
     447
     448    // function begin
    457449    #First find the reference exposure ID to speed up the subsequent queries
    458450    $date = gmdate("Y-m-d");
     
    464456    }
    465457    $qry->fetchInto($refExpID);
    466 
    467     #Find the number of chunks
    468     $query = "SELECT groupchunk.chunk,groupchunk.Nquad_firstvisit,group4.Nquad_fourvisits FROM";
    469     $query .= "   (";
    470     $query .= "     SELECT dateobs,comment,substr(comment, 1, position(' ' in comment)) AS chunk,count(distinct(comment)) AS Nquad_firstvisit";
    471     $query .= "     FROM rawExp";
    472     $query .= "     WHERE dateobs LIKE '$date%' AND exp_id > $refExpID[0]";
    473     $query .= "     AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING'";
    474     $query .= "     AND comment LIKE '%visit 1%'";
    475     $query .= "     GROUP BY chunk";
    476     $query .= "   ) AS groupchunk";
    477     $query .= "   LEFT JOIN";
    478     $query .= "   (";
    479     $query .= "     SELECT groupobj.chunk,count(*) AS Nquad_fourvisits FROM ";
    480     $query .= "       (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(distinct(comment)) AS Nvisits";
    481     $query .= "         FROM rawExp";
    482     $query .= "         WHERE dateobs LIKE '$date%' AND exp_id > $refExpID[0] AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%')";
    483     $query .= "         AND obs_mode NOT LIKE 'ENGINEERING' AND comment LIKE '%visit%'";
    484     $query .= "         GROUP BY object, filter, chunk";
    485     $query .= "       ) AS groupobj";
    486     $query .= "     WHERE groupobj.Nvisits = 4 ";
    487     $query .= "     GROUP BY groupobj.chunk";
    488     $query .= "   ) AS group4";
    489     $query .= "   on groupchunk.chunk=group4.chunk ORDER BY dateobs";
    490 
    491     #$sql = "SELECT DISTINCT substr(comment, 1, position(' ' in comment)) FROM rawExp WHERE dateobs LIKE '$date%' AND exp_id > $refExpID AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND comment LIKE '%visit 1%'";
     458    if ($refExpID[0] = 'NULL') {
     459        $refExpID[0] = 0;
     460    }
     461
     462    #do a query of raw/chip/cam/warp counts for this night, split by chunk.
     463    #we need to do a subquery to find the total number of skycells in warpSkyfile, as well as the number of those with a bad quality
     464    $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad FROM ";
     465    $query .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(if(rawExp.comment LIKE '%visit 1%',1,NULL)) AS Nvis1,";
     466    $query .= "    count(if(rawExp.comment LIKE '%visit 2%',1,NULL)) AS Nvis2,count(if(rawExp.comment LIKE '%visit 3%',1,NULL)) AS Nvis3,";
     467    $query .= "    count(if(rawExp.comment LIKE '%visit 4%',1,NULL)) AS Nvis4, count(if(camProcessedExp.sigma_ra <= 5 AND camProcessedExp.sigma_dec <= 5 AND camProcessedExp.quality = 0,1,NULL)) AS Ncamgood,";
     468    $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad";
     469    $query .= "    FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) JOIN camProcessedExp USING (cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id)";
     470    $query .= "    WHERE dateobs like '$date%' AND exp_id > $refExpID[0] AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%'";
     471    $query .= "    AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     472    $query .= "    GROUP BY chunk ORDER BY dateobs) as suba ";
     473    $query .= "LEFT JOIN";
     474    $query .= "    (SELECT subc.chunk, count(if(subc.Nwarpskycellbad < subc.Nwarpskycell,1,NULL)) AS Nwarpgood, count(if(subc.Nwarpskycellbad = subc.Nwarpskycell,1,NULL)) AS Nwarpbad";
     475    $query .= "    FROM ";
     476    $query .= "      (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(warpSkyfile.quality) AS Nwarpskycell,count(if(warpSkyfile.quality > 0,1,NULL)) AS Nwarpskycellbad";
     477    $query .= "      FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) JOIN warpSkyfile USING (warp_id)";
     478    $query .= "      WHERE dateobs like '$date%' AND exp_id > $refExpID[0] AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%'";
     479    $query .= "      AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     480    $query .= "      GROUP BY exp_name) as subc";
     481    $query .= "    GROUP BY chunk) AS subb ";
     482    $query .= "ON suba.chunk=subb.chunk";
    492483
    493484    $qry = $projectdb->query($query);
    494485    if (dberror($qry)) {
    495         echo "<b>error reading rawExp table</b><br>\n";
     486        echo "<b>error querying SQL table</b><br>\n";
    496487        echo "<br><small><b> table query : $query </b></small><br>\n";
    497488        menu_end();
     
    502493    echo $table;
    503494    echo "<tr>";
    504     createTableTitle("Status of last night's chunks", 5);
     495    createTableTitle("Status of last night's chunks", 10);
    505496    echo "<tr>";
    506497    createTableColumnHeader("Chunk");
    507     createTableColumnHeader("Nobs_1stvisit");
    508     createTableColumnHeader("Nobs_4visits(bad cam)");
    509     createTableColumnHeader("Ndiffs_published");
     498    createTableColumnHeader("Nobs");
     499    createTableColumnHeader("Ncam");
     500    createTableColumnHeader("Nwrp");
     501    createTableColumnHeader("wrp_pub");
     502    createTableColumnHeader("Nwwd");
     503    createTableColumnHeader("wwd_pub");
     504    createTableColumnHeader("Nwsd");
     505    createTableColumnHeader("wsd_pub");
    510506    createTableColumnHeader("Completion");
    511507
     
    514510    // list the results
    515511    while ($qry->fetchInto($row)) {
    516         $Nfirstvisits = 0;
    517         $Nfourvisits = 0;
    518         $badcam = 0;
     512        $Nvis1 = 0;
     513        $Nvis2 = 0;
     514        $Nvis3 = 0;
     515        $Nvis4 = 0;
     516        $Ncamgood = 0;
     517        $Ncambad = 0;
     518        $Nwarpgood = 0;
     519        $Nwarpbad = 0;
     520        $NexpWWdiff = 0;
     521        $Npubwarps = 0;
    519522
    520523        $chunkname = $row[0];
    521         if($row[1] > 0) $Nfirstvisits = $row[1];
    522         if($row[2] > 0) $Nfourvisits = $row[2];
    523 
    524         $query2 = "     SELECT warp_id FROM ";
    525         $query2 .= "           warpRun JOIN fakeRun USING (fake_id) JOIN camRun USING (cam_id) JOIN camProcessedExp USING (cam_id) JOIN chipRun USING (chip_id) JOIN rawExp USING (exp_id)";
    526         $query2 .= "           WHERE rawExp.dateobs LIKE '$date%' AND exp_id > $refExpID[0] AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%')";
    527         $query2 .= "           AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%'";
     524        if($row[1] > 0) $Nvis1 = $row[1];
     525        if($row[2] > 0) $Nvis2 = $row[2];
     526        if($row[3] > 0) $Nvis3 = $row[3];
     527        if($row[4] > 0) $Nvis4 = $row[4];
     528        if($row[5] > 0) $Ncamgood = $row[5];
     529        if($row[6] > 0) $Ncambad = $row[6];
     530        if($row[7] > 0) $Nwarpgood = $row[7];
     531        if($row[8] > 0) $Nwarpbad = $row[8];
     532
     533        #set flags if present
     534        if($Ncambad >= 1) $badcamflag = 1;
     535        if($Nwarpbad >= 1) $badwarpflag = 1;
     536
     537        $query1 = "SELECT suba.chunk, SUM(IF(suba.Nvisits = 2,1,NULL)) as totvis2, SUM(IF(suba.Nvisits = 3 OR suba.Nvisits = 4,2,NULL)) as totvis34 FROM";
     538        $query1 .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(distinct(comment)) AS Nvisits FROM";
     539        $query1 .= "    rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) WHERE dateobs like '$date%'";
     540        $query1 .= "    AND exp_id > $refExpID[0] AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%' AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     541        $query1 .= "    AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%' group by object) as suba group by chunk;";
     542        $qry1 = $projectdb->query($query1);
     543        while ($qry1->fetchInto($row)) {$NexpWWdiff = $row[1] + $row[2];}
     544
     545        #find the unique diff_ids for each chunk, to be matched to the diffRun catalog
     546        $query2 = "     SELECT diff_id,warp1,stack1,warp2,stack2 FROM ";
     547        $query2 .= "           diffInputSkyfile JOIN warpRun ON (warp1=warp_id OR warp2=warp_id) JOIN fakeRun USING (fake_id) JOIN camRun USING (cam_id) JOIN camProcessedExp USING (cam_id) JOIN chipRun USING (chip_id) JOIN rawExp USING (exp_id)";
     548        $query2 .= "           WHERE rawExp.dateobs LIKE '$date%' AND exp_id > $refExpID[0] AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%' AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%')";
     549        $query2 .= "            AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL' AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%' GROUP By diff_id";
    528550        $qry2 = $projectdb->query($query2);
    529551
    530         $Ndiffs = 0;
     552        $NWWdiffgood = 0;
     553        $NWWdiffbad = 0;
     554        $NWWdiffpub = 0;
     555
     556        $NWSdiffgood = 0;
     557        $NWSdiffbad = 0;
     558        $NWSdiffpub = 0;
     559        $wrpcnt = array();
     560
    531561        while ($qry2->fetchInto($row2)) {
    532             $query3 = "     SELECT diff_id FROM ";
    533             $query3 .= "           diffRun JOIN diffInputSkyfile USING (diff_id) JOIN publishRun ON (diff_id = stage_id) JOIN warpRun ON (warp1=warp_id)";
    534             $query3 .= "           WHERE stack2 IS NULL AND publishRun.state LIKE 'full' AND warp_id='$row2[0]' GROUP BY diff_id";
    535             $qry3 = $projectdb->query($query3);
    536             while ($qry3->fetchInto($row3)) {
    537                 if ($row3[0] !=0) $Ndiffs ++;
    538             }
    539 
    540             $query3 = "     SELECT diff_id FROM ";
    541             $query3 .= "           diffRun JOIN diffInputSkyfile USING (diff_id) JOIN publishRun ON (diff_id = stage_id) JOIN warpRun ON (warp2=warp_id)";
    542             $query3 .= "           WHERE stack2 IS NULL AND publishRun.state LIKE 'full' AND warp_id='$row2[0]' GROUP BY diff_id";
    543             $qry3 = $projectdb->query($query3);
    544             while ($qry3->fetchInto($row3)) {
    545                 if ($row3[0] !=0) $Ndiffs ++;
    546             }
     562              #distinguish between WW and WS diffs based on stack2
     563              if ($row2[4] == 0) {
     564                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state
     565                  $query3 = "     SELECT count(diffSkyfile.quality) AS Ndiff,count(if(diffSkyfile.quality > 0,1,NULL)) AS Ndiffbad,count(if(publishRun.state LIKE 'full',1,NULL)) AS Npub FROM ";
     566                  $query3 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
     567                  $query3 .= "           WHERE diff_id='$row2[0]' GROUP BY diffRun.diff_id";
     568                  $qry3 = $projectdb->query($query3);
     569
     570                  while ($qry3->fetchInto($row3)) {
     571                      #if all skycells have bad quality, this is a bad diff. If all the skycells are in a full state in publishRun, it is fully published
     572                      if ($row3[1]<$row3[0]) $NWWdiffgood ++;
     573                      if ($row3[1]==$row3[0]) $NWWdiffbad ++;
     574                      if ($row3[2]==$row3[0]) $NWWdiffpub ++;
     575
     576                      #if this wwdiff is published, record its corresponding warp_ids to see how many unique ones there are
     577                      if ($row3[2]==$row3[0]) $wrpcnt{$row2[1]}++;  # record the presence of warp1
     578                      if ($row3[2]==$row3[0]) $wrpcnt{$row2[3]}++;  # record the presence of warp2
     579                  }
     580              }
     581
     582              if ($row2[4] > 0) {
     583                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state
     584                  $query3 = "     SELECT count(diffSkyfile.quality) AS Ndiff,count(if(diffSkyfile.quality > 0,1,NULL)) AS Ndiffbad,count(if(publishRun.state LIKE 'full',1,NULL)) AS Npub FROM ";
     585                  $query3 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
     586                  $query3 .= "           WHERE diff_id='$row2[0]' GROUP BY diffRun.diff_id";
     587                  $qry3 = $projectdb->query($query3);
     588
     589                  while ($qry3->fetchInto($row3)) {
     590                      #if all skycells have bad quality, this is a bad diff. If all the skycells are in a full state in publishRun, it is fully published
     591                      if ($row3[1]<$row3[0]) $NWSdiffgood ++;
     592                      if ($row3[1]==$row3[0]) $NWSdiffbad ++;
     593                      if ($row3[2]==$row3[0]) $NWSdiffpub ++;
     594                  }
     595              }
    547596        }
    548 
    549         if ($Ndiffs != ($Nfirstvisits*4)) $complete = "chunk not done"; 
    550         if ($Ndiffs == ($Nfirstvisits*4)) $complete = "chunk done";       
    551 
    552         if ($Nfirstvisits != $Nfourvisits) {
    553             $Ndiffs .= "/?  ";
     597        #pull out the unique warp_ids
     598        $Npubwarps = count($wrpcnt);
     599
     600        #check for bad diffs
     601        if(($NWWdiffbad >= 1) or ($NWSdiffbad >= 1)) $baddiffflag = 1;
     602
     603        if ($Nvis1 != $Nvis4) {
     604          if ($NWWdiffpub != $NexpWWdiff) $complete = "chunk incomplete, not done"; 
     605          if ($NWWdiffpub == $NexpWWdiff) $complete = "chunk incomplete, done"; 
    554606        }
    555         if ($Nfirstvisits == $Nfourvisits) {
    556             $Ndiffs .= "/";
    557             $Ndiffs .= $Nfirstvisits*4;
     607        if ($Nvis1 == $Nvis4) {
     608          if ($NWWdiffpub != $NexpWWdiff) $complete = "chunk complete, not done"; 
     609          if ($NWWdiffpub == $NexpWWdiff) $complete = "chunk complete, done"; 
     610
    558611        }
    559612
    560         #also query for bad quality camRun exposures
    561         $query4 = "SELECT count(*) ";
    562         $query4 .= " FROM rawExp";
    563         $query4 .= " JOIN chipRun USING (exp_id)";
    564         $query4 .= " JOIN camRun USING (chip_id)";
    565         $query4 .= " JOIN camProcessedExp USING (cam_id)";
    566         $query4 .= " WHERE dateobs LIKE '$date%'";
    567         $query4 .= " AND exp_id > $refExpID[0]";
    568         $query4 .= " AND exp_type = 'OBJECT'";
    569         $query4 .= " AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%'";
    570         $query4 .= " AND (camProcessedExp.quality > 0)";
    571         $qry4 = $projectdb->query($query4);
    572         $qry4->fetchInto($badcam);
    573 
    574 
    575 
    576613        echo "<tr>";
    577614
    578615        echo "<td>$chunkname</td>";
    579         echo "<td>$Nfirstvisits</td>";
    580         if ($badcam[0]==0) {
    581            echo "<td>$Nfourvisits</td>";
    582         } else {
    583            $DLStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">$Nfourvisits ($badcam[0])</font>";
    584            echo "<td>$DLStatus</td>";
    585         }
    586         echo "<td>$Ndiffs</td>";
     616        echo "<td>$Nvis1/$Nvis2/$Nvis3/$Nvis4</td>";
     617        echo "<td>$Ncamgood/$Ncambad</td>";
     618        echo "<td>$Nwarpgood/$Nwarpbad</td>";
     619        echo "<td>$Npubwarps</td>";
     620        echo "<td>$NWWdiffgood/$NWWdiffbad</td>";
     621        echo "<td>$NWWdiffpub</td>";
     622        echo "<td>$NWSdiffgood/$NWSdiffbad</td>";
     623        echo "<td>$NWSdiffpub</td>";
    587624        echo "<td>$complete</td>";
    588625
    589626        echo "</tr>";
    590627    }
    591     echo "</table>\n";
     628
     629
     630    // timer finished
     631    echo "<tr><th colspan=10>";
     632    $time = microtime();
     633    $time = explode(' ', $time);
     634    $time = $time[1] + $time[0];
     635    $finish = $time;
     636    $total_time = round(($finish - $start), 3);
     637    echo "loading in $total_time seconds.";
     638    $start= $finish;
     639    echo "</th></tr>";
     640    echo "</table></br>";
    592641
    593642}
     
    631680        $selectedLabel, $selectedStage, $plotType) {
    632681
     682    // timer start
     683    $time = microtime();
     684    $time = explode(' ', $time);
     685    $time = $time[1] + $time[0];
     686    $start = $time;
     687
     688    // function begin
    633689    $isUpdate = ($selectedMode == "update");
    634690    global $headerColor;
     
    754810
    755811    echo "</tr>\n";
    756     echo "</table>\n";
     812
     813    // timer finished
     814    echo "<tr><th colspan=11>";
     815    $time = microtime();
     816    $time = explode(' ', $time);
     817    $time = $time[1] + $time[0];
     818    $finish = $time;
     819    $total_time = round(($finish - $start), 3);
     820    echo "loading in $total_time seconds.";
     821    $start= $finish;
     822    echo "</th></tr>";
     823    echo "</table><br>";
    757824}
    758825
     
    902969function createDatesTable($db, $proj) {
    903970
     971    // timer start
     972    $time = microtime();
     973    $time = explode(' ', $time);
     974    $time = $time[1] + $time[0];
     975    $start = $time;
     976
     977    // function begin
    904978    global $table;
    905979    echo $table;
     
    914988    createServerDateRow($db, $proj, "registration");
    915989
    916     echo "</table>\n";
     990    // timer finished
     991    echo "<tr><th colspan=11>";
     992    $time = microtime();
     993    $time = explode(' ', $time);
     994    $time = $time[1] + $time[0];
     995    $finish = $time;
     996    $total_time = round(($finish - $start), 3);
     997    echo "loading in $total_time seconds.";
     998    $start= $finish;
     999    echo "</th></tr>";
     1000    echo "</table><br>";
     1001
    9171002}
    9181003
     
    9561041function createServersTable($pass, $proj, $selectedMode, $db, $servers, $selectedLabel, $selectedStage, $plotType) {
    9571042
     1043    // timer start
     1044    $time = microtime();
     1045    $time = explode(' ', $time);
     1046    $time = $time[1] + $time[0];
     1047    $start = $time;
     1048
     1049    // function begin
    9581050    // set up table columns
    9591051    global $table;
     
    10421134    }
    10431135
    1044     echo "</table>\n";
     1136    // timer finished
     1137    echo "<tr><th colspan=5>";
     1138    $time = microtime();
     1139    $time = explode(' ', $time);
     1140    $time = $time[1] + $time[0];
     1141    $finish = $time;
     1142    $total_time = round(($finish - $start), 3);
     1143    echo "loading in $total_time seconds.";
     1144    $start= $finish;
     1145    echo "</th></tr>";
     1146    echo "</table><br>\n";
    10451147}
    10461148
     
    10841186function getServerStatus($db,$proj, $server, &$alive, &$running) {
    10851187
    1086     $sql = "SELECT alive, running FROM science_servers WHERE server LIKE '$server' AND telescope LIKE '$proj' ORDER BY timestamp DESC LIMIT 1";
     1188#    $sql = "SELECT alive, running FROM science_servers WHERE server LIKE '$server' AND telescope LIKE '$proj' ORDER BY timestamp DESC LIMIT 1";
     1189    $sql = "SELECT alive, running FROM live_servers WHERE server LIKE '$server' AND telescope LIKE '$proj' ORDER BY timestamp DESC LIMIT 1";
    10871190    if($debug){echo "$sql<br>";}
    10881191
     
    12031306###########################################################################
    12041307function showPingStatus($Host, $DatabaseName) {
     1308    // timer start
     1309    $time = microtime();
     1310    $time = explode(' ', $time);
     1311    $time = $time[1] + $time[0];
     1312    $start = $time;
     1313
     1314    // function begin
    12051315    exec("ping -c 1 $Host", $res, $rval);
    12061316    if ($rval == 0){
     
    12091319      $PingStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">DOWN</font>";
    12101320    }
    1211     echo "<tr><td>$DatabaseName</td><td>$PingStatus</td></tr>";
    1212 }
    1213 
     1321    echo "<tr><td>$DatabaseName</td>";
     1322
     1323    echo "</td><td>$PingStatus</td>";
     1324    // timer finished
     1325    echo "<td>";
     1326    $time = microtime();
     1327    $time = explode(' ', $time);
     1328    $time = $time[1] + $time[0];
     1329    $finish = $time;
     1330    $total_time = round(($finish - $start), 3);
     1331    echo "$total_time seconds";
     1332    $start= $finish;
     1333    echo "</td></tr>";
     1334}
     1335
     1336
     1337###########################################################################
     1338#
     1339# Creates a table of summitExp against rawExp
     1340#
     1341###########################################################################
     1342function createSummitDataTable($projectdb) {
     1343
     1344    // timer start
     1345    $time = microtime();
     1346    $time = explode(' ', $time);
     1347    $time = $time[1] + $time[0];
     1348    $start = $time;
     1349
     1350    // function begin
     1351    $date = date("Y-m-d");
     1352    $sql = "SELECT DISTINCT exp_type FROM summitExp WHERE dateobs > '$date'";
     1353
     1354    $qry = $projectdb->query($sql);
     1355    if (dberror($qry)) {
     1356        echo "<b>error reading newExp table</b><br>\n";
     1357        echo "<br><small><b> table query : $sql </b></small><br>\n";
     1358        menu_end();
     1359    }
     1360
     1361    // set up the table
     1362    global $table;
     1363    echo $table;
     1364    echo "<tr>";
     1365    createTableTitle("Data status > $date", 4);
     1366    echo "<tr>";
     1367    createTableColumnHeader("Exposure type");
     1368    createTableColumnHeader("At summit");
     1369    createTableColumnHeader("Registered at MHPCC");
     1370    createTableColumnHeader("Summit (Drop/Null)");
     1371
     1372    $msg = "No science images taken since $date";
     1373
     1374    // list the results
     1375    while ($qry->fetchInto($expType)) {
     1376
     1377        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id)
     1378                WHERE dateobs > '$date' AND exp_type = '$expType[0]'";
     1379             //   AND state != 'drop' AND state is not null AND fault != 1042";
     1380        $qry2 = $projectdb->query($sql);
     1381        $qry2->fetchInto($summit);
     1382
     1383        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name
     1384                WHERE summitExp.dateobs > '$date' AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
     1385        $qry2 = $projectdb->query($sql);
     1386        $qry2->fetchInto($mhpcc);
     1387
     1388        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id)
     1389                WHERE dateobs > '$date' AND exp_type = '$expType[0]' AND (state = 'drop' OR state is null)";
     1390        $qry2 = $projectdb->query($sql);
     1391        $qry2->fetchInto($dropped);
     1392
     1393
     1394        #Query with 30 minutes delay to check during the night if any exposures are missing.
     1395        $datehour = gmdate("Y-m-d H:i:s");
     1396        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id)
     1397                WHERE dateobs > '$date' AND dateobs <= date_sub('$datehour', interval 30 minute)
     1398                AND exp_type = '$expType[0]' AND (state != 'drop' OR state is null) and fault != 1042";
     1399
     1400        $qry2 = $projectdb->query($sql);
     1401        $qry2->fetchInto($summitdelay);
     1402
     1403        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name
     1404                WHERE summitExp.dateobs > '$date' AND summitExp.dateobs <= date_sub('$datehour', interval 30 minute)
     1405                AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
     1406        $qry2 = $projectdb->query($sql);
     1407        $qry2->fetchInto($mhpccdelay);
     1408
     1409        echo "<tr>";
     1410
     1411        $DLdiff = $summit[0] - $mhpcc[0];
     1412        if ($DLdiff == 0) $error = 0;
     1413        else $error = 1;
     1414
     1415        $delayDLdiff = $summitdelay[0] - $mhpccdelay[0];
     1416        if ($delayDLdiff == 0) $errordelay = 0;
     1417        else $errordelay = 1;
     1418
     1419        echo "<td>$expType[0]</td>";
     1420        echo "<td>$summit[0]</td>";
     1421        if ($delayDLdiff==0) {
     1422           createFormattedTableCell("", "", $mhpcc[0], $error, 0);
     1423        } else {
     1424           $DLStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">$mhpcc[0] ($delayDLdiff)</font>";
     1425           echo "<td>$DLStatus</td>";
     1426        }
     1427
     1428        echo "<td>$dropped[0]</td>";
     1429
     1430        echo "</tr>";
     1431    }
     1432
     1433    // timer finished
     1434    echo "<tr><th colspan=4>";
     1435    $time = microtime();
     1436    $time = explode(' ', $time);
     1437    $time = $time[1] + $time[0];
     1438    $finish = $time;
     1439    $total_time = round(($finish - $start), 3);
     1440    echo "loading in $total_time seconds.";
     1441    $start= $finish;
     1442    echo "</th></tr>";
     1443    echo "</table><br>";
     1444}
     1445
     1446
     1447function createSummitDataTable2($projectdb) {
     1448
     1449    // timer start
     1450    $time = microtime();
     1451    $time = explode(' ', $time);
     1452    $time = $time[1] + $time[0];
     1453    $start = $time;
     1454
     1455    // function begin
     1456    $date = date("Y-m-d");
     1457    // set up the table
     1458    global $table;
     1459    global $columnHeaderColor;
     1460    echo $table;
     1461    echo "<tr>";
     1462    createTableTitle("Data status > $date", 4);
     1463    echo "<tr>";
     1464    createTableColumnHeader("Exp_type at summit");
     1465    createTableColumnHeader("Status at summit");
     1466    createTableColumnHeader("Status at mhpcc");
     1467    createTableColumnHeader("Number");
     1468    $sql = "SELECT summitExp.exp_type,pzDownloadExp.state,rawExp.state,COUNT(*) FROM summitExp
     1469            LEFT JOIN pzDownloadExp USING (summit_id) LEFT JOIN rawExp on summitExp.exp_name = rawExp.exp_name
     1470            WHERE summitExp.dateobs > '$date' group by summitExp.exp_type,pzDownloadExp.state,rawExp.state";
     1471    $qry = $projectdb->query($sql);
     1472    while ($qry->fetchInto($tmp)) {
     1473        if ($tmp[1] == NULL) {
     1474          echo  "<tr><td>$tmp[0]<td> null <td> null <td bgcolor=\"yellow\"> <font color=\"red\">$tmp[3]";
     1475        }
     1476        else {
     1477          if ($tmp[1] == 'run') {
     1478            echo  "<tr><td>$tmp[0]<td> loading <td> null <td bgcolor=$columnHeaderColor> <font color=\"red\">$tmp[3]";
     1479          }
     1480          else {
     1481            if ($tmp[2] == NULL) {
     1482              echo  "<tr><td>$tmp[0] <td> $tmp[1] <td> loading <td bgcolor=$columnHeaderColor> <font color=\"blue\">$tmp[3]";
     1483            }
     1484            else {
     1485              echo  "<tr><td>$tmp[0]<td> $tmp[1] <td> downloaded <td> $tmp[3]";
     1486            }
     1487          }
     1488        }
     1489    }
     1490
     1491    // timer finished
     1492    echo "<tr><th colspan=4>";
     1493    $time = microtime();
     1494    $time = explode(' ', $time);
     1495    $time = $time[1] + $time[0];
     1496    $finish = $time;
     1497    $total_time = round(($finish - $start), 3);
     1498    echo "loading in $total_time seconds.";
     1499    $start= $finish;
     1500    echo "</th></tr>";
     1501    echo "</table><br>";
     1502}
    12141503?>
    12151504
Note: See TracChangeset for help on using the changeset viewer.