def get_city_stats_daily(adomain, latest=None): start, end = get_start_end(latest, datetime.timedelta(days=7)) cities = get_top_cities(adomain, start, end) for city in cities: for t in dtrange(start.replace(minute=0, second=0, microsecond=0), end, datetime.timedelta(days=1)): city.history.extend(list(VisitorCityDailyStats.objects.filter(adomain=adomain, timestamp=t, city=city)) or [VisitorCityDailyStats(timestamp=t)]) return json.dumps(json_transform(Wrapper(cities, end), CITY_STATS_TEMPLATE), default=json_handler)
def get_top_entry_pages_stats_daily(adomain, latest=None): start, end = get_start_end(latest, datetime.timedelta(days=7)) pages = get_top_exit_pages(adomain, start, end) for page in pages: page.history = [] for t in dtrange(start.replace(hour=0, minute=0, second=0, microsecond=0), end, datetime.timedelta(days=1)): page.history.extend(list(DomainPageDailyStats.objects.filter(adomain=adomain, timestamp=t, pathname=page.pathname)) or [DomainPageHourlyStats(timestamp=t)]) return json.dumps(json_transform(Wrapper(pages, end), ENTRY_EXIT_PAGE_STATS_TEMPLATE), default=json_handler)
def get_country_stats_hourly(adomain, latest=None): start, end = get_start_end(latest, datetime.timedelta(days=1)) countries = get_top_countries(adomain, start, end) for country in countries: country.history = [] for t in dtrange(start.replace(minute=0, second=0, microsecond=0), end, datetime.timedelta(hours=1)): country.history.extend(list(VisitorCountryHourlyStats.objects.filter(adomain=adomain, timestamp=t, country=country)) or [VisitorCountryHourlyStats(timestamp=t)]) return json.dumps(json_transform(Wrapper(countries, end), COUNTRY_STATS_TEMPLATE), default=json_handler)
def get_hourly_stats_history(adomain, latest=None): start, end = get_start_end(latest, datetime.timedelta(days=1)) last_stat = get_domain_page_view_stats(adomain, start, end, VisitorPageviewTenMinuteStats) last_stat.history = list(VisitorPageviewHourlyStats.objects.filter(timestamp__gt=start, adomain=adomain).order_by("timestamp")) return json.dumps(json_transform(last_stat, PAGEVIEW_STATS_TEMPLATE, {'latest': end, 'live': live_pageview_stats(adomain)}), default=json_handler)