1
This commit is contained in:
parent
580b5228dd
commit
ef65397d8a
@ -6,6 +6,8 @@ const Redis = require('../services/redis');
|
|||||||
const RANKING_KEY = 'game2006api:';
|
const RANKING_KEY = 'game2006api:';
|
||||||
const LAST_IDX = 'userLastIdx';
|
const LAST_IDX = 'userLastIdx';
|
||||||
|
|
||||||
|
const BASE_SCORE = 2800;
|
||||||
|
|
||||||
class Rankings {
|
class Rankings {
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
@ -28,7 +30,7 @@ class Rankings {
|
|||||||
await Redis.del(RANKING_KEY + 'account')
|
await Redis.del(RANKING_KEY + 'account')
|
||||||
await Redis.del(RANKING_KEY + 'ranking')
|
await Redis.del(RANKING_KEY + 'ranking')
|
||||||
await this.calcRanking();
|
await this.calcRanking();
|
||||||
console.log("跟新rank榜单")
|
console.log("刷新rank榜单")
|
||||||
}else {
|
}else {
|
||||||
await this.calcRanking();
|
await this.calcRanking();
|
||||||
console.log("生成rank榜单")
|
console.log("生成rank榜单")
|
||||||
@ -56,22 +58,16 @@ class Rankings {
|
|||||||
if (lastIdx != -1) {
|
if (lastIdx != -1) {
|
||||||
this.recordsSort(sorted, result.records)
|
this.recordsSort(sorted, result.records)
|
||||||
}
|
}
|
||||||
|
console.log(lastIdx, sorted);
|
||||||
}
|
}
|
||||||
await this.pushResultToRedis(sorted);
|
await this.pushResultToRedis(sorted);
|
||||||
|
|
||||||
// let rankList = await this.pushRankingResult(sorted);
|
|
||||||
// console.log(rankList);
|
|
||||||
|
|
||||||
//存储到redis中
|
|
||||||
// let listJson = JSON.stringify(rankList);
|
|
||||||
// Redis.set(RANKING_KEY + "rank",listJson);
|
|
||||||
console.log("calc ranking end");
|
console.log("calc ranking end");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//增加排名列
|
//增加排名列
|
||||||
async pushResultToRedis(sorted) {
|
async pushResultToRedis(sorted) {
|
||||||
|
console.log(sorted);
|
||||||
let rankingList = [];
|
let rankingList = [];
|
||||||
await utils.serial(
|
await utils.serial(
|
||||||
sorted,
|
sorted,
|
||||||
@ -112,7 +108,7 @@ class Rankings {
|
|||||||
recordsSort(sorted, records) {
|
recordsSort(sorted, records) {
|
||||||
// 根据分数加入到排序表中
|
// 根据分数加入到排序表中
|
||||||
for (let element of records) {
|
for (let element of records) {
|
||||||
if (element.score>2800) {
|
if (element.score>BASE_SCORE) {
|
||||||
if (sorted.length >= 10000){
|
if (sorted.length >= 10000){
|
||||||
if (element.score >= sorted[sorted.length - 1].score){
|
if (element.score >= sorted[sorted.length - 1].score){
|
||||||
this._recordsSort(sorted,element);
|
this._recordsSort(sorted,element);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user