コード例 #1
0
 def get(self):
   counter_name = self.request.get('counter_name')
   namespace = self.request.get('namespace')
   if not namespace:
       namespace = "default"
   delta = self.request.get('delta')
   if not delta:
     delta = 0
   logging.info("getting LivecountCounters for namespace = " + str(namespace))
   modified_counter = None
   if counter_name:
     modified_counter = LivecountCounter.get_by_key_name(namespace + ":" + counter_name)
   
   counter_entities_query = LivecountCounter.all().filter("namespace = ", namespace).order('-count')
   counter_entities = counter_entities_query.fetch(20)
   logging.info("counter_entities: " + str(counter_entities))
   
   stats = counter.GetMemcacheStats()
   template_values = {
     'namespace': namespace,
     'counters': counter_entities,
     'modified_counter': modified_counter,
     'counter_name': counter_name,
     'delta': delta,
     '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))
コード例 #2
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)
コード例 #3
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))
コード例 #4
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))
コード例 #5
0
ファイル: views.py プロジェクト: 1ncnspcuous/WebPutty
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)
コード例 #6
0
  def get(self):
    counter_name = self.request.get('counter_name')
    namespace = self.request.get('namespace')
    if not namespace:
        namespace = "share_domain_count"
    fetch_limit = self.request.get('fetch_limit')
    if not fetch_limit:
        fetch_limit = "20"
    
    if counter_name:
        logging.info("querying counter directly for counter_name = " + str(counter_name) + ", namespace = " + str(namespace))
        count = counter.load_and_get_count(counter_name, namespace=namespace)
        
        self.response.set_status(200)
        self.response.out.write(count)
    else:
        logging.info("querying datastore for LivecountCounters for counter_name = " + str(counter_name) + ", namespace = " + str(namespace))
        counter_entities_query = LivecountCounter.all().order('-count')
        if counter_name:
            counter_entities_query.filter("counter_name = ", counter_name)
        if namespace:
            counter_entities_query.filter("namespace = ", namespace)
        counter_entities = counter_entities_query.fetch(int(fetch_limit))
        logging.info("counter_entities: " + str(counter_entities))

        counters = []
        for entity in counter_entities:
            counter_data = {'key': str(entity.key().name()),
                            'count': str(entity.count)}
            counters.append(counter_data)
        json_counters_data = simplejson.dumps(counters)
            
        if json_counters_data:
            self.response.set_status(200)
            self.response.out.write(json_counters_data)
            return