More realistic maplist seeding script

This commit is contained in:
Kalle (Sendou)
2021-12-15 08:32:44 +02:00
parent a868ce390e
commit 9addeb0e26
3 changed files with 63 additions and 9 deletions

11
package-lock.json generated
View File

@@ -18,6 +18,7 @@
"cross-env": "^7.0.3",
"express": "^4.17.1",
"express-session": "^1.17.2",
"just-shuffle": "^4.0.1",
"morgan": "^1.10.0",
"passport": "^0.5.0",
"passport-discord": "^0.1.4",
@@ -4077,6 +4078,11 @@
"verror": "1.10.0"
}
},
"node_modules/just-shuffle": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/just-shuffle/-/just-shuffle-4.0.1.tgz",
"integrity": "sha512-zi6tkAMmnrMc39Tmxma7uEJ4c/NmzreJYHNqpZZ5CR8DluhfarzSmAZ/Tr3HjCYJrXajX6L+rEmC2Z/Fq3uuyg=="
},
"node_modules/keyv": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.4.tgz",
@@ -11540,6 +11546,11 @@
"verror": "1.10.0"
}
},
"just-shuffle": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/just-shuffle/-/just-shuffle-4.0.1.tgz",
"integrity": "sha512-zi6tkAMmnrMc39Tmxma7uEJ4c/NmzreJYHNqpZZ5CR8DluhfarzSmAZ/Tr3HjCYJrXajX6L+rEmC2Z/Fq3uuyg=="
},
"keyv": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.4.tgz",

View File

@@ -34,6 +34,7 @@
"cross-env": "^7.0.3",
"express": "^4.17.1",
"express-session": "^1.17.2",
"just-shuffle": "^4.0.1",
"morgan": "^1.10.0",
"passport": "^0.5.0",
"passport-discord": "^0.1.4",

View File

@@ -11,6 +11,7 @@ import {
import { readFile } from "fs/promises";
import path from "path";
import crypto from "crypto";
import shuffle from "just-shuffle";
const prisma = new PrismaClient();
export async function seed(variation?: "check-in") {
@@ -29,6 +30,7 @@ export async function seed(variation?: "check-in") {
//
await prisma.tournamentTeamMember.deleteMany();
await prisma.tournamentTeam.deleteMany();
await prisma.tournamentBracket.deleteMany({});
await prisma.tournament.deleteMany();
await prisma.organization.deleteMany();
await prisma.trustRelationships.deleteMany();
@@ -46,8 +48,8 @@ export async function seed(variation?: "check-in") {
const tournament = await tournaments(organization.id);
await tournamentTeams(tournament.id, userIds, adminUserCreated.id);
await trustRelationship(nzapUserCreated.id, adminUserCreated.id);
const stageIds = await stages();
await tournamentAddMaps(tournament.id, stageIds);
await stages();
await tournamentAddMaps(tournament.id);
} finally {
await prisma.$disconnect();
}
@@ -245,19 +247,59 @@ export async function seed(variation?: "check-in") {
});
}
async function tournamentAddMaps(id: string, stageIds: number[]) {
const mapIds = [
6, 13, 16, 17, 20, 23, 26, 39, 41, 43, 49, 51, 61, 63, 75, 78, 79, 83, 84,
94, 95, 98, 99, 101,
];
async function tournamentAddMaps(id: string) {
const stages = await prisma.stage.findMany({});
const mapIdObjects = mapIds.map((id) => ({ id: stageIds[id] }));
const mapsIncluded: string[] = [];
const modesIncluded = {
SZ: 0,
TC: 0,
RM: 0,
CB: 0,
};
const connect: { id: number }[] = [];
for (const stage of shuffle(stages)) {
if (
modesIncluded.SZ === 8 &&
modesIncluded.TC === 6 &&
modesIncluded.RM === 6 &&
modesIncluded.CB === 6
) {
break;
}
if (stage.mode === "TW") continue;
if (modesIncluded.SZ === 8 && stage.mode === "SZ") {
continue;
}
if (modesIncluded.TC === 6 && stage.mode === "TC") {
continue;
}
if (modesIncluded.RM === 6 && stage.mode === "RM") {
continue;
}
if (modesIncluded.CB === 6 && stage.mode === "CB") {
continue;
}
if (
mapsIncluded.reduce(
(acc, cur) => acc + (cur === stage.name ? 1 : 0),
0
) >= 2
) {
continue;
}
connect.push({ id: stage.id });
modesIncluded[stage.mode]++;
mapsIncluded.push(stage.name);
}
return prisma.tournament.update({
where: { id },
data: {
mapPool: {
connect: mapIdObjects,
connect,
},
},
});