Now adds total amount of finishes per map...
This commit is contained in:
parent
9972572b3a
commit
11c430276c
|
@ -12,9 +12,9 @@ const log = initLog("sqlite2mongo")
|
|||
async function sqlite2mongo() {
|
||||
log("Checking for additions to 'ddnet.sqlite'...")
|
||||
|
||||
await checkForMaps()
|
||||
await checkForPlayers()
|
||||
await checkForFinishes()
|
||||
// await checkForMaps()
|
||||
// await checkForPlayers()
|
||||
// await checkForFinishes()
|
||||
|
||||
await postTasks()
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ import Finish from '../../../schemas/Finish.js'
|
|||
import Level from '../../../schemas/Level.js'
|
||||
import Player from '../../../schemas/Player.js'
|
||||
import initLog from '../../utills/log.js'
|
||||
import { sqlite } from '../init.js'
|
||||
|
||||
import decodeMsgpack from './decodeMsgpack.js'
|
||||
const log = initLog("sqlite2mongo")
|
||||
|
||||
/**
|
||||
|
@ -12,19 +11,21 @@ const log = initLog("sqlite2mongo")
|
|||
*/
|
||||
export default async function postTasks() {
|
||||
log("Post tasks...")
|
||||
|
||||
log("Calculating player points...")
|
||||
const playerAmount = await Player.find({}).count()
|
||||
const playerAgg = Player.aggregate([])
|
||||
|
||||
let processedPlayers = 0
|
||||
for await (const player of playerAgg) {
|
||||
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
|
||||
log("Loading cached info from DDNet...")
|
||||
const cache = decodeMsgpack()
|
||||
|
||||
Player.updateOne({ name: player.name }, { rankPoints: points }, () => log(`Task ${processedPlayers}/${playerAmount} >> Player «${player.name}» has ${points} points!`))
|
||||
++processedPlayers
|
||||
log("Adding total amounts of finishes to maps!")
|
||||
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!")
|
||||
}
|
|
@ -6,7 +6,8 @@ const Level = new mongoose.Schema({
|
|||
release: Date,
|
||||
category: String,
|
||||
rating: Number,
|
||||
awardPoints: Number
|
||||
awardPoints: Number,
|
||||
totalFinishes: Number
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user