|
|
@ -206,17 +206,29 @@ SocketAdmin.email.test = function(socket, data, callback) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketAdmin.analytics.get = function(socket, data, callback) {
|
|
|
|
SocketAdmin.analytics.get = function(socket, data, callback) {
|
|
|
|
data.units = 'hours'; // temp
|
|
|
|
// Default returns views from past 24 hours, by hour
|
|
|
|
|
|
|
|
if (data.units === 'days') {
|
|
|
|
|
|
|
|
data.amount = 30;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data.amount = 24;
|
|
|
|
data.amount = 24;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (data && data.graph && data.units && data.amount) {
|
|
|
|
if (data && data.graph && data.units && data.amount) {
|
|
|
|
if (data.graph === 'traffic') {
|
|
|
|
if (data.graph === 'traffic') {
|
|
|
|
async.parallel({
|
|
|
|
async.parallel({
|
|
|
|
uniqueVisitors: function(next) {
|
|
|
|
uniqueVisitors: function(next) {
|
|
|
|
getHourlyStatsForSet('analytics:uniquevisitors', data.amount, next);
|
|
|
|
if (data.units === 'days') {
|
|
|
|
|
|
|
|
getDailyStatsForSet('analytics:uniquevisitors', Date.now(), data.amount, next);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
getHourlyStatsForSet('analytics:uniquevisitors', Date.now(), data.amount, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pageviews: function(next) {
|
|
|
|
pageviews: function(next) {
|
|
|
|
getHourlyStatsForSet('analytics:pageviews', data.amount, next);
|
|
|
|
if (data.units === 'days') {
|
|
|
|
|
|
|
|
getDailyStatsForSet('analytics:pageviews', Date.now(), data.amount, next);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
getHourlyStatsForSet('analytics:pageviews', Date.now(), data.amount, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
monthlyPageViews: function(next) {
|
|
|
|
monthlyPageViews: function(next) {
|
|
|
|
analytics.getMonthlyPageViews(next);
|
|
|
|
analytics.getMonthlyPageViews(next);
|
|
|
@ -240,14 +252,14 @@ SocketAdmin.logs.clear = function(socket, data, callback) {
|
|
|
|
meta.logs.clear(callback);
|
|
|
|
meta.logs.clear(callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function getHourlyStatsForSet(set, hours, callback) {
|
|
|
|
function getHourlyStatsForSet(set, hour, numHours, callback) {
|
|
|
|
var hour = new Date(),
|
|
|
|
var terms = {},
|
|
|
|
terms = {},
|
|
|
|
|
|
|
|
hoursArr = [];
|
|
|
|
hoursArr = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hour = new Date(hour);
|
|
|
|
hour.setHours(hour.getHours(), 0, 0, 0);
|
|
|
|
hour.setHours(hour.getHours(), 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0, ii = hours; i < ii; i++) {
|
|
|
|
for (var i = 0, ii = numHours; i < ii; i++) {
|
|
|
|
hoursArr.push(hour.getTime());
|
|
|
|
hoursArr.push(hour.getTime());
|
|
|
|
hour.setHours(hour.getHours() - 1, 0, 0, 0);
|
|
|
|
hour.setHours(hour.getHours() - 1, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -272,6 +284,30 @@ function getHourlyStatsForSet(set, hours, callback) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
SocketAdmin.getMoreEvents = function(socket, next, callback) {
|
|
|
|
var start = parseInt(next, 10);
|
|
|
|
var start = parseInt(next, 10);
|
|
|
|
if (start < 0) {
|
|
|
|
if (start < 0) {
|
|
|
|