From 6ca97cca5e9e100bbf47b41212b75ae113f72022 Mon Sep 17 00:00:00 2001 From: bsimpson63 Date: Thu, 11 Apr 2013 18:41:57 -0400 Subject: [PATCH] Sum promotion_history for all rows with the same interval/codename/date. Also don't return uniques because their summed values are not meaningful. --- r2/r2/models/traffic.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/r2/r2/models/traffic.py b/r2/r2/models/traffic.py index 0c00c2a89..b09b01c46 100644 --- a/r2/r2/models/traffic.py +++ b/r2/r2/models/traffic.py @@ -326,14 +326,20 @@ def total_by_codename(cls, codenames): def promotion_history(cls, codename, start, stop): - """Get hourly traffic for a self-serve promotion across all campaigns.""" + """Get hourly traffic for a self-serve promotion. + + Traffic stats are summed over all targets for classes that include a target. + + """ + time_points = get_time_points('hour', start, stop) - q = (Session.query(cls) + q = (Session.query(cls.date, sum(cls.pageview_count)) .filter(cls.interval == "hour") .filter(cls.codename == codename) .filter(cls.date.in_(time_points)) + .group_by(cls.date) .order_by(cls.date)) - return [(r.date, (r.unique_count, r.pageview_count)) for r in q.all()] + return [(r[0], (r[1],)) for r in q.all()] @memoize("traffic_last_modified", time=60 * 10)