Exemple #1
0
def update_daily_stats(request):
    """
    Group stories by day of the week and record the totals in the database.
    """
    qs = Story.all().filter("updated_date >=", ANALYSIS_STARTDATE).order("-updated_date")
    data_dict = {}
    for obj in qs:
        this_weekday = obj.updated_local().weekday()
        try:
            data_dict[this_weekday] += 1
        except KeyError:
            data_dict[this_weekday] = 1
    data_json = simplejson.dumps(data_dict)
    logging.info("Creating a new DailyStats record")
    obj = DailyStats(creation_datetime=datetime.now(), data=data_json)
    obj.put()
    return HttpResponse('ok!')
Exemple #2
0
def byline_stats(request):
    """
    Statistics about Politico bylines
    """
    hourly_stats = HourlyStats.all().order("-creation_datetime").get()
    daily_stats = DailyStats.all().order("-creation_datetime").get()
    context = {
        'hourly_stats': hourly_stats,
        'daily_stats': daily_stats,
        'selected': 'byline_stats',
    }
    return direct_to_template(request, 'byline_stats.html', context)