{% extends "dashboard/main.html" %}
{% block content %}

    <div class="row">
        <!-- Advanced Tables -->
        <div class="panel panel-default">
            <div class="panel-heading">
                Grouped test results
            </div>
            <br/>
            <div class="panel-body">


                <div class="panel-group" id="accordion">
                    {% for group in groups %}
                        {% if group in endpoints %}

                            <div class="panel panel-default">
                                <div class="panel-heading" style="background-color: {{ colors[group] }}">
                                    <h4 class="panel-title">
                                        <a data-toggle="collapse" data-parent="#accordion" href={{ "#" + group|replace(".", "-") }}
                                                class="collapsed"
                                           style="background-color: #ffffff">&#9654; {{ group + " ..." }}</a>
                                    </h4>
                                </div>
                                <div id={{ group|replace(".", "-") }} class="panel-collapse collapse
                                " style="height: auto;">
                                <div class="panel-body">


                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover sortable">
                                            <tr>
                                                <th class="clickable">Name: <i>functionName (fileName.className)</i>
                                                </th>
                                                <th class="clickable">Run .. times</th>
                                                <th class="clickable">Average run time (ms)</th>
                                                <th class="clickable">Run .. times [current version]</th>
                                                <th class="clickable">Average run time [current version] (ms)</th>
                                                <th class="clickable">Last run</th>
                                            </tr>
                                            {% for test in tests %}
                                                {% if test.name in groups[group] %}
                                                    <tr>
                                                        <td>
                                                            <a href="{{ url_for('dashboard.test_result', test=test.name) }}">{{ test.name }}</a>
                                                            <br> <b
                                                                style="color:green;">{{ " Succeeded" if test.succeeded }}</b>
                                                            <b style="color:red;">{{ " Failed" if test.succeeded == False }}</b>
                                                            <b style="color:black;">{{ " Never run" if test.succeeded == None }}</b>
                                                        </td>
                                                        {% if results[0] %}
                                                            {% for result in results %}
                                                                {% if result.name == test.name %}
                                                                    <td style="text-align: right;">{{ result.count if result.count else "" }}</td>
                                                                    <td style="text-align: right;">{{ ((result.average*10)|round)/10 if result.average else "" }}
                                                                    </td>
                                                                {% endif %}
                                                            {% endfor %}
                                                        {% else %}
                                                            <td></td>
                                                            <td></td>
                                                        {% endif %}
                                                        {% if res_current_version[0] %}
                                                            {% for res in res_current_version %}
                                                                {% if res.name == test.name %}
                                                                    <td style="text-align: right;">{{ res.count if res.count else "" }}</td>
                                                                    <td style="text-align: right;">{{ ((res.average*10)|round)/10 if res.average else "" }}</td>
                                                                {% endif %}
                                                            {% endfor %}
                                                        {% else %}
                                                            <td></td>
                                                            <td></td>
                                                        {% endif %}
                                                        <td style="text-align: center;">{{ "{:%Y-%m-%d %H:%M:%S }".format(test.lastRun) if test.lastRun
                            != None else "" }}
                                                        </td>
                                                    </tr>
                                                {% endif %}
                                            {% endfor %}
                                        </table>
                                    </div>


                                </div>
                            </div>
                            </div>
                        {% endif %}
                    {% endfor %}
            </div>


        </div>
    </div>
    </div>


    <div class="row">
        <div class="panel panel-default">
            <div class="panel-heading">
                Overall execution times
            </div>
            <div class="panel-body">

                <div id="loading">
                    <div class="col-md-12 col-sm-12">
                        <br>
                        <center>
                            <img src="{{ url_for('dashboard.static', filename='assets/loading.gif') }}"
                                 alt="Be patient..." align="center"/>
                        </center>
                    </div>
                </div>


                {% if boxplot %}
                    <div class="col-md-12 col-sm-12">
                        {{ boxplot|safe }}
                    </div>
                {% else %}
                    <p>No data available.</p>
                {% endif %}


            </div>
        </div>
    </div>

    <script>
        $(window).ready(function () {
            $('#loading').hide();
        });
    </script>

{% endblock %}