IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41697


Ignore:
Timestamp:
Jul 7, 2021, 4:55:31 PM (5 years ago)
Author:
eugene
Message:

check in changes from trunk: various ippMonitor improvements

Location:
tags/ipp-ps1-20210510/ippMonitor
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-ps1-20210510/ippMonitor

  • tags/ipp-ps1-20210510/ippMonitor/Makefile.in

    r41253 r41697  
    6868$(DESTWWW)/ipp.czartool.dat \
    6969$(DESTWWW)/czartool_labels.php \
    70 $(DESTWWW)/czartool_labels_old.php \
    7170$(DESTWWW)/czartool_getplot.php \
    7271$(DESTWWW)/czartool_exposures.php \
  • tags/ipp-ps1-20210510/ippMonitor/config.dat.in

    r40852 r41697  
    1717$CZARPLOTDIR = "";
    1818
    19 // Temporary files belonging to DELETION_USER and older than
    20 // DELETION_DELAY minutes will be delayed by the
    21 // delete_old_tmp_files() function (see raw/ipp.php)
    22 
    2319$DELETION_USER   = "";
    2420$DELETION_DELAY  =5;
     21
     22$HOST_GPC1  = "";
     23$USER_GPC1  = "";
     24$PASSWORD_GPC1  = "";
     25$LABEL_GPC1  = "";
     26
     27$REPL_HOST_GPC1  = "";
     28$REPL_USER_GPC1  = "";
     29$REPL_PASSWORD_GPC1  = "";
     30$REPL_LABEL_GPC1  = "";
     31
     32$REPL_HOST_GPC1_SECONDARY  = "";
     33$REPL_USER_GPC1_SECONDARY  = "";
     34$REPL_PASSWORD_GPC1_SECONDARY  = "";
     35$REPL_LABEL_GPC1_SECONDARY  = "";
     36
     37$REPL_HOST_GPC1_TERTIARY = "";
     38$REPL_USER_GPC1_TERTIARY = "";
     39$REPL_PASSWORD_GPC1_TERTIARY = "";
     40$REPL_LABEL_GPC1_TERTIARY = "";
    2541
    2642$HOST_NEBULOUS  = "";
    2743$USER_NEBULOUS  = "";
    2844$PASSWORD_NEBULOUS  = "";
    29 $DBNAME_NEBULOUS  = "";
     45$LABEL_NEBULOUS  = "";
    3046
    3147$REPL_HOST_NEBULOUS  = "";
    3248$REPL_USER_NEBULOUS  = "";
    3349$REPL_PASSWORD_NEBULOUS  = "";
    34 $REPL_DBNAME_NEBULOUS  = "";
     50$REPL_LABEL_NEBULOUS  = "";
    3551
    3652$REPL_HOST_NEBULOUS_SECONDARY  = "";
    3753$REPL_USER_NEBULOUS_SECONDARY  = "";
    3854$REPL_PASSWORD_NEBULOUS_SECONDARY  = "";
    39 $REPL_DBNAME_NEBULOUS_SECONDARY  = "";
     55$REPL_LABEL_NEBULOUS_SECONDARY  = "";
     56
     57$REPL_HOST_NEBULOUS_TERTIARY  = "";
     58$REPL_USER_NEBULOUS_TERTIARY  = "";
     59$REPL_PASSWORD_NEBULOUS_TERTIARY  = "";
     60$REPL_LABEL_NEBULOUS_TERTIARY  = "";
    4061
    4162$REPL_HOST_PSTAMP  = "";
    4263$REPL_USER_PSTAMP  = "";
    4364$REPL_PASSWORD_PSTAMP  = "";
    44 $REPL_DBNAME_PSTAMP  = "";
     65$REPL_LABEL_PSTAMP  = "";
    4566
    46 $REPL_HOST_ISP  = "";
    47 $REPL_USER_ISP  = "";
    48 $REPL_PASSWORD_ISP  = "";
    49 $REPL_DBNAME_ISP  = "";
    50 
    51 $HOST_GPC1  = "";
    52 $USER_GPC1  = "";
    53 $PASSWORD_GPC1  = "";
    54 $DBNAME_GPC1  = "";
    55 
    56 $REPL_HOST_GPC1  = "";
    57 $REPL_USER_GPC1  = "";
    58 $REPL_PASSWORD_GPC1  = "";
    59 $REPL_DBNAME_GPC1  = "";
    60 
    61 $REPL_HOST_GPC1_SECONDARY  = "";
    62 $REPL_USER_GPC1_SECONDARY  = "";
    63 $REPL_PASSWORD_GPC1_SECONDARY  = "";
    64 $REPL_DBNAME_GPC1_SECONDARY  = "";
    65 
    66 $REPL_HOST_DATASTORE_SECONDARY  = "";
    67 $REPL_USER_DATASTORE_SECONDARY  = "";
    68 $REPL_PASSWORD_DATASTORE_SECONDARY  = "";
    69 $REPL_DBNAME_DATASTORE_SECONDARY  = "";
     67$REPL_HOST_DATASTORE  = "";
     68$REPL_USER_DATASTORE  = "";
     69$REPL_PASSWORD_DATASTORE  = "";
     70$REPL_LABEL_DATASTORE  = "";
    7071
    7172//Important machines that should be checked for accessibiltiy
    7273$HOST_GATEWAY  = "";
    73 $DBNAME_GATEWAY  = "";
     74$LABEL_GATEWAY  = "";
    7475
    7576$HOST_GATEWAY_SECONDARY  = "";
    76 $DBNAME_GATEWAY_SECONDARY  = "";
     77$LABEL_GATEWAY_SECONDARY  = "";
     78
     79$HOST_PROXY  = "";
     80$LABEL_PROXY  = "";
    7781
    7882$HOST_APACHE1  = "";
    79 $DBNAME_APACHE1  = "";
     83$LABEL_APACHE1  = "";
    8084
    8185$HOST_APACHE2  = "";
    82 $DBNAME_APACHE2  = "";
     86$LABEL_APACHE2  = "";
    8387
    8488$HOST_APACHE3  = "";
    85 $DBNAME_APACHE3  = "";
     89$LABEL_APACHE3  = "";
    8690
    8791$HOST_APACHE4  = "";
    88 $DBNAME_APACHE4  = "";
     92$LABEL_APACHE4  = "";
    8993
    9094$HOST_APACHE5  = "";
    91 $DBNAME_APACHE5  = "";
     95$LABEL_APACHE5  = "";
    9296
    9397$HOST_APACHE6  = "";
    94 $DBNAME_APACHE6  = "";
     98$LABEL_APACHE6  = "";
    9599
    96 $HOST_APACHE7  = "";
    97 $DBNAME_APACHE7  = "";
     100$HOST_APACHE_BACKUP1  = ";"
     101$LABEL_APACHE_BACKUP1  = ";"
    98102
    99 $HOST_PROXY  = "";
    100 $DBNAME_PROXY  = "";
     103$HOST_APACHE_BACKUP2  = ";"
     104$LABEL_APACHE_BACKUP2  = ";"
     105
     106$HOST_HOME  = "";
     107$LABEL_HOME  = "";
     108
     109$HOST_HOME_BACKUP  = "";
     110$LABEL_HOME_BACKUP  = "";
     111
     112$HOST_NAGIOS  = "";
     113$LABEL_NAGIOS  = "";
    101114
    102115$HOST_SVN  = "";
    103 $DBNAME_SVN  = "";
     116$LABEL_SVN  = "";
    104117
    105118$HOST_CONFLUENCE  = "";
    106 $DBNAME_CONFLUENCE  = "";
     119$LABEL_CONFLUENCE  = "";
    107120
    108 
     121$HOST_MAILMAN  = "";
     122$LABEL_MAILMAN  = "";
  • tags/ipp-ps1-20210510/ippMonitor/raw/czartool_labels.php

    r41458 r41697  
    1919$LD_LIBRARY_PATH = getenv("LD_LIBRARY_PATH");
    2020putenv("LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH");
    21 
    2221
    2322if ($ID['menu']) {$myMenu = $ID['menu'];}
     
    3837        "pub",
    3938        );
    40         # "chipbackground");
    4139
    4240$getFailures = array(
     
    8684if ($proj == 'gpc1') {
    8785    $servers=array(
    88         #"addstar",
    89         #"addstarlap",
    90         "ippqub:stdscience_ws",
    9186        "cleanup",
    92         #"detrend",
    9387        "distribution",
     88        "ippqub:stdscience_ws",
    9489        "pstamp",
    95         # "update",
    96         # "publishing",
    9790        "registration",
    9891        "stack",
    99         # "deepstack",
    10092        "stdscience",
    10193        "summitcopy");
    10294} else {
    10395    $servers=array(
    104         "ippqub2:stdscience_ws",
    10596        "cleanup",
    10697        "distribution",
     98        "ippqub2:stdscience_ws",
    10799        "registration",
    108100        "stdscience",
     
    110102}
    111103
    112 
    113 // The Update mode of czartool is obsolete since we don't use the update
    114 // pantasks.
     104// The Update mode of czartool is obsolete since we don't use the update pantasks.
    115105// $selectedMode = $_GET[mode];
    116106$selectedMode = "stdscience";
     
    141131// tell all servers to stop or run
    142132if ($allServerCmd) {
    143 
    144133    foreach ($servers as &$server) serverStopRun($czardb, $server,  $allServerCmd);
    145134}
     
    147136
    148137$debug = 0;
    149 $table = "<table bgcolor=\"#FFFFFF\" width=\"900\" align=\"middle\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\" style=\"font-size:80%\">\n";
     138$table = "<table bgcolor=\"#FFFFFF\" width=\"100%\" align=\"middle\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\" style=\"font-size:80%\">\n";
    150139
    151140// $labels is generated with sequential integer key values
     
    187176// set up the form
    188177echo "<form action=\"czartool_labels.php\" method=\"POST\">\n";
    189 
    190178echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
    191179echo "<input type=\"hidden\" name=\"proj\" value=\"$proj\">\n";
     
    194182
    195183echo "<table border=\"0\">";
    196 
     184// timer begin for main page
     185$time = microtime();
     186$time = explode(' ', $time);
     187$time = $time[1] + $time[0];
     188$mainstart = $time;
     189
     190# headers
    197191echo "<tr>";
    198 echo "<td colspan=\"3\" style=\"background-color:#0080c0;\">";
    199 echo "<h1 align=\"middle\">Czartool</h1>";
    200 echo "<h2 align=\"middle\">$modeText (change to <a href=\"$link&proj=$newproj\"><font color=\"blue\">$newproj</font></a>)</h2>";
    201 echo "</td>";
     192echo "  <td colspan=\"3\" style=\"background-color:#0080c0;\">";
     193echo "  <h1 align=\"middle\">Czartool</h1>";
     194echo "  <h2 align=\"middle\">$modeText (change to <a href=\"$link&proj=$newproj\"><font color=\"blue\">$newproj</font></a>)</h2>";
     195echo "  </td>";
    202196echo "</tr>";
    203197
    204 // PLOTS
     198# table rows
    205199echo "<tr valign=\"top\">";
    206 echo "<td style=width:100px;text-align:top;\">";
    207  # time series plot
    208 echo "<br><img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br>";
    209 # log time series plot
    210 echo "<br><img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=log\"><br>";
    211  # rate time series plot
    212 echo "<br><img src=\"czartool_getplot.php?mode=$selectedMode&type=rt&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br>";
    213  # histogram plot
    214 # echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=h&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br>";
    215  # storage plot
    216 echo "<br><a href=\"czartool_getplot.php?type=sl\"><img title=\"Click to enlarge me\" src=\"czartool_getplot.php?type=s\"></a><br>";
    217  # storage timeseries
    218 echo "<br><img src=\"czartool_getplot.php?type=st\"><br>";
    219  # pantasks server status, if requested
     200
     201#1st table column for status
     202echo "<td style=height:200px;width:800px;text-align:top;\">";
     203
     204// status table at top
     205exec("svnversion /data/ippc64.1/ippitc/ippMonitor", $svnversion);
     206$phpversion = phpversion();
     207$ganglia = "http://ganglia.pan-starrs.ifa.hawaii.edu";
     208$svnlink = "https://svn.pan-starrs.ifa.hawaii.edu/trac/ipp";
     209$conflink = "https://confluence.ipp.ifa.hawaii.edu";
     210$jiralink = "https://jira.ipp.ifa.hawaii.edu";
     211$hsttime1 = date("Y-m-d H:i:s", strtotime("$lastUpdateTime"));
     212$utctime1 = gmdate("Y-m-d H:i:s", strtotime("$lastUpdateTime"));
     213
    220214echo "<br>";
    221  if ($selectedServer && !$serverCmd) showServerStatus($selectedServer);
    222 echo "</td>";
    223 
    224 
    225 echo "<td style=height:200px;width:10px;text-align:top;\">";
    226 echo "<td style=height:200px;width:400px;text-align:top;\">";
    227 
    228 /////////////////////////////////////////
    229 // timer begin for status and links
    230 /////////////////////////////////////////
     215echo $table;
     216createTableTitle("Status and links", 2);
     217echo "<tr><td>ippMonitor Notes </td>
     218          <td> PHP: v.$phpversion
     219  &nbsp|&nbsp <a href=\"$svnlink/browser/trunk/ippMonitor\" target=new><font color=\"blue\">SVN: v.$svnversion[0]</font></a>
     220  &nbsp|&nbsp <a href=\"$jiralink/browse/IPP-86\" target=new><font color=\"blue\">Jira</font></a>
     221  &nbsp|&nbsp <a href=\"http://ippmonitor.ipp.ifa.hawaii.edu/ippMonitor/czartool_labels.php?pass=$pass&proj=$proj\"><font color=\"blue\">online</font></a>,
     222       &nbsp <a href=\"http://ipp117.ipp.ifa.hawaii.edu/ippMonitor/czartool_labels.php?pass=$pass&proj=$proj\"><font color=\"blue\">dev</font></a>,
     223       &nbsp <a href=\"czartool_labels_last.php?pass=$pass&proj=$proj\"><font color=\"blue\">last</font></a>
     224       version </td></tr>";
     225echo "<tr><td>Pan-STARRS Data Store</td>
     226          <td><a href=\"https://svn.ifa.hawaii.edu/\" target=new><font color=\"blue\">Home</font></a>
     227  &nbsp|&nbsp <a href=\"https://svn.ifa.hawaii.edu/summit/ds/gpc1/\" target=new><font color=\"blue\">GPC1</font></a>
     228  &nbsp|&nbsp <a href=\"https://svn.ifa.hawaii.edu/conductorb/ds/gpc2/\" target=new><font color=\"blue\">GPC2</font></a>
     229  &nbsp|&nbsp <a href=\"http://ipp.ifa.hawaii.edu/skycoverage.20201110\" target=new><font color=\"blue\">Sky Coverage</font></a></td></tr>";
     230echo "<tr><td>Observations Metrics</td>
     231          <td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\" target=new><font color = \"blue\"> PS1</font></a>
     232  &nbsp|&nbsp <a href=\"https://ps1wiki.ifa.hawaii.edu/data/ps2metrics/index.html\"  target=new><font color = \"blue\"> PS2</font></a>
     233  &nbsp|&nbsp <a href=\"http://ippmonitor.ipp.ifa.hawaii.edu/ippMonitor/ippMetrics/index.html\" target=new><font color=\"blue\">IPP</font></a></td></tr>";
     234echo "<tr><td>Postage Stamp Server</td>
     235          <td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/pshome.php\" target=new><font color=\"blue\">Home</font></a>
     236  &nbsp|&nbsp <a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\" target=new><font color=\"blue\">Status</font></a>
     237  &nbsp|&nbsp <a href=\"http://pstamp.ipp.ifa.hawaii.edu/dsroot.php\" target=new><font color=\"blue\">Data Store</font></a></td></tr>";
     238echo "<tr><td>IPP Cluster Ganglia Monitor</td>
     239          <td><a href=\"$ganglia/?r=hour&s=descending&hc=6&c=IPP%2520Production\" target=new> <font color=\"blue\">Load_reports</font></a>
     240  &nbsp|&nbsp <a href=\"$ganglia/?m=cpu_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\" target=new> <font color=\"blue\">CPU_reports</font></a>
     241  &nbsp|&nbsp <a href=\"$ganglia/?m=mem_report&r=hour&s=by%2520name&c=IPP+Production&h=&sh=1&hc=8&z=small\" target=new> <font color=\"blue\">Memory_reports</font></a></td></tr>";
     242echo "<tr><td>Documentations for IPP</td>
     243          <td><a href=\"$conflink/pages/viewrecentblogposts.action?key=IPPCZAR\" target=new><font color=\"blue\">Czarblog</font></a>
     244  &nbsp|&nbsp <a href=\"$conflink/display/IPPCZAR/IPP-Czaring+Home\" target=new><font color=\"blue\">Confluence</font></a>
     245  &nbsp|&nbsp <a href=\"$jiralink/projects/IPP/issues/filter=allissues\" target=new><font color=\"blue\">Jira</font></a>
     246  &nbsp|&nbsp <a href=\"$svnlink/\" target=new><font color=\"blue\">trac</font></a></td></tr>";
     247echo "<tr><td>Current nightly science status</td>
     248          <td>".getNightlyScienceStatus($czardb, $proj)."</td></tr>";
     249echo "<tr><td>Czardb last update time</td>
     250          <td> $hsttime1 (HST), $utctime1 (UTC)</td></tr>";
     251echo "</table><br>";
     252
     253
     254createLabelsTable($pass, $proj, $czardb, $selectedMode, $labels, $distLabelsExist, $pubLabelsExist, $stages, "new", $selectedLabel, $selectedStage, $plotType);
     255if ($selectedMode == "update") {echo "<br>"; createPStampDataTable();}
     256
     257# XXX EAM : 2017.09.17 : debugging slowness
     258# CCL : 2019.11.09 : debugging slowness
     259//createSummitDataTable($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
     260createSummitDataTable2($projectdb, $pass, $proj); // this is slow because of the join between summitExp and rawExp, but not the major one
     261
     262createChunkDataTable($projectdb);  // this is another part for slowness during nightly processing
     263
     264createDatesTable($czardb, $proj);
     265
     266// Database status
     267// timer begin for Database status
    231268$time = microtime();
    232269$time = explode(' ', $time);
     
    234271$start = $time;
    235272
    236 // status table at top
    237 $nsStatus = getNightlyScienceStatus($czardb, $proj);
    238 $plotTypeLink = ($plotType == "linear") ? "log" : "linear";
    239 $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel .
    240         "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
    241 
    242 echo "<br>";
    243273echo $table;
    244 createTableTitle("Status and links", 2);
    245 echo "<tr>\n";
    246 echo "<tr><td>Time of last update</td>
    247           <td>$lastUpdateTime</td></tr>";
    248 echo "<tr><td>ippMonitor SVN version</td>
    249           <td>"; include 'version.php'; echo "</td></tr>";
    250 echo "<tr><td>Current PHP version: </td>
    251           <td>" . phpversion(); echo "</td></tr>";
    252 echo "<tr><td>Current nightly science status</td>
    253           <td>$nsStatus</td></tr>";
    254 echo "<tr><td>Postage stamp server status</td>
    255           <td><a href=\"http://pstamp.ipp.ifa.hawaii.edu/status.php\" target=new><font color=\"blue\">here</font></a></td></tr>";
    256 echo "<tr><td>Documentation</td>
    257           <td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\" target=new><font color=\"blue\">here</font></a></td></tr>";
    258 echo "<tr><td>Cluster load</td>
    259           <td><a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&hc=6&c=IPP%2520Production\">
    260               <font color=\"blue\">here</font></a>
    261               <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\">
    262               <font color=\"blue\">cpu_report</font></a>
    263               <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\">
    264               <font color=\"blue\">mem_report</font></a></td></tr>";
    265 echo "<tr><td>IPP metrics</td>
    266           <td><a href=\"https://ps1wiki.ifa.hawaii.edu/data/metrics/index.html\"><font color=\"blue\" target=new>here</font></a></td></tr>";
    267 echo "<tr><td>Czar log pages</td>
    268           <td><a href=\"https://confluence.ipp.ifa.hawaii.edu/pages/viewrecentblogposts.action?key=IPPCZAR\" target=new><font color=\"blue\">here</font></a></td></tr>";
    269 echo "<tr><td>Exposure summary</td>
    270           <td><a href=\"czartool_exposures.php?pass=$pass&proj=$proj\"><font color=\"blue\">here</font></a></td></tr>";
    271 echo "<tr><td>Confluence</td>
    272           <td><a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IPPCZAR/IPP-Czaring+Home\" target=new><font color=\"blue\">here</font></a></td></tr>";
    273 echo "<tr><td>JIRA</td>
    274           <td><a href=\"https://jira.ipp.ifa.hawaii.edu/secure/Dashboard.jspa\" target=new><font color=\"blue\">here</font></a></td></tr>";
    275 echo "<tr><td>data store</td>
    276           <td><a href=\"https://svn.ifa.hawaii.edu/\" target=new><font color=\"blue\">here</font></a></td></tr>";
    277 echo "<tr><td>Pan-STARRS data overview plots</td>
    278           <td><a href=\"http://ipp.ifa.hawaii.edu/skycoverage.20201110\" target=new><font color=\"blue\">here</font></a></td></tr>";
    279 
    280 $plotTypeLink = ($plotType == "linear") ? "log" : "linear";
    281 $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&mode=" . $selectedMode .
    282         "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
    283 
    284 // timer finished
    285 echo "<tr><th colspan=4>";
    286 $time = microtime();
    287 $time = explode(' ', $time);
    288 $time = $time[1] + $time[0];
    289 $finish = $time;
    290 $total_time = round(($finish - $start), 3);
    291 echo "loading in $total_time seconds.";
    292 echo "</th></tr>";
    293 echo "</table><br>";
    294 
    295 createLabelsTable($pass, $proj, $czardb, $selectedMode, $labels,
    296   $distLabelsExist, $pubLabelsExist, $stages, "new", $selectedLabel,
    297   $selectedStage, $plotType);
    298 if ($selectedMode == "update") {echo "<br>"; createPStampDataTable();}
    299 
    300 # XXX EAM : 2017.09.17 : debugging slowness
    301 # CCL : 2019.11.09 : debugging slowness
    302 //createSummitDataTable($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
    303 createSummitDataTable2($projectdb); // this is slow because of the join between summitExp and rawExp, but not the major one
    304 
    305 createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType);
    306 // this was the major slowness part due to large table in czardb
    307 
    308 createChunkDataTable($projectdb);  // this is another part for slowness during nightly processing
    309 
    310 createDatesTable($czardb, $proj);
    311 
    312 /////////////////////////////////////////
    313 // timer begin for Database status
    314 /////////////////////////////////////////
    315 $time = microtime();
    316 $time = explode(' ', $time);
    317 $time = $time[1] + $time[0];
    318 $start = $time;
    319 
    320 // status table at top
    321   echo $table;
    322   echo "<tr>";
    323   createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\">here</a>)", 2);
     274echo "<tr>";
     275createTableTitle("Database status (update fix log <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Replication_Issues\"><font color=\"blue\">here</a>)", 2);
    324276 
    325   echo "<tr>";
    326   createTableColumnHeader("Database");
    327   createTableColumnHeader("Status (sec behind master)");
    328   showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $DBNAME_GPC1);
    329   showReplicationsStatus($REPL_HOST_GPC1, $REPL_USER_GPC1, $REPL_PASSWORD_GPC1, $REPL_DBNAME_GPC1);
    330   showReplicationsStatus($REPL_HOST_GPC1_SECONDARY, $REPL_USER_GPC1_SECONDARY, $REPL_PASSWORD_GPC1_SECONDARY, $REPL_DBNAME_GPC1_SECONDARY);
    331  
    332   echo "<tr>";
    333   showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $DBNAME_NEBULOUS);
    334   showReplicationsStatus($REPL_HOST_NEBULOUS, $REPL_USER_NEBULOUS, $REPL_PASSWORD_NEBULOUS, $REPL_DBNAME_NEBULOUS);
    335   showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
    336   showReplicationsStatus($REPL_HOST_NEBULOUS_THIRD, $REPL_USER_NEBULOUS_THIRD, $REPL_PASSWORD_NEBULOUS_THIRD, $REPL_DBNAME_NEBULOUS_THIRD);
    337   showReplicationsStatus($REPL_HOST_NEBULOUS_FOURTH, $REPL_USER_NEBULOUS_FOURTH, $REPL_PASSWORD_NEBULOUS_FOURTH, $REPL_DBNAME_NEBULOUS_FOURTH);
    338   showReplicationsStatus($REPL_HOST_DATASTORE_SECONDARY, $REPL_USER_DATASTORE_SECONDARY, $REPL_PASSWORD_DATASTORE_SECONDARY, $REPL_DBNAME_DATASTORE_SECONDARY);
    339  
    340 //  some mysql replication slaves to add when they are returned to service
    341 //  showReplicationsStatus($REPL_HOST_PSTAMP, $REPL_USER_PSTAMP, $REPL_PASSWORD_PSTAMP, $REPL_DBNAME_PSTAMP);
    342 //  showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
     277echo "<tr>";
     278createTableColumnHeader("Database");
     279createTableColumnHeader("Status (sec behind master)");
     280// gpc dbs
     281showDatabaseStatus($HOST_GPC1, $USER_GPC1, $PASSWORD_GPC1, $LABEL_GPC1);
     282showReplicationsStatus($REPL_HOST_GPC1, $REPL_USER_GPC1, $REPL_PASSWORD_GPC1, $REPL_LABEL_GPC1);
     283showReplicationsStatus($REPL_HOST_GPC1_SECONDARY, $REPL_USER_GPC1_SECONDARY, $REPL_PASSWORD_GPC1_SECONDARY, $REPL_LABEL_GPC1_SECONDARY);
     284showReplicationsStatus($REPL_HOST_GPC1_TERTIARY, $REPL_USER_GPC1_TERTIARY, $REPL_PASSWORD_GPC1_TERTIARY, $REPL_LABEL_GPC1_TERTIARY);
     285// nebulous dbs
     286showDatabaseStatus($HOST_NEBULOUS, $USER_NEBULOUS, $PASSWORD_NEBULOUS, $LABEL_NEBULOUS);
     287showReplicationsStatus($REPL_HOST_NEBULOUS, $REPL_USER_NEBULOUS, $REPL_PASSWORD_NEBULOUS, $REPL_LABEL_NEBULOUS);
     288showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_LABEL_NEBULOUS_SECONDARY);
     289showReplicationsStatus($REPL_HOST_NEBULOUS_TERTIARY, $REPL_USER_NEBULOUS_TERTIARY, $REPL_PASSWORD_NEBULOUS_TERTIARY, $REPL_LABEL_NEBULOUS_TERTIARY);
     290// other dbs
     291showDatabaseStatus($HOST_PSTAMP, $USER_PSTAMP, $PASSWORD_PSTAMP, $LABEL_PSTAMP);
     292showReplicationsStatus($REPL_HOST_DATASTORE, $REPL_USER_DATASTORE, $REPL_PASSWORD_DATASTORE, $REPL_LABEL_DATASTORE);
    343293
    344294// timer finished
     
    353303echo "</table><br>";
    354304
    355 /////////////////////////////////////////
     305
     306// critical machines status
    356307// timer begin for critical machines
    357 /////////////////////////////////////////
    358308$time = microtime();
    359309$time = explode(' ', $time);
     
    361311$start = $time;
    362312
    363 // status table at top
    364   $PingStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">DOWN</font>";
    365   echo $table;
    366   echo "<tr>";
    367   createTableTitle("Critical machine status", 3);
    368 
    369   echo "<tr>";
    370   createTableColumnHeader("Hostname");
    371   createTableColumnHeader("Status");
    372   createTableColumnHeader("Loading time");
    373   showPingStatus($HOST_GATEWAY, $DBNAME_GATEWAY);
    374   showPingStatus($HOST_GATEWAY_SECONDARY, $DBNAME_GATEWAY_SECONDARY);
    375   showPingStatus($HOST_APACHE1, $DBNAME_APACHE1);
    376   showPingStatus($HOST_APACHE2, $DBNAME_APACHE2);
    377   showPingStatus($HOST_APACHE3, $DBNAME_APACHE3);
    378   showPingStatus($HOST_APACHE4, $DBNAME_APACHE4);
    379   showPingStatus($HOST_APACHE5, $DBNAME_APACHE5);
    380   showPingStatus($HOST_APACHE6, $DBNAME_APACHE6);
    381   showPingStatus($HOST_APACHE7, $DBNAME_APACHE7);
    382   showPingStatus($HOST_APACHE8, $DBNAME_APACHE8);
    383 //     echo "<td>ippc70 (apache node) <td> $PingStatus <td> 0 seconds ";  // comment out if ippc70 is back
    384   showPingStatus($HOST_PROXY, $DBNAME_PROXY);
    385   showPingStatus($HOST_SVN, $DBNAME_SVN);
    386   showPingStatus($HOST_CONFLUENCE, $DBNAME_CONFLUENCE);
    387 
     313$PingStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">DOWN</font>";
     314echo $table;
     315echo "<tr>";
     316createTableTitle("Critical machine status", 3);
     317
     318echo "<tr>";
     319createTableColumnHeader("Hostname");
     320createTableColumnHeader("Status");
     321createTableColumnHeader("Loading time");
     322showPingStatus($HOST_GATEWAY, $LABEL_GATEWAY);
     323showPingStatus($HOST_GATEWAY_SECONDARY, $LABEL_GATEWAY_SECONDARY);
     324showPingStatus($HOST_PROXY, $LABEL_PROXY);
     325showPingStatus($HOST_APACHE1, $LABEL_APACHE1);
     326showPingStatus($HOST_APACHE2, $LABEL_APACHE2);
     327showPingStatus($HOST_APACHE3, $LABEL_APACHE3);
     328showPingStatus($HOST_APACHE4, $LABEL_APACHE4);
     329showPingStatus($HOST_APACHE5, $LABEL_APACHE5);
     330showPingStatus($HOST_APACHE6, $LABEL_APACHE6);
     331showPingStatus($HOST_APACHE_BACKUP1, $LABEL_APACHE_BACKUP1);
     332showPingStatus($HOST_APACHE_BACKUP2, $LABEL_APACHE_BACKUP2);
     333showPingStatus($HOST_HOME, $LABEL_HOME);
     334showPingStatus($HOST_HOME_BACKUP, $LABEL_HOME_BACKUP);
     335showPingStatus($HOST_NAGIOS, $LABEL_NAGIOS);
     336showPingStatus($HOST_SVN, $LABEL_SVN);
     337showPingStatus($HOST_CONFLUENCE, $LABEL_CONFLUENCE);
     338showPingStatus($HOST_MAILMAN, $LABEL_MAILMAN);
     339//  echo "<td>ippc70 (apache node) <td> $PingStatus <td> 0 seconds ";  // comment out if ippc70 is back
    388340// timer finished
    389341echo "<tr><th colspan=3>";
     
    396348echo "</th></tr>";
    397349echo "</table><br>";
    398    
     350
     351createServersTable($pass, $proj,$selectedMode,$czardb, $servers, $selectedLabel, $selectedStage, $plotType); // this was the major slowness part due to large table in czardb
     352
     353# pantasks server status, if requested
     354if ($selectedServer && !$serverCmd) showServerStatus($selectedServer, $proj);
     355
     356#2nd table column for space
     357echo "<td style=height:200px;width: 10px;text-align:top;\"><br>";
     358
     359#3rd table column for plots
     360echo "<td style=height:200px;width:600px;text-align:top;\"><br>";
     361# plots
     362if ($selectedStage == "all_stages" & $selectedLabel == "all") {
     363   # with all stages and all labels, the rate query is too slow so I use the old method until it get improved. CCL 20210117
     364   # gnuplots
     365   # time series plot
     366   echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br><br>";
     367   echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=t&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=log\"><br><br>";
     368   # rate series plot
     369   echo "<img src=\"czartool_getplot.php?mode=$selectedMode&type=rt&label=$selectedLabel&proj=$proj&stage=$selectedStage&plottype=linear\"><br><br>";
     370} else {
     371   # google chart
     372   # time series plot
     373   echo Gettimeseries($czardb, $selectedMode, $selectedLabel, $proj, $selectedStage);
     374   # rate series plot
     375   echo Getrate($czardb, $selectedMode, $selectedLabel, $proj, $selectedStage);
     376}
     377
     378# storage timeseries
     379echo getSpaces($czardb);
     380# storage plot
     381echo getHosts($czardb);
     382
     383# timer for main page end
     384echo "<tr><th colspan=3>";
     385$time = microtime();
     386$time = explode(' ', $time);
     387$time = $time[1] + $time[0];
     388$finish = $time;
     389$total_time = round(($finish - $mainstart), 3);
     390echo "overall loading in $total_time seconds.";
     391echo "</th></tr>";
     392echo "</table>";
    399393
    400394menu_end();
    401395
    402396
    403 #############################################################################
    404 #############################  Functions Below  #############################
    405 #############################################################################
     397/////////////////////////////////////////////////////////////////////////////
     398//                                                                         //
     399//                               Functions                                 //
     400//                                                                         //
     401/////////////////////////////////////////////////////////////////////////////
    406402
    407403###########################################################################
     
    436432    // list the results
    437433    while ($qry->fetchInto($row)) {
    438 
    439434        echo "<tr>";
    440 
    441435        echo "<td>$row[0]</td>";
    442436        echo "<td>$row[1]</td>";
    443437        echo "<td>$row[2]</td>";
    444        
    445438        echo "</tr>";
    446439    }
    447 
    448440    echo "</table>\n";
    449 
    450441}
    451442
     
    480471    #do a query of raw/chip/cam/warp counts for this night, split by chunk.
    481472    #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
    482     $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad,suba.uniNvis1,suba.uniNvis2,suba.uniNvis3,suba.uniNvis4 FROM ";
     473    $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad FROM ";
    483474    $query .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(if(rawExp.comment LIKE '%visit 1%',1,NULL)) AS Nvis1,";
    484475    $query .= "    count(if(rawExp.comment LIKE '%visit 2%',1,NULL)) AS Nvis2,count(if(rawExp.comment LIKE '%visit 3%',1,NULL)) AS Nvis3,";
    485476    $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,";
    486     $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad, COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 1%' THEN rawExp.comment END) AS uniNvis1,";
    487     $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 2%' THEN rawExp.comment END) AS uniNvis2,COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 3%' THEN rawExp.comment END) AS uniNvis3,";
    488     $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 4%' THEN rawExp.comment END) AS uniNvis4";
     477    $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad";
    489478    $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)";
    490479    $query .= "    WHERE dateobs like '$date%' AND exp_id > $refExpID[0] AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%'";
     
    540529        $NexpWWdiff = 0;
    541530        $Npubwarps = 0;
    542         $uniNvis1 = 0;
    543         $uniNvis2 = 0;
    544         $uniNvis3 = 0;
    545         $uniNvis4 = 0;
    546531
    547532        $chunkname = $row[0];
     
    554539        if($row[7] > 0) $Nwarpgood = $row[7];
    555540        if($row[8] > 0) $Nwarpbad = $row[8];
    556         if($row[9] > 0) $uniNvis1 = $row[9];
    557         if($row[10] > 0) $uniNvis2 = $row[10];
    558         if($row[11] > 0) $uniNvis3 = $row[11];
    559         if($row[12] > 0) $uniNvis4 = $row[12];
    560541
    561542        #set flags if present
     
    629610        if(($NWWdiffbad >= 1) or ($NWSdiffbad >= 1)) $baddiffflag = 1;
    630611
    631         if (($uniNvis1 != $uniNvis2) or ($uniNvis1 != $uniNvis3) or ($uniNvis1 != $uniNvis4)) {
     612        if ($Nvis1 != $Nvis4) {
    632613          if ($NWWdiffpub != $NexpWWdiff) $complete = "chunk incomplete, not done"; 
    633614          if ($NWWdiffpub == $NexpWWdiff) $complete = "chunk incomplete, done"; 
    634615        }
    635         if (($uniNvis1 == $uniNvis2) and ($uniNvis1 == $uniNvis3) and ($uniNvis1 == $uniNvis4)) {
     616        if ($Nvis1 == $Nvis4) {
    636617          if ($NWWdiffpub != $NexpWWdiff) $complete = "chunk complete, not done"; 
    637618          if ($NWWdiffpub == $NexpWWdiff) $complete = "chunk complete, done"; 
     619
    638620        }
    639621
     
    920902        $pubLabelsExist,
    921903        $stages,
    922         $selectedState,
    923         $selectedLabel, $selectedStage, $plotType) {
     904        $selectedState, $selectedLabel, $selectedStage, $plotType) {
    924905
    925906    // timer start
     
    951932    createFormattedTableCell(($selectedStage != "all_stages"), $link, "All stages", 0, "$columnHeaderColor");
    952933
    953     #echo "<th>Label (in order of priority)</th>";
     934    //echo "<th>Label (in order of priority)</th>";
    954935    foreach ($stages as &$stage) {
    955936
     
    965946
    966947        createFormattedTableCell($showLink, $link, $stage, 0, "$columnHeaderColor");
    967 #        createTableColumnHeader("Dates");
     948        #createTableColumnHeader("Dates");
    968949    }
    969950
     
    1006987        foreach ($stages as &$stage) {
    1007988          // Note: Do not include the state for chip, cam, and warp so that both new and update faults are listed
    1008           $myTable    = $mainTable[$stage];
    1009           $myFailures = $getFailures[$stage];
     989      $myTable    = $mainTable[$stage];
     990      $myFailures = $getFailures[$stage];
    1010991          # echo "myTable: $myTable";
    1011992
    1012           if ("$myFailures" == "NONE") {
     993      if ("$myFailures" == "NONE") {
    1013994            $link = $defaultlink;
    1014995          } else {
    1015996            $link = $myFailures . "?pass=" . $pass . "&proj=" . $proj . "&" . $myTable . ".label=" . $thisLabel;
    1016             if ($addSearchState[$stage]) {
     997        if ($addSearchState[$stage]) {
    1017998              // Note: Do not include the state for chip, cam, and warp so that both new and update faults are listed
    1018999              $link .= "&" . $myTable . ".state=" . $searchState;
    10191000            }
    10201001          }
    1021           // echo "getStateAndFaults $db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults<br>";
    1022           getStateAndFaults($db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults);
    1023 
    1024           $cellcolor = 0;
    1025           if ("$stage" == "dist") {
    1026             $cellcolor = (!$isUpdate && !$distributing) ? "gray" : 0;
     1002      // echo "getStateAndFaults $db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults<br>";
     1003      getStateAndFaults($db, $thisLabel, $proj, $selectedState, $stage, $str, $anyFaults);
     1004
     1005      $cellcolor = 0;
     1006      if ("$stage" == "dist") {
     1007        $cellcolor = (!$isUpdate && !$distributing) ? "gray" : 0;
    10271008          }
    10281009          if ("$stage" == "pub") {
    1029             $cellcolor = (!$isUpdate && !$publishing) ? "gray" : 0;
     1010        $cellcolor = (!$isUpdate && !$publishing) ? "gray" : 0;
    10301011          }
    10311012          createFormattedTableCell($anyFaults, $link, $str, $anyFaults, $cellcolor);
     
    12321213
    12331214    // timer finished
    1234     echo "<tr><th colspan=11>";
     1215#    echo "<tr><th colspan=11>";
    12351216    $time = microtime();
    12361217    $time = explode(' ', $time);
     
    12381219    $finish = $time;
    12391220    $total_time = round(($finish - $start), 3);
    1240     echo "loading in $total_time seconds.";
     1221#    echo "loading in $total_time seconds.";
    12411222    $start= $finish;
    1242     echo "</th></tr>";
     1223#    echo "</th></tr>";
    12431224    echo "</table><br>";
    12441225
     
    12611242    $firstIn = true;
    12621243    while ($qry->fetchInto($row)) {
    1263 
    12641244        if ($firstIn) {
    1265 
    12661245            $dates = $row[0];
    12671246            $firstIn = false;
     
    13001279    createTableColumnHeader("Alive?");
    13011280    createTableColumnHeader("Running?");
    1302 
    1303     //write_header_cell($class, "Server");
    1304     //write_header_cell($class, "Alive?");
    1305     //$link = "czartool_labels.php?pass=".$pass
    1306     //    ."&proj=".$proj
    1307     //    ."&label=".$selectedLabel
    1308     //    ."&stage=".$selectedStage
    1309     //    ."&plottype=".$plotType
    1310     //    ."&allservercmd=stop";
    1311 
    1312     //$link = ""; # TODO removed links temporarily
    1313     //    write_table_cell($class, '%s', $link, "Stop all");
    1314     //$link = "czartool_labels.php?pass=".$pass
    1315     //    ."&proj=".$proj
    1316     //    ."&label=".$selectedLabel
    1317     //    ."&stage=".$selectedStage
    1318     //    ."&plottype=".$plotType
    1319     //    ."&allservercmd=run";
    1320 
    1321     //$link = ""; # TODO removed links temporarily
    1322     //    write_table_cell($class, '%s', $link, "Run all");
    13231281    echo "</tr>\n";
    13241282
     
    13361294            ."&plottype=".$plotType;
    13371295
    1338         #$link = ""; # TODO removed links temporarily
    1339         //write_table_cell($class, '%s', $link, $server);
    1340         //write_table_cell($class, '%s', "", $alive ? "yes" : "NO");
    1341         //echo "<td>$server</td>";
    13421296        createFormattedTableCell(1, $link, $server, 0, 0);
    13431297        createFormattedTableCell(0, "", $alive ? "yes" : "NO", !$alive, 0);
    13441298        createFormattedTableCell(0, "", $running ? "yes" : "NO", !$running, 0);
    1345 
    1346         //if ($alive) {
    1347 
    1348           //  $link = "czartool_labels.php?pass=".$pass
    1349             //    ."&proj=".$proj
    1350               //  ."&label=".$selectedLabel
    1351               //  ."&stage=".$selectedStage
    1352               //  ."&plottype=".$plotType
    1353               //  ."&server=".$server
    1354               //  ."&servercmd=";
    1355 
    1356             //if ($running)  {
    1357 
    1358               //  $link = $link . "stop";
    1359               //  $link = ""; # TODO removed links temporarily
    1360               //      write_table_cell($class, '%s', $link, "stop");
    1361               //  write_table_cell($class, '%s', "", "");
    1362            // }
    1363            // else {
    1364 
    1365              //   $link = $link . "run";
    1366               //  write_table_cell($class, '%s', "", "");
    1367               //  $link = ""; # TODO removed links temporarily
    1368                //     write_table_cell($class, '%s', $link, "run");
    1369            // }
    1370        // }
    1371        // else {
    1372 
    1373          //   write_table_cell($class, '%s', "", "");
    1374          //   write_table_cell($class, '%s', "", "");
    1375        // }
    13761299        echo "</tr>\n";
    13771300    }
     
    14641387#
    14651388###########################################################################
    1466 function showServerStatus($server) {
    1467 
    1468     echo "<p> Status for $server server </p>";
     1389function showServerStatus($server, $proj) {
     1390
     1391    echo "<p> $server server status for $proj</p>";
    14691392
    14701393    $results=array();
    1471     exec("czartool_getServerStatus.pl -s $server", $results, $status);
     1394    exec("czartool_getServerStatus.pl -s $server -p $proj", $results, $status);
    14721395
    14731396    foreach ($results as &$line) {
     
    14751398        echo "$line\n";
    14761399        echo "</pre>\n";
    1477 
    14781400    }
    14791401}
     
    15831505#
    15841506###########################################################################
    1585 function createSummitDataTable2($projectdb) {
     1507function createSummitDataTable2($projectdb, $pass, $proj) {
    15861508
    15871509    // timer start
     
    16011523    echo $table;
    16021524    echo "<tr>";
    1603     createTableTitle("Data status tonight $date (UT) <br> current time $datetime", 4);
     1525    createTableTitle("Data status tonight $date <br> current time $datetime (UTC)", 4);
    16041526    echo "<tr>";
    1605     createTableColumnHeader("Exp_type at summit");
    1606     createTableColumnHeader("Status at summit");
    1607     createTableColumnHeader("Status at mhpcc");
    1608     createTableColumnHeader("Number");
     1527
     1528    createTableColumnHeader("Exposure type");
     1529    createTableColumnHeader("<a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=summitExp\"><font color=\"blue\">summitExp status</font></a>");
     1530    createTableColumnHeader("<a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=downloadExp\"><font color=\"blue\">downloadExp status</font></a>");
     1531    createTableColumnHeader("<a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=rawExp\"><font color=\"blue\">rawExp </a>/
     1532                             <a href=\"czartool_labels.php?pass=".$pass."&proj=".$proj."&label=all&stage=newExp\"><font color=\"blue\"> newExp</font></a>");
    16091533    $sql = "SELECT summitExp.exp_type,pzDownloadExp.state,rawExp.state,COUNT(*) FROM summitExp
    16101534            LEFT JOIN pzDownloadExp USING (summit_id) LEFT JOIN rawExp on summitExp.exp_name = rawExp.exp_name
     
    16141538        if ($tmp[1] == NULL) {
    16151539          echo  "<tr><td>$tmp[0]<td> null <td> null <td bgcolor=\"yellow\"> <font color=\"red\">$tmp[3]";
    1616         }
    1617         else {
     1540        } else {
    16181541          if ($tmp[1] == 'run') {
    16191542            echo  "<tr><td>$tmp[0]<td> loading <td> null <td bgcolor=$columnHeaderColor> <font color=\"red\">$tmp[3]";
    1620           }
    1621           else {
     1543          } else {
    16221544            if ($tmp[2] == NULL) {
    16231545              echo  "<tr><td>$tmp[0] <td> $tmp[1] <td> loading <td bgcolor=$columnHeaderColor> <font color=\"blue\">$tmp[3]";
    1624             }
    1625             else {
     1546            } else {
    16261547              echo  "<tr><td>$tmp[0]<td> $tmp[1] <td> downloaded <td> $tmp[3]";
    16271548            }
     
    16301551    }
    16311552
    1632     echo "<tr><th colspan=4>Last night $datem1 (UT)";
     1553    echo "<tr><th colspan=4>Last night $datem1 (UTC)";
    16331554    $sql = "SELECT summitExp.exp_type,pzDownloadExp.state,rawExp.state,COUNT(*) FROM summitExp
    16341555            LEFT JOIN pzDownloadExp USING (summit_id) LEFT JOIN rawExp on summitExp.exp_name = rawExp.exp_name
     
    16381559        if ($tmp[1] == NULL) {
    16391560          echo  "<tr><td>$tmp[0]<td> null <td> null <td bgcolor=\"yellow\"> <font color=\"red\">$tmp[3]";
    1640         }
    1641         else {
     1561        } else {
    16421562          if ($tmp[1] == 'run') {
    16431563            echo  "<tr><td>$tmp[0]<td> loading <td> null <td bgcolor=$columnHeaderColor> <font color=\"red\">$tmp[3]";
    1644           }
    1645           else {
     1564          } else {
    16461565            if ($tmp[2] == NULL) {
    16471566              echo  "<tr><td>$tmp[0] <td> $tmp[1] <td> loading <td bgcolor=$columnHeaderColor> <font color=\"blue\">$tmp[3]";
    1648             }
    1649             else {
     1567            } else {
    16501568              echo  "<tr><td>$tmp[0]<td> $tmp[1] <td> downloaded <td> $tmp[3]";
    16511569            }
     
    16651583    echo "</table><br>";
    16661584}
    1667 ////////////////////////////////////////////////////////////////////////////////
    1668 ///                         no needed functions                              ///
    1669 ////////////////////////////////////////////////////////////////////////////////
    1670 //function createSummitDataTable($projectdb) {
    1671 //
    1672 //    // timer start
    1673 //    $time = microtime();
    1674 //    $time = explode(' ', $time);
    1675 //    $time = $time[1] + $time[0];
    1676 //    $start = $time;
    1677 //
    1678 //    // function begin
    1679 //    $date = date("Y-m-d");
    1680 //    $sql = "SELECT DISTINCT exp_type FROM summitExp WHERE dateobs > '$date'";
    1681 //
    1682 //    $qry = $projectdb->query($sql);
    1683 //    if (dberror($qry)) {
    1684 //        echo "<b>error reading newExp table</b><br>\n";
    1685 //        echo "<br><small><b> table query : $sql </b></small><br>\n";
    1686 //        menu_end();
    1687 //    }
    1688 //
    1689 //    // set up the table
    1690 //    global $table;
    1691 //    echo $table;
    1692 //    echo "<tr>";
    1693 //    createTableTitle("Data status > $date", 4);
    1694 //    echo "<tr>";
    1695 //    createTableColumnHeader("Exposure type");
    1696 //    createTableColumnHeader("At summit");
    1697 //    createTableColumnHeader("Registered at MHPCC");
    1698 //    createTableColumnHeader("Summit (Drop/Null)");
    1699 //
    1700 //    $msg = "No science images taken since $date";
    1701 //
    1702 //    // list the results
    1703 //    while ($qry->fetchInto($expType)) {
    1704 //
    1705 //        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id)
    1706 //                WHERE dateobs > '$date' AND exp_type = '$expType[0]'";
    1707 //             //   AND state != 'drop' AND state is not null AND fault != 1042";
    1708 //        $qry2 = $projectdb->query($sql);
    1709 //        $qry2->fetchInto($summit);
    1710 //
    1711 //        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name
    1712 //                WHERE summitExp.dateobs > '$date' AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
    1713 //        $qry2 = $projectdb->query($sql);
    1714 //        $qry2->fetchInto($mhpcc);
    1715 //
    1716 //        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id)
    1717 //                WHERE dateobs > '$date' AND exp_type = '$expType[0]' AND (state = 'drop' OR state is null)";
    1718 //        $qry2 = $projectdb->query($sql);
    1719 //        $qry2->fetchInto($dropped);
    1720 //
    1721 //
    1722 //        #Query with 30 minutes delay to check during the night if any exposures are missing.
    1723 //        $datehour = gmdate("Y-m-d H:i:s");
    1724 //        $sql = "SELECT COUNT(*) FROM summitExp LEFT JOIN pzDownloadExp USING (summit_id)
    1725 //                WHERE dateobs > '$date' AND dateobs <= date_sub('$datehour', interval 30 minute)
    1726 //                AND exp_type = '$expType[0]' AND (state != 'drop' OR state is null) and fault != 1042";
    1727 //
    1728 //        $qry2 = $projectdb->query($sql);
    1729 //        $qry2->fetchInto($summitdelay);
    1730 //
    1731 //        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name
    1732 //                WHERE summitExp.dateobs > '$date' AND summitExp.dateobs <= date_sub('$datehour', interval 30 minute)
    1733 //                AND rawExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
    1734 //        $qry2 = $projectdb->query($sql);
    1735 //        $qry2->fetchInto($mhpccdelay);
    1736 //
    1737 //        echo "<tr>";
    1738 //
    1739 //        $DLdiff = $summit[0] - $mhpcc[0];
    1740 //        if ($DLdiff == 0) $error = 0;
    1741 //        else $error = 1;
    1742 //
    1743 //        $delayDLdiff = $summitdelay[0] - $mhpccdelay[0];
    1744 //        if ($delayDLdiff == 0) $errordelay = 0;
    1745 //        else $errordelay = 1;
    1746 //
    1747 //        echo "<td>$expType[0]</td>";
    1748 //        echo "<td>$summit[0]</td>";
    1749 //        if ($delayDLdiff==0) {
    1750 //           createFormattedTableCell("", "", $mhpcc[0], $error, 0);
    1751 //        } else {
    1752 //           $DLStatus = "<font style=\"BACKGROUND-COLOR: yellow\"  color=\"red\">$mhpcc[0] ($delayDLdiff)</font>";
    1753 //           echo "<td>$DLStatus</td>";
    1754 //        }
    1755 //
    1756 //        echo "<td>$dropped[0]</td>";
    1757 //
    1758 //        echo "</tr>";
    1759 //    }
    1760 //
    1761 //    // timer finished
    1762 //    echo "<tr><th colspan=4>";
    1763 //    $time = microtime();
    1764 //    $time = explode(' ', $time);
    1765 //    $time = $time[1] + $time[0];
    1766 //    $finish = $time;
    1767 //    $total_time = round(($finish - $start), 3);
    1768 //    echo "loading in $total_time seconds.";
    1769 //    $start= $finish;
    1770 //    echo "</th></tr>";
    1771 //    echo "</table><br>";
    1772 //}
     1585###########################################################################
     1586#
     1587# Gets disk status
     1588#
     1589###########################################################################
     1590function getHosts($db) {
     1591    // timer start
     1592    $time = microtime();
     1593    $time = explode(' ', $time);
     1594    $time = $time[1] + $time[0];
     1595    $start = $time;
     1596
     1597    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
     1598    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
     1599    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640px\">";
     1600    echo "  <div id=\"disk_div\" style=\"width:640px; height:1200px\"></div>";
     1601    echo "  <div class=\"overlay\" style=\"position: absolute; width: 100px; top: 35px; right: 20px;\">";
     1602    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #00ff00\"><center>Free</div>";
     1603    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ffff00\"><center>Used</div>";
     1604    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ff0000\"><center>> 97% limit</div>";
     1605    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #bbbbbb\"><center>Down | Repair</div>";
     1606    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ffffff\"><center>Power Off</div>";
     1607    echo "    <div style=\"font-size: 12px; height: 14px; border: 1px solid; background-color: #ffffff\"><center>
     1608                 <a href=\"https://confluence.ipp.ifa.hawaii.edu/display/IKB/IPP+Hardware+Status#IPPHardwareStatus-StorageNodes\" target=new><font color=\"blue\">Notes</font></a></div>";
     1609    echo "  </div>";
     1610    echo "</div>";
     1611
     1612    echo "<script type=\"text/javascript\">";
     1613    echo "google.charts.load('current', {packages: ['corechart', 'bar']});";
     1614    echo "google.charts.setOnLoadCallback(drawBarColors);";
     1615    echo "function drawBarColors() {";
     1616    echo "  var data = google.visualization.arrayToDataTable([";
     1617    echo "    ['Host', ";
     1618    echo "     'used', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}, ";
     1619    echo "     'free', {type: 'string', role: 'style'}, {type: 'string', role: 'tooltip', 'p': {'html': true}}],";
     1620
     1621    $sql = "SELECT host, format(total,1), format(available,2), format(used,2), writable, readable, format(used/total*100,2) FROM hosts";
     1622    if ($debug) {echo "$sql<br>";}
     1623    $qry = $db->query($sql);
     1624    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
     1625    # not sure why neb-host doesn't work on ipp113 CCL.20210216
     1626    exec("neb-host |cut -b 17-30,86-", $hostnoteall);
     1627    while ($qry->fetchInto($row)) {
     1628        list($host, $total, $available, $used, $writable, $readable, $ratio) = $row;
     1629       $hostnotes = preg_grep("/$host/", $hostnoteall);
     1630       $hostnote = array_values($hostnotes);
     1631       if ($writable == 1 && $readable == 1) {
     1632          if ($ratio >= 97) {
     1633            # space used over limits, up mode (read/write ok).
     1634            echo "[ \"$host\", ";
     1635            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ff0000;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", ";
     1636            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],";
     1637          }
     1638          else {
     1639            # enough space, up mode (read/write ok).
     1640            echo "[ \"$host\", ";
     1641            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used</b></i><br>$hostnote[0]\", ";
     1642            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #00ff00;\", \"<i><b>$host: $available TB free</b></i>\"],";
     1643         }
     1644       }
     1645       else if ($writable == 0 && $readable == 1) {
     1646          if ($ratio >= 97) {
     1647            # space used over limits, repair mode (read only).
     1648            echo "[ \"$host\", ";
     1649            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ff0000;\", \"<i><b>$host: $ratio% of $total TB used<br><font color=red>$hostnote[0]\", ";
     1650            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
     1651          }
     1652          else {
     1653            # enough space, but hosts are unstable, repair mode (read only).
     1654            echo "[ \"$host\", ";
     1655            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #ffff00;\", \"<i><b>$host: $ratio% of $total TB used<br>$hostnote[0]\", ";
     1656            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
     1657          }
     1658       }
     1659       else {
     1660            # down mode (can't read or write).
     1661            echo "[ \"$host\", ";
     1662            echo "      $used, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $ratio% used<br>$hostnote[0]\", ";
     1663            echo " $available, \"stroke-width: 0.3;\"+\"stroke-color: black;\"+\"color: #bbbbbb;\", \"<i><b>$host: $available TB free</b></i>\"],";
     1664       }
     1665    }
     1666   echo "  ]);";
     1667   echo "   var options = {";
     1668   echo "     title: 'Nebulous Disk Use across IPP Clusters',";
     1669   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
     1670   echo "     width: '100%',";
     1671   echo "     height: '100%',";
     1672   echo "     tooltip: {isHtml: true},";
     1673   echo "     legend: { position: 'none',";
     1674   echo "               alignment: 'end',";
     1675   echo "               maxLines: 3},";
     1676   echo "     hAxis: {  title: 'Space (TB)',";
     1677   echo "               gridlines: {count: 10}";
     1678   echo "     },";
     1679   echo "     bar: { groupWidth: '95%' },";
     1680   echo "     chartArea: {left:70, top:30, right:20, bottom:40},";
     1681   echo "     fontSize: 12,";
     1682   echo "     isStacked: true";
     1683   echo "   };";
     1684   echo "   var chart = new google.visualization.BarChart(document.getElementById('disk_div'));";
     1685   echo "   chart.draw(data, options);";
     1686   echo " }";
     1687   echo "</script>";
     1688    $time = microtime();
     1689    $time = explode(' ', $time);
     1690    $time = $time[1] + $time[0];
     1691    $finish = $time;
     1692    $total_time = round(($finish - $start), 3);
     1693    $start= $finish;
     1694    echo "<center>loading in $total_time seconds<br></center>";
     1695}
     1696
     1697###########################################################################
     1698#
     1699# Gets disk spaces status
     1700#
     1701###########################################################################
     1702function getSpaces($db) {
     1703    // timer start
     1704    $time = microtime();
     1705    $time = explode(' ', $time);
     1706    $time = $time[1] + $time[0];
     1707    $start = $time;
     1708
     1709    $db->query("SELECT sum(format(available, 2)) FROM hosts where host like 'ippb%'")->fetchInto($row);
     1710    $ippbusable = $row[0];
     1711    $db->query("SELECT sum(format(available, 2)) FROM hosts where host like 'ippb%' and writable = 1")->fetchInto($row);
     1712    $ippbfree = $row[0];
     1713
     1714    $db->query("SELECT sum(format(available, 2)) FROM hosts where host not like 'ippb%'")->fetchInto($row);
     1715    $ippusable = $row[0];
     1716    $db->query("SELECT sum(format(available, 2)) FROM hosts where host not like 'ippb%' and writable = 1")->fetchInto($row);
     1717    $ippfree = $row[0];
     1718
     1719    $sql = "select format(used/total*100,1), usable from cluster_space order by timestamp desc limit 1;";
     1720    if ($debug) {echo "$sql<br>";}
     1721    $qry = $db->query($sql);
     1722    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
     1723    $qry->fetchInto($row);
     1724    $allocated = $row[0];
     1725    $usable    = $row[1];
     1726
     1727    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
     1728    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
     1729    echo "<br><div class=\"chartWithOverlay\" style=\"position: relative; width: 640; height:400\">";
     1730    echo "  <div id=\"space_div\" style=\"width:640; \"></div>";
     1731    echo "  <div class=\"overlay\" style=\"position: absolute; width: 400px; bottom: 60px; left: 85px;\">";
     1732    echo "    <div style=\"font-size: 16px; color:#0000ff; background-color:#ffffff\"><b>ipp + ippb nodes: $ippusable + $ippbusable TB (latest usable)</b></div>";
     1733    echo "    <div style=\"font-size: 16px; color:#33a532; background-color:#ffffff\"><b>ipp + ippb nodes: $ippfree + $ippbfree TB (latest free)</b></div>";
     1734    echo "  </div>";
     1735    echo "</div>";
     1736
     1737    echo "<script type=\"text/javascript\">";
     1738    echo "google.charts.load('current', {packages: ['corechart']});";
     1739    echo "google.charts.setOnLoadCallback(drawChart);";
     1740    echo "function drawChart() {";
     1741    echo "  var data = new google.visualization.DataTable();";
     1742    echo "        data.addColumn('datetime', 'Day');";
     1743    echo "        data.addColumn('number', 'Usable');";
     1744    echo "        data.addColumn('number', 'Free');";
     1745    echo "   data.addRows([";
     1746    $interval = 10;
     1747    $sql = "select sub.dated, sub.usable, sub.available from (select date_format(timestamp, \"%Y.%m.%d.%H.%i\") as dated, usable, available from cluster_space where timestamp > curdate() - INTERVAL $interval DAY) as sub group by dated;";
     1748    if ($debug) {echo "$sql<br>";}
     1749    $qry = $db->query($sql);
     1750    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
     1751    while ($qry->fetchInto($row)) {
     1752        $tsp = explode('.', $row[0]);
     1753        $mon = $tsp[1]-1;
     1754        $timestamp = $row[0];
     1755        $usable    = $row[1];
     1756        $available = $row[2];
     1757#       new Date(Year, Month, Day, Hours, Minutes, Seconds, Milliseconds)
     1758       echo "[new Date($tsp[0], $mon, $tsp[2], $tsp[3], $tsp[4]), $usable, $available],";
     1759    }
     1760   echo "  ]);";
     1761   echo "   var options = {";
     1762   echo "      chart: {"; 
     1763   echo "               position: 'center', " ;
     1764   echo "              },";
     1765   echo "     title: 'Total Available Cluster Space in the Past $interval Days ($allocated% of total allocated)',";
     1766   echo "     titleTextStyle: {color: 'black', fontSize: 15},";
     1767   echo "     width: '100%',";
     1768   echo "     height: 400,";
     1769   echo "     legend: { position: 'top',";
     1770   echo "               alignment: 'center',";
     1771   echo "              },";
     1772   echo "     lineWidth: 2, ";
     1773   echo "     series: {";
     1774   echo "         0: { color: '#0000ff', lineWidth: 3 },      ";
     1775   echo "         1: { color: '#33a532', lineWidth: 3 },      ";
     1776   echo "              },";
     1777   echo "     hAxis: {  ";
     1778   echo "             title: 'Date/Time (HST)',";
     1779   echo "             format: 'MMM dd',";
     1780   echo "            gridlines: {count: -1},";
     1781   echo "     },";
     1782   echo "     vAxis: {  ";
     1783   echo "                  title: 'Available (TB)',";
     1784   echo "     viewWindow: {   min: 500    },  ";
     1785   echo "     },";
     1786   echo "     chartArea: {left:80, top:50, right:20, bottom:50},";
     1787   echo "     fontSize: 12,";
     1788   echo "   };";
     1789   echo "   var chart = new google.visualization.LineChart(document.getElementById('space_div'));";
     1790   echo "   chart.draw(data, options);";
     1791   echo " }";
     1792   echo "</script>";
     1793    $time = microtime();
     1794    $time = explode(' ', $time);
     1795    $time = $time[1] + $time[0];
     1796    $finish = $time;
     1797    $total_time = round(($finish - $start), 3);
     1798    $start= $finish;
     1799    echo "<center>loading in $total_time seconds<br></center>";
     1800}
     1801
     1802###########################################################################
     1803#
     1804# Gets time series plot
     1805#
     1806###########################################################################
     1807function Gettimeseries($db, $selectedMode, $selectedLabel, $proj, $selectedStage) {
     1808    // timer start
     1809    $time = microtime();
     1810    $time = explode(' ', $time);
     1811    $time = $time[1] + $time[0];
     1812    $start = $time;
     1813
     1814    // google chart javascript source code
     1815    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
     1816    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
     1817
     1818    // if button doesn't work, maybe plot linear and log chart separately
     1819    #echo "<div id=\"time_series_div_lin\" style=\"width:640; height:400;\"></div><br>";
     1820    #echo "<div id=\"time_series_div_log\" style=\"width:640; height:400;\"></div>";
     1821    echo "<div id=\"time_series_div\" style=\"width:640; height:400;\"></div>";
     1822
     1823    // click button to switch linear or log plot, but sometimes it doesn't work well.
     1824    echo "<div><center><button id=\"linlogchart\"></button></div>";
     1825
     1826    // javascript start
     1827    echo "<script type=\"text/javascript\">";
     1828    echo "google.charts.load('current', {'packages': ['corechart', 'line']});";
     1829    echo "google.charts.setOnLoadCallback(drawChart);";
     1830    // draw funciton start
     1831    echo "function drawChart() {";
     1832    echo "  var button   = document.getElementById('linlogchart');";  // for linear and log button
     1833    echo "  var chartDiv = document.getElementById('time_series_div');";
     1834    echo "  var data = new google.visualization.DataTable();";
     1835   
     1836    // plot data
     1837    $dayshift = -0; // query back to N-th day
     1838    // check labels
     1839    if ($selectedLabel == "all") {
     1840      $selectedLabel = "stdscience_labels";
     1841      $plotlabel = "all";
     1842    } else {
     1843      $plotlabel = $selectedLabel;
     1844    }
     1845
     1846    // check stages
     1847    if ($selectedStage == "all_stages") {
     1848      $plotstage = "all";
     1849      if ($selectedLabel == "stdscience_labels") {
     1850        // all stages and all labels
     1851        $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
     1852        $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, ";
     1853        $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     1854        $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, ";
     1855        $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, ";
     1856        $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     1857        $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, ";
     1858        $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     1859        $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, ";
     1860        $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, ";
     1861        $plotseries .= "             10: { color: 'cyan'    , lineWidth: 2, lineDashStyle: [3, 4]}, ";
     1862        $plotseries .= "             11: { color: '#c51b7d' , lineWidth: 2, lineDashStyle: [3, 4]}, ";
     1863        $plotseries .= "             12: { color: '#b15928' , lineWidth: 2, lineDashStyle: [3, 4]}, ";
     1864        $plotseries .= "             13: { color: '#000004' , lineWidth: 2, lineDashStyle: [3, 4]}, },";
     1865       
     1866        // data header
     1867        echo "  data.addColumn('datetime',        'Time');";
     1868        echo "  data.addColumn(  'number',        'chip'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1869        echo "  data.addColumn(  'number',         'cam'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1870        echo "  data.addColumn(  'number',        'fake'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1871        echo "  data.addColumn(  'number',        'warp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1872        echo "  data.addColumn(  'number',       'stack'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1873        echo "  data.addColumn(  'number',   'staticsky'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1874        echo "  data.addColumn(  'number',        'diff'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1875        echo "  data.addColumn(  'number',   'fullforce'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1876        echo "  data.addColumn(  'number',        'dist'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1877        echo "  data.addColumn(  'number',         'pub'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1878        echo "  data.addColumn(  'number',   'summitExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1879        echo "  data.addColumn(  'number', 'downloadExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1880        echo "  data.addColumn(  'number',      'newExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1881        echo "  data.addColumn(  'number',      'rawExp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1882        // data content
     1883        echo "  data.addRows([";
     1884 
     1885        //  query data from czardb
     1886        $sql = "select date_format(addtime(rawrun.timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, summrun.proc as sumproc, downrun.proc as downproc, newrun.proc as newproc, rawrun.proc as rawproc, timestamp";
     1887        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from rawExp   ,   (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as rawrun                ";
     1888        $sql.= " join (select @rank2:=@rank2+1 AS rank,            processed as proc from newExp   ,   (select @rank2:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as newrun   using (rank) ";
     1889        $sql.= " join (select @rank3:=@rank3+1 AS rank,            processed as proc from summitExp,   (select @rank3:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as summrun  using (rank) ";
     1890        $sql.= " join (select @rank4:=@rank4+1 AS rank,            processed as proc from downloadExp, (select @rank4:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as downrun  using (rank) ";
     1891        $sql.= " join (select @rank5:=@rank5+1 AS rank,            processed as proc from chip,        (select @rank5:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as chiprun  using (rank) ";
     1892        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as camrun   using (rank) ";
     1893        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as fakerun  using (rank) ";
     1894        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as warprun  using (rank) ";
     1895        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as stackrun using (rank) ";
     1896        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as statrun  using (rank) ";
     1897        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as diffrun  using (rank) ";
     1898        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as ffrun    using (rank) ";
     1899        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as distrun  using (rank) ";
     1900        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as pubrun   using (rank);";
     1901
     1902        // define last process and total process
     1903        list($lastproc1 , $sumproc1 ) = array(-1, 0);
     1904        list($lastproc2 , $sumproc2 ) = array(-1, 0);
     1905        list($lastproc3 , $sumproc3 ) = array(-1, 0);
     1906        list($lastproc4 , $sumproc4 ) = array(-1, 0);
     1907        list($lastproc5 , $sumproc5 ) = array(-1, 0);
     1908        list($lastproc6 , $sumproc6 ) = array(-1, 0);
     1909        list($lastproc7 , $sumproc7 ) = array(-1, 0);
     1910        list($lastproc8 , $sumproc8 ) = array(-1, 0);
     1911        list($lastproc9 , $sumproc9 ) = array(-1, 0);
     1912        list($lastproc10, $sumproc10) = array(-1, 0);
     1913        list($lastproc11, $sumproc11) = array(-1, 0);
     1914        list($lastproc12, $sumproc12) = array(-1, 0);
     1915        list($lastproc13, $sumproc13) = array(-1, 0);
     1916        list($lastproc14, $sumproc14) = array(-1, 0);
     1917
     1918        // query from czardb 
     1919        if ($debug) {echo "$sql<br>";}
     1920        $qry = $db->query($sql);
     1921        if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
     1922        // define plot title
     1923        //$plottitle = "title: 'Items + N x 150 offset',";
     1924        $plottitle = "title: 'Items',";
     1925
     1926        // loading all the data
     1927        while ($qry->fetchInto($row)) {
     1928          // get UTC time info.
     1929          $tsp = explode('.', $row[0]);
     1930
     1931          // get processing info. from all stages and get time series.
     1932          $thisproc1  = $row[1] ; list($thisproc1 , $lastproc1 , $sumproc1 ) = gettotalprocessed($thisproc1 , $lastproc1 , $sumproc1 ); // chip
     1933          $thisproc2  = $row[2] ; list($thisproc2 , $lastproc2 , $sumproc2 ) = gettotalprocessed($thisproc2 , $lastproc2 , $sumproc2 ); // cam
     1934          $thisproc3  = $row[3] ; list($thisproc3 , $lastproc3 , $sumproc3 ) = gettotalprocessed($thisproc3 , $lastproc3 , $sumproc3 ); // fake
     1935          $thisproc4  = $row[4] ; list($thisproc4 , $lastproc4 , $sumproc4 ) = gettotalprocessed($thisproc4 , $lastproc4 , $sumproc4 ); // warp
     1936          $thisproc5  = $row[5] ; list($thisproc5 , $lastproc5 , $sumproc5 ) = gettotalprocessed($thisproc5 , $lastproc5 , $sumproc5 ); // stack
     1937          $thisproc6  = $row[6] ; list($thisproc6 , $lastproc6 , $sumproc6 ) = gettotalprocessed($thisproc6 , $lastproc6 , $sumproc6 ); // staticsky
     1938          $thisproc7  = $row[7] ; list($thisproc7 , $lastproc7 , $sumproc7 ) = gettotalprocessed($thisproc7 , $lastproc7 , $sumproc7 ); // diff
     1939          $thisproc8  = $row[8] ; list($thisproc8 , $lastproc8 , $sumproc8 ) = gettotalprocessed($thisproc8 , $lastproc8 , $sumproc8 ); // fullforce
     1940          $thisproc9  = $row[9] ; list($thisproc9 , $lastproc9 , $sumproc9 ) = gettotalprocessed($thisproc9 , $lastproc9 , $sumproc9 ); // dist
     1941          $thisproc10 = $row[10]; list($thisproc10, $lastproc10, $sumproc10) = gettotalprocessed($thisproc10, $lastproc10, $sumproc10); // pub
     1942          $thisproc11 = $row[11]; list($thisproc11, $lastproc11, $sumproc11) = gettotalprocessed($thisproc11, $lastproc11, $sumproc11); // rawExp
     1943          $thisproc12 = $row[12]; list($thisproc12, $lastproc12, $sumproc12) = gettotalprocessed($thisproc12, $lastproc12, $sumproc12); // newExp
     1944          $thisproc13 = $row[13]; list($thisproc13, $lastproc13, $sumproc13) = gettotalprocessed($thisproc13, $lastproc13, $sumproc13); // summitExp
     1945          $thisproc14 = $row[14]; list($thisproc14, $lastproc14, $sumproc14) = gettotalprocessed($thisproc14, $lastproc14, $sumproc14); // downloadExp
     1946
     1947          // get HST time info.
     1948          $hsttime    = $row[15];
     1949
     1950          // data content
     1951          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
     1952          echo "$sumproc1 , \"<i><b>$hsttime (HST) $sumproc1   chip        </i></b> \",";  //+ 7*150 chip
     1953          echo "$sumproc2 , \"<i><b>$hsttime (HST) $sumproc2   cam         </i></b> \",";  //+ 6*150 cam
     1954          echo "$sumproc3 , \"<i><b>$hsttime (HST) $sumproc3   fake        </i></b> \",";  //+ 5*150 fake
     1955          echo "$sumproc4 , \"<i><b>$hsttime (HST) $sumproc4   warp        </i></b> \",";  //+ 4*150 warp
     1956          echo "$sumproc5 , \"<i><b>$hsttime (HST) $sumproc5   stack       </i></b> \",";  //+ 0*150 stack
     1957          echo "$sumproc6 , \"<i><b>$hsttime (HST) $sumproc6   staticsky   </i></b> \",";  //+ 0*150 staticsky
     1958          echo "$sumproc7 , \"<i><b>$hsttime (HST) $sumproc7   diff        </i></b> \",";  //+10*150 diff
     1959          echo "$sumproc8 , \"<i><b>$hsttime (HST) $sumproc8   fullforce   </i></b> \",";  //+ 0*150 fullforce
     1960          echo "$sumproc9 , \"<i><b>$hsttime (HST) $sumproc9   dist        </i></b> \",";  //+ 8*150 dist
     1961          echo "$sumproc10, \"<i><b>$hsttime (HST) $sumproc10  pub         </i></b> \",";  //+ 9*150 pub
     1962          echo "$sumproc11, \"<i><b>$hsttime (HST) $sumproc11  summitExp   </i></b> \",";  //+ 3*150 summitExp
     1963          echo "$sumproc12, \"<i><b>$hsttime (HST) $sumproc12  downloadExp </i></b> \",";  //+ 2*150 downloadExp
     1964          echo "$sumproc13, \"<i><b>$hsttime (HST) $sumproc13  newExp      </i></b> \",";  //+ 1*150 newExp
     1965          echo "$sumproc14, \"<i><b>$hsttime (HST) $sumproc14  rawExp      </i></b> \" ";  //+ 0*150 rawExp
     1966          echo "], ";
     1967        }
     1968      } else {
     1969        // all stages, but selected label
     1970        $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
     1971        $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, ";
     1972        $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     1973        $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, ";
     1974        $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, ";
     1975        $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     1976        $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, ";
     1977        $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     1978        $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, ";
     1979        $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, },";
     1980
     1981        // data header
     1982        echo "  data.addColumn('datetime',        'Time');";
     1983        echo "  data.addColumn(  'number',        'chip'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1984        echo "  data.addColumn(  'number',         'cam'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1985        echo "  data.addColumn(  'number',        'fake'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1986        echo "  data.addColumn(  'number',        'warp'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1987        echo "  data.addColumn(  'number',       'stack'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1988        echo "  data.addColumn(  'number',   'staticsky'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1989        echo "  data.addColumn(  'number',        'diff'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1990        echo "  data.addColumn(  'number',   'fullforce'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1991        echo "  data.addColumn(  'number',        'dist'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1992        echo "  data.addColumn(  'number',         'pub'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     1993
     1994        // data content
     1995        echo "  data.addRows([";
     1996 
     1997        //  query data from czardb
     1998        $sql = "select date_format(addtime(chiprun.timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, timestamp";
     1999        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from chip,        (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as chiprun              ";
     2000        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as camrun   using (rank) ";
     2001        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as fakerun  using (rank) ";
     2002        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as warprun  using (rank) ";
     2003        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as stackrun using (rank) ";
     2004        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as statrun  using (rank) ";
     2005        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as diffrun  using (rank) ";
     2006        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as ffrun    using (rank) ";
     2007        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as distrun  using (rank) ";
     2008        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and dbname like '$proj') as pubrun   using (rank);";
     2009 
     2010        // define last process and total process
     2011        list($lastproc1 , $sumproc1 ) = array(-1, 0);
     2012        list($lastproc2 , $sumproc2 ) = array(-1, 0);
     2013        list($lastproc3 , $sumproc3 ) = array(-1, 0);
     2014        list($lastproc4 , $sumproc4 ) = array(-1, 0);
     2015        list($lastproc5 , $sumproc5 ) = array(-1, 0);
     2016        list($lastproc6 , $sumproc6 ) = array(-1, 0);
     2017        list($lastproc7 , $sumproc7 ) = array(-1, 0);
     2018        list($lastproc8 , $sumproc8 ) = array(-1, 0);
     2019        list($lastproc9 , $sumproc9 ) = array(-1, 0);
     2020        list($lastproc10, $sumproc10) = array(-1, 0);
     2021
     2022        // query from czardb 
     2023        if ($debug) {echo "$sql<br>";}
     2024        $qry = $db->query($sql);
     2025        if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
     2026        // define plot title
     2027        //$plottitle = "title: 'Items + N x 30 offset',";
     2028        $plottitle = "title: 'Items',";
     2029
     2030        // loading all the data
     2031        while ($qry->fetchInto($row)) {
     2032          // get UTC time info.
     2033          $tsp = explode('.', $row[0]);
     2034
     2035          // get processing info. from all stages and get time series.
     2036          $thisproc1  = $row[1] ; list($thisproc1 , $lastproc1 , $sumproc1 ) = gettotalprocessed($thisproc1 , $lastproc1 , $sumproc1 ); // chip
     2037          $thisproc2  = $row[2] ; list($thisproc2 , $lastproc2 , $sumproc2 ) = gettotalprocessed($thisproc2 , $lastproc2 , $sumproc2 ); // cam
     2038          $thisproc3  = $row[3] ; list($thisproc3 , $lastproc3 , $sumproc3 ) = gettotalprocessed($thisproc3 , $lastproc3 , $sumproc3 ); // fake
     2039          $thisproc4  = $row[4] ; list($thisproc4 , $lastproc4 , $sumproc4 ) = gettotalprocessed($thisproc4 , $lastproc4 , $sumproc4 ); // warp
     2040          $thisproc5  = $row[5] ; list($thisproc5 , $lastproc5 , $sumproc5 ) = gettotalprocessed($thisproc5 , $lastproc5 , $sumproc5 ); // stack
     2041          $thisproc6  = $row[6] ; list($thisproc6 , $lastproc6 , $sumproc6 ) = gettotalprocessed($thisproc6 , $lastproc6 , $sumproc6 ); // staticsky
     2042          $thisproc7  = $row[7] ; list($thisproc7 , $lastproc7 , $sumproc7 ) = gettotalprocessed($thisproc7 , $lastproc7 , $sumproc7 ); // diff
     2043          $thisproc8  = $row[8] ; list($thisproc8 , $lastproc8 , $sumproc8 ) = gettotalprocessed($thisproc8 , $lastproc8 , $sumproc8 ); // fullforce
     2044          $thisproc9  = $row[9] ; list($thisproc9 , $lastproc9 , $sumproc9 ) = gettotalprocessed($thisproc9 , $lastproc9 , $sumproc9 ); // dist
     2045          $thisproc10 = $row[10]; list($thisproc10, $lastproc10, $sumproc10) = gettotalprocessed($thisproc10, $lastproc10, $sumproc10); // pub
     2046
     2047          // get HST time info.
     2048          $hsttime  = $row[11];
     2049
     2050          // data content
     2051          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
     2052          echo "$sumproc1 , \"<i><b>$hsttime (HST) $sumproc1  chip      </i></b> \", "; //+ 3*30 chip
     2053          echo "$sumproc2 , \"<i><b>$hsttime (HST) $sumproc2  cam       </i></b> \", "; //+ 2*30 cam
     2054          echo "$sumproc3 , \"<i><b>$hsttime (HST) $sumproc3  fake      </i></b> \", "; //+ 1*30 fake
     2055          echo "$sumproc4 , \"<i><b>$hsttime (HST) $sumproc4  warp      </i></b> \", "; //+ 0*30 warp
     2056          echo "$sumproc5 , \"<i><b>$hsttime (HST) $sumproc5  stack     </i></b> \", "; //+ 0*30 stack
     2057          echo "$sumproc6 , \"<i><b>$hsttime (HST) $sumproc6  staticsky </i></b> \", "; //+ 0*30 staticsky
     2058          echo "$sumproc7 , \"<i><b>$hsttime (HST) $sumproc7  diff      </i></b> \", "; //+ 6*30 diff
     2059          echo "$sumproc8 , \"<i><b>$hsttime (HST) $sumproc8  fullforce </i></b> \", "; //+ 0*30 fullforce
     2060          echo "$sumproc9 , \"<i><b>$hsttime (HST) $sumproc9  dist      </i></b> \", "; //+ 5*30 dist
     2061          echo "$sumproc10, \"<i><b>$hsttime (HST) $sumproc10 pub       </i></b> \"  "; //+ 4*30 pub
     2062          echo "],";
     2063        }
     2064      } 
     2065    } else {
     2066      // selected stages and selected label
     2067      $plottitle = "title: 'Items',";
     2068      $plotseries  = "    series: { 0: { color: '#33a532', lineWidth: 3 }, ";   // traffic light green code
     2069      $plotseries .= "              1: { color: '#e7b416', lineWidth: 3 }, ";   // traffic light yellow code
     2070      $plotseries .= "              2: { color: '#cc3232', lineWidth: 3 }, },"; // traffic light red code
     2071      $plotstage = $selectedStage;
     2072
     2073      // data header
     2074      echo "   data.addColumn('datetime', 'Time');";
     2075      echo "   data.addColumn('number', 'Processed'); data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2076      echo "   data.addColumn('number', 'Pending')  ; data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2077      echo "   data.addColumn('number', 'Faults')   ; data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2078      echo "   data.addRows([";
     2079
     2080      //  query data from czardb
     2081      $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, processed, pending, faults, timestamp "
     2082            ."from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day) "
     2083            ."and (timestamp < utc_date() + INTERVAL 14 hour + interval $dayshift day) and label like '$selectedLabel';";
     2084      if ($debug) {echo "$sql<br>";}
     2085      $qry = $db->query($sql);
     2086      if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
     2087
     2088      // define last process and total process
     2089      list($lastproc, $sumproc) = array(-1, 0);
     2090      while ($qry->fetchInto($row)) {
     2091        // get UTC time info.
     2092        $tsp = explode('.', $row[0]);
     2093        $pending  = $row[2];
     2094        $faults   = $row[3];
     2095
     2096        // get HST time info.
     2097        $hsttime  = $row[4];
     2098
     2099        // get processing info. from selected stages and get time series.
     2100        $thisproc = $row[1]; list($thisproc, $lastproc, $sumproc) = gettotalprocessed($thisproc, $lastproc, $sumproc);
     2101        if ($pending < 200 & $faults < 200) {
     2102          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
     2103          echo "$sumproc, \"<i><b>$hsttime (HST) $sumproc $selectedStage processed </i></b> \", ";
     2104          echo "$pending, \"<i><b>$hsttime (HST) $pending $selectedStage pendings  </i></b> \", ";
     2105          echo "$faults , \"<i><b>$hsttime (HST) $faults  $selectedStage faults    </i></b> \" ], ";
     2106        } else {
     2107          echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
     2108          echo "$sumproc, \"<i><b>$hsttime (HST) $sumproc $selectedStage processed </i></b> \", ";
     2109          echo "0,        \"<i><b>$hsttime (HST) $pending $selectedStage pendings  </i></b> \", ";
     2110          echo "0 ,       \"<i><b>$hsttime (HST) $faults  $selectedStage faults    </i></b> \" ], ";
     2111        }
     2112      }
     2113    }
     2114    // data content end
     2115    echo "  ]);";
     2116   
     2117    // define x-axis range in terms of UTC from 0 to current time
     2118    $utcyy = gmdate("Y", strtotime("$dayshift day"));
     2119    $utcmm = gmdate("m", strtotime("$dayshift day"));
     2120    $utcdd = gmdate("d", strtotime("$dayshift day"));
     2121    if ($dayshift != 0) {
     2122      $utchh = 23;
     2123      $utcmn = 59;
     2124    } else {
     2125      $utchh = gmdate("H", strtotime("$dayshift day"));
     2126      $utcmn = gmdate("i", strtotime("$dayshift day"));
     2127    }
     2128
     2129    // linear plot options
     2130    echo " var opt_linear = {
     2131      title: 'Processed Items: $plotstage stages for $plotlabel labels on $proj',
     2132      titleTextStyle: {color: 'black', fontSize: 16},
     2133      width:  640, height: 400, fontSize: 12,
     2134      legend: { position: 'top', maxLines: 3 },
     2135      chartArea: {left:60, top:70, right:20, bottom:40},
     2136      tooltip: {isHtml: true},
     2137      hAxis: { 
     2138        title: 'Time on $utcyy-$utcmm-$utcdd (UTC)',
     2139        format: 'HH:mm',
     2140        gridlines: {count: -1},
     2141        viewWindow: {
     2142          min: new Date($utcyy, $utcmm-1, $utcdd, 0, 0, 0),
     2143          max: new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn)
     2144        }, 
     2145      },
     2146      vAxis: { 
     2147        title: 'Items',
     2148        gridlines: {count: -1},
     2149        viewWindow: {
     2150          min: 0.1
     2151        }, 
     2152      },
     2153      $plotseries
     2154    };";
     2155 
     2156    // draw linear function
     2157    echo "      function drawLinearChart() { ";
     2158    // for separately plot
     2159    # echo "        var linearChart = new google.visualization.LineChart(time_series_div_lin);";
     2160    echo "        var linearChart = new google.visualization.LineChart(time_series_div);";
     2161    echo "        linearChart.draw(data, opt_linear);";
     2162    echo "        button.innerText = 'Change y-axis to Log scale'  ; ";
     2163    echo "        button.onclick = drawLogChart; ";
     2164    echo "      } ";
     2165 
     2166    // log scale options
     2167    echo " var opt_log = {
     2168      title: 'Processed Items: $plotstage stages for $plotlabel labels on $proj',
     2169      titleTextStyle: {color: 'black', fontSize: 16},
     2170      width:  640, height: 400, fontSize: 12,
     2171      legend: { position: 'top', maxLines: 3 },
     2172      chartArea: {left:60, top:70, right:20, bottom:40},
     2173      tooltip: {isHtml: true},
     2174      hAxis: { 
     2175        title: 'Time on $utcyy-$utcmm-$utcdd (UTC)',
     2176        format: 'HH:mm',
     2177        gridlines: {count: -1},
     2178        viewWindow: {
     2179          min: new Date($utcyy, $utcmm-1, $utcdd, 0, 0, 0),
     2180          max: new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn)
     2181        }, 
     2182      },
     2183      vAxis: { 
     2184        title: 'Log(Items)',
     2185        scaleType: 'log',
     2186        gridlines: {count: -1},
     2187        viewWindow: {
     2188          min: 0.1
     2189        }, 
     2190      },
     2191      $plotseries
     2192    };";
     2193 
     2194    // draw log function
     2195    echo "      function drawLogChart() { ";
     2196    // for separately plot
     2197    #echo "        var logChart    = new google.visualization.LineChart(time_series_div_log);";
     2198    echo "        var logChart    = new google.visualization.LineChart(time_series_div);";
     2199    echo "        logChart.draw(data,       opt_log);";
     2200    echo "        button.innerText = 'Change y-axis to Linear scale';";
     2201    echo "        button.onclick = drawLinearChart; ";
     2202    echo "      } ";
     2203 
     2204    // default plot in linear scale
     2205    echo "   drawLinearChart(); ";
     2206    #echo "   drawLogChart(); ";
     2207    echo " }";
     2208 
     2209    // end javascript
     2210    echo "</script>";
     2211 
     2212    // timer end
     2213    $time = microtime();
     2214    $time = explode(' ', $time);
     2215    $time = $time[1] + $time[0];
     2216    $finish = $time;
     2217    $total_time = round(($finish - $start), 3);
     2218    $start= $finish;
     2219    echo "<center>loading in $total_time seconds</center>";
     2220}
     2221
     2222// sub function to find total processed items
     2223function gettotalprocessed ($thisProcessed, $lastProcessed, $totalProcessed) {
     2224  if($thisProcessed > $lastProcessed & $lastProcessed != -1) {
     2225      if ($thisProcessed - $lastProcessed < 50) {
     2226          $totalProcessed = $totalProcessed + $thisProcessed - $lastProcessed;
     2227      } else {
     2228          $totalProcessed = $totalProcessed;
     2229      }
     2230  }
     2231  $lastProcessed = $thisProcessed;
     2232  return array($thisProcessed, $lastProcessed, $totalProcessed);
     2233}
     2234
     2235###########################################################################
     2236#
     2237# Gets rate series plot
     2238#
     2239###########################################################################
     2240function Getrate($db, $selectedMode, $selectedLabel, $proj, $selectedStage) {
     2241    // timer start
     2242    $time = microtime();
     2243    $time = explode(' ', $time);
     2244    $time = $time[1] + $time[0];
     2245    $start = $time;
     2246
     2247    #echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>";
     2248    echo "<script type=\"text/javascript\" src=\"loader.js\"></script>";
     2249    echo "<br><div id=\"rate_series_div\" style=\"width:640; height:400\"></div>";
     2250
     2251    echo "<script type=\"text/javascript\">";
     2252    echo "google.charts.load('current', {packages: ['corechart']});";
     2253    echo "google.charts.setOnLoadCallback(drawChart);";
     2254    // draw funciton start
     2255    echo "function drawChart() {";
     2256    echo "  var data = new google.visualization.DataTable();";
     2257
     2258    if ($selectedLabel == "all") {
     2259       $selectedLabel = "stdscience_labels";
     2260       $plotlabel = "all"; }
     2261    else {
     2262       $plotlabel = $selectedLabel;
     2263    }
     2264
     2265    $dayshift = -0;
     2266    $binsize = 30; // 30 mins gap
     2267    $bshift  = 5; // 10 mins step
     2268    $difflimit = 100; // diff items limit for a time interval
     2269    $plotscale = 50; // diff items limit for a time interval
     2270    if ($selectedStage == "all_stages") {
     2271      $plotstage = "all";
     2272      $plottitle = "title: 'Items per hour + N x 50 offset',";
     2273      $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
     2274      $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, ";
     2275      $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     2276      $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, ";
     2277      $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, ";
     2278      $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     2279      $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, ";
     2280      $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     2281      $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, ";
     2282      $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, ";
     2283      $plotseries .= "             10: { color: 'cyan'    , lineWidth: 2, lineDashStyle: [3, 4]}, ";
     2284      $plotseries .= "             11: { color: '#c51b7d' , lineWidth: 2, lineDashStyle: [3, 4]}, ";
     2285      $plotseries .= "             12: { color: '#b15928' , lineWidth: 2, lineDashStyle: [3, 4]}, ";
     2286      $plotseries .= "             13: { color: '#000004' , lineWidth: 2, lineDashStyle: [3, 4]}, },";
     2287      if ($selectedLabel == "stdscience_labels") {
     2288        echo "  data.addColumn('datetime',        'Time');";
     2289        echo "  data.addColumn(  'number',        'chip');";
     2290        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2291        echo "  data.addColumn(  'number',         'cam');";
     2292        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2293        echo "  data.addColumn(  'number',        'fake');";
     2294        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2295        echo "  data.addColumn(  'number',        'warp');";
     2296        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2297        echo "  data.addColumn(  'number',       'stack');";
     2298        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2299        echo "  data.addColumn(  'number',   'staticsky');";
     2300        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2301        echo "  data.addColumn(  'number',        'diff');";
     2302        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2303        echo "  data.addColumn(  'number',   'fullforce');";
     2304        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2305        echo "  data.addColumn(  'number',        'dist');";
     2306        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2307        echo "  data.addColumn(  'number',         'pub');";
     2308        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2309        echo "  data.addColumn(  'number',   'summitExp');";
     2310        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2311        echo "  data.addColumn(  'number', 'downloadExp');";
     2312        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2313        echo "  data.addColumn(  'number',      'newExp');";
     2314        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2315        echo "  data.addColumn(  'number',      'rawExp');";
     2316        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2317        echo "   data.addRows([";
     2318
     2319      $datemin  = -$dayshift*1440+gmdate("H")*60+gmdate("i");
     2320      for ($t_i = 0; $t_i <= $datemin/$bshift; $t_i++) {
     2321        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, summrun.proc as sumproc, downrun.proc as downproc, newrun.proc as newproc, rawrun.proc as rawproc, timestamp";
     2322        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from rawExp   ,   (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as rawrun                ";
     2323        $sql.= " join (select @rank2:=@rank2+1 AS rank,            processed as proc from newExp   ,   (select @rank2:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as newrun   using (rank) ";
     2324        $sql.= " join (select @rank3:=@rank3+1 AS rank,            processed as proc from summitExp,   (select @rank3:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as summrun  using (rank) ";
     2325        $sql.= " join (select @rank4:=@rank4+1 AS rank,            processed as proc from downloadExp, (select @rank4:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as downrun  using (rank) ";
     2326        $sql.= " join (select @rank5:=@rank5+1 AS rank,            processed as proc from chip,        (select @rank5:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun  using (rank) ";
     2327        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
     2328        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
     2329        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
     2330        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
     2331        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
     2332        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
     2333        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
     2334        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
     2335        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp limit 1;";
     2336        $qry = $db->query($sql);
     2337        $qry->fetchInto($row);
     2338        list($tstamp, $chipproc0, $camproc0, $fakeproc0, $warpproc0, $stackproc0, $statproc0, $diffproc0, $ffproc0, $distproc0, $pubproc0, $sumproc0, $downproc0, $newproc0, $rawproc0, $hsttime) = $row;
     2339//        $tsp = explode('.', $tstamp);
     2340 
     2341        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, summrun.proc as sumproc, downrun.proc as downproc, newrun.proc as newproc, rawrun.proc as rawproc, timestamp";
     2342        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from rawExp   ,   (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as rawrun                ";
     2343        $sql.= " join (select @rank2:=@rank2+1 AS rank,            processed as proc from newExp   ,   (select @rank2:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as newrun   using (rank) ";
     2344        $sql.= " join (select @rank3:=@rank3+1 AS rank,            processed as proc from summitExp,   (select @rank3:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as summrun  using (rank) ";
     2345        $sql.= " join (select @rank4:=@rank4+1 AS rank,            processed as proc from downloadExp, (select @rank4:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as downrun  using (rank) ";
     2346        $sql.= " join (select @rank5:=@rank5+1 AS rank,            processed as proc from chip,        (select @rank5:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun  using (rank) ";
     2347        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
     2348        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
     2349        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
     2350        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
     2351        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
     2352        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
     2353        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
     2354        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
     2355        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp desc limit 1;";
     2356        $qry = $db->query($sql);
     2357        $qry->fetchInto($row);
     2358        list($tstamp, $chipproc1, $camproc1, $fakeproc1, $warpproc1, $stackproc1, $statproc1, $diffproc1, $ffproc1, $distproc1, $pubproc1, $sumproc1, $downproc1, $newproc1, $rawproc1, $hsttime) = $row;
     2359        list( $chip_diff,  $chip_rate) = getprocrate( $chipproc1 ,  $chipproc0, $binsize);
     2360        list(  $cam_diff,   $cam_rate) = getprocrate(  $camproc1 ,   $camproc0, $binsize);
     2361        list( $fake_diff,  $fake_rate) = getprocrate( $fakeproc1 ,  $fakeproc0, $binsize);
     2362        list( $warp_diff,  $warp_rate) = getprocrate( $warpproc1 ,  $warpproc0, $binsize);
     2363        list($stack_diff, $stack_rate) = getprocrate($stackproc1 , $stackproc0, $binsize);
     2364        list( $stat_diff,  $stat_rate) = getprocrate( $statproc1 ,  $statproc0, $binsize);
     2365        list( $diff_diff,  $diff_rate) = getprocrate( $diffproc1 ,  $diffproc0, $binsize);
     2366        list(   $ff_diff,    $ff_rate) = getprocrate(   $ffproc1 ,    $ffproc0, $binsize);
     2367        list( $dist_diff,  $dist_rate) = getprocrate( $distproc1 ,  $distproc0, $binsize);
     2368        list(  $pub_diff,   $pub_rate) = getprocrate(  $pubproc1 ,   $pubproc0, $binsize);
     2369        list(  $raw_diff,   $raw_rate) = getprocrate(  $rawproc1 ,   $rawproc0, $binsize);
     2370        list(  $new_diff,   $new_rate) = getprocrate(  $newproc1 ,   $newproc0, $binsize);
     2371        list(  $sum_diff,   $sum_rate) = getprocrate(  $sumproc1 ,   $sumproc0, $binsize);
     2372        list( $down_diff,  $down_rate) = getprocrate( $downproc1 ,  $downproc0, $binsize);
     2373
     2374        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp)) - 14*3600 ), \"%H.%i.%s\"), date_format(timestamp, \"%Y-%m-%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp))), \"%H:%i:%s\") from rawExp where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj'";
     2375        $qry = $db->query($sql);
     2376        $qry->fetchinto($row);
     2377        list($datestamp, $timestamp, $hstdate, $hsttime) = $row;
     2378        $dsp = explode('.', $datestamp);
     2379        $tsp = explode('.', $timestamp);
     2380
     2381        $utcyy = gmdate("Y", strtotime("$dayshift day"));
     2382        $utcmm = gmdate("m", strtotime("$dayshift day"));
     2383        $utcdd = gmdate("d", strtotime("$dayshift day"));
     2384        $utchh = floor($t_i*$bshift/60);
     2385        $utcmn = $t_i*$bshift % 60;
     2386        $hstdatetime = date("Y-m-d H:i", strtotime($utcyy."-".$utcmm."-".$utcdd." ".$utchh.":".$utcmn.":00"." UTC"));
     2387        if ($row[0] != NULL & $dsp[2] == $utcdd) {
     2388          if ($chip_diff < 0 || $cam_diff < 0 || $fake_diff < 0 || $warp_diff < 0 || $stack_diff < 0 || $stat_diff < 0 || $diff_diff < 0 || $ff_diff < 0 || $dist_diff < 0 || $pub_diff < 0 || $raw_diff < 0 || $new_diff < 0 || $sum_diff < 0 || $down_idff < 0 || $chip_diff > $difflimit || $cam_diff > $difflimit || $fake_diff > $difflimit || $warp_diff > $difflimit || $stack_diff > $difflimit || $stat_diff > $difflimit || $diff_diff > $difflimit || $ff_diff > $difflimit || $dist_diff > $difflimit || $pub_diff > $difflimit || $raw_diff > $difflimit || $new_diff > $difflimit || $sum_diff > $difflimit || $down_idff > $difflimit) {
     2389//            echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4]), ";
     2390            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2391            echo " 0, \"<i><b>$hstdatetime (HST) 0 chip/hr       </i></b>\", "; //+10*50 chip
     2392            echo " 0, \"<i><b>$hstdatetime (HST) 0 cam/hr        </i></b>\", "; //+ 9*50 cam
     2393            echo " 0, \"<i><b>$hstdatetime (HST) 0 fake/hr       </i></b>\", "; //+ 8*50 fake
     2394            echo " 0, \"<i><b>$hstdatetime (HST) 0 warp/hr       </i></b>\", "; //+ 7*50 warp
     2395            echo " 0, \"<i><b>$hstdatetime (HST) 0 stack/hr      </i></b>\", "; //+ 0*50 stack
     2396            echo " 0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr  </i></b>\", "; //+ 0*50 staticsky
     2397            echo " 0, \"<i><b>$hstdatetime (HST) 0 diff/hr       </i></b>\", "; //+ 6*50 diff
     2398            echo " 0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr  </i></b>\", "; //+ 0*50 fullforce
     2399            echo " 0, \"<i><b>$hstdatetime (HST) 0 dist/hr       </i></b>\", "; //+ 5*50 dist
     2400            echo " 0, \"<i><b>$hstdatetime (HST) 0 pub/hr        </i></b>\", "; //+ 4*50 pub
     2401            echo " 0, \"<i><b>$hstdatetime (HST) 0 summitExp/hr  </i></b>\", "; //+ 3*50 summitExp
     2402            echo " 0, \"<i><b>$hstdatetime (HST) 0 downloadExp/hr</i></b>\", "; //+ 2*50 downloadExp
     2403            echo " 0, \"<i><b>$hstdatetime (HST) 0 newExp/hr     </i></b>\", "; //+ 1*50 newExp
     2404            echo " 0, \"<i><b>$hstdatetime (HST) 0 rawExp/hr     </i></b>\", "; //+ 0*50 rawExp
     2405            echo "],";
     2406//            echo "], $t_i, <br>";
     2407          } else {
     2408//            echo "[new Date($tsp[0], $tsp[1]-1, $tsp[2], $tsp[3], $tsp[4], $tsp[5]), ";
     2409            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2410            echo "  $chip_rate, \"<i><b>$hstdatetime (HST)  $chip_rate  chip/hr       </i></b> \", "; //+10*50 chip
     2411            echo "   $cam_rate, \"<i><b>$hstdatetime (HST)   $cam_rate  cam/hr        </i></b> \", "; //+ 9*50 cam
     2412            echo "  $fake_rate, \"<i><b>$hstdatetime (HST)  $fake_rate  fake/hr       </i></b> \", "; //+ 8*50 fake
     2413            echo "  $warp_rate, \"<i><b>$hstdatetime (HST)  $warp_rate  warp/hr       </i></b> \", "; //+ 7*50 warp
     2414            echo " $stack_rate, \"<i><b>$hstdatetime (HST) $stack_rate  stack/hr      </i></b> \", "; //+ 0*50 stack
     2415            echo "  $stat_rate, \"<i><b>$hstdatetime (HST)  $stat_rate  staticsky/hr  </i></b> \", "; //+ 0*50 staticsky
     2416            echo "  $diff_rate, \"<i><b>$hstdatetime (HST)  $diff_rate  diff/hr       </i></b> \", "; //+ 6*50 diff
     2417            echo "    $ff_rate, \"<i><b>$hstdatetime (HST)    $ff_rate  fullforce/hr  </i></b> \", "; //+ 0*50 fullforce
     2418            echo "  $dist_rate, \"<i><b>$hstdatetime (HST)  $dist_rate  dist/hr       </i></b> \", "; //+ 5*50 dist
     2419            echo "   $pub_rate, \"<i><b>$hstdatetime (HST)   $pub_rate  pub/hr        </i></b> \", "; //+ 4*50 pub
     2420            echo "   $sum_rate, \"<i><b>$hstdatetime (HST)   $sum_rate  summitExp/hr  </i></b> \", "; //+ 3*50 summitExp
     2421            echo "  $down_rate, \"<i><b>$hstdatetime (HST)  $down_rate  downloadExp/hr</i></b> \", "; //+ 2*50 downloadExp
     2422            echo "   $new_rate, \"<i><b>$hstdatetime (HST)   $new_rate  newExp/hr     </i></b> \", "; //+ 1*50 newExp
     2423            echo "   $raw_rate, \"<i><b>$hstdatetime (HST)   $raw_rate  rawExp/hr     </i></b> \", "; //+ 0*50 rawExp
     2424            echo "],";
     2425//            echo "], $t_i, <br>";
     2426          }
     2427        } else {
     2428            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2429            echo " 0, \"<i><b>$hstdatetime (HST) 0 chip/hr       </i></b>\", "; //+10*50 chip
     2430            echo " 0, \"<i><b>$hstdatetime (HST) 0 cam/hr        </i></b>\", "; //+ 9*50 cam
     2431            echo " 0, \"<i><b>$hstdatetime (HST) 0 fake/hr       </i></b>\", "; //+ 8*50 fake
     2432            echo " 0, \"<i><b>$hstdatetime (HST) 0 warp/hr       </i></b>\", "; //+ 7*50 warp
     2433            echo " 0, \"<i><b>$hstdatetime (HST) 0 stack/hr      </i></b>\", "; //+ 0*50 stack
     2434            echo " 0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr  </i></b>\", "; //+ 0*50 staticsky
     2435            echo " 0, \"<i><b>$hstdatetime (HST) 0 diff/hr       </i></b>\", "; //+ 6*50 diff
     2436            echo " 0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr  </i></b>\", "; //+ 0*50 fullforce
     2437            echo " 0, \"<i><b>$hstdatetime (HST) 0 dist/hr       </i></b>\", "; //+ 5*50 dist
     2438            echo " 0, \"<i><b>$hstdatetime (HST) 0 pub/hr        </i></b>\", "; //+ 4*50 pub
     2439            echo " 0, \"<i><b>$hstdatetime (HST) 0 summitExp/hr  </i></b>\", "; //+ 3*50 summitExp
     2440            echo " 0, \"<i><b>$hstdatetime (HST) 0 downloadExp/hr</i></b>\", "; //+ 2*50 downloadExp
     2441            echo " 0, \"<i><b>$hstdatetime (HST) 0 newExp/hr     </i></b>\", "; //+ 1*50 newExp
     2442            echo " 0, \"<i><b>$hstdatetime (HST) 0 rawExp/hr     </i></b>\", "; //+ 0*50 rawExp
     2443            echo "],";
     2444//            echo "], $t_i, <br>";
     2445        }
     2446       }
     2447      }
     2448      else {
     2449        $plottitle = "title: 'Items per hour + N x 50 offset',";
     2450        $plotseries  = "    series: { 0: { color: '#a6cee3' , lineWidth: 2                       }, ";
     2451        $plotseries .= "              1: { color: '#1f78b4' , lineWidth: 2                       }, ";
     2452        $plotseries .= "              2: { color: '#fb9a99' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     2453        $plotseries .= "              3: { color: '#e31a1c' , lineWidth: 2                       }, ";
     2454        $plotseries .= "              4: { color: '#33a02c' , lineWidth: 2                       }, ";
     2455        $plotseries .= "              5: { color: '#b2df8a' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     2456        $plotseries .= "              6: { color: '#ff7f00' , lineWidth: 2                       }, ";
     2457        $plotseries .= "              7: { color: '#fdbf6f' , lineWidth: 2, lineDashStyle: [8, 4]}, ";
     2458        $plotseries .= "              8: { color: '#cab2d6' , lineWidth: 2                       }, ";
     2459        $plotseries .= "              9: { color: '#6a3d9a' , lineWidth: 2                       }, },";
     2460        echo "  data.addColumn('datetime',        'Time');";
     2461        echo "  data.addColumn(  'number',        'chip');";
     2462        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2463        echo "  data.addColumn(  'number',         'cam');";
     2464        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2465        echo "  data.addColumn(  'number',        'fake');";
     2466        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2467        echo "  data.addColumn(  'number',        'warp');";
     2468        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2469        echo "  data.addColumn(  'number',       'stack');";
     2470        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2471        echo "  data.addColumn(  'number',   'staticsky');";
     2472        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2473        echo "  data.addColumn(  'number',        'diff');";
     2474        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2475        echo "  data.addColumn(  'number',   'fullforce');";
     2476        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2477        echo "  data.addColumn(  'number',        'dist');";
     2478        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2479        echo "  data.addColumn(  'number',         'pub');";
     2480        echo "  data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2481        echo "   data.addRows([";
     2482 
     2483      $datemin  = -$dayshift*1440+gmdate("H")*60+gmdate("i");
     2484      for ($t_i = 0; $t_i <= $datemin/$bshift; $t_i++) {
     2485        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, timestamp";
     2486        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from chip,        (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun              ";
     2487        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
     2488        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
     2489        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
     2490        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
     2491        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
     2492        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
     2493        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
     2494        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
     2495        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp limit 1;";
     2496        $qry = $db->query($sql);
     2497        $qry->fetchInto($row);
     2498        list($tstamp, $chipproc0, $camproc0, $fakeproc0, $warpproc0, $stackproc0, $statproc0, $diffproc0, $ffproc0, $distproc0, $pubproc0, $hsttime) = $row;
     2499 //       $tsp = explode('.', $tstamp);
     2500
     2501        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i.%s\") as dated, chiprun.proc as chipproc, camrun.proc as camproc, fakerun.proc as fakeproc, warprun.proc as warpproc, stackrun.proc as stackproc, statrun.proc as statproc, diffrun.proc as diffproc, ffrun.proc as ffproc, distrun.proc as distproc, pubrun.proc as pubproc, timestamp";
     2502        $sql.= " from (select @rank1:=@rank1+1 AS rank, timestamp, processed as proc from chip,        (select @rank1:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as chiprun              ";
     2503        $sql.= " join (select @rank6:=@rank6+1 AS rank,            processed as proc from cam,         (select @rank6:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as camrun   using (rank) ";
     2504        $sql.= " join (select @rank7:=@rank7+1 AS rank,            processed as proc from fake,        (select @rank7:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as fakerun  using (rank) ";
     2505        $sql.= " join (select @rank8:=@rank8+1 AS rank,            processed as proc from cam,         (select @rank8:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as warprun  using (rank) ";
     2506        $sql.= " join (select @rank9:=@rank9+1 AS rank,            processed as proc from stack,       (select @rank9:=0)  r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as stackrun using (rank) ";
     2507        $sql.= " join (select @rank10:=@rank10+1 AS rank,          processed as proc from staticsky,   (select @rank10:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as statrun  using (rank) ";
     2508        $sql.= " join (select @rank11:=@rank11+1 AS rank,          processed as proc from diff,        (select @rank11:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as diffrun  using (rank) ";
     2509        $sql.= " join (select @rank12:=@rank12+1 AS rank,          processed as proc from fullforce,   (select @rank12:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as ffrun    using (rank) ";
     2510        $sql.= " join (select @rank13:=@rank13+1 AS rank,          processed as proc from dist,        (select @rank13:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as distrun  using (rank) ";
     2511        $sql.= " join (select @rank14:=@rank14+1 AS rank,          processed as proc from pub,         (select @rank14:=0) r where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj') as pubrun   using (rank) order by timestamp desc limit 1;";
     2512        $qry = $db->query($sql);
     2513        $qry->fetchInto($row);
     2514        list($tstamp, $chipproc1, $camproc1, $fakeproc1, $warpproc1, $stackproc1, $statproc1, $diffproc1, $ffproc1, $distproc1, $pubproc1, $hsttime) = $row;
     2515        list( $chip_diff,  $chip_rate) = getprocrate( $chipproc1 ,  $chipproc0, $binsize);
     2516        list(  $cam_diff,   $cam_rate) = getprocrate(  $camproc1 ,   $camproc0, $binsize);
     2517        list( $fake_diff,  $fake_rate) = getprocrate( $fakeproc1 ,  $fakeproc0, $binsize);
     2518        list( $warp_diff,  $warp_rate) = getprocrate( $warpproc1 ,  $warpproc0, $binsize);
     2519        list($stack_diff, $stack_rate) = getprocrate($stackproc1 , $stackproc0, $binsize);
     2520        list( $stat_diff,  $stat_rate) = getprocrate( $statproc1 ,  $statproc0, $binsize);
     2521        list( $diff_diff,  $diff_rate) = getprocrate( $diffproc1 ,  $diffproc0, $binsize);
     2522        list(   $ff_diff,    $ff_rate) = getprocrate(   $ffproc1 ,    $ffproc0, $binsize);
     2523        list( $dist_diff,  $dist_rate) = getprocrate( $distproc1 ,  $distproc0, $binsize);
     2524        list(  $pub_diff,   $pub_rate) = getprocrate(  $pubproc1 ,   $pubproc0, $binsize);
     2525
     2526        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp)) - 14*3600 ), \"%H.%i.%s\"), date_format(timestamp, \"%Y-%m-%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp))), \"%H:%i:%s\") from chip where label like '$selectedLabel' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and dbname like '$proj'";
     2527        $qry = $db->query($sql);
     2528        $qry->fetchinto($row);
     2529        list($datestamp, $timestamp, $hstdate, $hsttime) = $row;
     2530        $dsp = explode('.', $datestamp);
     2531        $tsp = explode('.', $timestamp);
     2532
     2533        $utcyy = gmdate("Y", strtotime("$dayshift day"));
     2534        $utcmm = gmdate("m", strtotime("$dayshift day"));
     2535        $utcdd = gmdate("d", strtotime("$dayshift day"));
     2536        $utchh = floor($t_i*$bshift/60);
     2537        $utcmn = $t_i*$bshift % 60;
     2538        $hstdatetime = date("Y-m-d H:i", strtotime($utcyy."-".$utcmm."-".$utcdd." ".$utchh.":".$utcmn.":00"." UTC"));
     2539        if ($row[0] != NULL & $dsp[2] == $utcdd) {
     2540          if ($chip_diff < 0 || $cam_diff < 0 || $fake_diff < 0 || $warp_diff < 0 || $stack_diff < 0 || $stat_diff < 0 || $diff_diff < 0 || $ff_diff < 0 || $dist_diff < 0 || $pub_diff < 0 || $chip_diff > $difflimit || $cam_diff > $difflimit || $fake_diff > $difflimit || $warp_diff > $difflimit || $stack_diff > $difflimit || $stat_diff > $difflimit || $diff_diff > $difflimit || $ff_diff > $difflimit || $dist_diff > $difflimit || $pub_diff > $difflimit) {
     2541//            echo "[new Date($dsp[0], $dsp[1]-1, $dsp[2], $tsp[0], $tsp[1]), ";
     2542            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2543            echo "  0, \"<i><b>$hstdatetime (HST) 0 chip/hr     </i></b> \","; //+ 6*50 chip
     2544            echo "  0, \"<i><b>$hstdatetime (HST) 0 cam/hr      </i></b> \","; //+ 5*50 cam
     2545            echo "  0, \"<i><b>$hstdatetime (HST) 0 fake/hr     </i></b> \","; //+ 4*50 fake
     2546            echo "  0, \"<i><b>$hstdatetime (HST) 0 warp/hr     </i></b> \","; //+ 3*50 warp
     2547            echo "  0, \"<i><b>$hstdatetime (HST) 0 stack/hr    </i></b> \","; //+ 0*50 stack
     2548            echo "  0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr</i></b> \","; //+ 0*50 staticsky
     2549            echo "  0, \"<i><b>$hstdatetime (HST) 0 diff/hr     </i></b> \","; //+ 2*50 diff
     2550            echo "  0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr</i></b> \","; //+ 0*50 fullforce
     2551            echo "  0, \"<i><b>$hstdatetime (HST) 0 dist/hr     </i></b> \","; //+ 1*50 dist
     2552            echo "  0, \"<i><b>$hstdatetime (HST) 0 pub/hr      </i></b> \","; //+ 0*50 pub
     2553            echo "], ";
     2554          } else {
     2555//            echo "[new Date($dsp[0], $dsp[1]-1, $dsp[2], $tsp[0], $tsp[1]), ";
     2556            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2557            echo "  $chip_rate, \"<i><b>$hstdatetime (HST)  $chip_rate chip/hr     </i></b> \","; //+ 6*50 chip
     2558            echo "   $cam_rate, \"<i><b>$hstdatetime (HST)   $cam_rate cam/hr      </i></b> \","; //+ 5*50 cam
     2559            echo "  $fake_rate, \"<i><b>$hstdatetime (HST)  $fake_rate fake/hr     </i></b> \","; //+ 4*50 fake
     2560            echo "  $warp_rate, \"<i><b>$hstdatetime (HST)  $warp_rate warp/hr     </i></b> \","; //+ 3*50 warp
     2561            echo " $stack_rate, \"<i><b>$hstdatetime (HST) $stack_rate stack/hr    </i></b> \","; //+ 0*50 stack
     2562            echo "  $stat_rate, \"<i><b>$hstdatetime (HST)  $stat_rate staticsky/hr</i></b> \","; //+ 0*50 staticsky
     2563            echo "  $diff_rate, \"<i><b>$hstdatetime (HST)  $diff_rate diff/hr     </i></b> \","; //+ 2*50 diff
     2564            echo "    $ff_rate, \"<i><b>$hstdatetime (HST)    $ff_rate fullforce/hr</i></b> \","; //+ 0*50 fullforce
     2565            echo "  $dist_rate, \"<i><b>$hstdatetime (HST)  $dist_rate dist/hr     </i></b> \","; //+ 1*50 dist
     2566            echo "   $pub_rate, \"<i><b>$hstdatetime (HST)   $pub_rate pub/hr      </i></b> \","; //+ 0*50 pub
     2567            echo "], ";
     2568          } 
     2569        } else {
     2570            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2571            echo "  0, \"<i><b>$hstdatetime (HST) 0 chip/hr     </i></b> \","; //+ 6*50 chip
     2572            echo "  0, \"<i><b>$hstdatetime (HST) 0 cam/hr      </i></b> \","; //+ 5*50 cam
     2573            echo "  0, \"<i><b>$hstdatetime (HST) 0 fake/hr     </i></b> \","; //+ 4*50 fake
     2574            echo "  0, \"<i><b>$hstdatetime (HST) 0 warp/hr     </i></b> \","; //+ 3*50 warp
     2575            echo "  0, \"<i><b>$hstdatetime (HST) 0 stack/hr    </i></b> \","; //+ 0*50 stack
     2576            echo "  0, \"<i><b>$hstdatetime (HST) 0 staticsky/hr</i></b> \","; //+ 0*50 staticsky
     2577            echo "  0, \"<i><b>$hstdatetime (HST) 0 diff/hr     </i></b> \","; //+ 2*50 diff
     2578            echo "  0, \"<i><b>$hstdatetime (HST) 0 fullforce/hr</i></b> \","; //+ 0*50 fullforce
     2579            echo "  0, \"<i><b>$hstdatetime (HST) 0 dist/hr     </i></b> \","; //+ 1*50 dist
     2580            echo "  0, \"<i><b>$hstdatetime (HST) 0 pub/hr      </i></b> \","; //+ 0*50 pub
     2581            echo "], ";
     2582        }
     2583      }
     2584    }
     2585    }
     2586    else {
     2587      $plottitle = "title: 'Items per hour',";
     2588      echo "  data.addColumn('datetime',          'Time');";
     2589      echo "  data.addColumn(  'number','$selectedStage');";
     2590      echo "   data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});";
     2591      echo "   data.addRows([";
     2592      $plotstage = $selectedStage;
     2593      $plotseries  = "    series: { 0: { color: '#33a532', lineWidth: 3 }, },";
     2594      $binsize = 30; // 30 mins gap
     2595      $bshift  = 2; // 2 mins step
     2596      $datemin  = -$dayshift*1440+gmdate("H")*60+gmdate("i");
     2597      for ($t_i = 0; $t_i <= $datemin/$bshift; $t_i++) {
     2598        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i\") as dated, processed, timestamp from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and label like '$selectedLabel' order by timestamp limit 1;";
     2599        $qry = $db->query($sql);
     2600        $qry->fetchinto($row);
     2601        list($tstamp, $stageproc0) = $row;
     2602 
     2603        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d.%H.%i\") as dated, processed, timestamp from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and label like '$selectedLabel' order by timestamp desc limit 1;";
     2604        $qry = $db->query($sql);
     2605        $qry->fetchinto($row);
     2606        list($tstamp, $stageproc1) = $row;
     2607
     2608        $sql = "select date_format(addtime(timestamp, '10:00:00'), \"%Y.%m.%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp)) - 14*3600 ), \"%H.%i.%s\"), date_format(timestamp, \"%Y-%m-%d\"), time_format(sec_to_time(avg(time_to_sec(timestamp))), \"%H:%i:%s\") from $selectedStage where dbname like '$proj' and (timestamp > utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift-$binsize/2 minute) and (timestamp < utc_date() - INTERVAL 10 hour + interval $dayshift day + interval $t_i*$bshift+$binsize/2 minute) and label like '$selectedLabel';";
     2609        $qry = $db->query($sql);
     2610        $qry->fetchinto($row);
     2611        list($datestamp, $timestamp, $hstdate, $hsttime) = $row;
     2612        $dsp = explode('.', $datestamp);
     2613        $tsp = explode('.', $timestamp);
     2614
     2615
     2616        list(  $stage_diff,   $stage_rate) = getprocrate(  $stageproc1 , $stageproc0, $binsize);
     2617 
     2618        $utcyy = gmdate("Y", strtotime("$dayshift day"));
     2619        $utcmm = gmdate("m", strtotime("$dayshift day"));
     2620        $utcdd = gmdate("d", strtotime("$dayshift day"));
     2621        $utchh = floor($t_i*$bshift/60);
     2622        $utcmn = $t_i*$bshift % 60;
     2623        $hstdatetime = date("Y-m-d H:i", strtotime($utcyy."-".$utcmm."-".$utcdd." ".$utchh.":".$utcmn.":00"." UTC"));
     2624        if ($row[0] != null & $dsp[2] == $utcdd) {
     2625          if ($stage_diff < 0 || $stage_diff > $difflimit) {
     2626            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2627            echo " 0, \"<i><b> $hstdatetime (HST) 0 $selectedStage/hr</i></b> \", ";
     2628            echo "], ";
     2629          } else {
     2630            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2631            echo " $stage_rate, \"<i><b> $hstdatetime (HST) $stage_rate $selectedStage/hr</i></b> \", ";
     2632            echo "], ";
     2633          }
     2634        } else {
     2635            echo "[new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn), ";
     2636            echo " 0, \"<i><b> $hstdatetime (HST) 0 $selectedStage/hr</i></b> \", ";
     2637            echo "], ";
     2638        }
     2639      }
     2640   }
     2641
     2642   $utcyy = gmdate("Y", strtotime("$dayshift day"));
     2643   $utcmm = gmdate("m", strtotime("$dayshift day"));
     2644   $utcdd = gmdate("d", strtotime("$dayshift day"));
     2645   if ($dayshift != 0) {
     2646     $utchh = 23;
     2647     $utcmn = 59;
     2648   } else {
     2649     $utchh = gmdate("H", strtotime("$dayshift day"));
     2650     $utcmn = gmdate("i", strtotime("$dayshift day"));
     2651   }
     2652   echo "  ]);";
     2653
     2654
     2655    // linear plot options
     2656    echo " var options = {
     2657      title: 'Processed Items: $plotstage stages for $plotlabel labels on $proj',
     2658      titleTextStyle: {color: 'black', fontSize: 16},
     2659      width:  640, height: 400, fontSize: 12,
     2660      legend: { position: 'top', maxLines: 3 },
     2661      chartArea: {left:60, top:70, right:20, bottom:40},
     2662      tooltip: {isHtml: true},
     2663      hAxis: { 
     2664        title: 'Time on $utcyy-$utcmm-$utcdd (UTC)',
     2665        format: 'HH:mm',
     2666        gridlines: {count: -1},
     2667        viewWindow: {
     2668          min: new Date($utcyy, $utcmm-1, $utcdd, 0, 0, 0),
     2669          max: new Date($utcyy, $utcmm-1, $utcdd, $utchh, $utcmn)
     2670        }, 
     2671      },
     2672      vAxis: { 
     2673        title: 'Items per hour',
     2674        gridlines: {count: -1},
     2675      },
     2676      $plotseries
     2677    };";
     2678
     2679
     2680   echo "   var chart = new google.visualization.LineChart(document.getElementById('rate_series_div'));";
     2681   echo "   chart.draw(data, options);";
     2682   echo " }";
     2683   echo "</script>";
     2684
     2685    $time = microtime();
     2686    $time = explode(' ', $time);
     2687    $time = $time[1] + $time[0];
     2688    $finish = $time;
     2689    $total_time = round(($finish - $start), 3);
     2690    $start= $finish;
     2691    echo "<center>loading in $total_time seconds<br></center>";
     2692#    echo $sql;
     2693}
     2694
     2695function getprocrate ($proc1, $proc0, $trange) {
     2696  if($proc1 > $proc0) {
     2697    $diffproc = $proc1-$proc0;
     2698  } else {
     2699    $diffproc = 0;
     2700  }
     2701  $procrate = $diffproc / $trange * 60;
     2702  return array($diffproc, $procrate);
     2703}
     2704
     2705
    17732706
    17742707?>
  • tags/ipp-ps1-20210510/ippMonitor/raw/site.php

    r41381 r41697  
    66$WWWHOST    = "ipp113.ifa.hawaii.edu";
    77
    8 $PERLLIB    = "/data/ippc18.0/home/tdeboer/ipp/default.lin64/lib";
     8$PERLLIB    = "/data/ippc64.1/ippitc/psconfig/ipp-20170121.lin64/lib";
    99$BINDIR     = "/data/ippc64.1/ippitc/psconfig/ipp-20170121.lin64/bin";
    10 $LIBDIR     = "/data/ippc18.0/home/tdeboer/ipp/default.lin64/lib";
     10$LIBDIR     = "/data/ippc64.1/ippitc/psconfig/ipp-20170121.lin64/lib";
    1111$SITE       = "/data/ippc64.1/ippitc/ippconfig/ippmonitor.config";
    1212
    1313$DBI     = "DB";
     14
     15// location of plots produced by czarpoll.pl
     16$CZARPLOTDIR     = "./czartool_plots";
     17$METRICSPLOTDIR  = "./ippMetrics";
    1418
    1519// insert config.dat here. this contains a number of system-specific things like
     
    1822
    1923// host and user information for the main processing database (contains, e.g., gpc1, gpc2, etc)
    20 $DBHOST    = "ippdb08";
    21 $DBUSER    = "ippuser";
    22 $DBPASS    = "ippuser";
     24$DBHOST    = "ippdb05";
     25$DBUSER    = "ipp";
     26$DBPASS    = "ipp";
    2327
    2428// location of nebulous apache interface machine
    25 $NEB_SERVER = "http://ippc74/nebulous";
     29$NEB_SERVER = "http://ippc33/nebulous";
    2630
    2731// Czartool configuration variables
    2832// NOTE: These should match the configuration file used by the czartool perl modules: czartool/czarconfig.xml
    2933$CZARDBNAME = "czardb";
    30 $CZARDBHOST = "ippdb08";
     34$CZARDBHOST = "ippdb05";
    3135
    3236// location of plots produced by czarpoll.pl
    33 $CZARPLOTDIR = "/export/ipp113.0/ipp/czartool_plots";
     37//$CZARPLOTDIR = "/export/ipp113.0/ipp/czartool_plots";
     38//$CZARPLOTDIR = "/export/ipp117.0/ipp/czartool_plots";
    3439
    3540// Temporary files belonging to DELETION_USER and older than
     
    4045$DELETION_DELAY  = 15;
    4146
    42 $HOST_NEBULOUS  = "ippdb09.IfA.Hawaii.Edu";
     47$HOST_GPC1  = "ippdb05.IfA.Hawaii.Edu";
     48$USER_GPC1  = "ippMonitor";
     49$PASSWORD_GPC1  = "ippMonitor";
     50$LABEL_GPC1  = "ippdb05 master db(czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
     51
     52$REPL_HOST_GPC1  = "ippdb01.IfA.Hawaii.Edu";
     53$REPL_USER_GPC1  = "ippMonitor";
     54$REPL_PASSWORD_GPC1  = "ippMonitor";
     55$REPL_LABEL_GPC1  = "ippdb01 repl1 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
     56
     57$REPL_HOST_GPC1_SECONDARY  = "ippdb09.IfA.Hawaii.Edu";
     58$REPL_USER_GPC1_SECONDARY  = "ippMonitor";
     59$REPL_PASSWORD_GPC1_SECONDARY  = "ippMonitor";
     60$REPL_LABEL_GPC1_SECONDARY  = "ippdb09 repl2 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
     61
     62$REPL_HOST_GPC1_TERTIARY = "ipp116.IfA.Hawaii.Edu";
     63$REPL_USER_GPC1_TERTIARY = "ippMonitor";
     64$REPL_PASSWORD_GPC1_TERTIARY = "ippMonitor";
     65$REPL_LABEL_GPC1_TERTIARY = "ipp116 repl3 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
     66
     67$HOST_NEBULOUS  = "nebulous.ipp.ifa.hawaii.edu";
    4368$USER_NEBULOUS  = "ippMonitor";
    4469$PASSWORD_NEBULOUS  = "ippMonitor";
    45 $DBNAME_NEBULOUS  = "ippdb09 nebulous master";
     70$LABEL_NEBULOUS  = "ippdb11 nebulous master";
    4671
    47 $REPL_HOST_NEBULOUS  = "ippdb01.IfA.Hawaii.Edu";
    48 $REPL_USER_NEBULOUS  = "ippMonitor";
    49 $REPL_PASSWORD_NEBULOUS  = "ippMonitor";
    50 $REPL_DBNAME_NEBULOUS  = "ippdb01 nebulous repl1 (50,000s behind is acceptable / usually stopped on Mon/Tues for backups)";
     72$REPL_HOST_NEBULOUS = "ippdb06.IfA.Hawaii.Edu";
     73$REPL_USER_NEBULOUS = "ippMonitor";
     74$REPL_PASSWORD_NEBULOUS = "ippMonitor";
     75$REPL_LABEL_NEBULOUS = "ippdb06 nebulous repl1";
    5176
    52 $REPL_HOST_NEBULOUS_SECONDARY  = "ippdb06.IfA.Hawaii.Edu";
     77$REPL_HOST_NEBULOUS_SECONDARY  = "ippdb12.IfA.Hawaii.Edu";
    5378$REPL_USER_NEBULOUS_SECONDARY  = "ippMonitor";
    5479$REPL_PASSWORD_NEBULOUS_SECONDARY  = "ippMonitor";
    55 $REPL_DBNAME_NEBULOUS_SECONDARY  = "ippdb06 nebulous repl2 (50,000s behind is acceptable / usually stopped on Mon/Tues for backups)";
     80$REPL_LABEL_NEBULOUS_SECONDARY  = "ippdb12 nebulous repl2";
    5681
    57 $REPL_HOST_NEBULOUS_THIRD  = "ippdb12.IfA.Hawaii.Edu";
    58 $REPL_USER_NEBULOUS_THIRD  = "ippMonitor";
    59 $REPL_PASSWORD_NEBULOUS_THIRD  = "ippMonitor";
    60 $REPL_DBNAME_NEBULOUS_THIRD  = "ippdb12 nebulous repl3";
     82$REPL_HOST_NEBULOUS_TERTIARY  = "ippdb13.IfA.Hawaii.Edu";
     83$REPL_USER_NEBULOUS_TERTIARY  = "ippMonitor";
     84$REPL_PASSWORD_NEBULOUS_TERTIARY  = "ippMonitor";
     85$REPL_LABEL_NEBULOUS_TERTIARY  = "ippdb13 nebulous repl3";
    6186
    62 $REPL_HOST_NEBULOUS_FOURTH  = "ippdb13.IfA.Hawaii.Edu";
    63 $REPL_USER_NEBULOUS_FOURTH  = "ippMonitor";
    64 $REPL_PASSWORD_NEBULOUS_FOURTH  = "ippMonitor";
    65 $REPL_DBNAME_NEBULOUS_FOURTH  = "ippdb13 nebulous repl4";
     87$HOST_PSTAMP  = "ipp113.IfA.Hawaii.Edu";
     88$USER_PSTAMP  = "ipp";
     89$PASSWORD_PSTAMP  = "ipp";
     90$LABEL_PSTAMP  = "ipp113 (ippRequestServer)";
    6691
    67 $REPL_HOST_PSTAMP  = "ippc19.IfA.Hawaii.Edu";
    68 $REPL_USER_PSTAMP  = "ippMonitor";
    69 $REPL_PASSWORD_PSTAMP  = "ippMonitor";
    70 $REPL_DBNAME_PSTAMP  = "ippc19 (ippRequestServer)";
    71 
    72 $REPL_HOST_ISP  = "ippc17.IfA.Hawaii.Edu";
    73 $REPL_USER_ISP  = "ippMonitor";
    74 $REPL_PASSWORD_ISP  = "ippMonitor";
    75 $REPL_DBNAME_ISP  = "ippc17 (isp)";
    76 
    77 $HOST_GPC1  = "ippdb08.IfA.Hawaii.Edu";
    78 $USER_GPC1  = "ippMonitor";
    79 $PASSWORD_GPC1  = "ippMonitor";
    80 $DBNAME_GPC1  = "ippdb08 master db(czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
    81 
    82 $REPL_HOST_GPC1  = "ippdb05.IfA.Hawaii.Edu";
    83 $REPL_USER_GPC1  = "ippMonitor";
    84 $REPL_PASSWORD_GPC1  = "ippMonitor";
    85 $REPL_DBNAME_GPC1  = "ippdb05 repl1 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
    86 
    87 $REPL_HOST_GPC1_SECONDARY  = "ipp116.IfA.Hawaii.Edu";
    88 $REPL_USER_GPC1_SECONDARY  = "ippMonitor";
    89 $REPL_PASSWORD_GPC1_SECONDARY  = "ippMonitor";
    90 $REPL_DBNAME_GPC1_SECONDARY  = "ipp116 repl2 (czardb, gpc1, gpc2, ippadmin, ipptopsps, megacam, ssp, uip)";
    91 
    92 $REPL_HOST_DATASTORE_SECONDARY  = "ipp117.IfA.Hawaii.Edu";
    93 $REPL_USER_DATASTORE_SECONDARY  = "ipp";
    94 $REPL_PASSWORD_DATASTORE_SECONDARY  = "ipp";
    95 $REPL_DBNAME_DATASTORE_SECONDARY  = "ipp117 (datastore replicant)";
     92$REPL_HOST_DATASTORE  = "ipp117.IfA.Hawaii.Edu";
     93$REPL_USER_DATASTORE  = "ipp";
     94$REPL_PASSWORD_DATASTORE  = "ipp";
     95$REPL_LABEL_DATASTORE  = "ipp117 (datastore replicant)";
    9696
    9797//Important machines that should be checked for accessibiltiy
    9898$HOST_GATEWAY  = "ipp113.IfA.Hawaii.Edu";
    99 $DBNAME_GATEWAY  = "ipp113 (gateway server)";
     99$LABEL_GATEWAY  = "ipp113 (gateway server)";
    100100
    101101$HOST_GATEWAY_SECONDARY  = "ipp117.IfA.Hawaii.Edu";
    102 $DBNAME_GATEWAY_SECONDARY  = "ipp117 (gateway backup)";
    103 
    104 $HOST_APACHE1  = "ippc70.IfA.Hawaii.Edu";
    105 $DBNAME_APACHE1  = "ippc70 (apache node)";
    106 
    107 $HOST_APACHE2  = "ippc71.IfA.Hawaii.Edu";
    108 $DBNAME_APACHE2  = "ippc71 (apache node)";
    109 
    110 $HOST_APACHE3  = "ippc72.IfA.Hawaii.Edu";
    111 $DBNAME_APACHE3  = "ippc72 (apache node)";
    112 
    113 $HOST_APACHE4  = "ippc73.IfA.Hawaii.Edu";
    114 $DBNAME_APACHE4  = "ippc73 (apache node)";
    115 
    116 $HOST_APACHE5  = "ippc74.IfA.Hawaii.Edu";
    117 $DBNAME_APACHE5  = "ippc74 (apache node)";
    118 
    119 $HOST_APACHE6  = "ippc75.IfA.Hawaii.Edu";
    120 $DBNAME_APACHE6  = "ippc75 (apache node)";
     102$LABEL_GATEWAY_SECONDARY  = "ipp117 (gateway backup)";
    121103
    122104$HOST_PROXY  = "ippops1.IfA.Hawaii.Edu";
    123 $DBNAME_PROXY  = "ippops1 (proxy server)";
     105$LABEL_PROXY  = "ippops1 (proxy server)";
    124106
    125 $HOST_SVN  = "ippops2.IfA.Hawaii.Edu";
    126 $DBNAME_SVN  = "ippops2 (svn server)";
     107$HOST_APACHE1  = "ippc33.IfA.Hawaii.Edu";
     108$LABEL_APACHE1  = "ippc33 (apache node)";
     109
     110$HOST_APACHE2  = "ippc34.IfA.Hawaii.Edu";
     111$LABEL_APACHE2  = "ippc34 (apache node)";
     112
     113$HOST_APACHE3  = "ippc35.IfA.Hawaii.Edu";
     114$LABEL_APACHE3  = "ippc35 (apache node)";
     115
     116$HOST_APACHE4  = "ippc43.IfA.Hawaii.Edu";
     117$LABEL_APACHE4  = "ippc43 (apache node)";
     118
     119$HOST_APACHE5  = "ippc44.IfA.Hawaii.Edu";
     120$LABEL_APACHE5  = "ippc44 (apache node)";
     121
     122$HOST_APACHE6  = "ippc45.IfA.Hawaii.Edu";
     123$LABEL_APACHE6  = "ippc45 (apache node)";
     124
     125$HOST_APACHE_BACKUP1  = "ippc36.IfA.Hawaii.Edu";
     126$LABEL_APACHE_BACKUP1 = "ippc36 (backup apache)";
     127
     128$HOST_APACHE_BACKUP2  = "ippc46.IfA.Hawaii.Edu";
     129$LABEL_APACHE_BACKUP2 = "ippc46 (backup apache)";
     130
     131$HOST_HOME  = "ipphome0.IfA.Hawaii.Edu";
     132$LABEL_HOME  = "ipphome0 (ITC homedir)";
     133
     134$HOST_HOME_BACKUP  = "ipphome0.IfA.Hawaii.Edu";
     135$LABEL_HOME_BACKUP  = "ipphome0 (ITC homedir)";
     136
     137$HOST_NAGIOS  = "ipphome0.IfA.Hawaii.Edu";
     138$LABEL_NAGIOS  = "ipphome0 (nagios/ITC home backup)";
     139
     140$HOST_SVN  = "ippops4.IfA.Hawaii.Edu";
     141$LABEL_SVN  = "ippops4 (svn server)";
    127142
    128143$HOST_CONFLUENCE  = "ippops4.IfA.Hawaii.Edu";
    129 $DBNAME_CONFLUENCE  = "ippops4 (confluence/JIRA)";
     144$LABEL_CONFLUENCE  = "ippops4 (confluence/Jira)";
    130145
     146$HOST_MAILMAN  = "ippops3.IfA.Hawaii.Edu";
     147$LABEL_MAILMAN  = "ippops3 (mailman)";
    131148
    132149?>
Note: See TracChangeset for help on using the changeset viewer.