<commit_before>from django.contrib import admin
from .models import RedisServer

class RedisServerAdmin(admin.ModelAdmin):
    list_display = (
        '__unicode__', 'status', 'memory', 'clients', 'details'
    )
    def status(self, obj):
        return obj.stats['status']

    def memory(self, obj):
        return obj.stats['memory']

    def clients(self, obj):
        return obj.stats['clients']

    def details(self, obj):
        return "<table>%s</table>" % ''.join(
            "<tr><td>%s</td><td>%s</td></tr>" % i
                for i in sorted(obj.stats['details'].items(), key=lambda (k,v): k)
        )

    details.allow_tags = True

admin.site.register(RedisServer, RedisServerAdmin)<commit_msg>Added filters for details and prettify for timestamp/second values.<commit_after>from django.contrib import admin
from django.conf import settings
from .models import RedisServer

import re
from datetime import datetime, timedelta

REDISBOARD_DETAIL_FILTERS = [re.compile(name) for name in getattr(settings, 'REDISBOARD_DETAIL_FILTERS', (
    'aof_enabled', 'bgrewriteaof_in_progress', 'bgsave_in_progress',
    'changes_since_last_save', 'db.*', 'db1', 'last_save_time',
    'multiplexing_api', 'total_commands_processed',
    'total_connections_received', 'uptime_in_days', 'uptime_in_seconds',
    'vm_enabled'
))]
REDISBOARD_DETAIL_TIMESTAMP_KEYS = getattr(settings, 'REDISBOARD_DETAIL_TIMESTAMP_KEYS', (
    'last_save_time',
))
REDISBOARD_DETAIL_SECONDS_KEYS = getattr(settings, 'REDISBOARD_DETAIL_SECONDS_KEYS', (
    'uptime_in_seconds',
))


def prettify(key, value):
    if key in REDISBOARD_DETAIL_SECONDS_KEYS:
        return key, timedelta(seconds=value)
    elif key in REDISBOARD_DETAIL_TIMESTAMP_KEYS:
        return key, datetime.fromtimestamp(value)
    else:
        return key, value

class RedisServerAdmin(admin.ModelAdmin):
    list_display = (
        '__unicode__', 'status', 'memory', 'clients', 'details'
    )
    def status(self, obj):
        return obj.stats['status']

    def memory(self, obj):
        return obj.stats['memory']

    def clients(self, obj):
        return obj.stats['clients']

    def details(self, obj):
        return "<table>%s</table>" % ''.join(
            "<tr><td>%s</td><td>%s</td></tr>" % prettify(k, v)
                for k, v in sorted(obj.stats['details'].items(), key=lambda (k,v): k)
                if any(name.match(k) for name in REDISBOARD_DETAIL_FILTERS)
        )

    details.allow_tags = True

admin.site.register(RedisServer, RedisServerAdmin)
{'fraction_non_alphanumeric': 0.13209779179810727, 'fraction_numerical': 0.0003943217665615142, 'mean_word_length': 3.689463955637708, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1744793', 'n_tokens_mistral': 865, 'n_tokens_neox': 840, 'n_words': 175}