Skip to content

Commit

Permalink
Set all player current ranking last active
Browse files Browse the repository at this point in the history
  • Loading branch information
scottadkin committed Jun 14, 2024
1 parent bb1a03d commit b2fb33e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api/rankings.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,39 @@ class Rankings{

return await mysql.simpleQuery(query, [matchId]);
}


async _getAllPlayerIdsFromCurrent(){

const query = `SELECT player_id,gametype FROM nstats_ranking_player_current`;

const result = await mysql.simpleQuery(query);

return result.map((r) =>{
return {"player": r.player_id, "gametype": r.gametype}
});
}

async setAllPlayerCurrentLastActive(){

const data = await this._getAllPlayerIdsFromCurrent();

const query = `UPDATE nstats_ranking_player_current SET last_active=? WHERE player_id=? AND gametype=?`;

for(let i = 0; i < data.length; i++){

const {player, gametype} = data[i];

const last = await this._getPlayerLatestGametypeDate(player, gametype);

if(last === null){
new Message(`setAllPlayerCurrentLastActive last is null`,"warning");
continue;
}

await mysql.simpleQuery(query, [last, player, gametype]);
}
}
}

module.exports = Rankings;
15 changes: 15 additions & 0 deletions setrankinglastactive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mysql = require("./api/database");
const Message = require("./api/message");
const Rankings = require("./api/rankings");

(async () =>{

new Message(`Set all players last_active date script `,"note");

const r = new Rankings();

await r.setAllPlayerCurrentLastActive();

new Message(`Finished`,"pass");
process.exit();
})();

0 comments on commit b2fb33e

Please sign in to comment.