<!DOCTYPE HTML>
<html lang=en>
  <head>
    <meta http-equiv="refresh" content="1800">
    <link rel="stylesheet" type="text/css" href="stylin.css"/>
    <link rel="stylesheet" type="text/css" href="dynamo.css"/>
    <script type="text/javascript" src="sorttable.js"></script>
  </head>
  <body>

    <header id="header">
      <h1 id="pageTitle">Consistency Check Summary</h1>
    </header>

    <div>
      <center>
        <a href="?sites=good"><span class="topbutton">Debugged sites</span></a>
        <a href="?sites=need_checked"><span class="topbutton">Sites that need debugged or hand checking</span></a>
        <a href="?sites=all"><span class="topbutton">All sites</span></a>
      </center>
    </div>

    <div style="padding-top:1em;clear:both;">
      <table border="1" cellpadding="5" align="center" id="consistency_summary">
        <tr>
          <th onclick="sorttable(1, false)">
            Last Update
          </th>
          <th<?php if (!isset($_GET['history'])) echo(' onclick="sorttable(-2, false)"');?>>
            Site Name
          </th>
          <th onclick="sorttable(3)">
            Time [min]
          </th>
          <th onclick="sorttable(4)">
            Number Files
          </th>
          <th onclick="sorttable(5)">
            Number Nodes
          </th>
          <th onclick="sorttable(6)">
            Unlisted (error)
          </th>
          <th onclick="sorttable(7)">
            Empty Nodes
          </th>
          <th onclick="sorttable(8)">
            Num Missing
          </th>
          <th onclick="sorttable(9)">
            No Disk (no tape)
          </th>
          <th onclick="sorttable(10)">
            Size [TB]
          </th>
          <th onclick="sorttable(11)">
            Num Orphan
          </th>
          <th onclick="sorttable(12)">
            Size [TB]
          </th>
          <th onclick="sorttable(13)">
            Unmerged Cleaned (logs)
          </th>
        </tr>
<?php
         while ($row = $results->fetchArray()) {
           $bad_background = ' style="background-color:#ff6666;"';
           $queued_background = ' style="background-color:#66ffff;"';
           $good_background = ' style="background-color:#66ff66;"';
           $disabled_background = ' style="background-color:#bbbbbb;"';
           $long_background = ' style="background-color:#ffff66;"';

           $background_missing = ($row['missing'] > $config['MaxMissing']) ? $bad_background : '';
           $background_nosource = ($row['unrecoverable'] != 0) ? $bad_background : '';
           $background_orphan = ($row['orphan'] > $config['MaxOrphan']) ? $bad_background : '';
           $background_files = ($row['files'] == 0) ? $bad_background : '';
           $background_unlisted = ($row['unlisted_bad'] != 0) ? $bad_background : '';

           $tooltip = '';

           // Get the running cell colored based on running status
           if (isset($_GET['history'])) {
             $background_site = $background_files;
           } else {
             switch ($row['isrunning']) {

               case 0:
                 $background_site = $background_files;
                 break;
               case 1:
                 $background_site = $queued_background;
                 break;
               case 2:
                 $background_site = ((strtotime($row['laststarted']) + 24 * 3600) > time()) ? $good_background : $long_background;
                 $tooltip = '<span class="givestarted">Started run: ' . $row['laststarted'] . '</span>';
                 break;
               default:
                 $background_site = $disabled_background;

             }
           }

           $background_time = ((strtotime($row['entered']) + 24 * 3600) > time()) ? $good_background : '';

           $html_row = sprintf(
             '<td%s><a href="?history=%s">%s</a></td><td%s><a href="%s.log">%s</a>%s</td><td>%.0f</td><td%s><a href="%s_storage.json">%d</a></td><td>%d</td><td%s><a href="%s_unlisted.txt">%d</a> (%d)</td><td>%d</td><td%s><a href="%s_compare_missing.txt">%d</a> (<a href="%s_missing_datasets.txt">blocks</a>)</td><td%s><a href="%s_missing_nosite.txt">%d</a> (<a href="%s_unrecoverable.txt">%d</a>)</td><td>%.2f</td><td%s><a href="%s_compare_orphan.txt">%d</a></td><td>%.2f</td><td><a href="%s_unmerged.txt">%d</a> (%d)</td>',
             $background_time, $row['site'], $row['entered'],
             $background_site, $row['site'], $row['site'], $tooltip, $row['time']/60.,
             $background_files, $row['site'], $row['files'], $row['nodes'], 
             $background_unlisted, $row['site'], $row['unlisted'], $row['unlisted_bad'], $row['emtpy'],
             $background_missing, $row['site'], $row['missing'], $row['site'],
             $background_nosource, $row['site'], $row['nosource'], $row['site'], $row['unrecoverable'], $row['m_size']/pow(1024.,4),
             $background_orphan, $row['site'], $row['orphan'], $row['o_size']/pow(1024.,4), $row['site'], $row['unmerged'], $row['unmergedlogs']);

           if (isset($_GET['history'])) {
             $html_row = strip_tags($html_row, '<td>');
           }
           printf('<tr>%s</tr>', $html_row);
           printf("\n");
         }
?>
      </table>
    </div>

    <h2>Documentation</h2>

    <p>
      Explanations of columns are given <a href="explanations.html">here</a>.
    </p>

    <p>
      Details of the Consistency Check implementation can be seen
      <a href="http://dynamo-consistency.readthedocs.io" target="blank">here</a>.
    </p>

  </body>
</html>
