Refreshing dashboard graphs every 10 minutes. Why not?

This commit is contained in:
Samuel Clay 2011-04-24 22:47:20 -04:00
parent 2842162b0e
commit 8cf598fcbe
8 changed files with 120 additions and 66 deletions

View file

@ -2,6 +2,12 @@ from django import template
register = template.Library()
@register.inclusion_tag('statistics/render_statistics_graphs.xhtml')
def render_statistics_graphs(statistics):
return {
'statistics': statistics,
}
@register.filter
def format_graph(n, max_value, height=30):
if n == 0 or max_value == 0:

6
apps/statistics/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.conf.urls.defaults import *
from apps.statistics import views
urlpatterns = patterns('',
url(r'^dashboard_graphs', views.dashboard_graphs, name='statistics-graphs'),
)

View file

@ -1 +1,9 @@
# Create your views here.
from django.template import RequestContext
from django.shortcuts import render_to_response
from apps.statistics.models import MStatistics
def dashboard_graphs(request):
statistics = MStatistics.all()
return render_to_response('statistics/render_statistics_graphs.xhtml', {
'statistics': statistics,
}, context_instance=RequestContext(request))

View file

@ -683,6 +683,10 @@ NEWSBLUR.AssetModel.Reader.prototype = {
}, callback, error_callback, {request_type: 'GET'});
},
load_dashboard_graphs: function(callback, error_callback) {
this.make_request('/statistics/dashboard_graphs', {}, callback, error_callback, {request_type: 'GET'});
},
save_feed_order: function(folders, callback) {
this.make_request('/reader/save_feed_order', {'folders': $.toJSON(folders)}, callback);
},

View file

@ -102,6 +102,7 @@
this.apply_story_styling();
this.apply_tipsy_titles();
this.load_recommended_feeds();
this.setup_dashboard_graphs();
this.setup_howitworks_hovers();
};
@ -5039,6 +5040,31 @@
}, $.noop);
},
// ====================
// = Dashboard Graphs =
// ====================
setup_dashboard_graphs: function() {
// Reload dashboard graphs every 10 minutes.
clearInterval(this.locks.load_dashboard_graphs);
this.locks.load_dashboard_graphs = setInterval(_.bind(function() {
this.load_dashboard_graphs();
}, this), 10*60*1000);
},
load_dashboard_graphs: function(direction, refresh) {
var self = this;
var $module = $('.NB-module-stats');
$module.addClass('NB-loading');
this.model.load_dashboard_graphs(function(resp) {
if (!resp) return;
$module.removeClass('NB-loading');
$module.replaceWith(resp);
self.load_javascript_elements_on_page();
}, $.noop);
},
// ==========
// = Events =
// ==========

View file

@ -239,7 +239,7 @@ $(document).ready(function() {
{% else %}
<div class="NB-module NB-module-stats">
<div class="NB-module">
<h5 class="NB-module-header">
Welcome, {{ user.username }}
<div class="NB-module-header-right">
@ -303,70 +303,8 @@ $(document).ready(function() {
{% endif %}
<div class="NB-module NB-module-stats">
<h5 class="NB-module-header">
Status and Statistics
</h5>
<h3 class="NB-module-content-header">
Past day
</h3>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-number">{{ statistics.premium_users }}</div>
<div class="NB-module-stats-count-description">Premium Users</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-number">{{ statistics.standard_users }}</div>
<div class="NB-module-stats-count-description">Standard Users</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-number">{{ statistics.feeds_fetched|commify }}</div>
<div class="NB-module-stats-count-description">Feeds fetched</div>
</div>
<h3 class="NB-module-content-header">
Past day by hour
</h3>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-graph">
{% for i in statistics.sites_loaded %}
<div class="NB-graph-value">
<div class="NB-graph-label">{{ i }}</div>
<div class="NB-graph-bar" style="height:{{ i|format_graph:statistics.max_sites_loaded }}px"></div>
</div>
{% endfor %}
</div>
<div class="NB-module-stats-count-number">{{ statistics.latest_sites_loaded }}</div>
<div class="NB-module-stats-count-description">Sites loaded</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-graph">
{% for i in statistics.avg_time_taken %}
<div class="NB-graph-value">
<div class="NB-graph-label">{{ i|floatformat:2 }}</div>
<div class="NB-graph-bar" style="height:{{ i|format_graph:statistics.max_avg_time_taken }}px"></div>
</div>
{% endfor %}
</div>
<div class="NB-module-stats-count-number">{{ statistics.latest_avg_time_taken|floatformat:2 }} <small>sec</small></div>
<div class="NB-module-stats-count-description">Avg. load time</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-graph">
{% for i in 24|get_range %}
<div class="NB-graph-value">
<div class="NB-graph-label">0</div>
<div class="NB-graph-bar" style="height:1px"></div>
</div>
{% endfor %}
</div>
<div class="NB-module-stats-count-number">0</div>
<div class="NB-module-stats-count-description">Backlog</div>
</div>
</div>
{% render_statistics_graphs statistics %}
</div>
</div>

View file

@ -0,0 +1,65 @@
{% load utils_tags statistics_tags %}
<div class="NB-module NB-module-stats">
<h5 class="NB-module-header">
Status and Statistics
</h5>
<h3 class="NB-module-content-header">
Past day
</h3>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-number">{{ statistics.premium_users }}</div>
<div class="NB-module-stats-count-description">Premium Users</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-number">{{ statistics.standard_users }}</div>
<div class="NB-module-stats-count-description">Standard Users</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-number">{{ statistics.feeds_fetched|commify }}</div>
<div class="NB-module-stats-count-description">Feeds fetched</div>
</div>
<h3 class="NB-module-content-header">
Past day by hour
</h3>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-graph">
{% for i in statistics.sites_loaded %}
<div class="NB-graph-value">
<div class="NB-graph-label">{{ i }}</div>
<div class="NB-graph-bar" style="height:{{ i|format_graph:statistics.max_sites_loaded }}px"></div>
</div>
{% endfor %}
</div>
<div class="NB-module-stats-count-number">{{ statistics.latest_sites_loaded }}</div>
<div class="NB-module-stats-count-description">Sites loaded</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-graph">
{% for i in statistics.avg_time_taken %}
<div class="NB-graph-value">
<div class="NB-graph-label">{{ i|floatformat:2 }}</div>
<div class="NB-graph-bar" style="height:{{ i|format_graph:statistics.max_avg_time_taken }}px"></div>
</div>
{% endfor %}
</div>
<div class="NB-module-stats-count-number">{{ statistics.latest_avg_time_taken|floatformat:2 }} <small>sec</small></div>
<div class="NB-module-stats-count-description">Avg. load time</div>
</div>
<div class="NB-module-stats-count">
<div class="NB-module-stats-count-graph">
{% for i in 24|get_range %}
<div class="NB-graph-value">
<div class="NB-graph-label">0</div>
<div class="NB-graph-bar" style="height:1px"></div>
</div>
{% endfor %}
</div>
<div class="NB-module-stats-count-number">0</div>
<div class="NB-module-stats-count-description">Backlog</div>
</div>
</div>

View file

@ -12,6 +12,7 @@ urlpatterns = patterns('',
(r'^import/', include('apps.feed_import.urls')),
(r'^api/', include('apps.api.urls')),
(r'^recommendations/', include('apps.recommendations.urls')),
(r'^statistics/', include('apps.statistics.urls')),
url(r'^about/?', static_views.about, name='about'),
url(r'^faq/?', static_views.faq, name='faq'),
url(r'^api/?', static_views.api, name='api'),