This commit is contained in:
Cryptkeeper!
2017-03-11 17:44:21 -06:00
committed by GitHub
parent b973968eca
commit 2c4f3e0865
11 changed files with 104 additions and 94 deletions

View File

@ -108,26 +108,25 @@ exports.setIntervalNoDelay = function(func, delay) {
return task;
};
exports.convertPingsToGraph = function(sqlData) {
exports.convertServerHistory = function(sqlData) {
var serverIps = getServerIps();
var graphData = {};
var highestPlayerCount = {};
var startTime = exports.getCurrentTimeMs();
for (var i = 0; i < sqlData.length; i++) {
var entry = sqlData[i];
if (serverIps.indexOf(entry.ip) === -1) {
continue;
}
if (serverIps.indexOf(entry.ip) === -1) continue;
var name = getServerNameByIp(entry.ip);
if (!graphData[name]) {
graphData[name] = [];
}
if (!graphData[name]) graphData[name] = [];
graphData[name].push([entry.timestamp, entry.playerCount]);
if (!highestPlayerCount[entry.ip]) highestPlayerCount[entry.ip] = 0;
if (entry.playerCount > highestPlayerCount[entry.ip]) highestPlayerCount[entry.ip] = entry.playerCount;
}
// Break it into minutes.
@ -136,9 +135,12 @@ exports.convertPingsToGraph = function(sqlData) {
// Drop old data.
exports.trimOldPings(graphData);
logger.info('Converted data structure in ' + (exports.getCurrentTimeMs() - startTime) + 'ms');
logger.info('Parsed ' + sqlData.length + ' ping records in ' + (exports.getCurrentTimeMs() - startTime) + 'ms');
return graphData;
return {
graphData: graphData,
highestPlayerCount: highestPlayerCount
};
};
exports.getBootTime = function() {
@ -166,4 +168,4 @@ exports.unfurlSRV = function(hostname, port, callback) {
}
callback(records[0].name, records[0].port);
})
};
};