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