{% extends "layout.html" %}

{% block title %}
    Run {{ run.run_id }}
{% endblock %}

{% block contents %}
    <h1>Run {{ run.run_id }}</h1>

    <table class="noborders" style="margin-bottom:20px; margin-top:15px;">
        <tr>
            <td class="text-left">
                <b>Source:</b> {{ run.source|default("", true) }}
            </td>
            <td class="text-left">
                <b>Revision:</b> {{ run.git_commit|format_git_commit }}
            </td>
        </tr>
        <tr>
            <td class="text-left">
                <b>Start Time:</b> {{ run.start_date|format_date }}
            </td>
            <td class="text-left">
                <b>End Time:</b> {{ run.end_date|format_date }}
            </td>
        </tr>
        <tr>
            <td class="text-left">
                <b>Status:</b> {{ run.status }}
            </td>
        </tr>
    </table>

    <h3 name="parameters">Parameters</h3>
    {% if run.parameters %}
        <table>
            <thead>
                <th>Name</th><th>Value</th>
            </thead>
            <tbody>
                {% for key, value in run.parameters|dictsort %}
                    <tr>
                        <td>{{ key }}</td>
                        <td>{{ value }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>No parameters recorded.</p>
    {% endif %}

    <h3 name="metrics">Metrics</h3>
    {% if run.metrics %}
        <table>
            <thead>
                <th>Name</th><th>Value</th>
            </thead>
            <tbody>
                {% for key, values in run.metrics|dictsort %}
                    <tr>
                        <td>{{ key }}</td>
                        <td>
                            <a href="{{ url_for('plot_metric', metric=key, run_ids=run.run_id) }}" target="_blank">
                                {{ values|sparkline|safe }}
                            </a>
                            {{ values[-1]|round(2) }}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>No metrics recorded.</p>
    {% endif %}

    <h3 name="files">Output Files</h3>
    {% if run.output_files %}
        <p>
            {% for key in run.output_files|sort %}
                <a href="{{ url_for('show_output_file', run_id=run.run_id, path=key) }}">{{ key }}</a><br/>
            {% endfor %}
        </p>
        <p>
            <a class="btn btn-primary" role="button" href="{{ url_for('send_output_zip', run_id=run.run_id) }}">
                Download All <i class="fas fa-file-archive"></i>
            </a>
        </p>
    {% else %}
        <p>No output files recorded.</p>
    {% endif %}
{% endblock %}