Skip to content
Browse files

global stats dashboard (bug 697358)

  • Loading branch information...
1 parent f9e2c5f commit 333b68f360d8d1b78324395afb783cebdc4ea2f8 @potch potch committed Mar 6, 2012
View
1 apps/stats/templates/stats/dashboard.html
@@ -0,0 +1 @@
+{% extends "stats/stats.html" %}
View
36 apps/stats/templates/stats/global_report_menu.html
@@ -0,0 +1,36 @@
+<nav id="side-nav">
+ <ul>
+ <li>
+ <a href="{{ url('stats.dashboard') }}">
+ {{ _('Dashboard') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.addons_in_use') }}">
+ {{ _('Add-ons in Use') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.addons_created') }}">
+ {{ _('Add-ons Created') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.addons_downloaded') }}">
+ {{ _('Add-ons Downloaded') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.addons_updated') }}">
+ {{ _('Add-ons Updated') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.collections_created') }}">
+ {{ _('Collections Created') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.reviews_created') }}">
+ {{ _('Reviews Written') }}</a>
+ </li>
+ <li>
+ <a href="{{ url('stats.users_created') }}">
+ {{ _('User Signups') }}</a>
+ </li>
+ </ul>
+</nav>
View
5 apps/stats/templates/stats/reports/addons_created.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Add-ons Created by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
5 apps/stats/templates/stats/reports/addons_downloaded.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Add-ons Downloaded by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
5 apps/stats/templates/stats/reports/addons_downloads.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Add-ons in Use by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
5 apps/stats/templates/stats/reports/addons_in_use.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Add-ons in Use by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
5 apps/stats/templates/stats/reports/addons_updated.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Add-ons Updated by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
0 apps/stats/templates/stats/apps.html → apps/stats/templates/stats/reports/apps.html
File renamed without changes.
View
5 apps/stats/templates/stats/reports/collections_created.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Collections Created by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
0 apps/stats/templates/stats/downloads.html → ...ts/templates/stats/reports/downloads.html
File renamed without changes.
View
0 apps/stats/templates/stats/locales.html → ...tats/templates/stats/reports/locales.html
File renamed without changes.
View
0 apps/stats/templates/stats/os.html → apps/stats/templates/stats/reports/os.html
File renamed without changes.
View
0 apps/stats/templates/stats/overview.html → ...ats/templates/stats/reports/overview.html
File renamed without changes.
View
5 apps/stats/templates/stats/reports/reviews_created.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('Reviews Created by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
0 apps/stats/templates/stats/sources.html → ...tats/templates/stats/reports/sources.html
File renamed without changes.
View
0 apps/stats/templates/stats/statuses.html → ...ats/templates/stats/reports/statuses.html
File renamed without changes.
View
0 apps/stats/templates/stats/usage.html → .../stats/templates/stats/reports/usage.html
File renamed without changes.
View
5 apps/stats/templates/stats/reports/users_created.html
@@ -0,0 +1,5 @@
+{% extends "stats/stats.html" %}
+
+{% block csvtitle %}
+<h2>{{_('User Signups by Date')}}<a id="export_data" href=''>{{_('Export as CSV')}}</a></h2>
+{% endblock %}
View
0 apps/stats/templates/stats/versions.html → ...ats/templates/stats/reports/versions.html
File renamed without changes.
View
36 apps/stats/urls.py
@@ -10,13 +10,45 @@
series = dict((type, '%s-%s' % (type, series_re)) for type in views.SERIES)
urlpatterns = patterns('',
- # url('^$', views.dashboard, name='stats.dashboard'),
+ url('^$', views.dashboard, name='stats.dashboard'),
url('^site%s/%s$' % (format_re, group_date_re),
views.site, name='stats.site'),
url('^site-%s' % series_re, views.site, name='stats.site.new'),
url('^fake-%s' % series_re, views.fake_collection_stats),
url('^collection/(?P<uuid>[\w-]+).%s$' % (format_re),
- views.collection, name='stats.collection')
+ views.collection, name='stats.collection'),
+
+ # global series urls.
+ url(series['addons_in_use'], views.site_series,
+ kwargs={'field': 'addons_in_use'}),
+ url(series['addons_updated'], views.site_series,
+ kwargs={'field': 'addons_updated'}),
+ url(series['addons_downloaded'], views.site_series,
+ kwargs={'field': 'addons_downloaded'}),
+ url(series['addons_created'], views.site_series,
+ kwargs={'field': 'addons_created'}),
+ url(series['reviews_created'], views.site_series,
+ kwargs={'field': 'reviews_created'}),
+ url(series['collections_created'], views.site_series,
+ kwargs={'field': 'collections_created'}),
+ url(series['users_created'], views.site_series,
+ kwargs={'field': 'users_created'}),
+
+ # global series urls.
+ url('^addons_in_use/$', views.site_stats_report,
+ kwargs={'report': 'addons_in_use'}, name='stats.addons_in_use'),
+ url('^addons_updated/$', views.site_stats_report,
+ kwargs={'report': 'addons_updated'}, name='stats.addons_updated'),
+ url('^addons_downloaded/$', views.site_stats_report,
+ kwargs={'report': 'addons_downloaded'}, name='stats.addons_downloaded'),
+ url('^addons_created/$', views.site_stats_report,
+ kwargs={'report': 'addons_created'}, name='stats.addons_created'),
+ url('^reviews_created/$', views.site_stats_report,
+ kwargs={'report': 'reviews_created'}, name='stats.reviews_created'),
+ url('^collections_created/$', views.site_stats_report,
+ kwargs={'report': 'collections_created'}, name='stats.collections_created'),
+ url('^users_created/$', views.site_stats_report,
+ kwargs={'report': 'users_created'}, name='stats.users_created'),
)
# Addon specific stats.
View
60 apps/stats/views.py
@@ -35,8 +35,20 @@
SERIES_GROUPS = ('day', 'week', 'month')
SERIES_GROUPS_DATE = ('date', 'week', 'month') # Backwards compat.
SERIES_FORMATS = ('json', 'csv')
-SERIES = ('downloads', 'usage', 'contributions', 'overview',
- 'sources', 'os', 'locales', 'statuses', 'versions', 'apps')
+SERIES = ('downloads', 'usage', 'contributions', 'overview', 'global',
+ 'sources', 'os', 'locales', 'statuses', 'versions', 'apps',
+ 'addons_in_use', 'addons_updated', 'addons_downloaded',
+ 'collections_created', 'reviews_created', 'addons_created',
+ 'users_created')
+
+
+def dashboard(request):
+ stats_base_url = reverse('stats.dashboard')
+ view = get_report_view(request)
+ return jingo.render(request, 'stats/dashboard.html',
+ {'report': 'site',
+ 'view': view,
+ 'stats_base_url': stats_base_url})
def get_series(model, extra_field=None, **filters):
@@ -279,11 +291,20 @@ def stats_report(request, addon, report):
for_contributions=(report == 'contributions'))
stats_base_url = reverse('stats.overview', args=[addon.slug])
view = get_report_view(request)
- return jingo.render(request, 'stats/%s.html' % report,
+ return jingo.render(request, 'stats/reports/%s.html' % report,
{'addon': addon,
- 'report': report,
- 'view': view,
- 'stats_base_url': stats_base_url})
+ 'report': report,
+ 'view': view,
+ 'stats_base_url': stats_base_url})
+
+
+def site_stats_report(request, report):
+ stats_base_url = reverse('stats.dashboard')
+ view = get_report_view(request)
+ return jingo.render(request, 'stats/reports/%s.html' % report,
+ {'report': report, 'view': view,
+ 'stats_base_url': stats_base_url})
+
def get_report_view(request):
@@ -449,7 +470,7 @@ def _site_query(period, start, end):
assert period in SERIES_GROUPS_DATE, '%s period is not valid.'
sql = ("SELECT name, MIN(date), SUM(count) "
"FROM global_stats "
- "WHERE date > %%s AND date < %%s "
+ "WHERE date >= %%s AND date <= %%s "
"AND name IN (%s) "
"GROUP BY %s(date), name "
"ORDER BY %s(date) DESC;"
@@ -464,7 +485,8 @@ def _site_query(period, start, end):
if date not in result:
result[date] = default.copy()
result[date]['date'] = date
- result[date][keys[name]] = count
+ result[date]['data'] = {}
+ result[date]['data'][keys[name]] = count
return result.values(), sorted(keys.values())
@@ -487,13 +509,21 @@ def site(request, format, group, start=None, end=None):
return render_json(request, None, series)
-def collection_stats(request, username, slug):
- c = {'name': 'Sample Collection'}
- view = get_report_view(request)
- return jingo.render(request, 'stats/collections.html',
- {'collection': c,
- 'view': view,
- })
+def site_series(request, format, group, start, end, field):
+ """Pull a single field from the site_query data"""
+ start, end = get_daterange_or_404(start, end)
+ group = 'date' if group == 'day' else group
+ print format, group, start, end, field
+ series = []
+ full_series, keys = _site_query(group, start, end)
+ for row in full_series:
+ if field in row['data']:
+ series.append({
+ 'date': row['date'],
+ 'count': row['data'][field],
+ })
+ print series
+ return render_json(request, None, series)
def collection(request, uuid, format):
View
37 media/js/impala/stats/chart.js
@@ -62,15 +62,22 @@
var chart;
// which unit do we use for a given metric?
var metricTypes = {
- "usage" : "users",
- "apps" : "users",
- "locales" : "users",
- "os" : "users",
- "versions" : "users",
- "statuses" : "users",
- "downloads" : "downloads",
- "sources" : "downloads",
- "contributions" : "currency"
+ "usage" : "users",
+ "apps" : "users",
+ "locales" : "users",
+ "os" : "users",
+ "versions" : "users",
+ "statuses" : "users",
+ "users_created" : "users",
+ "downloads" : "downloads",
+ "sources" : "downloads",
+ "contributions" : "currency",
+ "reviews_created" : "reviews",
+ "addons_in_use" : "addons",
+ "addons_created" : "addons",
+ "addons_updated" : "addons",
+ "addons_downloaded" : "addons",
+ "colletions_created" : "collections"
};
var acceptedGroups = {
@@ -159,6 +166,9 @@
function monthFormatter(d) { return Highcharts.dateFormat('%B %Y', new Date(d)); }
function downloadFormatter(n) { return Highcharts.numberFormat(n, 0) + ' downloads'; }
function userFormatter(n) { return Highcharts.numberFormat(n, 0) + ' users'; }
+ function addonsFormatter(n) { return Highcharts.numberFormat(n, 0) + ' addons'; }
+ function collecitonsFormatter(n) { return Highcharts.numberFormat(n, 0) + ' collections'; }
+ function reviewsFormatter(n) { return Highcharts.numberFormat(n, 0) + ' reviews'; }
function currencyFormatter(n) { return '$' + Highcharts.numberFormat(n, 2); }
function addEventData(s, date) {
var e = events[date];
@@ -215,6 +225,15 @@
case "currency":
yFormatter = currencyFormatter;
break;
+ case "collections":
+ yFormatter = collectionsFormatter;
+ break;
+ case "reviews":
+ yFormatter = reviewsFormatter;
+ break;
+ case "addons":
+ yFormatter = addonsFormatter;
+ break;
}
return function() {
var ret = "<b>" + this.series.name + "</b><br>" +
View
42 media/js/impala/stats/csv_keys.js
@@ -147,6 +147,48 @@ var csv_keys = {
"fake" : [
"Fake data last {0} days",
"Fake data from {0} to {1}"
+ ],
+ "addons_in_use" : [
+ // L10n: {0} is an integer.
+ gettext("Add-ons in Use, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("Add-ons in Use from {0} to {1}")
+ ],
+ "addons_downloaded" : [
+ // L10n: {0} is an integer.
+ gettext("Add-ons Downloaded, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("Add-ons Downloaded from {0} to {1}")
+ ],
+ "addons_created" : [
+ // L10n: {0} is an integer.
+ gettext("Add-ons Created, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("Add-ons Created from {0} to {1}")
+ ],
+ "addons_updated" : [
+ // L10n: {0} is an integer.
+ gettext("Add-ons Updated, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("Add-ons Updated from {0} to {1}")
+ ],
+ "reviews_created" : [
+ // L10n: {0} is an integer.
+ gettext("Reviews Written, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("Reviews Written from {0} to {1}")
+ ],
+ "users_created" : [
+ // L10n: {0} is an integer.
+ gettext("User Signups, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("User Signups from {0} to {1}")
+ ],
+ "collections_created" : [
+ // L10n: {0} is an integer.
+ gettext("Collections Created, last {0} days"),
+ // L10n: both {0} and {1} are dates in YYYY-MM-DD format.
+ gettext("Collections Created from {0} to {1}")
]
},
aggregateLabel: {
View
3 media/js/impala/stats/stats.js
@@ -72,9 +72,10 @@
$exceptionModal.render();
});
+ $('.csv-table').csvTable();
+
// Trigger the initial data load.
$(window).trigger('changeview', initView);
});
- $('.csv-table').csvTable();
})();

0 comments on commit 333b68f

Please sign in to comment.
Something went wrong with that request. Please try again.