示例#1
0
def gae_stats_daily_request_log_urlroute_stats():
    """This dashboard shows stats for the most accessed URLs, grouped by the
    route patterns that they match for handlers on the website.
    """
    def result_iter():
        # Set 'url' so that we can reuse the same template as
        # daily_request_log_url_stats.  This is done one-by-one in a
        # generator and not by iterating over the results here in
        # order to avoid exhausting the "results" cursor.
        for row in results:
            row['url'] = row['url_route']
            yield row

    num_urls = int(flask.request.args.get('count', '100'))

    # Some days the data isn't generated properly, and some days
    # it takes a while for yesterday's report to be generated.  So
    # we try going back a few days.  When we go back far enough, we
    # say so in the date.
    for days_ago in xrange(1, 8):
        dt_string = utc_as_dt(days_ago)
        results = data.daily_request_log_urlroute_stats(db,
                                                        dt=dt_string,
                                                        limit=num_urls)
        if results.count():
            return flask.render_template(
                'gae-stats/daily-request-log-url-stats.html',
                collection_rows=result_iter(),
                count=num_urls,
                date=dt_string,
                days_ago=days_ago)
示例#2
0
文件: main.py 项目: arunpn/analytics
def gae_stats_daily_request_log_urlroute_stats():
    """This dashboard shows stats for the most accessed URLs, grouped by the
    route patterns that they match for handlers on the website.
    """
    def result_iter():
        # Set 'url' so that we can reuse the same template as
        # daily_request_log_url_stats.  This is done one-by-one in a
        # generator and not by iterating over the results here in
        # order to avoid exhausting the "results" cursor.
        for row in results:
            row['url'] = row['url_route']
            yield row

    num_urls = int(flask.request.args.get('count', '100'))

    # Some days the data isn't generated properly, and some days
    # it takes a while for yesterday's report to be generated.  So
    # we try going back a few days.  When we go back far enough, we
    # say so in the date.
    for days_ago in xrange(1, 8):
        dt_string = utc_as_dt(days_ago)
        results = data.daily_request_log_urlroute_stats(db, dt=dt_string,
                                                        limit=num_urls)
        if results.count():
            return flask.render_template(
                'gae-stats/daily-request-log-url-stats.html',
                collection_rows=result_iter(),
                count=num_urls, date=dt_string, days_ago=days_ago)
示例#3
0
def gae_stats_urlroute_stats():
    """This dashboard shows stats over time for a given URL."""
    # The URL route is passed in the "url" parameter because we're
    # reusing the url_stats.html template, which does deal in URLs.
    # Valid values are generated by
    # map_reduce/py/raw_log_to_request_log_mapper.py's route_for_url()
    # method, and look like "<app.yaml module>:<handler regexp>", where
    # the module and handlers come from the main website.
    url_route = flask.request.args.get('url', 'main:/')
    # Get up to 3 years(ish) worth of data.
    url_stats = data.daily_request_log_urlroute_stats(db,
                                                      url_route=url_route,
                                                      limit=1000)
    date_record_pairs = time_series(url_stats, 'dt', '%Y-%m-%d')

    def result_iter():
        # Set 'url' so that we can reuse the same template as
        # url_stats.  This is done one-by-one in a generator and not by
        # iterating over the results here in order to avoid exhausting
        # the "results" cursor.
        for date, record in date_record_pairs:
            record['url'] = record['url_route']
            yield date, record

    # Get a list of all the routes.  Some days this data isn't generated
    # properly, and some days it takes a while for yesterday's report to
    # be generated, so we just go back in time until we get a list of
    # routes; hopefully it's *fairly* up-to-date, at least.
    for days_ago in xrange(1, 8):
        dt_string = utc_as_dt(days_ago)
        routes = data.daily_request_log_urlroute_stats(db,
                                                       dt=dt_string,
                                                       fields=['url_route'])
        routes = [r['url_route'] for r in routes]
        if routes:
            break
    else:
        routes = [url_route, '(Could not fetch full list of urls)']

    return flask.render_template('gae-stats/url-stats.html',
                                 current_url=url_route,
                                 urls=routes,
                                 date_record_pairs=result_iter())
示例#4
0
文件: main.py 项目: arunpn/analytics
def gae_stats_urlroute_stats():
    """This dashboard shows stats over time for a given URL."""
    # The URL route is passed in the "url" parameter because we're
    # reusing the url_stats.html template, which does deal in URLs.
    # Valid values are generated by
    # map_reduce/py/raw_log_to_request_log_mapper.py's route_for_url()
    # method, and look like "<app.yaml module>:<handler regexp>", where
    # the module and handlers come from the main website.
    url_route = flask.request.args.get('url', 'main:/')
    # Get up to 3 years(ish) worth of data.
    url_stats = data.daily_request_log_urlroute_stats(db, url_route=url_route,
                                                      limit=1000)
    date_record_pairs = time_series(url_stats, 'dt', '%Y-%m-%d')

    def result_iter():
        # Set 'url' so that we can reuse the same template as
        # url_stats.  This is done one-by-one in a generator and not by
        # iterating over the results here in order to avoid exhausting
        # the "results" cursor.
        for date, record in date_record_pairs:
            record['url'] = record['url_route']
            yield date, record

    # Get a list of all the routes.  Some days this data isn't generated
    # properly, and some days it takes a while for yesterday's report to
    # be generated, so we just go back in time until we get a list of
    # routes; hopefully it's *fairly* up-to-date, at least.
    for days_ago in xrange(1, 8):
        dt_string = utc_as_dt(days_ago)
        routes = data.daily_request_log_urlroute_stats(db, dt=dt_string,
                                                       fields=['url_route'])
        routes = [r['url_route'] for r in routes]
        if routes:
            break
    else:
        routes = [url_route, '(Could not fetch full list of urls)']

    return flask.render_template('gae-stats/url-stats.html',
                                 current_url=url_route, urls=routes,
                                 date_record_pairs=result_iter())