{% extends "base.html" %}
{% block worker_submenu %}
    <ul class="nav nav-second-level">
        <li>
            <a href="#">{{ endpoint }}</a>
        </li>
    </ul>
{% endblock %}
{% block body %}
    {% set worker_details = worker_metrics['details'] %}
    <div class="row">
        <div><h2>Worker Info</h2></div>
        <table class="table">
            <thead>
            <tr>
                <th>Item</th>
                <th>Value</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>Host</td>
                <td><pre class="plain-pre">{{ worker_details['host_name'] }} ({{ endpoint }})</pre></td>
            </tr>
            {% if worker_details['k8s_pod_name'] is defined %}
            <tr>
                <td>Kubernetes Pod</td>
                <td>{{ worker_details['k8s_pod_name'] }}</td>
            </tr>
            {% endif %}
            <tr>
                <td>Git Branch</td>
                <td><pre class="plain-pre">{{ worker_details['git_info'] }}</pre></td>
            </tr>
            <tr>
                <td>Platform</td>
                <td><pre class="plain-pre">{{ worker_details['platform'] }}</pre></td>
            </tr>
            <tr>
                <td>Command</td>
                <td><pre class="plain-pre" style="white-space: inherit">{{ worker_details['command_line'] }}</pre></td>
            </tr>
            <tr>
                <td>Python</td>
                <td><pre class="plain-pre">{{ worker_details['sys_version'] }}</pre></td>
            </tr>
            <tr>
                <td>Numpy</td>
                <td><pre class="plain-pre">{{ worker_details['numpy_info'] }}</pre></td>
            </tr>
            <tr>
                <td>Scipy</td>
                <td><pre class="plain-pre">{{ worker_details['scipy_info'] }}</pre></td>
            </tr>
            </tbody>
        </table>
        <div><h2>Task Info</h2></div>
        <table class="table">
            <thead>
            <tr>
                <th>Item</th>
                <th>Value</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                {% if progresses['allocate_resource'] is defined %}
                    <td>Allocating ({{ progresses['allocate_resource']['total'] }})</td>
                    <td>{{ progresses['allocate_resource']['operands'] }}</td>
                {% else %}
                    <td>Allocating</td>
                    <td>Not available</td>
                {% endif %}
            </tr>
            <tr>
                {% if progresses['prepare_inputs'] is defined %}
                    <td>Preparing Data ({{ progresses['prepare_inputs']['total'] }})</td>
                    <td>{{ progresses['prepare_inputs']['operands'] }}</td>
                {% else %}
                    <td>Preparing Data</td>
                    <td>Not available</td>
                {% endif %}
            </tr>
            <tr>
                {% if progresses['calculate'] is defined %}
                    <td>Running ({{ progresses['calculate']['total'] }})</td>
                    <td>{{ progresses['calculate']['operands'] }}</td>
                {% else %}
                    <td>Running</td>
                    <td>Not available</td>
                {% endif %}
            </tr>
            <tr>
                {% if progresses['dump_cache'] is defined %}
                    <td>Storing ({{ progresses['dump_cache']['total'] }})</td>
                    <td>{{ progresses['dump_cache']['operands'] }}</td>
                {% else %}
                    <td>Storing</td>
                    <td>Not available</td>
                {% endif %}
            </tr>
            </tbody>
        </table>
        <div><h2>Resources</h2></div>
        <table class="table">
            <thead>
            <tr>
                <th>Item</th>
                <th>Value</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>CPU Info</td>
                <td><pre class="plain-pre">Usage: {{ '%0.2f' % worker_metrics['hardware']['cpu_used'] }}
Total: {{ worker_metrics['hardware']['cpu_total'] }}</pre></td>
            </tr>
            <tr>
                <td>Memory Info</td>
                <td><pre class="plain-pre">Usage: {{ worker_metrics['hardware']['memory_used'] | readable_size }}
Total: {{ worker_metrics['hardware']['memory_total'] | readable_size }}</pre></td>
            </tr>
            <tr>
                <td>Memory Quota Info</td>
                <td><pre class="plain-pre">Allocated: {{ worker_metrics['hardware']['mem_quota_used'] | readable_size }}
Hold: {{ worker_metrics['hardware']['mem_quota_hold'] | readable_size }}
Total: {{ worker_metrics['hardware']['mem_quota_total'] | readable_size }}</pre></td>
            </tr>
            <tr>
                <td>Cache Info</td>
                <td><pre class="plain-pre">Hold: {{ worker_metrics['hardware']['cached_hold'] | readable_size }}
Total: {{ worker_metrics['hardware']['cached_total'] | readable_size }}</pre></td>
            </tr>
            {% if worker_metrics['hardware']['disk_read'] is defined %}
            <tr>
                <td>Disk IO Info</td>
                <td><pre class="plain-pre">Read Speed: {{ worker_metrics['hardware']['disk_read'] | readable_size }}/s
Write Speed: {{ worker_metrics['hardware']['disk_write'] | readable_size }}/s</pre></td>
            </tr>
            {% endif %}
            {% if worker_metrics['hardware']['net_receive'] is defined %}
            <tr>
                <td>Network IO Info</td>
                <td><pre class="plain-pre">Receive Speed: {{ worker_metrics['hardware']['net_receive'] | readable_size }}/s
Send Speed: {{ worker_metrics['hardware']['net_send'] | readable_size }}/s</pre></td>
            </tr>
            {% endif %}
            {% if worker_metrics['hardware']['iowait'] is defined %}
            <tr>
                <td>IOWait</td>
                    <td><pre class="plain-pre">Percent: {{ worker_metrics['hardware']['iowait']}}%</pre></td>
            </tr>
            {% endif %}
            <tr>
                <td>Disk Info</td>
                {% if worker_metrics['hardware']['disk_used'] is defined %}
                    <td><pre class="plain-pre">Usage: {{ worker_metrics['hardware']['disk_used'] | readable_size }}
Total: {{ worker_metrics['hardware']['disk_total'] | readable_size }}</pre></td>
                {% else %}
                    <td>Not available</td>
                {% endif %}
            </tr>
            <tr>
                <td>Update Time</td>
                <td>{{ worker_metrics['update_time']}}</td>
            </tr>
            </tbody>
        </table>
        {% if worker_metrics['hardware']['disk_stats'] is defined %}
        <div><h3>Disk Details</h3></div>
        <table class="table">
            <thead>
            <tr>
                <th>Item</th>
                <th>Value</th>
            </tr>
            </thead>
            <tbody>
            {% for key, value in worker_metrics['hardware']['disk_stats'].items() %}
            <tr>
                <td>{{ key }}</td>
                <td><pre class="plain-pre">Usage: {{ value['disk_used'] | readable_size }}
Total: {{ value['disk_total'] | readable_size }}</pre></td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        {% endif %}
        {% set stats = worker_metrics['stats'] %}
        <div><h2>Performance</h2></div>
        <table class="table">
            <thead>
            <tr>
                <th>Item</th>
                <th>Value</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>Min Finish Time</td>
                {% if stats['min_est_finish_time'] is defined %}
                <td>{{ stats['min_est_finish_time'] | format_ts }}</td>
                {% else %}
                <td> N/A </td>
                {% endif %}
            </tr>
            <tr>
                <td>Max Finish Time</td>
                {% if stats['max_est_finish_time'] is defined %}
                <td>{{ stats['max_est_finish_time'] | format_ts }}</td>
                {% else %}
                <td> N/A </td>
                {% endif %}
            </tr>
            {% if stats['net_transfer_speed'] is defined %}
            <tr>
                {% set value = worker_metrics['stats']['net_transfer_speed'] %}
                <td>Networking</td>
                <td>{{ value['mean'] | readable_size }}/s std: {{ value['std'] | readable_size }}/s count: {{ value['count'] | int }}</td>
            </tr>
            {% endif %}
            {% if stats['disk_read_speed'] is defined %}
            <tr>
                {% set value = worker_metrics['stats']['disk_read_speed'] %}
                <td>Disk Reads</td>
                <td>{{ value['mean'] | readable_size }}/s std: {{ value['std'] | readable_size }}/s count: {{ value['count'] | int }}</td>
            </tr>
            {% endif %}
            {% if worker_metrics['stats']['disk_write_speed'] is defined %}
            <tr>
                {% set value = worker_metrics['stats']['disk_write_speed'] %}
                <td>Disk Writes</td>
                <td>{{ value['mean'] | readable_size }}/s std: {{ value['std'] | readable_size }}/s count: {{ value['count'] | int }}</td>
            </tr>
            {% endif %}
            {% if stats['wait_time.MemQuota'] is defined %}
            <tr>
                {% set value = worker_metrics['stats']['wait_time.MemQuota'] %}
                <td>MemQuota Wait Time</td>
                <td>{{ value['mean'] | round(2) }} std: {{ value['std'] | round(2) }} count: {{ value['count'] | round(2) }}</td>
            </tr>
            {% endif %}
            {% for key, value in worker_metrics['stats'].items() %}
                {% if key.startswith('calc_speed.') %}
                <tr>
                    <td>Calc Rate of {{ key[11:] }}</td>
                    <td>{{ value['mean'] | readable_size }}/s std: {{ value['std'] | readable_size }}/s count: {{ value['count'] | int }}</td>
                </tr>
                {% endif %}
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
