Expanded stats page

This commit is contained in:
2019-06-07 22:00:20 +10:00
parent 4ad5a258e3
commit ef2e5640f3
+9 -1
View File
@@ -4,12 +4,16 @@ require('dotenv').config();
const round = (x) => Math.round(x * 100) / 100;
const statisticsRequest = (connection) => (req, res) => {
let query = 'SELECT COUNT(*) AS playerCount, SUM(gold) / COUNT(*) AS goldAverage FROM profiles;';
let query = 'SELECT COUNT(*) AS playerCount, SUM(gold) / COUNT(*) AS goldAverage, SUM(recruits) AS recruitTotal, SUM(soldiers) AS soldierTotal, SUM(scientists) AS scientistTotal, SUM(spies) AS spyTotal FROM profiles;';
connection.query(query, (err, results) => {
if (err) throw err;
let playerCount = results[0].playerCount;
let goldAverage = results[0].goldAverage;
let recruitTotal = results[0].recruitTotal;
let soldierTotal = results[0].soldierTotal;
let scientistTotal = results[0].scientistTotal;
let spyTotal = results[0].spyTotal;
//determine the correct tick rate based on the current gold average
//NOTE: copy/pasted
@@ -33,6 +37,10 @@ const statisticsRequest = (connection) => (req, res) => {
'Player Count': playerCount,
'Active Players': activity,
'Active Percentage': { string: `${activePercentage}%`, color: activePercentage >= 10 ? 'lightgreen' : activePercentage >= 5 ? 'yellow' : 'red'},
'Recruits Total': recruitTotal,
'Soldier Total': soldierTotal,
'Scientist Total': scientistTotal,
'Spy Total': { string: '[Classified]', color: 'red' },
'Gold Average': `${round(goldAverage)}`,
'Tick Rate': `${tickRate} minutes`,
'Next Tick': `${nextTick} minute${nextTick === 1 ? '' : 's'} from now`