diff options
| author | sostler <sbostler@gmail.com> | 2010-02-16 01:40:34 -0500 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-02-16 01:40:34 -0500 |
| commit | 99e9cbe532166b154314b6107ce269162359f660 (patch) | |
| tree | 7aa1dae92ae7a3d9f85f94d6289e89970cce49c0 /static/js/stats.js | |
| parent | 099809e854c9f19ce8301b9cff12b9291619755b (diff) | |
Add stats-tracking
Diffstat (limited to 'static/js/stats.js')
| -rwxr-xr-x | static/js/stats.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/static/js/stats.js b/static/js/stats.js new file mode 100755 index 0000000..00e00a0 --- /dev/null +++ b/static/js/stats.js @@ -0,0 +1,79 @@ +var CurrentStats = ['msgs', 'today']; + +function refreshStats() { + $('a.statname, a.timescale').addClass('disabled'); + $('#statschart').empty().append('<img src="/static/spinner.gif">'); + + var onSuccess = function(json) { + var dataString = "Date,Count\n"; + $.each(json, function(i, v) { + dataString += v.created_on + "," + v.count + "\n"; + }); + $('#statschart').empty(); + new Dygraph($('#statschart')[0], + dataString, + { showRoller: false} + ); + + $('a.statname, a.timescale').removeClass('disabled'); + }; + + var onError = function(resp, textStatus, errorThrown) { + $('a.statname, a.timescale').removeClass('disabled'); + }; + + $.ajax({ + type: 'GET', + timeout: 5000, + url: '/stats', + data: { 'stat': CurrentStats[0], 'ts': CurrentStats[1] }, + cache: false, + dataType: 'json', + success: onSuccess, + error: onError + }); +} + +function makeStatsWindow() { + var statBox= $('<div class="stats" align="center">'); + var choices = ['msgs', 'new users']; + $(choices).map(function(i, c) { + return link = $('<a>') + .text(c) + .attr('href', '#') + .addClass('statname') + .addClass(i == 0 ? 'active' : 'inactive') + .click(function() { + if ($(this).hasClass('disabled') || + CurrentStats[0] == c) { return }; + $('.statname').removeClass('active'); + $(this).addClass('active'); + CurrentStats[0] = c; + refreshStats(); + }); + }).appendTo(statBox); + $('<div id="statschart" style="width:375px; height:300px;">').appendTo(statBox); + var timescales = ['today', 'all time']; + $(timescales).map(function(i, c) { + return link = $('<a>') + .text(c) + .attr('href', '#') + .addClass('timescale') + .addClass(i == 0 ? 'active' : 'inactive') + .click(function() { + if ($(this).hasClass('disabled') || + CurrentStats[1] == c) { return }; + $('.timescale').removeClass('active'); + $(this).addClass('active'); + CurrentStats[1] = c; + refreshStats(); + }); + })//.appendTo(statBox); + return statBox; +} + +function initStats() { + makeStatsWindow().appendTo('body'); + refreshStats(); +} + |
