Ejemplo n.º 1
0
    def get(self):
        last_metric_at = OrganicSearchMetric.gql("ORDER BY updated_at DESC").get()
        if last_metric_at == None:
            last_metric_at = "[Never]"
        else:
            last_metric_at = last_metric_at.updated_at

        h.output(self, '<html><head><link href="/public/css/admin/admin.css" type="text/css" rel="stylesheet" /></head><body><div id="loading-msg">Loading...</div><div id="auto-fetch-organic-search-metrics"></div><div>Organic Search Metric Re-Calculation Status: <span id="status">Last Run at: '+str(last_metric_at)+'</span> <a id="calculate-organic-search-metrics-button" href="#">RE-CALCULATE NOW!</a></div><div>Total Users: <span id="total-users">...</span></div><div>Histogram for Number of Searches: <div id="histogram-text">...</div></div><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script><script src="/public/js/admin/organic-search-metrics.js" type="text/javascript"></script></body></html>')
Ejemplo n.º 2
0
    def post(self):
        query = User.all()
        query.order('-created_at')
        cursor = self.request.get('cursor')
        if cursor != None:
            query.with_cursor(cursor)

        users = query.fetch(50)

        for user in users:
            user_queries = Query.gql("WHERE user = :1 ORDER BY created_at ASC", user).fetch(1000)
            user_search_strings = []

            for user_query in user_queries:
                if user_query.url != None:
                    parsed_url = urlparse(user_query.url)
                else:
                    parsed_url = urlparse('')
                
                
                params = cgi.parse_qs(parsed_url.query)
                    
                # Right now, we'll use the x (and y) param to signify an organic search.
                if 'x' in params and params['x'] != None:
                    user_search_strings.append(user_query.query_string)

            organic_search_metric = OrganicSearchMetric.gql("WHERE user = :1", user).get()
            if organic_search_metric == None:
                organic_search_metric = OrganicSearchMetric(
                    fb_user_id = user.fb_user_id,
                    user = user,
                    search_count = len(user_search_strings),
                    searches = "||".join(user_search_strings)
                )
            else:    
                organic_search_metric.fb_user_id = user.fb_user_id
                organic_search_metric.user = user
                organic_search_metric.search_count = len(user_search_strings)
                organic_search_metric.searches = "||".join(user_search_strings)

            organic_search_metric.put()

        self.response.out.write(simplejson.dumps({'status': 'ok', 'cursor': str(query.cursor()), 'count': len(users) }))
Ejemplo n.º 3
0
    def post(self):
        query = OrganicSearchMetric.all()
        query.order('-updated_at')
        cursor = self.request.get('cursor')
        if cursor != None:
            query.with_cursor(cursor)

        organic_search_metrics = query.fetch(1000)
        total_users = 0
        histogram = {}
        for organic_search_metric in organic_search_metrics:
            total_users += 1
            search_count_key = "%s_organic_searches" % str(organic_search_metric.search_count)
            if search_count_key in histogram:
                histogram[search_count_key] += 1
            else:
                histogram[search_count_key] = 1

        self.response.out.write(simplejson.dumps({'status': 'ok', 'cursor': str(query.cursor()), 'results': histogram, 'count': len(organic_search_metrics), 'total_users': total_users}))
Ejemplo n.º 4
0
 def get(self):
     c = h.context()
     c['model'] = 'organicsearchmetric'
     c['model_properties'] = sorted(OrganicSearchMetric.properties())
     h.render_out(self, 'admin.tplt', c)