Separeted Finishes from TeamFinishes.

This commit is contained in:
BurnyLlama 2021-09-29 20:56:00 +02:00
parent 450f243797
commit 78fec963f1

View File

@ -2,6 +2,7 @@ import initLog from "../utills/log.js"
import { sqlite } from "./init.js" import { sqlite } from "./init.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 Finish from '../../schemas/Finish.js'
const log = initLog("sqlite2mongo") const log = initLog("sqlite2mongo")
@ -78,6 +79,45 @@ async function checkForPlayers() {
} }
async function checkForFinishes() {
log("Checking for new players...")
const latestFinish = await Finish.findOne({}).sort({ "firstFinish": "desc" })
const date = latestFinish ? latestFinish.firstFinish.toISOString().replace(/[TZ]/g, " ").replace(/\.[0-9\s]+/, "") : undefined
const newFinishAmount = (await sqlite.get(`SELECT count(Name) FROM race ${date ? `WHERE Timestamp > datetime('${date}')` : ''}`))['count(Name)']
if (newFinishAmount === 0) return log("No new finishes found...")
log(`Found ${newFinishAmount} new players!`)
log("Importing new players...")
// await sqlite.exec("DROP TABLE IF EXISTS temp")
// await sqlite.exec("CREATE TABLE temp(Name varchar(128) NOT NULL, Timestamp timestamp NOT NULL)")
// await sqlite.exec(`INSERT INTO TEMP (Name, Timestamp) SELECT Name, Timestamp FROM (SELECT Name, Timestamp FROM (SELECT * FROM race ORDER BY Timestamp ASC, Name ASC) GROUP BY Name) ${date ? `WHERE Timestamp > datetime('${date}')` : ''}`)
// log("Imported new players into 'temp'!")
// let addedPlayers = 0
// let offset = -1
// while (offset < newFinishAmount) {
// await sqlite.each(
// `SELECT Name, Timestamp FROM temp LIMIT 10000 OFFSET ${offset + 1}`,
// [],
// async (err, player) => {
// if (err) return log(err)
// if (addedPlayers >= newFinishAmount) return {}
// Player.create({
// name: player.Name,
// firstFinish: player.Timestamp === '0000-00-00 00:00:00' ? new Date('January 1, 1970 00:00:00 UTC') : new Date(`${player.Timestamp}+00:00`)
// }).then(() => {
// ++addedPlayers
// log(`Added player ${addedPlayers}/${newFinishAmount} -> ${player.Name}`)
// })
// }
// )
// offset += 10000
// }
}
async function sqlite2mongo() { async function sqlite2mongo() {
log("Checking for additions to 'ddnet.sqlite'...") log("Checking for additions to 'ddnet.sqlite'...")