From b158edefdd8d2f4683221aa46b7221f475f1fcce Mon Sep 17 00:00:00 2001 From: zkldi Date: Wed, 9 Jun 2021 01:11:25 +0100 Subject: [PATCH] insert usc charts --- server/scripts/__JSON-TO-KTDB/usc/dedupe.ts | 31 +++++++++++++++++++++ server/scripts/__JSON-TO-KTDB/usc/insert.ts | 13 +++++++++ 2 files changed, 44 insertions(+) create mode 100644 server/scripts/__JSON-TO-KTDB/usc/dedupe.ts create mode 100644 server/scripts/__JSON-TO-KTDB/usc/insert.ts diff --git a/server/scripts/__JSON-TO-KTDB/usc/dedupe.ts b/server/scripts/__JSON-TO-KTDB/usc/dedupe.ts new file mode 100644 index 000000000..781f5e997 --- /dev/null +++ b/server/scripts/__JSON-TO-KTDB/usc/dedupe.ts @@ -0,0 +1,31 @@ +import fs from "fs"; +import path from "path"; +import db from "../../../src/external/mongo/db"; + +const charts = JSON.parse(fs.readFileSync(path.join(__dirname, "charts.json"), "utf-8")); + +const map: Map = new Map(); + +for (const chart of charts) { + const id = `${chart.songID}-${chart.difficulty}`; + const doc = map.get(id); + + if (doc) { + if (Array.isArray(doc.data.hashSHA1)) { + doc.data.hashSHA1.push(chart.data.hashSHA1); + } else { + doc.data.hashSHA1 = [doc.data.hashSHA1, chart.data.hashSHA1]; + } + + // insane hack + chart.erasethis = true; + } else { + map.set(id, chart); + } +} + +// works because byref +fs.writeFileSync( + path.join(__dirname, "deduped-charts.json"), + JSON.stringify(charts.filter((e: any) => e.erasethis !== true)) +); diff --git a/server/scripts/__JSON-TO-KTDB/usc/insert.ts b/server/scripts/__JSON-TO-KTDB/usc/insert.ts new file mode 100644 index 000000000..f28e7f3bc --- /dev/null +++ b/server/scripts/__JSON-TO-KTDB/usc/insert.ts @@ -0,0 +1,13 @@ +import fs from "fs"; +import path from "path"; +import db from "../../../src/external/mongo/db"; + +const songs = JSON.parse(fs.readFileSync(path.join(__dirname, "songs.json"), "utf-8")); +const charts = JSON.parse(fs.readFileSync(path.join(__dirname, "deduped-charts.json"), "utf-8")); + +(async () => { + await db.songs.usc.remove({}); + await db.charts.usc.remove({}); + await db.songs.usc.insert(songs); + await db.charts.usc.insert(charts); +})();