{% extends "main.html" %}
{% load karaage_tags %}
{% load humanize filters %}


{% block title %}Machine Category Usage{% endblock %}


{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href='{% url "index" %}'>Home</a>&nbsp;›
    Uasge
</div>
{% endblock %}


{% block content %}
<div id="content-main">
    <h2>Usage {{ start|date }} - {{ end|date }}</h2>
    <p>{% date_filter start end %}</p>
    <p>No. CPU's: (average) {{ avg_cpus|floatformat:"1" }}  Utilization: {{ utilization|floatformat:"2" }}%</p>
    <p>Total time {{ total|timeformat }} ({{ total_jobs|intcomma }} jobs) of available {{ available_time|timeformat }} </p>
    <div class="module">
        <h2>Trend</h2>
        <img src="{{ trend_graph.graph_url }}"/>
    </div>

    <div class="object-tools">
        <ul>
            <li><a href="{% url 'kg_usage_core_report' %}{% url_with_param start=start end=end %}">Core Report</a></li>
            <li><a href="{% url 'kg_usage_mem_report' %}{% url_with_param start=start end=end %}">Memory Report</a></li>
            <li><a href="{% url 'kg_usage_institute_trends' %}{% url_with_param start=start end=end %}">Trends</a></li>
            <li><a href="{% url 'kg_usage_top_users' %}{% url_with_param start=start end=end %}">Top Users</a></li>
            <li><a href="{% url 'kg_usage_job_list' %}{% url_with_param date__gte=start date__lte=end %}">All Jobs</a></li>
            <li><a href="{% url 'kg_usage_search' %}{% url_with_param start=start end=end %}">Advanced Search</a></li>
        </ul>
    </div>

    <div class="module">
        <h2>Institutes</h2>
        <img class="float-right middle" src="{{ institutes_graph.graph_url }}"/>
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>Institute</th>
                        <th>CPU Time</th>
                        <th>No. Jobs</th>
                        <th>Actual</th>
                        <th>Quota</th>
                        <th>Difference</th>
                        <th>% quota used</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td>Total</td>
                        <td>{{ total|timeformat }}</td>
                        <td>{{ total_jobs|intcomma }}</td>
                    </tr>
                </tfoot>
                <tbody>
                    {% for i in i_list|dictsortreversed:"usage" %}
                    <tr>
                        <td><a href="{% url 'kg_usage_institute' i.institute.id %}{% url_with_param start=start end=end %}">{{ i.institute.name }}</a> </td>
                        <td class="right">{{ i.usage|timeformat }}</td>
                        <td class="right">{{ i.jobs|intcomma }}</td>
                        <td class="right">{{ i.percent|floatformat:"2" }}</td>
                        <td class="right">{{ i.quota }}</td>
                        <td class="right {{ i.class }}">{{ i.diff|floatformat:"2" }}</td>
                        <td class="right {{ i.class }}">{{ i.p_used|floatformat:"2" }}</td>
                    </tr>
                    {% endfor %}
                    <tr>
                        <td>Unused</td>
                        <td class="right">{{ unused.usage|timeformat }}</td>
                        <td class="right"> </td>
                        <td class="right">{{ unused.percent|floatformat:"2" }}</td>
                        <td class="right"> </td>
                        <td class="right {{ unused.class }}">{{ unused.diff|floatformat:"2" }}</td>
                        <td> </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <p><a href="{{ institutes_graph.data_url }}">data</a></p>
        <br class="clear"/>
    </div>

    <div class="module">
        <h2>Machines</h2>
        <img class="float-right" src="{{ machines_graph.graph_url }}"/>
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>CPU Time</th>
                        <th>No. Jobs</th>
                    </tr>
                </thead>
                <tbody>
                    {% for m in m_list %}
                    <tr>
                        <td>{{ m.machine }}</td>
                        <td class="right">{{ m.usage|timeformat }}</td>
                        <td class="right">{{ m.jobs|intcomma }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        <p><a href="{{ machines_graph.data_url }}">data</a></p>
        <br class="clear"/>
    </div>
</div>
{% endblock %}
