From 882b38439e00ad7b502326707207cf2109710729 Mon Sep 17 00:00:00 2001 From: furo Date: Sat, 9 Oct 2021 23:22:56 +0200 Subject: [PATCH] Add more post processing tasks (points) --- libs/database/sqlite2mongo/postTasks.js | 57 ++++++++++++++++++++++++- schemas/Player.js | 2 + 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/libs/database/sqlite2mongo/postTasks.js b/libs/database/sqlite2mongo/postTasks.js index 840bbc2..891ac2e 100644 --- a/libs/database/sqlite2mongo/postTasks.js +++ b/libs/database/sqlite2mongo/postTasks.js @@ -14,7 +14,7 @@ export default async function postTasks() { log("Loading cached info from DDNet...") const cache = decodeMsgpack() - +/* log("Adding total amounts of finishes to maps!") for (const category in cache.maps) { for (const i in cache.maps[category]) { @@ -28,4 +28,59 @@ export default async function postTasks() { log(`Processed ${category} map ${i}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`) } } + + log("Adding points to players") + for (const entry of cache.pointsRanks) { + const playerFromDB = await Player.findOne({ name: entry[0] }) + if (!playerFromDB) continue + + playerFromDB.points = entry[1] + playerFromDB.save() + + log(`Processed ${entry[1]} points for ${entry[0]}`) + } + + log("Adding rank points to players") + for (const entry of cache.rankPoints) { + const playerFromDB = await Player.findOne({ name: entry[0] }) + if (!playerFromDB) continue + + playerFromDB.rankPoints = entry[1] + playerFromDB.save() + + log(`Processed ${entry[1]} rank points for ${entry[0]}`) + } + + log("Adding team points to players") + for (const entry of cache.teamRankPoints) { + const playerFromDB = await Player.findOne({ name: entry[0] }) + if (!playerFromDB) continue + + playerFromDB.teamPoints = entry[1] + playerFromDB.save() + + log(`Processed ${entry[1]} team points for ${entry[0]}`) + } +*/ + log("Adding weekly points to players") + for (const entry of cache.pointsThisWeek) { + const playerFromDB = await Player.findOne({ name: entry[0] }) + if (!playerFromDB) continue + + playerFromDB.pointsThisWeek = entry[1] + playerFromDB.save() + + log(`Processed ${entry[1]} weekly points for ${entry[0]}`) + } + + log("Adding monthly points to players") + for (const entry of cache.teamRankPoints) { + const playerFromDB = await Player.findOne({ name: entry[0] }) + if (!playerFromDB) continue + + playerFromDB.pointsThisMonth = entry[1] + playerFromDB.save() + + log(`Processed ${entry[1]} team points for ${entry[0]}`) + } } \ No newline at end of file diff --git a/schemas/Player.js b/schemas/Player.js index 53ab9ff..6658f51 100644 --- a/schemas/Player.js +++ b/schemas/Player.js @@ -5,6 +5,8 @@ const Player = new mongoose.Schema({ points: Number, rankPoints: Number, teamPoints: Number, + pointsThisWeek: Number, + pointsThisMonth: Number, firstFinish: Date })