Sum promotion_history for all rows with the same interval/codename/date.

Also don't return uniques because their summed values are not meaningful.
This commit is contained in:
bsimpson63
2013-04-11 18:41:57 -04:00
parent 637b5770c0
commit 6ca97cca5e

View File

@@ -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)