From a70be20a5644d7e7ddca73c02eee211451e906e7 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Wed, 16 Mar 2022 20:16:22 +0200 Subject: [PATCH] Add matches without details script --- package.json | 3 +- scripts/matchesWithoutDetails.ts | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 scripts/matchesWithoutDetails.ts diff --git a/package.json b/package.json index 5d5281cf3..03de0ca9a 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "cy:open": "npx cypress open", "cy:run": "npx cypress run", "test:unit": "uvu -r tsm -r tsconfig-paths/register -i cypress", - "tests": "npm run lint:styles && npm run lint:ts && npm run prettier:check && npm run typecheck" + "tests": "npm run lint:styles && npm run lint:ts && npm run prettier:check && npm run typecheck", + "matches": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/matchesWithoutDetails.ts" }, "dependencies": { "@dnd-kit/core": "^5.0.2", diff --git a/scripts/matchesWithoutDetails.ts b/scripts/matchesWithoutDetails.ts new file mode 100644 index 000000000..ab9e73251 --- /dev/null +++ b/scripts/matchesWithoutDetails.ts @@ -0,0 +1,50 @@ +import { PrismaClient } from "@prisma/client"; +import { playersWithResults } from "~/core/play/playerInfos/playerInfos.server"; +import fs from "fs"; + +const prisma = new PrismaClient(); + +async function main() { + const matches = await prisma.lfgGroupMatch.findMany({ + include: { + stages: { include: { stage: true } }, + groups: { include: { members: { include: { user: true } } } }, + }, + }); + + const result: { + id: string; + mapList: { mode: string; map: string }[]; + start_time: string; + end_time: string; + players: string[]; + }[] = []; + + for (const match of matches) { + const players = playersWithResults( + match.groups.flatMap((g) => g.members).flatMap((m) => m.user.discordId) + ); + const mapList = match.stages + .sort((a, b) => a.order - b.order) + .filter((stage) => stage.winnerGroupId) + .map((stage) => ({ map: stage.stage.name, mode: stage.stage.mode })); + + if (!players.length) continue; + if (!mapList.length) continue; + + result.push({ + id: match.id, + mapList, + start_time: match.createdAt.toISOString(), + end_time: new Date(match.createdAt.getTime() + 60 * 60000).toISOString(), + players, + }); + } + + fs.writeFileSync("for_lean.json", JSON.stringify(result, null, 2)); +} + +main() + // eslint-disable-next-line no-console + .then(() => console.log("done")) + .catch((e) => console.error(e));