This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

subreddit traffic: Link to subreddit search by time period.

Traffic spikes on the subreddit traffic pages are currently very opaque.
There's no simple way to determine what could have caused a big change.

This makes the date/time column of subreddit traffic tables link to
timestamp-limited subreddit search for that subreddit.  While this
doesn't cover external referrers etc. it should give some insight into
traffic.
  • Loading branch information...
1 parent 23704c8 commit b70f9608e2160cbc24fe16c0fa092cccf5d49b98 @spladug spladug committed Jul 1, 2013
Showing with 36 additions and 3 deletions.
  1. +3 −1 r2/r2/lib/pages/pages.py
  2. +27 −2 r2/r2/lib/pages/trafficpages.py
  3. +6 −0 r2/r2/templates/timeserieschart.html
View
@@ -3992,7 +3992,8 @@ class ConfirmAwardClaim(Templated):
class TimeSeriesChart(Templated):
def __init__(self, id, title, interval, columns, rows,
- latest_available_data=None, classes=[]):
+ latest_available_data=None, classes=[],
+ make_period_link=None):
self.id = id
self.title = title
self.interval = interval
@@ -4001,6 +4002,7 @@ def __init__(self, id, title, interval, columns, rows,
self.latest_available_data = (latest_available_data or
datetime.datetime.utcnow())
self.classes = " ".join(classes)
+ self.make_period_link = make_period_link
Templated.__init__(self)
@@ -33,12 +33,13 @@
from babel.numbers import format_currency
from r2.lib import promote
+from r2.lib.db.sorts import epoch_seconds
from r2.lib.menus import menu
from r2.lib.menus import NavButton, NamedButton, PageNameNav, NavMenu
from r2.lib.pages.pages import Reddit, TimeSeriesChart, UserList, TabbedPane
from r2.lib.promote import cost_per_mille, cost_per_click
from r2.lib.template_helpers import format_number
-from r2.lib.utils import Storage, to_date
+from r2.lib.utils import Storage, to_date, timedelta_by_name
from r2.lib.wrapped import Templated
from r2.models import Thing, Link, PromoCampaign, traffic
from r2.models.subreddit import Subreddit, _DefaultSR
@@ -104,6 +105,8 @@ def __init__(self, code):
class RedditTraffic(Templated):
"""A generalized content pane for traffic reporting."""
+ make_period_link = None
+
def __init__(self, place):
self.place = place
@@ -144,7 +147,9 @@ def make_tables(self):
columns,
data,
self.traffic_last_modified,
- classes=["traffic-table"])
+ classes=["traffic-table"],
+ make_period_link=self.make_period_link,
+ )
self.tables.append(graph)
try:
@@ -415,6 +420,26 @@ def __init__(self):
AdvertTrafficSummary.split_codename(code)[1])
for code in codes]
+ @staticmethod
+ def make_period_link(interval, date):
+ date = date.replace(tzinfo=g.tz) # won't be necessary after tz fixup
+ if interval == "month":
+ if date.month != 12:
+ end = date.replace(month=date.month + 1)
+ else:
+ end = date.replace(month=1, year=date.year + 1)
+ else:
+ end = date + timedelta_by_name(interval)
+
+ query = urllib.urlencode({
+ "syntax": "cloudsearch",
+ "restrict_sr": "on",
+ "sort": "top",
+ "q": "timestamp:{:d}..{:d}".format(int(epoch_seconds(date)),
+ int(epoch_seconds(end))),
+ })
+ return "/r/%s/search?%s" % (c.site.name, query)
+
def get_dow_summary(self):
return traffic.PageviewsBySubreddit.history("day", c.site.name)
@@ -52,13 +52,19 @@
% endif
>
<th data-value="${js_timestamp(date)}" scope="row">
+ % if thing.make_period_link:
+ <a href="${thing.make_period_link(thing.interval, date)}">
+ % endif
% if thing.interval == "hour":
${babel.dates.format_datetime(date, format="short", locale=c.locale)}
% elif thing.interval == "day":
${babel.dates.format_date(date, format="short", locale=c.locale)}
% else:
${month_names[date.month]}
% endif
+ % if thing.make_period_link:
+ </a>
+ % endif
</th>
% for datum in data:
% if date < thing.latest_available_data:

0 comments on commit b70f960

Please sign in to comment.