mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-23 05:48:11 -05:00
Report hourly unique clicks.
This commit is contained in:
@@ -4410,7 +4410,7 @@ class PromoteReport(PromoteLinkBase):
|
||||
self.link_report = link_report
|
||||
|
||||
@classmethod
|
||||
def _get_hits(cls, traffic_cls, campaigns, start, end):
|
||||
def _get_hits(cls, traffic_cls, campaigns, start, end, use_uniques=False):
|
||||
campaigns_by_name = {camp._fullname: camp for camp in campaigns}
|
||||
codenames = campaigns_by_name.keys()
|
||||
start = (start - promote.timezone_offset).replace(tzinfo=None)
|
||||
@@ -4432,9 +4432,9 @@ class PromoteReport(PromoteLinkBase):
|
||||
continue
|
||||
if sr == '':
|
||||
# LEGACY: traffic uses '' to indicate Frontpage
|
||||
fp_hits[codename] += pageviews
|
||||
fp_hits[codename] += uniques if use_uniques else pageviews
|
||||
else:
|
||||
sr_hits[codename] += pageviews
|
||||
sr_hits[codename] += uniques if use_uniques else pageviews
|
||||
return fp_hits, sr_hits
|
||||
|
||||
@classmethod
|
||||
@@ -4445,7 +4445,7 @@ class PromoteReport(PromoteLinkBase):
|
||||
@classmethod
|
||||
def get_clicks(cls, campaigns, start, end):
|
||||
return cls._get_hits(traffic.TargetedClickthroughsByCodename, campaigns,
|
||||
start, end)
|
||||
start, end, use_uniques=True)
|
||||
|
||||
def make_campaign_report(self):
|
||||
campaigns = PromoCampaign._by_link([link._id for link in self.links])
|
||||
|
||||
@@ -333,15 +333,20 @@ def total_by_codename(cls, codenames):
|
||||
return list(q)
|
||||
|
||||
|
||||
def promotion_history(cls, codename, start, stop):
|
||||
def promotion_history(cls, count_column, codename, start, stop):
|
||||
"""Get hourly traffic for a self-serve promotion.
|
||||
|
||||
Traffic stats are summed over all targets for classes that include a target.
|
||||
|
||||
count_column should be cls.pageview_count or cls.unique_count.
|
||||
|
||||
NOTE: when retrieving uniques the counts for ALL targets are summed, which
|
||||
isn't strictly correct but is the best we can do for now.
|
||||
|
||||
"""
|
||||
|
||||
time_points = get_time_points('hour', start, stop)
|
||||
q = (Session.query(cls.date, sum(cls.pageview_count))
|
||||
q = (Session.query(cls.date, sum(count_column))
|
||||
.filter(cls.interval == "hour")
|
||||
.filter(cls.codename == codename)
|
||||
.filter(cls.date.in_(time_points))
|
||||
@@ -499,7 +504,7 @@ class ClickthroughsByCodename(Base):
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
def promotion_history(cls, codename, start, stop):
|
||||
return promotion_history(cls, codename, start, stop)
|
||||
return promotion_history(cls, cls.unique_count, codename, start, stop)
|
||||
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
@@ -527,7 +532,7 @@ class TargetedClickthroughsByCodename(Base):
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
def promotion_history(cls, codename, start, stop):
|
||||
return promotion_history(cls, codename, start, stop)
|
||||
return promotion_history(cls, cls.unique_count, codename, start, stop)
|
||||
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
@@ -560,7 +565,7 @@ class AdImpressionsByCodename(Base):
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
def promotion_history(cls, codename, start, stop):
|
||||
return promotion_history(cls, codename, start, stop)
|
||||
return promotion_history(cls, cls.pageview_count, codename, start, stop)
|
||||
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
@@ -608,7 +613,7 @@ class TargetedImpressionsByCodename(Base):
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
def promotion_history(cls, codename, start, stop):
|
||||
return promotion_history(cls, codename, start, stop)
|
||||
return promotion_history(cls, cls.pageview_count, codename, start, stop)
|
||||
|
||||
@classmethod
|
||||
@memoize_traffic(time=3600)
|
||||
|
||||
Reference in New Issue
Block a user