Ejemplo n.º 1
0
def user(u, msg, request=None):
    from apps.statistics.models import MAnalyticsPageLoad
    platform = '------'
    time_elapsed = ""
    if isinstance(u, WSGIRequest) or request:
        if not request:
            request = u
            u = request.user
        platform = extract_user_agent(request)

        if hasattr(request, 'start_time'):
            seconds = time.time() - request.start_time
            color = '~FK~SB'
            if seconds >= .5:
                color = '~FR'
            elif seconds <= .15:
                color = '~FB'
            time_elapsed = "[%s%.4ss~SB] " % (
                color,
                seconds,
            )
    is_premium = u.is_authenticated() and u.profile.is_premium
    premium = '*' if is_premium else ''
    username = cipher(unicode(u)) if settings.CIPHER_USERNAMES else unicode(u)
    info(' ---> [~FB~SN%-6s~SB] %s[%s%s] %s' % (platform, time_elapsed, username, premium, msg))
    if request:
        MAnalyticsPageLoad.add(user=u, is_premium=is_premium, platform=platform, path=request.path, 
                               duration=seconds)
Ejemplo n.º 2
0
Archivo: log.py Proyecto: 4iji/NewsBlur
def user(u, msg, request=None):
    from apps.statistics.models import MAnalyticsPageLoad
    
    if not u:
        return debug(msg)
        
    platform = '------'
    time_elapsed = ""
    if isinstance(u, WSGIRequest) or request:
        if not request:
            request = u
            u = request.user
        platform = extract_user_agent(request)

        if hasattr(request, 'start_time'):
            seconds = time.time() - request.start_time
            color = '~FK~SB'
            if seconds >= 1:
                color = '~FR'
            elif seconds <= .2:
                color = '~FB'
            time_elapsed = "[%s%.4ss~SB] " % (
                color,
                seconds,
            )
    is_premium = u.is_authenticated() and u.profile.is_premium
    premium = '*' if is_premium else ''
    username = cipher(unicode(u)) if settings.CIPHER_USERNAMES else unicode(u)
    info(' ---> [~FB~SN%-6s~SB] %s[%s%s] %s' % (platform, time_elapsed, username, premium, msg))
    page_load_paths = [
        "/reader/feed/",
        "/social/stories/",
        "/reader/river_stories/",
        "/social/river_stories/"
    ]
    if request:
        path = MAnalyticsPageLoad.clean_path(request.path)
        if path in page_load_paths:
            MAnalyticsPageLoad.add(user=u, is_premium=is_premium, platform=platform, path=path, 
                                   duration=seconds)
            RStats.add('page_load', duration=seconds)
Ejemplo n.º 3
0
def user(u, msg, request=None, warn_color=True):
    if not u:
        return debug(msg)
        
    platform = '------'
    time_elapsed = ""
    if isinstance(u, WSGIRequest) or request:
        if not request:
            request = u
            u = request.user
        platform = extract_user_agent(request)

        if hasattr(request, 'start_time'):
            seconds = time.time() - request.start_time
            color = '~FB'
            if warn_color:
                if seconds >= 1:
                    color = '~FR'
                elif seconds > .2:
                    color = '~SB~FK'
            time_elapsed = "[%s%.4ss~SB] " % (
                color,
                seconds,
            )
    is_premium = u.is_authenticated() and u.profile.is_premium
    premium = '*' if is_premium else ''
    username = cipher(unicode(u)) if settings.CIPHER_USERNAMES else unicode(u)
    info(' ---> [~FB~SN%-6s~SB] %s[%s%s] %s' % (platform, time_elapsed, username, premium, msg))
    page_load_paths = [
        "/reader/feed/",
        "/social/stories/",
        "/reader/river_stories/",
        "/social/river_stories/"
    ]
    if request:
        path = RStats.clean_path(request.path)
        if path in page_load_paths:
            RStats.add('page_load', duration=seconds)