<commit_before>import re
import socket
from itertools import count
from collections import Counter

import django
from django.shortcuts import render
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
from django.utils.decorators import method_decorator
from django.conf import settings

from mygpo.admin.auth import require_staff
from mygpo.admin.group import PodcastGrouper
from mygpo.maintenance.merge import PodcastMerger, IncorrectMergeException
from mygpo.users.models import User
from mygpo.admin.clients import UserAgentStats, ClientStats
from mygpo.admin.tasks import merge_podcasts, unify_slugs
from mygpo.utils import get_git_head
from mygpo.api.httpresponse import JsonResponse
from mygpo.cel import celery
from mygpo.db.couchdb import get_main_database
from mygpo.db.couchdb.user import activate_user
from mygpo.db.couchdb.episode import episode_count, filetype_stats
from mygpo.db.couchdb.podcast import podcast_count, podcast_for_url


class InvalidPodcast(Exception):
    """ raised when we try to merge a podcast that doesn't exist """

class AdminView(TemplateView):

    @method_decorator(require_staff)
    def dispatch(self, *args, **kwargs):
        return super(AdminView, self).dispatch(*args, **kwargs)


class Overview(AdminView):
    template_name = 'admin/overview.html'


class HostInfo(AdminView):
    """ shows host information for diagnosis """

    template_name = 'admin/hostinfo.html'

    def get(self, request):
        commit, msg = get_git_head()
        base_dir = settings.BASE_DIR
        hostname = socket.gethostname()
        django_version = django.VERSION

        main_db = get_main_database()

        db_tasks = main_db.server.active_tasks()

        i = celery.control.inspect()
        num_celery_tasks = len(i.scheduled() or [])

        return self.render_to_response({
            'git_commit': commit,
            'git_msg': msg,
            'base_dir': base_dir,
            'hostname': hostname,
            'django_version': django_version,
            'main_db': main_db.uri,
            'db_tasks': db_tasks,
            'num_celery_tasks': num_celery_tasks,
        })



class MergeSelect(AdminView):
    template_name = 'admin/merge-select.html'

    def get(self, request):
        num = int(request.GET.get('podcasts', 2))<commit_msg>fix length calculation of celery queue<commit_after>import re
import socket
from itertools import count, chain
from collections import Counter

import django
from django.shortcuts import render
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
from django.utils.decorators import method_decorator
from django.conf import settings

from mygpo.admin.auth import require_staff
from mygpo.admin.group import PodcastGrouper
from mygpo.maintenance.merge import PodcastMerger, IncorrectMergeException
from mygpo.users.models import User
from mygpo.admin.clients import UserAgentStats, ClientStats
from mygpo.admin.tasks import merge_podcasts, unify_slugs
from mygpo.utils import get_git_head
from mygpo.api.httpresponse import JsonResponse
from mygpo.cel import celery
from mygpo.db.couchdb import get_main_database
from mygpo.db.couchdb.user import activate_user
from mygpo.db.couchdb.episode import episode_count, filetype_stats
from mygpo.db.couchdb.podcast import podcast_count, podcast_for_url


class InvalidPodcast(Exception):
    """ raised when we try to merge a podcast that doesn't exist """

class AdminView(TemplateView):

    @method_decorator(require_staff)
    def dispatch(self, *args, **kwargs):
        return super(AdminView, self).dispatch(*args, **kwargs)


class Overview(AdminView):
    template_name = 'admin/overview.html'


class HostInfo(AdminView):
    """ shows host information for diagnosis """

    template_name = 'admin/hostinfo.html'

    def get(self, request):
        commit, msg = get_git_head()
        base_dir = settings.BASE_DIR
        hostname = socket.gethostname()
        django_version = django.VERSION

        main_db = get_main_database()

        db_tasks = main_db.server.active_tasks()

        i = celery.control.inspect()
        scheduled = i.scheduled()
        if not scheduled:
            num_celery_tasks = None
        else:
            num_celery_tasks = sum(len(node) for node in scheduled.values())

        return self.render_to_response({
            'git_commit': commit,
            'git_msg': msg,
            'base_dir': base_dir,
            'hostname': hostname,
            'django_version': django_version,
            'main_db': main_db.uri,
            'db_tasks': db_tasks,
            'num_celery_tasks': num_celery_tasks,
        })



class MergeSelect(AdminView):
    template_name = 'admin/merge-select.html'

    def get(self, request):
        num = int(request.GET.get('podcasts', 2))
{'fraction_non_alphanumeric': 0.0798765193903145, 'fraction_numerical': 0.00038587690526721975, 'mean_word_length': 3.7041742286751362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '312047', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1492, 'n_words': 404}