2021-10-06 19:52:40 +02:00
|
|
|
import Level from '../../../schemas/Level.js'
|
|
|
|
import Player from '../../../schemas/Player.js'
|
2021-10-13 16:40:18 +02:00
|
|
|
import initLog from '../../utils/log.js'
|
2021-10-09 20:12:06 +02:00
|
|
|
import decodeMsgpack from './decodeMsgpack.js'
|
2021-10-16 19:11:16 +02:00
|
|
|
import { spread } from '../../utils/multithread.js'
|
2021-10-11 19:37:37 +02:00
|
|
|
|
2021-10-06 19:52:40 +02:00
|
|
|
const log = initLog("sqlite2mongo")
|
|
|
|
|
2021-10-06 20:36:20 +02:00
|
|
|
/**
|
|
|
|
* This handles some post-tasks that run after the initial checks.
|
|
|
|
* @module libs/database/sqlite2mongo/postTasks
|
|
|
|
*/
|
2021-10-06 19:52:40 +02:00
|
|
|
export default async function postTasks() {
|
|
|
|
log("Post tasks...")
|
|
|
|
|
2021-10-09 20:12:06 +02:00
|
|
|
log("Loading cached info from DDNet...")
|
|
|
|
const cache = decodeMsgpack()
|
2021-10-09 23:25:57 +02:00
|
|
|
|
2021-10-09 23:52:41 +02:00
|
|
|
log("Adding total amounts of finishes to maps...")
|
2021-10-16 19:11:16 +02:00
|
|
|
const totalMaps = await Level.find({}).count()
|
|
|
|
let processedMaps = 0
|
2021-10-09 20:12:06 +02:00
|
|
|
for (const category in cache.maps) {
|
2021-10-16 19:11:16 +02:00
|
|
|
for (const map of cache.maps[category]) {
|
2021-10-11 19:37:37 +02:00
|
|
|
Level.findOneAndUpdate(
|
|
|
|
{ name: map[0] },
|
|
|
|
{ totalFinishes: map[2] }
|
|
|
|
).then(
|
2021-10-16 19:11:16 +02:00
|
|
|
() => {
|
|
|
|
++processedMaps
|
|
|
|
log(`Processed map ${processedMaps}/${totalMaps} -> «${map[0]}» [${category}] with ${map[2]} finishes!`)
|
|
|
|
}
|
2021-10-11 19:37:37 +02:00
|
|
|
)
|
2021-10-09 20:12:06 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-09 23:22:56 +02:00
|
|
|
|
2021-10-16 19:11:16 +02:00
|
|
|
log("Reseting weekly and monthly points...")
|
|
|
|
await Player.updateMany({}, { pointsThisWeek: 0, pointsThisMonth: 0 })
|
|
|
|
log("Done!")
|
|
|
|
|
2021-10-09 23:52:41 +02:00
|
|
|
log("Processing points for players...")
|
2021-10-30 19:19:58 +02:00
|
|
|
const totalPlayers = await Player.find({}).count()
|
2021-10-11 19:37:37 +02:00
|
|
|
let processedPlayerPoints = 0
|
|
|
|
for (const entry of cache.pointsRanks) {
|
2021-10-16 19:11:16 +02:00
|
|
|
spread(
|
|
|
|
'./playerPoints.js',
|
|
|
|
{
|
|
|
|
name: entry[0],
|
|
|
|
points: entry[1]
|
|
|
|
}
|
2021-10-11 19:37:37 +02:00
|
|
|
).then(
|
|
|
|
() => {
|
|
|
|
++processedPlayerPoints
|
2021-10-30 19:19:58 +02:00
|
|
|
log(`Processed player ${processedPlayerPoints}/${totalPlayers} -> «${entry[0]}» has ${entry[1]} points!`)
|
2021-10-11 19:37:37 +02:00
|
|
|
}
|
|
|
|
)
|
2021-10-09 23:22:56 +02:00
|
|
|
}
|
|
|
|
|
2021-10-09 23:52:41 +02:00
|
|
|
log("Processing rank points for players...")
|
2021-10-11 19:37:37 +02:00
|
|
|
let processedPlayerRankPoints = 0
|
|
|
|
for (const entry of cache.rankPoints) {
|
2021-10-16 19:11:16 +02:00
|
|
|
spread(
|
|
|
|
'./playerRankPoints.js',
|
|
|
|
{
|
|
|
|
name: entry[0],
|
2021-10-30 19:19:58 +02:00
|
|
|
rankPoints: entry[1]
|
2021-10-16 19:11:16 +02:00
|
|
|
}
|
2021-10-11 19:37:37 +02:00
|
|
|
).then(
|
|
|
|
() => {
|
|
|
|
++processedPlayerRankPoints
|
|
|
|
log(`Processed player ${processedPlayerRankPoints}/${cache.rankPoints.length} -> «${entry[0]}» has ${entry[1]} rank points!`)
|
|
|
|
}
|
|
|
|
)
|
2021-10-09 23:22:56 +02:00
|
|
|
}
|
|
|
|
|
2021-10-09 23:52:41 +02:00
|
|
|
log("Processing team points for players...")
|
2021-10-11 19:37:37 +02:00
|
|
|
let processedTeamPoints = 0
|
|
|
|
for (const entry in cache.teamRankPoints) {
|
2021-10-16 19:11:16 +02:00
|
|
|
spread(
|
|
|
|
'./playerTeamPoints.js',
|
|
|
|
{
|
|
|
|
name: entry[0],
|
|
|
|
teamPoints: entry[1]
|
|
|
|
}
|
2021-10-11 19:37:37 +02:00
|
|
|
).then(
|
|
|
|
() => {
|
|
|
|
++processedTeamPoints
|
|
|
|
log(`Processed player ${processedTeamPoints}/${cache.teamRankPoints.length} -> «${entry[0]}» has ${entry[1]} team points!`)
|
|
|
|
}
|
|
|
|
)
|
2021-10-09 23:22:56 +02:00
|
|
|
}
|
2021-10-09 23:25:57 +02:00
|
|
|
|
2021-10-09 23:52:41 +02:00
|
|
|
log("Processing players' points for the last week...")
|
2021-10-11 19:37:37 +02:00
|
|
|
let processedPlayerPointsWeek = 0
|
|
|
|
for (const entry of cache.pointsThisWeek) {
|
2021-10-16 19:11:16 +02:00
|
|
|
spread(
|
|
|
|
'./playerWeekPoints.js',
|
|
|
|
{
|
|
|
|
name: entry[0],
|
|
|
|
pointsThisWeek: entry[1]
|
|
|
|
}
|
2021-10-11 19:37:37 +02:00
|
|
|
).then(
|
|
|
|
() => {
|
|
|
|
++processedPlayerPointsWeek
|
|
|
|
log(`Processed player ${processedPlayerPointsWeek}/${cache.pointsThisWeek.length} -> «${entry[0]}» got ${entry[1]} points this week!`)
|
|
|
|
}
|
|
|
|
)
|
2021-10-09 23:22:56 +02:00
|
|
|
}
|
|
|
|
|
2021-10-09 23:52:41 +02:00
|
|
|
log("Processing players' points for the last month...")
|
2021-10-11 19:37:37 +02:00
|
|
|
let processedPlayerPointsMonth = 0
|
|
|
|
for (const entry of cache.pointsThisMonth) {
|
2021-10-16 19:11:16 +02:00
|
|
|
spread(
|
|
|
|
'./playerMonthPoints.js',
|
|
|
|
{
|
|
|
|
name: entry[0],
|
|
|
|
pointsThisMonth: entry[1]
|
|
|
|
}
|
2021-10-11 19:37:37 +02:00
|
|
|
).then(
|
|
|
|
() => {
|
|
|
|
++processedPlayerPointsMonth
|
|
|
|
log(`Processed player ${processedPlayerPointsMonth}/${cache.pointsThisMonth.length} -> «${entry[0]}» got ${entry[1]} points this month!`)
|
|
|
|
}
|
|
|
|
)
|
2021-10-09 23:22:56 +02:00
|
|
|
}
|
2021-10-06 19:52:40 +02:00
|
|
|
}
|