{% extends "app.html" %}

{% block app_content %}
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active">Compare</li>
        {% if type == "batch" %}
        <li class="breadcrumb-item active">
          <a href="{{ compare_runs_url }}">Runs</a>
        </li>
        <li class="breadcrumb-item active">Batches</li>
        <li class="breadcrumb-item active" aria-current="page">
          <a href="{{ url_for('app.batch', batch_id=baseline_id) }}">Baseline</a>
           ...
          <a href="{{ url_for('app.batch', batch_id=contender_id) }}">Contender</a>
        </li>
        {% elif type == "run" %}
        <li class="breadcrumb-item active">Runs</li>
        <li class="breadcrumb-item active" aria-current="page">
          <a href="{{ url_for('app.run', run_id=baseline_id) }}">Baseline</a>
           ...
          <a href="{{ url_for('app.run', run_id=contender_id) }}">Contender</a>
        </li>
        {% endif %}
      </ol>
    </nav>

    {% if baseline_run and contender_run %}
      {% if baseline_run.commit.message and contender_run.commit.message %}
    <div class="row">
      <div class="col-md-12">
        <ul class="list-group">
          <li class="list-group-item" align="right" style="border-style:none">
          Baseline:
          <a href="{{ baseline_run.commit.url }}">{{ baseline_run.commit.message }}</a>
          <br/>
          Contender:
          <a href="{{ contender_run.commit.url }}">{{ contender_run.commit.message }}</a>
          </li>
         </ul>
      </div>
    </div>
      {% endif %}
    {% endif %}

    <div class="row">
        <div class="col-md-12">
            <table id="benchmarks" class="table table-striped table-bordered table-hover">
              <caption>
                {% if comparisons %}
                <span id="comparisons-tooltip" data-toggle="tooltip" data-html="true" data-placement="bottom" title="
                Based on the z-score,
                {{ regressions }}
                of these {{ comparisons|length }} benchmarks were regressions,
                and {{ improvements }} were improvements."
                >
                Comparisons
                <span class="glyphicon glyphicon-arrow-down"></span> <b>{{ (100 * regressions / comparisons|length) | round(2) }}%</b>
                <span class="glyphicon glyphicon-arrow-up"></span> <b>{{ (100 * improvements / comparisons|length) | round(2) }}%</b>
                </span>
                {% else %}
                Comparisons
                {% endif %}
                {% include 'units-tooltip.html' %}
              </caption>
                <thead>
                    <tr>
                        <th scope="col" nowrap>Z-Score</th>
                        <th scope="col">Change</th>
                        <th scope="col">Language</th>
                        <th scope="col">Batch</th>
                        <th scope="col">Benchmark</th>
                        <th scope="col">Baseline</th>
                        <th scope="col">Contender</th>
                    </tr>
                </thead>
                <tbody>
                    {% for c in comparisons %}
                    <tr>
                         {% if c.contender_z_score is not none %}
                           <td>{{ c.contender_z_score }}</td>
                         {% else %}
                           <td></td>
                         {% endif %}

                         {% if c.contender is not none and c.baseline is not none %}
                           <td>{{ c.change }}</td>
                         {% else %}
                           <td></td>
                         {% endif %}

                         <td>{{ c.language }}</td>

                         <td>
                           {% if type == "batch" %}
                             <div>{{ c.batch }}</div>
                           {% else %}
                             {% if c.contender is not none and c.baseline is not none %}
                               <a href="{{ c.compare_batches_url }}">
                                 <div>{{ c.batch }}</div>
                               </a>
                             {% else %}
                               <div>{{ c.batch }}</div>
                             {% endif %}
                           {% endif %}
                         </td>

                         <td>
                           {% if c.contender is not none and c.baseline is not none %}
                             <a href="{{ c.compare_benchmarks_url }}">
                               <div>{{ c.benchmark}}</div>
                             </a>
                           {% else %}
                             <div>{{ c.benchmark}}</div>
                           {% endif %}
                         </td>

                         {% if c.baseline is none %}
                           <td></td>
                         {% else %}
                           <td>{{ c.baseline }}</td>
                         {% endif %}

                         {% if c.contender is none %}
                           <td></td>
                         {% else %}
                           <td>{{ c.contender }}</td>
                         {% endif %}
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

{% endblock %}

{% block scripts %}
{{super()}}
<script type="text/javascript">
  var table = $('#benchmarks').dataTable( {
      "responsive": true,
      "order": [[0, 'asc']],
      "columnDefs": [{ "orderable": false, "targets": [5, 6] }]
  } );

  $(document).ready(function() {
    $('#unit-tooltip').tooltip()
  });

  $(document).ready(function() {
    $('#comparisons-tooltip').tooltip()
  });
  </script>
{% endblock %}
