mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-05 21:45:47 +01:00
Squashed commit of the following:
commit 49e6c0040cc82c1e2684933a8e167ef14854aff8 Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 25 16:12:15 2016 -0500 added recording and charts for topic and post counts globally and by cid commit e02ff70757f778aa016fbc42ef10a5da2d07a9d9 Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 25 15:35:49 2016 -0500 added labels to charts commit e75d83bf3886e5183bcf5fcd848d71c513761e01 Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 25 13:30:47 2016 -0500 added per category graphs to ACP management page commit e3f543200950925cc9e8bf33cccb592f949a100e Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 25 12:36:11 2016 -0500 updated analytics to move helper methods to analytics lib and sending per category analytics to ACP page commit 01891d8f7c408925fcdad18dcaa941e5ebbeb9b2 Author: Julian Lam <julian@designcreateplay.com> Date: Wed Feb 24 16:48:55 2016 -0500 saving per-category analytics, and updated the writeData method to use async for "clarity"
This commit is contained in:
@@ -217,16 +217,16 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
|
||||
async.parallel({
|
||||
uniqueVisitors: function(next) {
|
||||
if (data.units === 'days') {
|
||||
getDailyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
|
||||
analytics.getDailyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
|
||||
} else {
|
||||
getHourlyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
|
||||
analytics.getHourlyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
|
||||
}
|
||||
},
|
||||
pageviews: function(next) {
|
||||
if (data.units === 'days') {
|
||||
getDailyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
|
||||
analytics.getDailyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
|
||||
} else {
|
||||
getHourlyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
|
||||
analytics.getHourlyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
|
||||
}
|
||||
},
|
||||
monthlyPageViews: function(next) {
|
||||
@@ -251,62 +251,6 @@ SocketAdmin.logs.clear = function(socket, data, callback) {
|
||||
meta.logs.clear(callback);
|
||||
};
|
||||
|
||||
function getHourlyStatsForSet(set, hour, numHours, callback) {
|
||||
var terms = {},
|
||||
hoursArr = [];
|
||||
|
||||
hour = new Date(hour);
|
||||
hour.setHours(hour.getHours(), 0, 0, 0);
|
||||
|
||||
for (var i = 0, ii = numHours; i < ii; i++) {
|
||||
hoursArr.push(hour.getTime());
|
||||
hour.setHours(hour.getHours() - 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
db.sortedSetScores(set, hoursArr, function(err, counts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
hoursArr.forEach(function(term, index) {
|
||||
terms[term] = parseInt(counts[index], 10) || 0;
|
||||
});
|
||||
|
||||
var termsArr = [];
|
||||
|
||||
hoursArr.reverse();
|
||||
hoursArr.forEach(function(hour) {
|
||||
termsArr.push(terms[hour]);
|
||||
});
|
||||
|
||||
callback(null, termsArr);
|
||||
});
|
||||
}
|
||||
|
||||
function getDailyStatsForSet(set, day, numDays, callback) {
|
||||
var daysArr = [];
|
||||
|
||||
day = new Date(day);
|
||||
day.setHours(0, 0, 0, 0);
|
||||
|
||||
async.whilst(function() {
|
||||
return numDays--;
|
||||
}, function(next) {
|
||||
getHourlyStatsForSet(set, day.getTime()-(1000*60*60*24*numDays), 24, function(err, day) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
daysArr.push(day.reduce(function(cur, next) {
|
||||
return cur+next;
|
||||
}));
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
callback(err, daysArr);
|
||||
});
|
||||
}
|
||||
|
||||
SocketAdmin.getMoreEvents = function(socket, next, callback) {
|
||||
var start = parseInt(next, 10);
|
||||
if (start < 0) {
|
||||
|
||||
Reference in New Issue
Block a user