<commit_before>"""
Django settings for stagecraft project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

import os
import sys
from os.path import abspath, dirname, join as pjoin
from datetime import timedelta

try:
    from urllib.parse import urlparse  # Python 3
except ImportError:
    from urlparse import urlparse  # Python 2

BASE_DIR = abspath(pjoin(dirname(__file__), '..', '..'))

sys.path.append(pjoin(BASE_DIR, 'apps'))
sys.path.append(pjoin(BASE_DIR, 'libs'))

import djcelery
from celery.schedules import crontab

djcelery.setup_loader()

# Defined here for safety, they should also be defined in each environment.
DEBUG = False
TEMPLATE_DEBUG = False

ALLOWED_HOSTS = []

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

STATSD_HOST = 'localhost'
STATSD_PORT = 8125
STATSD_PREFIX = 'pp.apps.stagecraft'
STATSD_MAXUDPSIZE = 512
STATSD_CLIENT = 'django_statsd.clients.normal'


def load_databases_from_environment():
    # eg postgres://user3123:pass123@database.foo.com:6212/db982398
    DATABASE_URL = urlparse(os.environ['DATABASE_URL'])
    return {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': DATABASE_URL.path[1:],
            'USER': DATABASE_URL.username,
            'PASSWORD': DATABASE_URL.password,
            'HOST': DATABASE_URL.hostname,
            'PORT': DATABASE_URL.port,
        }
    }


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'djcelery',
    'reversion',

    'stagecraft.apps.collectors',
    'stagecraft.apps.datasets',
    'stagecraft.apps.dashboards',
    'stagecraft.apps.organisation',
    'stagecraft.apps.transforms',
    'stagecraft.apps.users',
)

MIDDLEWARE_CLASSES = (
    'dogslow.WatchdogMiddleware',
    'django_statsd.middleware.GraphiteRequestTimingMiddleware',
    'stagecraft.libs.request_logger.middleware.RequestLoggerMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'reversion.middleware.RevisionMiddleware',
)

STATSD_PATCHES = (
    'django_statsd.patches.db',
)
ROOT_URLCONF = 'stagecraft.urls'

WSGI_APPLICATION = 'stagecraft.wsgi.application'

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-gb'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

NOSE_ARGS = ['-s', '--exclude-dir=stagecraft/settings']

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = abspath(pjoin(BASE_DIR, 'assets'))

DOGSLOW_LOG_TO_FILE = False
DOGSLOW_TIMER = 1
DOGSLOW_LOGGER = 'stagecraft.apps'
DOGSLOW_LOG_LEVEL = 'INFO'

#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CELERY_RESULT_BACKEND = 'djcelery.backends.database.DatabaseBackend'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERYBEAT_SCHEDULE = {
    'realtime': {
        'task': 'stagecraft.apps.collectors.tasks.run_collectors_by_type',
        'schedule': timedelta(minutes=5),
        'args': ('ga-realtime', 'piwik-realtime')
    },
    'hourly': {
        'task': 'stagecraft.apps.collectors.tasks.run_collectors_by_type',
        'schedule': timedelta(hours=1),<commit_msg>Replace timedelta with crontab in task scheduling<commit_after>"""
Django settings for stagecraft project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

import os
import sys
from os.path import abspath, dirname, join as pjoin

try:
    from urllib.parse import urlparse  # Python 3
except ImportError:
    from urlparse import urlparse  # Python 2

BASE_DIR = abspath(pjoin(dirname(__file__), '..', '..'))

sys.path.append(pjoin(BASE_DIR, 'apps'))
sys.path.append(pjoin(BASE_DIR, 'libs'))

import djcelery
from celery.schedules import crontab

djcelery.setup_loader()

# Defined here for safety, they should also be defined in each environment.
DEBUG = False
TEMPLATE_DEBUG = False

ALLOWED_HOSTS = []

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

STATSD_HOST = 'localhost'
STATSD_PORT = 8125
STATSD_PREFIX = 'pp.apps.stagecraft'
STATSD_MAXUDPSIZE = 512
STATSD_CLIENT = 'django_statsd.clients.normal'


def load_databases_from_environment():
    # eg postgres://user3123:pass<PASSWORD>@database.foo.com:6212/db982398
    DATABASE_URL = urlparse(os.environ['DATABASE_URL'])
    return {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': DATABASE_URL.path[1:],
            'USER': DATABASE_URL.username,
            'PASSWORD': <PASSWORD>,
            'HOST': DATABASE_URL.hostname,
            'PORT': DATABASE_URL.port,
        }
    }


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'djcelery',
    'reversion',

    'stagecraft.apps.collectors',
    'stagecraft.apps.datasets',
    'stagecraft.apps.dashboards',
    'stagecraft.apps.organisation',
    'stagecraft.apps.transforms',
    'stagecraft.apps.users',
)

MIDDLEWARE_CLASSES = (
    'dogslow.WatchdogMiddleware',
    'django_statsd.middleware.GraphiteRequestTimingMiddleware',
    'stagecraft.libs.request_logger.middleware.RequestLoggerMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'reversion.middleware.RevisionMiddleware',
)

STATSD_PATCHES = (
    'django_statsd.patches.db',
)
ROOT_URLCONF = 'stagecraft.urls'

WSGI_APPLICATION = 'stagecraft.wsgi.application'

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-gb'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

NOSE_ARGS = ['-s', '--exclude-dir=stagecraft/settings']

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = abspath(pjoin(BASE_DIR, 'assets'))

DOGSLOW_LOG_TO_FILE = False
DOGSLOW_TIMER = 1
DOGSLOW_LOGGER = 'stagecraft.apps'
DOGSLOW_LOG_LEVEL = 'INFO'

#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CELERY_RESULT_BACKEND = 'djcelery.backends.database.DatabaseBackend'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERYBEAT_SCHEDULE = {
    'realtime': {
        'task': 'stagecraft.apps.collectors.tasks.run_collectors_by_type',
        'schedule': crontab(minute='*/5'),
        'args': ('ga-realtime', 'piwik-realtime')
    },
    'hourly': {
        'task': 'stagecraft.apps.collectors.tasks.run_collectors_by_type',
        'schedule': crontab(minute=0),
{'fraction_non_alphanumeric': 0.12384015835704565, 'fraction_numerical': 0.010763330446616355, 'mean_word_length': 4.335973597359736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2204264', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2853, 'n_words': 463}