Пример #1
0
def _stats():
    if not (users.is_current_user_admin()
            or users.get_current_user().email().endswith('@fogcreek.com')
            or request.remote_addr in ['127.0.0.1', '71.190.247.30']):
        abort(404)

    user_count = GqlQuery('SELECT __key__ FROM UserSettings').count(None)
    site_count = GqlQuery(
        'SELECT __key__ FROM Site WHERE example=false').count(None)
    now = datetime.now()
    days = list(reversed([now - timedelta(days) for days in range(14)]))
    day_views = [
        get_period_and_count('css:all', PeriodType.DAY, day) for day in days
    ]
    day_users = [
        get_period_and_count('user:all', PeriodType.DAY, day) for day in days
    ]
    day_sites = [
        get_period_and_count('site:all', PeriodType.DAY, day) for day in days
    ]
    # overwrite today's cached numbers with the live count we just got from the database
    day_users[-1] = day_users[-1][0], user_count
    day_sites[-1] = day_sites[-1][0], site_count

    # get the top referrers
    period_type = PeriodType.DAY
    fetch_limit = 50
    query = LivecountCounter.all().order('-count')
    query.filter('period_type = ', period_type)
    query.filter('period = ', PeriodType.find_scope(period_type,
                                                    datetime.now()))
    top_counters = query.fetch(fetch_limit)
    top_referrers = []
    for counter in top_counters:
        name = counter.name
        if name.startswith('css:page') and not name.startswith(
                'css:page:www.webputty.net'):
            parts = name.split(':')
            page = None
            preview_size = 0
            published_size = 0
            try:
                page = Page.get(parts[3])
            except Exception:
                logging.warn("_stats counldn't find matching page: %s",
                             parts[3])
            if page:
                preview_size = len(page.compressed_css(True))
                published_size = len(page.compressed_css(False))
            top_referrers.append((parts[2], counter.count, parts[3],
                                  preview_size, published_size))

    return render_template('_stats.html',
                           user_count=user_count,
                           site_count=site_count,
                           day_views=day_views,
                           day_users=day_users,
                           day_sites=day_sites,
                           top_referrers=top_referrers)
Пример #2
0
    def get(self):
        namespace = self.request.get('namespace')
        period_type = self.request.get('period_type')
        period_types = self.request.get('period_types').replace(" ", "")
        period = self.request.get('period')
        name = self.request.get('counter_name')
        delta = self.request.get('delta')
        fetch_limit = self.request.get('fetch_limit')

        if not namespace:
            namespace = "default"
        if not period_type:
            period_type = PeriodType.DAY
        if not period_types:
            period_types = PeriodType.DAY + "," + PeriodType.WEEK
        if not period:
            period = str(datetime.now()).split(".")[0]
        if not delta:
            delta = 1
        if not fetch_limit:
            fetch_limit = "20"

        modified_counter = None
        if name:
            full_key = LivecountCounter.KeyName(namespace, period_type, period,
                                                name)
            modified_counter = LivecountCounter.get_by_key_name(full_key)

        counter_entities_query = LivecountCounter.all().order('-count')
        if namespace:
            counter_entities_query.filter("namespace = ", namespace)
        if period_type:
            counter_entities_query.filter("period_type = ", period_type)
        scoped_period = PeriodType.find_scope(period_type, period)
        if period:
            counter_entities_query.filter("period = ", scoped_period)
        counter_entities = counter_entities_query.fetch(int(fetch_limit))
        logging.info("counter_entities: " + str(counter_entities))

        stats = counter.GetMemcacheStats()

        template_values = {
            'namespace': namespace,
            'period_type': period_type,
            'period_types': period_types,
            'period': period,
            'counter_name': name,
            'delta': delta,
            'modified_counter': modified_counter,
            'counters': counter_entities,
            'stats': stats
        }
        logging.info("template_values: " + str(template_values))
        template_file = os.path.join(os.path.dirname(__file__),
                                     'counter_admin.html')
        self.response.out.write(template.render(template_file,
                                                template_values))
Пример #3
0
    def get(self):
        period_type = self.request.get('period_type')
        period_types = self.request.get('period_types').replace(" ", "")
        period = self.request.get('period')
        name = self.request.get('counter_name')
        delta = self.request.get('delta')
        fetch_limit = self.request.get('fetch_limit')

        if not period_type:
            period_type = PeriodType.DAY
        if not period_types:
            period_types = PeriodType.DAY + "," + PeriodType.WEEK
        if not period:
            period = str(datetime.now()).split(".")[0]
        if not delta:
            delta = 1
        if not fetch_limit:
            fetch_limit = "20"

        modified_counter = None
        if name:
            full_key = LivecountCounter.get_key(None, period_type, period,
                                                name)
            modified_counter = full_key.get()

        counter_entities_query = LivecountCounter.query().order(
            -LivecountCounter.count)
        if period_type:
            counter_entities_query.filter(
                LivecountCounter.period_type == period_type)
        scoped_period = PeriodType.find_scope(period_type, period)
        if period:
            counter_entities_query.filter(
                LivecountCounter.period == scoped_period)
        counter_entities = counter_entities_query.fetch(int(fetch_limit))
        logging.info("counter_entities: " + str(counter_entities))

        stats = counter.GetMemcacheStats()

        template_values = {
            'period_type': period_type,
            'period_types': period_types,
            'period': period,
            'counter_name': name,
            'delta': delta,
            'modified_counter': modified_counter,
            'counters': counter_entities,
            'stats': stats
        }
        logging.info("template_values: " + str(template_values))
        template_file = os.path.join(os.path.dirname(__file__),
                                     'counter_admin.html')
        self.response.out.write(
            template.render(template_file, template_values))
Пример #4
0
def _stats():
    if not (users.is_current_user_admin() or users.get_current_user().email().endswith('@fogcreek.com') or request.remote_addr in ['127.0.0.1', '71.190.247.30']):
        abort(404)

    user_count = GqlQuery('SELECT __key__ FROM UserSettings').count(None)
    site_count = GqlQuery('SELECT __key__ FROM Site WHERE example=false').count(None)
    now = datetime.now()
    days = list(reversed([now-timedelta(days) for days in range(14)]))
    day_views = [get_period_and_count('css:all', PeriodType.DAY, day) for day in days]
    day_users = [get_period_and_count('user:all', PeriodType.DAY, day) for day in days]
    day_sites = [get_period_and_count('site:all', PeriodType.DAY, day) for day in days]
    # overwrite today's cached numbers with the live count we just got from the database
    day_users[-1] = day_users[-1][0], user_count
    day_sites[-1] = day_sites[-1][0], site_count

    # get the top referrers
    period_type = PeriodType.DAY
    fetch_limit = 50
    query = LivecountCounter.all().order('-count')
    query.filter('period_type = ', period_type)
    query.filter('period = ', PeriodType.find_scope(period_type, datetime.now()))
    top_counters = query.fetch(fetch_limit)
    top_referrers = []
    for counter in top_counters:
        name = counter.name
        if name.startswith('css:page') and not name.startswith('css:page:www.webputty.net'):
            parts = name.split(':')
            page = None
            preview_size = 0
            published_size = 0
            try:
                page = Page.get(parts[3])
            except Exception:
                logging.warn("_stats counldn't find matching page: %s", parts[3])
            if page:
                preview_size = len(page.compressed_css(True))
                published_size = len(page.compressed_css(False))
            top_referrers.append((parts[2], counter.count, parts[3], preview_size, published_size))

    return render_template('_stats.html', user_count=user_count, site_count=site_count, day_views=day_views, day_users=day_users, day_sites=day_sites, top_referrers=top_referrers)
Пример #5
0
def get_period_and_count(name, period_type, period):
    period = PeriodType.find_scope(period_type, period)
    count = counter.load_and_get_count(name, period_type=period_type, period=period)
    return period, count
Пример #6
0
def get_period_and_count(name, period_type, period):
    period = PeriodType.find_scope(period_type, period)
    count = counter.load_and_get_count(name,
                                       period_type=period_type,
                                       period=period)
    return period, count