Now adds total amount of finishes per map...

This commit is contained in:
BurnyLlama 2021-10-09 20:12:06 +02:00
parent 9972572b3a
commit 11c430276c
3 changed files with 20 additions and 18 deletions

View File

@ -12,9 +12,9 @@ const log = initLog("sqlite2mongo")
async function sqlite2mongo() { async function sqlite2mongo() {
log("Checking for additions to 'ddnet.sqlite'...") log("Checking for additions to 'ddnet.sqlite'...")
await checkForMaps() // await checkForMaps()
await checkForPlayers() // await checkForPlayers()
await checkForFinishes() // await checkForFinishes()
await postTasks() await postTasks()
} }

View File

@ -2,8 +2,7 @@ import Finish from '../../../schemas/Finish.js'
import Level from '../../../schemas/Level.js' import Level from '../../../schemas/Level.js'
import Player from '../../../schemas/Player.js' import Player from '../../../schemas/Player.js'
import initLog from '../../utills/log.js' import initLog from '../../utills/log.js'
import { sqlite } from '../init.js' import decodeMsgpack from './decodeMsgpack.js'
const log = initLog("sqlite2mongo") const log = initLog("sqlite2mongo")
/** /**
@ -12,19 +11,21 @@ const log = initLog("sqlite2mongo")
*/ */
export default async function postTasks() { export default async function postTasks() {
log("Post tasks...") log("Post tasks...")
log("Calculating player points...")
const playerAmount = await Player.find({}).count()
const playerAgg = Player.aggregate([])
let processedPlayers = 0 log("Loading cached info from DDNet...")
for await (const player of playerAgg) { const cache = decodeMsgpack()
const points = (await sqlite.get(`SELECT sum(Points) FROM maps JOIN (SELECT DISTINCT Map FROM race WHERE Name = "${player.name}") AS r ON maps.Map = r.Map`))['sum(Points)']
player.points = points
Player.updateOne({ name: player.name }, { rankPoints: points }, () => log(`Task ${processedPlayers}/${playerAmount} >> Player «${player.name}» has ${points} points!`)) log("Adding total amounts of finishes to maps!")
++processedPlayers for (const category in cache.maps) {
for (const i in cache.maps[category]) {
const map = cache.maps[category][i]
const mapFromDB = await Level.findOne({ name: map[0] })
if (!mapFromDB) continue
mapFromDB.totalFinishes = map[2]
mapFromDB.save()
log(`Processed ${category} map ${i}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`)
}
} }
log("Done calculating points!")
} }

View File

@ -6,7 +6,8 @@ const Level = new mongoose.Schema({
release: Date, release: Date,
category: String, category: String,
rating: Number, rating: Number,
awardPoints: Number awardPoints: Number,
totalFinishes: Number
}) })
/** /**