<commit_before>"""
sentry_quotas.plugin
~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from django import forms
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from nydus.db import create_cluster
from sentry.plugins import Plugin

import logging
import time
import sentry_quotas

if not getattr(settings, 'SENTRY_QUOTAS', None):
    raise ImproperlyConfigured('You need to configure SENTRY_QUOTAS')


def get_cluster(hosts=None, router='nydus.db.routers.keyvalue.PartitionRouter'):
    hosts = {
        0: {}  # localhost / default
    }

    return create_cluster({
        'engine': 'nydus.db.backends.redis.Redis',
        'router': router,
        'hosts': hosts,
    })

redis = get_cluster(settings.SENTRY_QUOTAS['redis'])


def get_default_events_per_minute():
    # It'd be nice if this were configurable via the sentry web interface (system level)
    return settings.SENTRY_QUOTAS.get('default_events_per_minute')


class QuotasOptionsForm(forms.Form):
    per_minute = forms.CharField(label=_('Events / Minute'),
        widget=forms.Textarea(attrs={'class': 'span6', 'placeholder': 'e.g. 500'}),
        help_text=_('The maximum events per minute before dropping data. (system default is %s)', get_default_events_per_minute()))


class QuotasPlugin(Plugin):
    author = 'Sentry Team'
    author_url = 'https://github.com/getsentry/sentry'
    version = sentry_quotas.VERSION
    description = "Integrates quotas."
    resource_links = [
        ('Bug Tracker', 'https://github.com/getsentry/sentry-quotas/issues'),
        ('Source', 'https://github.com/getsentry/sentry-quotas'),
    ]

    slug = 'quotas'
    title = _('Quotas')
    conf_title = title
    conf_key = 'quotas'<commit_msg>Fix/improve help text<commit_after>"""
sentry_quotas.plugin
~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from django import forms
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from nydus.db import create_cluster
from sentry.plugins import Plugin

import logging
import time
import sentry_quotas

if not getattr(settings, 'SENTRY_QUOTAS', None):
    raise ImproperlyConfigured('You need to configure SENTRY_QUOTAS')


def get_cluster(hosts=None, router='nydus.db.routers.keyvalue.PartitionRouter'):
    hosts = {
        0: {}  # localhost / default
    }

    return create_cluster({
        'engine': 'nydus.db.backends.redis.Redis',
        'router': router,
        'hosts': hosts,
    })

redis = get_cluster(settings.SENTRY_QUOTAS['redis'])


def get_default_events_per_minute():
    # It'd be nice if this were configurable via the sentry web interface (system level)
    return settings.SENTRY_QUOTAS.get('default_events_per_minute')


def get_per_minute_help_text():
    if get_default_events_per_minute():
        return _('The maximum events per minute before dropping data (system default is %s).') % get_default_events_per_minute()
    return _('The maximum events per minute before dropping data.') % get_default_events_per_minute()


class QuotasOptionsForm(forms.Form):
    per_minute = forms.CharField(label=_('Events / Minute'),
        help_text=get_per_minute_help_text())


class QuotasPlugin(Plugin):
    author = 'Sentry Team'
    author_url = 'https://github.com/getsentry/sentry'
    version = sentry_quotas.VERSION
    description = "Integrates quotas."
    resource_links = [
        ('Bug Tracker', 'https://github.com/getsentry/sentry-quotas/issues'),
        ('Source', 'https://github.com/getsentry/sentry-quotas'),
    ]

    slug = 'quotas'
    title = _('Quotas')
    conf_title = title
    conf_key = 'quotas'
{'fraction_non_alphanumeric': 0.11887223774447549, 'fraction_numerical': 0.003556007112014224, 'mean_word_length': 4.120936280884266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '4010840', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1215, 'n_words': 306}