mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
traffic updates to include subreddit subscription graphs and tables
This commit is contained in:
@@ -134,7 +134,7 @@ class LineGraph(object):
|
||||
google_api = "http://chart.apis.google.com/chart"
|
||||
|
||||
def __init__(self, xydata, colors = ("FF4500", "336699"),
|
||||
width = 350, height = 200):
|
||||
width = 300, height = 175):
|
||||
|
||||
series = zip(*xydata)
|
||||
|
||||
|
||||
@@ -1290,6 +1290,8 @@ class RedditTraffic(Traffic):
|
||||
"FF4500"),
|
||||
("impressions", (1, 3) if c.site.domain else (1,),
|
||||
"336699")]
|
||||
if not c.default_sr and ival == 'day':
|
||||
slices.append(("subscriptions", (4,), "00FF00"))
|
||||
setattr(self, ival + "_data", data)
|
||||
for name, indx, color in slices:
|
||||
data2 = self.slice_traffic(data, *indx)
|
||||
|
||||
@@ -26,42 +26,51 @@
|
||||
return locale.format('%d', x, True)
|
||||
%>
|
||||
|
||||
<h1>Traffic for ${c.site.name}</h1>
|
||||
|
||||
|
||||
|
||||
%if not thing.has_data:
|
||||
<p class="error">
|
||||
${_("There doesn't seem to be any traffic data at the moment. Please check back later.")}
|
||||
</p>
|
||||
%else:
|
||||
|
||||
<img class="traffic-graph" alt='hourly uniques'
|
||||
src="${thing.uniques_hour}"/>
|
||||
<img class="traffic-graph" alt='hourly impressions'
|
||||
src="${thing.impressions_hour}"/>
|
||||
<br/>
|
||||
<img class="traffic-graph" alt='daily uniques'
|
||||
src="${thing.uniques_day}"/>
|
||||
<img class="traffic-graph" alt='daily impressions'
|
||||
src="${thing.impressions_day}"/>
|
||||
|
||||
<br/>
|
||||
|
||||
%if c.default_sr:
|
||||
<img class="traffic-graph" alt='monthly uniques'
|
||||
style="clear:left"
|
||||
src="${thing.uniques_month}"/>
|
||||
<img class="traffic-graph" alt='monthly impressions'
|
||||
src="${thing.impressions_month}"/>
|
||||
%endif
|
||||
|
||||
<%def name="daily_summary()">
|
||||
<%
|
||||
umin = min(data[0] for date, data in filter(None, thing.day_data))
|
||||
umax = max(data[0] for date, data in filter(None, thing.day_data))
|
||||
%>
|
||||
|
||||
<div style="float:left">
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
%if c.site.domain:
|
||||
<th></th>
|
||||
<th colspan="2">total</th>
|
||||
<th colspan="2">${c.site.domain}</th>
|
||||
</tr><tr>
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
<th>${_("subscriptions")}</th>
|
||||
%else:
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
%if not c.default_sr:
|
||||
<th>${_("subscriptions")}</th>
|
||||
%endif
|
||||
</tr>
|
||||
%endif
|
||||
</tr>
|
||||
%for x, (date, data) in enumerate(reversed(thing.day_data)):
|
||||
<tr class="${'odd' if x % 2 else 'even'} ${'max' if data[0] == umax else 'min' if data[0] == umin else ''}"
|
||||
<td>${date.strftime("%Y-%m-%d")}</td>
|
||||
<%
|
||||
indx = range(5) if c.site.domain else \
|
||||
[0,1,4] if not c.default_sr else [0,1]
|
||||
%>
|
||||
%for i in indx:
|
||||
<td>${num(data[i]) if data[i] else "-"}</td>
|
||||
%endfor
|
||||
${bars(data[0], data[1])}
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
</%def>
|
||||
|
||||
<%def name="weekly_summary()">
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
<th colspan="3">Weekly summary</th>
|
||||
@@ -89,102 +98,116 @@
|
||||
<td>${num(int(thing.impressions_mean))}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
%if c.site.domain:
|
||||
</%def>
|
||||
|
||||
<h1>Traffic for ${c.site.name}</h1>
|
||||
|
||||
%if not thing.has_data:
|
||||
<p class="error">
|
||||
${_("There doesn't seem to be any traffic data at the moment. Please check back later.")}
|
||||
</p>
|
||||
%else:
|
||||
|
||||
<div style="float:left">
|
||||
<div>
|
||||
<img class="traffic-graph" alt='hourly uniques' style="float:right;"
|
||||
src="${thing.uniques_hour}"/>
|
||||
</div>
|
||||
<div>
|
||||
<img class="traffic-graph" alt='daily uniques' style="float:right;"
|
||||
src="${thing.uniques_day}"/>
|
||||
</div>
|
||||
%if c.default_sr:
|
||||
<div>
|
||||
<img class="traffic-graph" alt='monthly uniques' style="float:right;"
|
||||
src="${thing.uniques_month}"/>
|
||||
</div>
|
||||
%endif
|
||||
${weekly_summary()}
|
||||
%if c.default_sr:
|
||||
${daily_summary()}
|
||||
%endif
|
||||
</div>
|
||||
<div>
|
||||
<img class="traffic-graph" alt='hourly impressions'
|
||||
src="${thing.impressions_hour}"/>
|
||||
</div>
|
||||
<div>
|
||||
<img class="traffic-graph" alt='daily impressions'
|
||||
src="${thing.impressions_day}"/>
|
||||
</div>
|
||||
%if c.default_sr:
|
||||
<div>
|
||||
<img class="traffic-graph" alt='monthly impressions'
|
||||
src="${thing.impressions_month}"/>
|
||||
</div>
|
||||
<% data = thing.monthly_summary() %>
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
<th colspan="3">Monthly data</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
</tr>
|
||||
%for i, d in enumerate(reversed(data)):
|
||||
<tr class="${'odd' if i % 2 else 'even'}">
|
||||
%for cls, x in d:
|
||||
<td class="${cls}">${x}</td>
|
||||
%endfor
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th colspan="2">total</th>
|
||||
<th colspan="2">${c.site.domain}</th>
|
||||
</tr><tr>
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
%else:
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
%endif
|
||||
</tr>
|
||||
%for x, (date, data) in enumerate(reversed(thing.day_data)):
|
||||
<tr class="${'odd' if x % 2 else 'even'} ${'max' if data[0] == umax else 'min' if data[0] == umin else ''}"
|
||||
<td>${date.strftime("%Y-%m-%d")}</td>
|
||||
%for i in xrange(4 if c.site.domain else 2):
|
||||
<td>${num(data[i]) if data[i] else "-"}</td>
|
||||
%endfor
|
||||
${bars(data[0], data[1])}
|
||||
<th colspan="2">${_("cnamed")}</th>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
</div>
|
||||
|
||||
%if c.default_sr:
|
||||
<% data = thing.monthly_summary() %>
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
<th colspan="3">Monthly data</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr>
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
</tr>
|
||||
%for i, d in enumerate(reversed(data)):
|
||||
<tr class="${'odd' if i % 2 else 'even'}">
|
||||
%for cls, x in d:
|
||||
<td class="${cls}">${x}</td>
|
||||
%endfor
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
<th>${_("cname")}</th>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
|
||||
<table class="traffic-table">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th colspan="2">total</th>
|
||||
<th colspan="2">${_("cnamed")}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>${_("date")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
<th>${_("uniques")}</th>
|
||||
<th>${_("impressions")}</th>
|
||||
<th>${_("cname")}</th>
|
||||
</tr>
|
||||
%for i, (sr, d) in enumerate(thing.reddits_summary()):
|
||||
<tr class="${'odd' if i % 2 else 'even'}">
|
||||
|
||||
<td
|
||||
%if isinstance(sr, FakeSubreddit):
|
||||
style="font-style: left; text-align: left"
|
||||
%else:
|
||||
style="font-weight:bold; text-align: left"
|
||||
%endif
|
||||
>
|
||||
%if isinstance(sr, DomainSR):
|
||||
<a href="${sr.path}">[domain:${sr.name}]</a>
|
||||
%elif isinstance(sr, FakeSubreddit):
|
||||
<a href="${sr.path}">[meta:${sr.name}]</a>
|
||||
%else:
|
||||
<a href="${sr.path}about/traffic">${sr.name}</a>
|
||||
%for i, (sr, d) in enumerate(thing.reddits_summary()):
|
||||
<tr class="${'odd' if i % 2 else 'even'}">
|
||||
|
||||
<td
|
||||
%if isinstance(sr, FakeSubreddit):
|
||||
style="font-style: left; text-align: left"
|
||||
%else:
|
||||
style="font-weight:bold; text-align: left"
|
||||
%endif
|
||||
>
|
||||
%if isinstance(sr, DomainSR):
|
||||
<a href="${sr.path}">[domain:${sr.name}]</a>
|
||||
%elif isinstance(sr, FakeSubreddit):
|
||||
<a href="${sr.path}">[meta:${sr.name}]</a>
|
||||
%else:
|
||||
<a href="${sr.path}about/traffic">${sr.name}</a>
|
||||
%endif
|
||||
</a>
|
||||
</td>
|
||||
%for x in d:
|
||||
<td>${num(x) if x else "--"}</td>
|
||||
%endfor
|
||||
<td>
|
||||
%if not isinstance(sr, FakeSubreddit) and sr.domain:
|
||||
<a href="http://${sr.domain}/">${sr.domain}</a>
|
||||
%endif
|
||||
</a>
|
||||
</td>
|
||||
%for x in d:
|
||||
<td>${num(x) if x else "--"}</td>
|
||||
%endfor
|
||||
<td>
|
||||
%if not isinstance(sr, FakeSubreddit) and sr.domain:
|
||||
<a href="http://${sr.domain}/">${sr.domain}</a>
|
||||
%endif
|
||||
</td>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
%endif
|
||||
</td>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
%else:
|
||||
<img class="traffic-graph" alt='daily subscriptions'
|
||||
src="${thing.subscriptions_day}"/>
|
||||
${daily_summary()}
|
||||
%endif
|
||||
%endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user