From 99e9cbe532166b154314b6107ce269162359f660 Mon Sep 17 00:00:00 2001 From: sostler Date: Tue, 16 Feb 2010 01:40:34 -0500 Subject: Add stats-tracking --- static/js/stats.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ template/chat.st | 56 +++++++++++++++++++++----------------- 2 files changed, 111 insertions(+), 24 deletions(-) create mode 100755 static/js/stats.js 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(''); + + 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= $('
'); + var choices = ['msgs', 'new users']; + $(choices).map(function(i, c) { + return link = $('') + .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); + $('
').appendTo(statBox); + var timescales = ['today', 'all time']; + $(timescales).map(function(i, c) { + return link = $('') + .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(); +} + diff --git a/template/chat.st b/template/chat.st index 90e2602..4d792ae 100755 --- a/template/chat.st +++ b/template/chat.st @@ -16,36 +16,13 @@ $endif$ $if(isadminroom)$ @@ -60,6 +37,37 @@ function MM_swapImage() { //v3.0 }); } + $if(isadminroom)$ + + + + + $endif$ $banner()$ -- cgit v1.2.3-70-g09d2