From ef176a9cdc6155aaeecf2567c9bd8a96ba3783bf Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 12 Oct 2022 20:33:37 +0100 Subject: [PATCH] feat: update popn-merge script to work pretty much without intervention --- .../scripts/rerunners/parse-duck-popn.js | 83 ++++++++++++------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/database-seeds/scripts/rerunners/parse-duck-popn.js b/database-seeds/scripts/rerunners/parse-duck-popn.js index fca5a9a54..e560c28d4 100644 --- a/database-seeds/scripts/rerunners/parse-duck-popn.js +++ b/database-seeds/scripts/rerunners/parse-duck-popn.js @@ -1,47 +1,65 @@ const fs = require("fs"); const { Command } = require("commander"); -const { CreateChartID } = require("../util"); -const path = require("path"); +const { + CreateChartID, + ReadCollection, + GetFreshScoreIDGenerator, + WriteCollection, +} = require("../util"); const program = new Command(); -program.option("-f, --file "); +program.requiredOption("-f, --file "); +program.requiredOption("-v, --version "); program.parse(process.argv); const options = program.opts(); -if (!options.file) { - throw new Error(`Please specify a file with --file.`); -} +const data = JSON.parse(fs.readFileSync(options.file)); -let data = JSON.parse(fs.readFileSync(options.file)); +const curCharts = ReadCollection("charts-popn.json"); -data = data.filter((e) => e !== null); +const existingSongs = new Map(curCharts.map((e) => [e.data.inGameID, e.songID])); +const existingCharts = new Map(curCharts.map((e) => [e.data.hashSHA256, e])); const songs = []; const charts = []; -let songID = 1; +const getNewSongID = GetFreshScoreIDGenerator("popn"); + for (const song of data) { + // some datapoints might be null + if (song === null) { + continue; + } + + const index = song.music_entry; + const isUpper = song.charts.some((k) => k !== null && k.filename.startsWith("exx")); const isUra = song.charts.some((k) => k !== null && k.filename.endsWith("_ura2")); let title = isUpper ? `${song.title} (UPPER)` : song.title; title = isUra ? `${title} (URA)` : title; - songs.push({ - id: songID, - title, - artist: song.artist, - searchTerms: [], - altTitles: [], - data: { - displayVersion: null, - genre: song.genre, - }, - }); + let songID = existingSongs.get(index); - for (const [index, chart] of Object.entries(song.charts)) { + if (!songID) { + songID = getNewSongID(); + songs.push({ + id: songID, + title, + artist: song.artist, + searchTerms: [], + altTitles: [], + data: { + displayVersion: null, + genre: song.genre, + genreEN: null, + }, + }); + } + + for (const chart of song.charts) { if (chart === null) { continue; } @@ -50,6 +68,16 @@ for (const song of data) { continue; } + const existingChart = existingCharts.get(chart.hash); + if (existingChart) { + if (!existingChart.versions.includes(options.version)) { + existingChart.versions.push(options.version); + } + + // don't add a new chart, just update versions + continue; + } + charts.push({ songID, chartID: CreateChartID(), @@ -68,15 +96,12 @@ for (const song of data) { inGameID: index, }, tierlistInfo: {}, - versions: ["peace"], + versions: [options.version], }); } - - songID++; } -// fs.writeFileSync(path.join(__dirname, "../../collections/charts-popn.json"), JSON.stringify(charts, null, "\t")); -fs.writeFileSync( - path.join(__dirname, "../../collections/songs-popn.json"), - JSON.stringify(songs, null, "\t") -); +const curSongs = ReadCollection("songs-popn.json"); + +WriteCollection("songs-popn.json", [...curSongs, ...songs]); +WriteCollection("charts-popn.json", [...existingCharts.values(), ...charts]);