From 7bc68065338e2bc8241bf7b33f941ebe58902abf Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Thu, 1 Jul 2021 19:23:28 +0300 Subject: [PATCH] Delete league jsons script --- prisma/scripts/leagueJsons.ts | 126 ---------------------------------- 1 file changed, 126 deletions(-) delete mode 100644 prisma/scripts/leagueJsons.ts diff --git a/prisma/scripts/leagueJsons.ts b/prisma/scripts/leagueJsons.ts deleted file mode 100644 index 831b3f8f8..000000000 --- a/prisma/scripts/leagueJsons.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { Prisma } from "@prisma/client"; -import fs from "fs"; -import path from "path"; -import { getWeaponNormalized } from "../../utils/lists/weapons"; -import prisma from "../client"; - -const files = ["P_EU", "P_US", "T_EU", "T_US", "P_JP", "T_JP"]; - -let oldestDate = new Date("2050"); - -async function main() { - const freshest = await prisma.leagueSquad.findFirst({ - orderBy: { startTime: "desc" }, - }); - if (!freshest) throw Error("that's not fresh"); - for (const file of files) { - const squadsData: Prisma.LeagueSquadCreateManyInput[] = []; - const playersData: Prisma.PlayerCreateManyInput[] = []; - const data = fs.readFileSync( - path.resolve(__dirname, `./data/league/${file}.json`) - ); - const league = JSON.parse(data.toString()); - - for (const rotation of league) { - for (const ranking of rotation.rankings) { - if (ranking.cheater) continue; - if (ranking.point < 2200) continue; - - const startTime = new Date(rotation.start_time * 1000); - - if (startTime.getTime() <= freshest.startTime.getTime()) { - continue; - } - - if (startTime.getTime() < oldestDate.getTime()) { - oldestDate = startTime; - } - - squadsData.push({ - leaguePower: ranking.point, - region: - rotation.league_ranking_region.code === "US" - ? "NA" - : rotation.league_ranking_region.code, - startTime, - type: rotation.league_type.key === "pair" ? "TWIN" : "QUAD", - }); - - ranking.tag_members.forEach((member: any) => { - playersData.push({ - switchAccountId: member.unique_id, - principalId: member.principal_id, - }); - }); - } - } - - console.log("oldest =", oldestDate.getTime()); - - await prisma.leagueSquad.createMany({ data: squadsData }); - - console.log("leagueSquads created"); - - await prisma.player.createMany({ data: playersData, skipDuplicates: true }); - - console.log("players created"); - - const createdSquads = await prisma.leagueSquad.findMany({ - where: { startTime: { gte: oldestDate } }, - }); - const ids = new Set(); - const leagueMembersData: Prisma.LeagueSquadMemberCreateManyInput[] = []; - - for (const rotation of league) { - for (const ranking of rotation.rankings) { - if (ranking.cheater) continue; - if (ranking.point < 2200) continue; - - const startTime = new Date(rotation.start_time * 1000); - - if (startTime.getTime() <= freshest.startTime.getTime()) { - continue; - } - - const type = rotation.league_type.key === "pair" ? "TWIN" : "QUAD"; - const region = - rotation.league_ranking_region.code === "US" - ? "NA" - : rotation.league_ranking_region.code; - - const squad = createdSquads.find( - (squad) => - squad.leaguePower === ranking.point && - squad.region === region && - squad.type === type && - squad.startTime.getTime() === startTime.getTime() && - !ids.has(squad.id) - ); - - if (!squad) throw Error("squad not found"); - - ids.add(squad.id); - - ranking.tag_members.forEach((member: any) => { - leagueMembersData.push({ - switchAccountId: member.unique_id, - squadId: squad.id, - weapon: getWeaponNormalized(member.weapon[1].trim()), - }); - }); - } - } - - await prisma.leagueSquadMember.createMany({ data: leagueMembersData }); - - console.log("members created"); - - console.log("done with", file); - } -} - -main() - .catch((e) => console.error(e)) - .finally(async () => { - await prisma.$disconnect(); - });