Now imports points...
This commit is contained in:
parent
10eff256cb
commit
0bafd5e4a6
|
@ -1,8 +1,8 @@
|
||||||
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 decodeMsgpack from './decodeMsgpack.js'
|
import decodeMsgpack from './decodeMsgpack.js'
|
||||||
|
|
||||||
const log = initLog("sqlite2mongo")
|
const log = initLog("sqlite2mongo")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,73 +19,82 @@ export default async function postTasks() {
|
||||||
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]
|
||||||
const mapFromDB = await Level.findOne({ name: map[0] })
|
Level.findOneAndUpdate(
|
||||||
if (!mapFromDB) continue
|
{ name: map[0] },
|
||||||
|
{ totalFinishes: map[2] }
|
||||||
mapFromDB.totalFinishes = map[2]
|
).then(
|
||||||
mapFromDB.save()
|
() => log(`Processed ${category} map ${i + 1}/${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("Processing points for players...")
|
log("Processing points for players...")
|
||||||
for (const i in cache.pointsRanks) {
|
let processedPlayerPoints = 0
|
||||||
const entry = cache.pointsRanks[i]
|
for (const entry of cache.pointsRanks) {
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
Player.findOneAndUpdate(
|
||||||
if (!playerFromDB) continue
|
{ name: entry[0] },
|
||||||
|
{ points: entry[1] }
|
||||||
playerFromDB.points = entry[1]
|
).then(
|
||||||
playerFromDB.save()
|
() => {
|
||||||
|
++processedPlayerPoints
|
||||||
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} points!`)
|
log(`Processed player ${processedPlayerPoints}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} points!`)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Processing rank points for players...")
|
log("Processing rank points for players...")
|
||||||
for (const i in cache.rankPoints) {
|
let processedPlayerRankPoints = 0
|
||||||
const entry = cache.rankPoints[i]
|
for (const entry of cache.rankPoints) {
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
Player.findOneAndUpdate(
|
||||||
if (!playerFromDB) continue
|
{ name: entry[0] },
|
||||||
|
{ rankPoints: entry[1] }
|
||||||
playerFromDB.rankPoints = entry[1]
|
).then(
|
||||||
playerFromDB.save()
|
() => {
|
||||||
|
++processedPlayerRankPoints
|
||||||
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} rank points!`)
|
log(`Processed player ${processedPlayerRankPoints}/${cache.rankPoints.length} -> «${entry[0]}» has ${entry[1]} rank points!`)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Processing team points for players...")
|
log("Processing team points for players...")
|
||||||
for (const i in cache.teamRankPoints) {
|
let processedTeamPoints = 0
|
||||||
const entry = cache.teamRankPoints[i]
|
for (const entry in cache.teamRankPoints) {
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
Player.findOneAndUpdate(
|
||||||
if (!playerFromDB) continue
|
{ name: entry[0] },
|
||||||
|
{ teamPoints: entry[1] }
|
||||||
playerFromDB.teamPoints = entry[1]
|
).then(
|
||||||
playerFromDB.save()
|
() => {
|
||||||
|
++processedTeamPoints
|
||||||
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} team points!`)
|
log(`Processed player ${processedTeamPoints}/${cache.teamRankPoints.length} -> «${entry[0]}» has ${entry[1]} team points!`)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Processing players' points for the last week...")
|
log("Processing players' points for the last week...")
|
||||||
for (const i of cache.pointsThisWeek) {
|
let processedPlayerPointsWeek = 0
|
||||||
const entry = cache.pointsThisWeek[i]
|
for (const entry of cache.pointsThisWeek) {
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
Player.findOneAndUpdate(
|
||||||
if (!playerFromDB) continue
|
{ name: entry[0] },
|
||||||
|
{ pointsThisWeek: entry[1] }
|
||||||
playerFromDB.pointsThisWeek = entry[1]
|
).then(
|
||||||
playerFromDB.save()
|
() => {
|
||||||
|
++processedPlayerPointsWeek
|
||||||
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» got ${entry[1]} points this week!`)
|
log(`Processed player ${processedPlayerPointsWeek}/${cache.pointsThisWeek.length} -> «${entry[0]}» got ${entry[1]} points this week!`)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Processing players' points for the last month...")
|
log("Processing players' points for the last month...")
|
||||||
for (const i of cache.pointsThisMonth) {
|
let processedPlayerPointsMonth = 0
|
||||||
const entry = cache.pointsThisMonth[i]
|
for (const entry of cache.pointsThisMonth) {
|
||||||
const playerFromDB = await Player.findOne({ name: entry[0] })
|
Player.findOneAndUpdate(
|
||||||
if (!playerFromDB) continue
|
{ name: entry[0] },
|
||||||
|
{ pointsThisWeek: entry[1] }
|
||||||
playerFromDB.pointsThisMonth = entry[1]
|
).then(
|
||||||
playerFromDB.save()
|
() => {
|
||||||
|
++processedPlayerPointsMonth
|
||||||
log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» got ${entry[1]} points this month!`)
|
log(`Processed player ${processedPlayerPointsMonth}/${cache.pointsThisMonth.length} -> «${entry[0]}» got ${entry[1]} points this month!`)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user