mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 08:17:58 -05:00
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.
This commit is contained in:
@@ -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 @@ class TimeSeriesChart(Templated):
|
||||
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.dates import format_datetime
|
||||
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 @@ class AdvertTrafficPage(TrafficPage):
|
||||
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 @@ class RedditTraffic(Templated):
|
||||
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 @@ class SubredditTraffic(RedditTraffic):
|
||||
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,6 +52,9 @@
|
||||
% 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":
|
||||
@@ -59,6 +62,9 @@
|
||||
% else:
|
||||
${month_names[date.month]}
|
||||
% endif
|
||||
% if thing.make_period_link:
|
||||
</a>
|
||||
% endif
|
||||
</th>
|
||||
% for datum in data:
|
||||
% if date < thing.latest_available_data:
|
||||
|
||||
Reference in New Issue
Block a user