<commit_before>"""
This module contains the settings for this app. We'll attempt to pull values
from django's settings, falling back to the default values.
"""
from django.conf import settings


app_settings = {
    'REDIS_METRICS_HOST': getattr(settings, 'REDIS_METRICS_HOST', 'localhost'),
    'REDIS_METRICS_PORT': int(getattr(settings, 'REDIS_METRICS_PORT', 6379)),
    'REDIS_METRICS_DB': int(getattr(settings, 'REDIS_METRICS_DB', 0)),
    'REDIS_METRICS_PASSWORD': getattr(settings, 'REDIS_METRICS_PASSWORD', None),
    'REDIS_METRICS_SOCKET_TIMEOUT': getattr(
        settings, 'REDIS_METRICS_SOCKET_TIMEOUT', None
    ),
    'REDIS_METRICS_SOCKET_CONNECTION_POOL': getattr(
        settings, 'REDIS_METRICS_SOCKET_CONNECTION_POOL', None
    ),
}<commit_msg>app_settings should always default to django's settings if they exist; so building this as a class taht always does the lookup first.<commit_after>"""
This module contains the settings for this app. We'll attempt to pull values
from django's settings, falling back to the default values.
"""
from django.conf import settings


class AppSettings(object):
    """This application-specific settings class will acts just like a
    dictionary or an object. It provides access to settings values via:

        app_settings['REDIS_METRICS_HOST']

    or as attribute values:

        app_settings.REDIS_METRICS_HOST

    On access, we'll first try to look up values in Django's settings, and
    if the setting is not found there, we'll provide a default value.
    """

    # list of (setting name, default value)
    _default_settings = {
        'REDIS_METRICS_HOST': 'localhost',
        'REDIS_METRICS_PORT': 6397,
        'REDIS_METRICS_DB': 0,
        'REDIS_METRICS_PASSWORD': None,
        'REDIS_METRICS_SOCKET_TIMEOUT': None,
        'REDIS_METRICS_SOCKET_CONNECTION_POOL': None,
        'REDIS_METRICS_MIN_GRANULARITY': 'daily',
        'REDIS_METRICS_MAX_GRANULARITY': 'yearly',
    }

    def __getattr__(self, name):
        """Access settings as an attribute."""
        try:
            return self[name]
        except KeyError as e:
            # Failed attribute access should raise an AttributeError
            raise AttributeError(e)

    def __getitem__(self, key):
        """Access settings as a dictionary key."""
        return getattr(settings, key, self._default_settings[key])


app_settings = AppSettings()


# All possible granularity values.
GRANULARITIES = ['seconds', 'minutes', 'hourly', 'daily', 'weekly', 'monthly', 'yearly']


# The Redis metric key and date formatting patterns for each key, by granularity
METRIC_KEY_PATTERNS = {
    "seconds": {"key": "m:{0}:s:{1}", "date_format": "%Y-%m-%d-%H-%M-%S"},
    "minutes": {"key": "m:{0}:i:{1}", "date_format": "%Y-%m-%d-%H-%M"},
    "hourly": {"key": "m:{0}:h:{1}", "date_format": "%Y-%m-%d-%H"},
    "daily": {"key": "m:{0}:{1}", "date_format": "%Y-%m-%d"},
    "weekly": {"key": "m:{0}:w:{1}", "date_format": "%Y-%U"},
    "monthly": {"key": "m:{0}:m:{1}", "date_format": "%Y-%m"},
    "yearly": {"key": "m:{0}:y:{1}", "date_format": "%Y"},
}
{'fraction_non_alphanumeric': 0.14451988360814744, 'fraction_numerical': 0.007759456838021339, 'mean_word_length': 3.9822866344605474, 'pattern_counts': {'":': 21, '<': 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': '5598170', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1004, 'n_words': 278}