<body data-spy="scroll" data-target=".topbar" data-offset="90">
<nav class="navbar navbar-default navbar-fixed-top topbar">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="https://github.com/linkedin/naarad">naarad</a>
    </div>
    <div id="navbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="diff_report.html" title="Summary"><span>Summary</span></a></li>
        <li><a href="report.html"></span>Chart</span></a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Back to Top</a></li>
      </ul>
    </div>
  </div>
</nav>

<!-- Container -->
<div class="container-fluid">
  <div class="content">
    {%- if sla_failure_list %}
    <!-- SLA Failures -->
    <div class="row">
      <div class="col-md-12">
        <div id="sla failure summary" style="overflow-x:auto;">
          <h2 class="content-title">
            <span class="text">SLA Failure Summary</span>
          </h2>
          <table id="table-diff-sla-failure" class="table table-bordered table-striped sortable">
            <caption>Summary of SLA Failures</caption>
            <thead>
              <tr>
                <th>metric</th>
                <th>sub_metric</th>
                <th>sla_rule</th>
                <th>Baseline Value</th>
                <th>Current Value</th>
                <th>Diff</th>
              </tr>
            </thead>
            <tbody>
              {%- for sla_failure in sla_failure_list %}
              {%- if sla_failure.sla.sla_passed == True %}
              <tr class="success">
              {%- elif sla_failure.sla.sla_passed == False %}
              <tr class="danger">
              {%- else %}
              <tr>
              {%- endif %}
                <td>{{sla_failure.sla.metric}}</td>
                <td>{{sla_failure.sla.sub_metric}}</td>
                <td>{{sla_failure.sla.stat_name}} {{sla_failure.sla.sla_type}} {{sla_failure.sla.threshold}}{{sla_failure.sla.display}}</td>
                <td>{{sla_failure.diff_metric[0]}}</td>
                <td>{{sla_failure.diff_metric[1]}}</td>
                {%- if sla_failure.sla.display == '' %}
                  <td>{{sla_failure.diff_metric['absolute_diff']}}{{sla_failure.sla.display}}</td>
                {%- else %}
                  <td>{{sla_failure.diff_metric['percent_diff']}}{{sla_failure.sla.display}}</td>
                {%- endif %}
              </tr>
             {%- endfor %}
            </tbody>
          </table>
       </div>
      </div>
    </div>
    {%- endif %}

    <!-- Diff Data -->
    {%- if diff_data %}
      <!-- Jumps -->
      <div class="dropdown">
        <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
          Quick Jump
          <span class="caret"></span>
        </button>

        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
          {%- for metric in diff_data|sort %}
          <li role="presentation"><a role="menuitem" tabindex="-1" href="#{{ metric }}-jump">{{ metric }}</a></li>
          {%- endfor %}
        </ul>
      </div>
      
      <!-- Metric Tables -->
      {%- for metric in diff_data|sort %}
      <a name="{{ metric }}-jump"></a>
      <div class="row">
        <div class="col-md-12">
         <div id="div-diff-{{ metric }}" style="overflow-x:auto;">
          <h2 class="content-title">
            <span class="text">{{ metric }}</span>
          </h2>
          <form>
            <input type="radio" name="radio-diff-{{ metric }}" id="radio-diff-{{ metric }}" value="%" checked onclick="switchDiffTable('{{ metric }}')">%
            <input type="radio" name="radio-diff-{{ metric }}" value="#" onclick="switchDiffTable('{{ metric }}')">#
          </form>
          <table id="table-diff-percent-{{ metric }}" class="table table-bordered table-striped sortable">
            <caption>{{ metric }} : % diff</caption>
            <thead>
              <th>sub-metric</th>
              {%- for header in diff_data[metric][diff_data[metric].keys()[0]].keys()|sort %}
              <th>{{ header }}</th>
              {%- endfor %}
            </thead>
            <tbody>
              {%- for sub_metric in diff_data[metric]|sort %}
                <tr>
                  <td><a href="#{{ metric }}.{{ sub_metric | sanitize_string }}">{{ sub_metric }}</a></td>
                  {%- for stats in diff_data[metric][sub_metric]|sort %}
                    {%- if sub_metric in sla_map[metric].keys() %}
                      {%- if stats in sla_map[metric][sub_metric].keys() %}
                        {%- if sla_map[metric][sub_metric][stats].display == '%' %}
                          {%- if sla_map[metric][sub_metric][stats].sla_passed == True %} 
                          <td class="success" type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                          {%- elif sla_map[metric][sub_metric][stats].sla_passed ==  False %}
                          <td class="danger" type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                          {%- else %}
                          <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                          {%- endif %}
                        {%- else %}
                        <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                        {%- endif %}
                      {%- else %}
                      <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                      {%- endif %}
                    {%- else %}
                    <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                    {%- endif %}
                    {{ diff_data[metric][sub_metric][stats]['percent_diff'] }}%
                  </td>
                  {%- endfor %}
                </tr>
               {%- endfor %}
            </tbody>
          </table>
          <table id="table-diff-absolute-{{ metric }}" class="table table-bordered table-striped sortable" hidden="true">
            <caption>{{ metric }} : absolute diff</caption>
            <thead>
              <th>sub-metric</th>
              {%- for header in diff_data[metric][diff_data[metric].keys()[0]].keys()|sort %}
              <th>{{ header }}</th>
              {%- endfor %}
            </thead>
            <tbody>
              {%- for sub_metric in diff_data[metric]|sort %}
                <tr>
                  <td><a href="#{{ metric }}.{{ sub_metric | sanitize_string }}">{{ sub_metric }}</a></td>
                  {%- for stats in diff_data[metric][sub_metric]|sort %}
                    {%- if sub_metric in sla_map[metric].keys() %}
                      {%- if stats in sla_map[metric][sub_metric].keys() %}
                        {%- if sla_map[metric][sub_metric][stats].display == '' %}
                          {%- if sla_map[metric][sub_metric][stats].sla_passed == True %} 
                          <td class="success" type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                          {%- elif sla_map[metric][sub_metric][stats].sla_passed ==  False %}
                          <td class="danger" type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                          {%- else %}
                          <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                          {%- endif %}
                        {%- else %}
                        <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                        {%- endif %}
                      {%- else %}
                      <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                      {%- endif %}
                    {%- else %}
                    <td type="naarad-diff-td-percentage" title="{{ sub_metric }} , {{ stats }} , Report 1={{ diff_data[metric][sub_metric][stats][0] }} , Report 2={{ diff_data[metric][sub_metric][stats][1] }} , diff={{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}, %diff={{diff_data[metric][sub_metric][stats]['percent_diff'] }}">
                    {%- endif %}
                    {{ diff_data[metric][sub_metric][stats]['absolute_diff'] }}
                  </td>
                  {%- endfor %}
                </tr>
              {%- endfor %}
            </tbody>
          </table>
         </div>
        </div>
      </div>
      {%- endfor %}
    {%- endif %}

    <!-- Plots -->
    {%- if plot_div_content %}
    <div id="diff-metric-plots" class="row">
      <div id="diff-metric-plots-span" class="col-md-12">
        <h3>Metrics Diff Plots</h3>
        <p>{{ plot_div_content }}</p>
      </div>
    </div>
    {%- endif %}

    <!-- Locations -->
    <div class="row">
      <div class="col-md-12">
        <table class="table">
            <h2 class="content-title">
                <span class="text">Source Files Locations</span>
            </h2>
            <tr>
              <td class="col-xs-2" style="text-align: right;">Baseline Report:</td>
              <td><a href={{ reports[0].location }}>{{ reports[0].location }}</a></td>
            </tr>
            <tr>
              <td class="col-xs-2" style="text-align: right;">Current Report:</td>
              <td><a href={{ reports[1].location }}>{{ reports[1].location }}</a></td>
            </tr>
            <tr><td colspan="2"></td></tr>
        </table>
      </div>
    </div>
  </div><!-- /content -->
</div><!-- /container -->
