Пример #1
0
    def init_app(self, app, config=None):
        "This is used to initialize bitmapist with your app object"
        self.app = app
        self.redis_url = app.config.get('BITMAPIST_REDIS_URL',
                                        'redis://localhost:6379')
        self.redis_auth = app.config.get('BITMAPIST_REDIS_PASSWORD')

        if self.redis_url not in _bitmapist.SYSTEMS.values():
            host, port = _get_redis_connection(self.redis_url)
            _bitmapist.setup_redis(
                app.config.get('BITMAPIST_REDIS_SYSTEM', 'default'),
                host,
                port,
                password=self.redis_auth)

        _bitmapist.TRACK_HOURLY = app.config.get('BITMAPIST_TRACK_HOURLY',
                                                 False)

        if not hasattr(app, 'extensions'):
            app.extensions = {}

        app.extensions['bitmapist'] = self

        if not app.config.get('BITMAPIST_DISABLE_BLUEPRINT', False):
            app.register_blueprint(bitmapist_bp)
Пример #2
0
    def __init__(self):
        # We call setup_redis to setup bitmapist, but we can also just use
        # the connection that it makes by calling get_redis
        setup_redis(
            'default',
            settings.REDIS_HOSTNAME,
            port=settings.REDIS_PORT,
            password=settings.REDIS_PASSWORD)

        self.redis = get_redis(system='default')
Пример #3
0
    def save(self, *args, **kwargs):
        created = self.pk is None
        super(Account, self).save(*args, **kwargs)

        setup_redis(
            'engine_redis',
            settings.REDIS_HOSTNAME,
            port=settings.REDIS_PORT,
            password=settings.REDIS_PASSWORD)

        if created:
            mark_event('account:created', self.id, system='engine_redis')
        else:
            mark_event('account:updated', self.id, system='engine_redis')
Пример #4
0
    def save(self, *args, **kwargs):
        created = self.pk is None
        super(Issue, self).save(*args, **kwargs)

        setup_redis(
            'engine_redis',
            settings.REDIS_HOSTNAME,
            port=settings.REDIS_PORT,
            password=settings.REDIS_PASSWORD)

        if created:
            mark_event('issue:created', self.id, system='engine_redis')
        else:
            mark_event('issue:updated', self.id, system='engine_redis')

        if self.status != 0:
            mark_event('issue:solved', self.id, system='engine_redis')
Пример #5
0
    def init_app(self, app, config=None):
        "This is used to initialize bitmapist with your app object"
        self.app = app
        self.redis_url = app.config.get('BITMAPIST_REDIS_URL', 'redis://localhost:6379')

        if self.redis_url not in _bitmapist.SYSTEMS.values():
            host, port = _get_redis_connection(self.redis_url)
            _bitmapist.setup_redis(
                app.config.get('BITMAPIST_REDIS_SYSTEM', 'default'),
                host,
                port)

        _bitmapist.TRACK_HOURLY = app.config.get('BITMAPIST_TRACK_HOURLY', False)

        if not hasattr(app, 'extensions'):
            app.extensions = {}

        app.extensions['bitmapist'] = self
        app.register_blueprint(bitmapist_bp)
Пример #6
0
    def get_context_data(self, **kwargs):
        context = super(AnalyticsView, self).get_context_data(**kwargs)

        # This sets up redis as well for bitmapist lib as well as custom analytics

        setup_redis(
            'engine_redis',
            settings.REDIS_HOSTNAME,
            port=settings.REDIS_PORT,
            password=settings.REDIS_PASSWORD)

        now = datetime.utcnow()

        context['number_of_accounts'] = Account.objects.count()
        context['number_of_accounts_this_week'] = len(WeekEvents('account:created', now.year, now.isocalendar()[1]))
        context['number_of_accounts_this_month'] = len(MonthEvents('account:created', now.year, now.month))

        context['number_of_resources'] = Resource.objects.count()
        context['number_of_resources_this_week'] = len(WeekEvents('resource:created', now.year, now.isocalendar()[1]))
        context['number_of_resources_this_month'] = len(MonthEvents('resource:created', now.year, now.month))

        context['number_of_tags'] = Tag.objects.count()
        context['number_of_tags_this_week'] = len(WeekEvents('tag:created', now.year, now.isocalendar()[1]))
        context['number_of_tags_this_month'] = len(MonthEvents('tag:created', now.year, now.month))

        context['number_of_locations'] = Location.objects.count()
        context['number_of_locations_this_week'] = len(WeekEvents('location:created', now.year, now.isocalendar()[1]))
        context['number_of_locations_this_month'] = len(MonthEvents('location:created', now.year, now.month))

        context['number_of_unsolved_issues'] = Issue.objects.filter(status=Issue.RESOLUTION_NONE).count()
        context['number_of_solved_issues_this_week'] = len(WeekEvents('issue:solved', now.year, now.isocalendar()[1]))
        context['number_of_solved_issues_this_month'] = len(MonthEvents('issue:solved', now.year, now.month))

        end_date = datetime.utcnow()
        start_date = end_date - timedelta(days=30)

        context['popular_search_terms'] = analytics.get_category('search_query', start_date, end_date)
        context['popular_search_locations'] = analytics.get_category('search_location', start_date, end_date)
        context['recent_searches'] = analytics.get_list('recent_searches')

        return context
Пример #7
0
def setup_module():
    setup_redis("default", "localhost", 6380)
    setup_redis("default_copy", "localhost", 6380)
Пример #8
0
from django.conf import settings
from django.db import transaction
from django.utils import timezone
from bitmapist import setup_redis, mark_event, unmark_event, WeekEvents, MonthEvents, DayEvents, HourEvents
import pytz

from omaha.utils import get_id, is_new_install, valuedispatch, redis
from omaha.settings import DEFAULT_CHANNEL
from omaha.models import ACTIVE_USERS_DICT_CHOICES, Request, AppRequest, Os, Hw, Event, Version, Channel
from sparkle.models import SparkleVersion

__all__ = ['userid_counting', 'is_user_active']

host, port, db = settings.CACHES['statistics']['LOCATION'].split(':')
setup_redis('default', host, port, db=db)


def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event('request', id, now=now)
    list(
        map(partial(add_app_statistics, id, platform, now=now), apps_list
            or []))


def add_app_statistics(userid, platform, app, now=None):
    mark = partial(mark_event, now=now)
    if not now:
        now = timezone.now()
    appid = app.get('appid')
Пример #9
0
from bitmapist import (setup_redis, mark_event, unmark_event, WeekEvents,
                       MonthEvents, DayEvents, HourEvents)
import pytz

from omaha.utils import (get_id, is_new_install, valuedispatch, redis,
                         get_platforms_by_appid)
from omaha import parser
from omaha.models import (ACTIVE_USERS_DICT_CHOICES, Request, AppRequest, Os,
                          Hw, Event, Version, Channel, Platform)
from sparkle.models import SparkleVersion

__all__ = ['userid_counting', 'is_user_active']

setup_redis('default',
            settings.REDIS_STAT_HOST,
            settings.REDIS_STAT_PORT,
            db=settings.REDIS_STAT_DB,
            password=settings.REDIS_PASSWORD)


def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event('request', id, now=now)
    list(
        map(partial(add_app_statistics, id, platform, now=now), apps_list
            or []))


def add_app_statistics(userid, platform, app, now=None):
    mark = partial(mark_event, now=now)
    if not now:
Пример #10
0
from django.conf import settings
from django.db import transaction
from django.utils import timezone
from bitmapist import setup_redis, mark_event, unmark_event, WeekEvents, MonthEvents, DayEvents, HourEvents
import pytz

from omaha.utils import get_id, is_new_install, valuedispatch, redis
from omaha.settings import DEFAULT_CHANNEL
from omaha.models import ACTIVE_USERS_DICT_CHOICES, Request, AppRequest, Os, Hw, Event, Version, Channel
from sparkle.models import SparkleVersion

__all__ = ['userid_counting', 'is_user_active']

host, port, db = settings.CACHES['statistics']['LOCATION'].split(':')
setup_redis('default', host, port, db=db)


def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event('request', id, now=now)
    list(map(partial(add_app_statistics, id, platform, now=now), apps_list or []))


def add_app_statistics(userid, platform, app, now=None):
    mark = partial(mark_event, now=now)
    if not now:
        now = timezone.now()
    appid = app.get('appid')
    version = app.get('version')
    channel = app.get('tag') or DEFAULT_CHANNEL
Пример #11
0
def setup_module():
    setup_redis('default', 'localhost', 6380)
    setup_redis('default_copy', 'localhost', 6380)
Пример #12
0
def setup_module():
    setup_redis('default', 'localhost', 6380)
    setup_redis('default_copy', 'localhost', 6380)
Пример #13
0
def setup_redis_for_bitmapist():
    setup_redis('default', 'localhost', 6399)
    setup_redis('default_copy', 'localhost', 6399)
    setup_redis('db1', 'localhost', 6399, db=1)
Пример #14
0
from omaha.utils import (
    get_id, is_new_install, valuedispatch,
    redis, get_platforms_by_appid
)
from omaha import parser
from omaha.models import (
    ACTIVE_USERS_DICT_CHOICES, Request, AppRequest,
    Os, Hw, Event, Version, Channel, Platform
)
from sparkle.models import SparkleVersion

__all__ = ['userid_counting', 'is_user_active']

setup_redis('default',
            settings.REDIS_STAT_HOST,
            settings.REDIS_STAT_PORT,
            db=settings.REDIS_STAT_DB,
            password=settings.REDIS_PASSWORD)


def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event('request', id, now=now)
    list(map(partial(add_app_statistics, id, platform, now=now), apps_list or []))


def add_app_statistics(userid, platform, app, now=None):
    mark = partial(mark_event, now=now)
    if not now:
        now = timezone.now()
    appid = app.get('appid')
Пример #15
0
from functools import partial
from datetime import datetime, timedelta

from django.conf import settings
from django.db import transaction
from django.utils import timezone
from bitmapist import setup_redis, mark_event, WeekEvents, MonthEvents, DayEvents

from omaha.utils import get_id, valuedispatch
from omaha.settings import DEFAULT_CHANNEL
from omaha.models import ACTIVE_USERS_DICT_CHOICES, Request, AppRequest, Os, Hw, Event, Version, Channel

__all__ = ["userid_counting", "is_user_active"]

host, port, db = settings.CACHES["statistics"]["LOCATION"].split(":")
setup_redis("default", host, port, db=db)


def userid_counting(userid, apps_list, platform, now=None):
    id = get_id(userid)
    mark_event("request", id, now=now)
    list(map(partial(add_app_statistics, id, platform, now=now), apps_list or []))


def add_app_statistics(userid, platform, app, now=None):
    mark = partial(mark_event, now=now)
    appid = app.get("appid")
    version = app.get("version")
    channel = app.get("tag") or DEFAULT_CHANNEL
    mark("request:%s" % appid, userid)
    mark("request:{}:{}".format(appid, version), userid)
Пример #16
0
def setup_redis_for_bitmapist():
    setup_redis('default', 'localhost', 6399)
    setup_redis('default_copy', 'localhost', 6399)