Minor "refactor".
This commit is contained in:
parent
808949ac0c
commit
10eff256cb
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default async function postTasks() {
|
||||||
log("Loading cached info from DDNet...")
|
log("Loading cached info from DDNet...")
|
||||||
const cache = decodeMsgpack()
|
const cache = decodeMsgpack()
|
||||||
|
|
||||||
log("Adding total amounts of finishes to maps!")
|
log("Adding total amounts of finishes to maps...")
|
||||||
for (const category in cache.maps) {
|
for (const category in cache.maps) {
|
||||||
for (const i in cache.maps[category]) {
|
for (const i in cache.maps[category]) {
|
||||||
const map = cache.maps[category][i]
|
const map = cache.maps[category][i]
|
||||||
|
@ -25,62 +25,67 @@ export default async function postTasks() {
|
||||||
mapFromDB.totalFinishes = map[2]
|
mapFromDB.totalFinishes = map[2]
|
||||||
mapFromDB.save()
|
mapFromDB.save()
|
||||||
|
|
||||||
log(`Processed ${category} map ${i}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`)
|
log(`Processed ${category} map ${i + 1}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Adding points to players")
|
log("Processing points for players...")
|
||||||
for (const entry of cache.pointsRanks) {
|
for (const i in cache.pointsRanks) {
|
||||||
|
const entry = cache.pointsRanks[i]
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
const playerFromDB = await Player.findOne({ name: entry[0] })
|
||||||
if (!playerFromDB) continue
|
if (!playerFromDB) continue
|
||||||
|
|
||||||
playerFromDB.points = entry[1]
|
playerFromDB.points = entry[1]
|
||||||
playerFromDB.save()
|
playerFromDB.save()
|
||||||
|
|
||||||
log(`Processed ${entry[1]} points for ${entry[0]}`)
|
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} points!`)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Adding rank points to players")
|
log("Processing rank points for players...")
|
||||||
for (const entry of cache.rankPoints) {
|
for (const i in cache.rankPoints) {
|
||||||
|
const entry = cache.rankPoints[i]
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
const playerFromDB = await Player.findOne({ name: entry[0] })
|
||||||
if (!playerFromDB) continue
|
if (!playerFromDB) continue
|
||||||
|
|
||||||
playerFromDB.rankPoints = entry[1]
|
playerFromDB.rankPoints = entry[1]
|
||||||
playerFromDB.save()
|
playerFromDB.save()
|
||||||
|
|
||||||
log(`Processed ${entry[1]} rank points for ${entry[0]}`)
|
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} rank points!`)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Adding team points to players")
|
log("Processing team points for players...")
|
||||||
for (const entry of cache.teamRankPoints) {
|
for (const i in cache.teamRankPoints) {
|
||||||
|
const entry = cache.teamRankPoints[i]
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
const playerFromDB = await Player.findOne({ name: entry[0] })
|
||||||
if (!playerFromDB) continue
|
if (!playerFromDB) continue
|
||||||
|
|
||||||
playerFromDB.teamPoints = entry[1]
|
playerFromDB.teamPoints = entry[1]
|
||||||
playerFromDB.save()
|
playerFromDB.save()
|
||||||
|
|
||||||
log(`Processed ${entry[1]} team points for ${entry[0]}`)
|
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} team points!`)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Adding weekly points to players")
|
log("Processing players' points for the last week...")
|
||||||
for (const entry of cache.pointsThisWeek) {
|
for (const i of cache.pointsThisWeek) {
|
||||||
|
const entry = cache.pointsThisWeek[i]
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
const playerFromDB = await Player.findOne({ name: entry[0] })
|
||||||
if (!playerFromDB) continue
|
if (!playerFromDB) continue
|
||||||
|
|
||||||
playerFromDB.pointsThisWeek = entry[1]
|
playerFromDB.pointsThisWeek = entry[1]
|
||||||
playerFromDB.save()
|
playerFromDB.save()
|
||||||
|
|
||||||
log(`Processed ${entry[1]} weekly points for ${entry[0]}`)
|
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» got ${entry[1]} points this week!`)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Adding monthly points to players")
|
log("Processing players' points for the last month...")
|
||||||
for (const entry of cache.teamRankPoints) {
|
for (const i of cache.pointsThisMonth) {
|
||||||
|
const entry = cache.pointsThisMonth[i]
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
const playerFromDB = await Player.findOne({ name: entry[0] })
|
||||||
if (!playerFromDB) continue
|
if (!playerFromDB) continue
|
||||||
|
|
||||||
playerFromDB.pointsThisMonth = entry[1]
|
playerFromDB.pointsThisMonth = entry[1]
|
||||||
playerFromDB.save()
|
playerFromDB.save()
|
||||||
|
|
||||||
log(`Processed ${entry[1]} monthly points for ${entry[0]}`)
|
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» got ${entry[1]} points this month!`)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user