{% extends "admin/index.html" %}

{% load redis_status_tags %}
{% load i18n %}

{% block extrahead %}
<style type="text/css">
div.cache_stats{
    margin: 1em 0 2em 0;
}

div.cache_stats table{
    width: 100%
}

div.cache_stats table tbody th,
div.cache_stats table tbody td{
    width: 50% !important;
}

div.cache_stats table tbody th{
    text-align: right;
}

div.cache_stats table tbody th.cache_title{
    text-align: center;
    font-weight: normal;
    padding-top: 1em;
}

div.cache_stats tbody{
    display: none;
}

div.cache_graph{
    height: 1em;
    width: 100%;
    background-color: #BEEE37;
    -webkit-box-shadow: 0.1em 0.1em 0.2em #aaa;
    -moz-box-shadow: 0.1em 0.1em 0.2em #aaa;
}

div.cache_graph.inline{
    display: inline-block;
    width: 180px;
    margin-left: 2em;
}

div.cache_graph_value{
    height: 1em;
    background-color: #E84A2F;
}
</style>
{% endblock %}

{% block content %}
    {% get_cache_stats %}
    {% if cache_stats and user.is_superuser %}
    <div class="cache_stats">
    <div class="module">
        <table>
        <caption>
            <a href="#" class="section" onclick="
                var elem = document.getElementById('cache_block');
                if(elem.style.display == 'none'){
                    elem.style.display = 'table-row-group';
                }else{
                    elem.style.display = 'none';
                }
                return false;
            ">redis: {{ cache_stats.server }} - {{ cache_stats.used_memory }} bytes used</a>
        </caption>
        <tbody id="cache_block">
        <tr>
            <th>{% trans "Miss Ratio" %}</th>
            <td>
                {% widthratio cache_stats.keyspace_misses cache_stats.keyspace_hits 100 %}%
                <div class="cache_graph inline">
                    <div class="cache_graph_value" style="width: {% widthratio cache_stats.keyspace_misses cache_stats.keyspace_hits 100 %}%"></div>
                </div>
            </td>
        </tr>
        <tr>
            <th>{% trans "Avg GET by item" %}</th>
            <td>{% widthratio cache_stats.keyspace_hits cache_stats.total_keys 1 %}</td>
        </tr>        
        <tr>
            <th>{% trans "Avg GET by seconds/minutes" %}</th>
            <td>{% widthratio cache_stats.keyspace_hits cache_stats.uptime_in_seconds 1 %}/{% widthratio cache_stats.keyspace_hits cache_stats.uptime_in_seconds 60 %}</td>
        </tr>
        
        
        {# ----- Detailed Statistics ----- #}
        <tr><th class="cache_title" colspan="2">{% trans "Detailed Statistics:" %}</th></tr>
        {% for k,v in cache_stats.items %}
        <tr><th>{{ k|prettyname }}</th><td>{{ v|prettyvalue:k }}</td></tr>
        {% endfor %}
        </tbody>
        </table>
    </div>
    </div>
    {% endif %}

    {{ block.super }}
{% endblock %}
