finalize ranking change
This commit is contained in:
parent
2e199612a0
commit
54627ec4f1
|
@ -53,17 +53,14 @@ class Ranks {
|
||||||
};
|
};
|
||||||
await Ranks.updateRanking();
|
await Ranks.updateRanking();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.error(`Error initialize ranks: ${err.message}`);
|
console.error(`Error initialize ranks: ${err.message}`);
|
||||||
}
|
}
|
||||||
setInterval(Ranks.updateRanking, 5 * MINUTE);
|
setInterval(Ranks.updateRanking, 5 * MINUTE);
|
||||||
|
HourlyCron.hook(Ranks.setHourlyRanking);
|
||||||
DailyCron.hook(Ranks.setDailyRanking);
|
DailyCron.hook(Ranks.setDailyRanking);
|
||||||
setInterval(Ranks.setHourlyRanking, 5 * MINUTE);
|
|
||||||
//HourlyCron.hook(Ranks.setHourlyRanking);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* get daily and total ranking from database
|
|
||||||
*/
|
|
||||||
static async updateRanking() {
|
static async updateRanking() {
|
||||||
// only main shard does it
|
// only main shard does it
|
||||||
if (!socketEvents.amIImportant()) {
|
if (!socketEvents.amIImportant()) {
|
||||||
|
@ -89,14 +86,11 @@ class Ranks {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* get online counter stats,
|
|
||||||
* list of users online per hour
|
|
||||||
*/
|
|
||||||
static async hourlyUpdateRanking() {
|
static async hourlyUpdateRanking() {
|
||||||
const onlineStats = await getOnlineUserStats();
|
const onlineStats = await getOnlineUserStats();
|
||||||
const cHistStats = await getCountryDailyHistory();
|
const cHistStats = await getCountryDailyHistory();
|
||||||
const histStats = await getTopDailyHistory();
|
const histStats = await getTopDailyHistory();
|
||||||
|
histStats.users = await populateRanking(histStats.users);
|
||||||
const ret = {
|
const ret = {
|
||||||
onlineStats,
|
onlineStats,
|
||||||
cHistStats,
|
cHistStats,
|
||||||
|
@ -109,9 +103,6 @@ class Ranks {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* get prevTop from database
|
|
||||||
*/
|
|
||||||
static async dailyUpdateRanking() {
|
static async dailyUpdateRanking() {
|
||||||
const prevTop = await populateRanking(
|
const prevTop = await populateRanking(
|
||||||
await getPrevTop(),
|
await getPrevTop(),
|
||||||
|
@ -126,21 +117,13 @@ class Ranks {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* get and store amount of online users into stats
|
|
||||||
*/
|
|
||||||
static async setHourlyRanking() {
|
static async setHourlyRanking() {
|
||||||
if (!socketEvents.amIImportant()) {
|
if (!socketEvents.amIImportant()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let amount;
|
const amount = socketEvents.onlineCounter.total;
|
||||||
try {
|
await storeOnlinUserAmount(amount);
|
||||||
amount = socketEvents.onlineCounter.total;
|
await Ranks.hourlyUpdateRanking();
|
||||||
await storeOnlinUserAmount(amount);
|
|
||||||
await Ranks.hourlyUpdateRanking();
|
|
||||||
} catch (err) {
|
|
||||||
console.error(`error on hourly ranking: ${err.message} / ${amount}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -106,8 +106,8 @@ export async function storeOnlinUserAmount(amount) {
|
||||||
* get list of online counters
|
* get list of online counters
|
||||||
*/
|
*/
|
||||||
export async function getOnlineUserStats() {
|
export async function getOnlineUserStats() {
|
||||||
const onlineStats = await client.lRange(ONLINE_CNTR_KEY, 0, -1);
|
let onlineStats = await client.lRange(ONLINE_CNTR_KEY, 0, -1);
|
||||||
console.log('STAAATTTSS', onlineStats);
|
onlineStats = onlineStats.map((s) => Number(s));
|
||||||
return onlineStats;
|
return onlineStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user