{% if comparison %}

{% if comparison_type == 'test' %}
  {% include "squad/_results_transitions_filter.jinja2" %}
{% endif %}

<table class='test-results'>
  <thead>
    <tr>
      <td rowspan='2'></td>
      {% for build, environments in comparison.environments.items() %}
      <th colspan={{environments|length}}>
        <a href="{{project_url(build)}}">
          {% if project %}
            {{ _('build %s') % build.version }}
          {% else %}
            {{ _('%s, build %s') % (build.project, build.version) }}
          {% endif %}
        </a>
      </th>
      {% endfor %}
    </tr>
    <tr>
      {% for build, environments in comparison.environments.items() %}
        {% for environment in environments %}
        <th>
          {{environment}}
          {% if comparison_type == 'metric' %}
            <br />
            {{ _('mean (stdev)') }}
          {% endif %}
        </th>
        {% endfor %}
      {% endfor %}
    </tr>
  </thead>
  {% if not comparison.results %}
    <tr>
      <th>No tests to display</th>
    </tr>
  {% else %}
    {% for test, results in comparison.results %}
      <tr>
        <th>{{test}}</th>
        {% for build, environments in comparison.environments.items() %}
          {% for environment in environments %}
            {% with result=results.get((build, environment)) %}
              {% if result %}
                {% if comparison_type == 'test' %}
                  {% if result is not string %}
                    <td class='{{result.0|slugify}}'>
                      <a href="{{url('legacy_test_history', args=[build.project.group.slug, build.project.slug, test])}}">
                        <strong>{{result.0}}{% if result.1 %} ({{ result.1 }}%){% endif %}</strong>
                      </a>
                     </td>
                  {% else %}
                    <td class='{{result|slugify}}'>
                      <a href="{{url('legacy_test_history', args=[build.project.group.slug, build.project.slug, test])}}">
                        <strong>{{result}}</strong>
                      </a>
                    </td>
                  {% endif %}
                {% else %}
                  {% set mean = result.0|float %}
                  {% set stddev = result.1|float %}
                  {% set total = result.2|int %}
                  <td title="{{_('Number of measurements: %d' % total)}}">
                    <strong>{{'%.2f' % mean}} ({{'%.2f' % stddev}})</strong>
                  </td>
                {% endif %}
              {% else %}
                <td><i>{{ _('n/a') }}</i></td>
              {% endif %}
            {% endwith %}
          {% endfor %}
        {% endfor %}
      </tr>
    {% endfor %}
  {% endif %}
</table>
{% endif %}
