From c493f0082a6783dc9da3e943d9021a27ee786b06 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Mon, 13 Dec 2021 11:36:17 +0200 Subject: [PATCH] Show round names and default best of on /start --- app/core/tournament/utils.ts | 93 +++++++ .../to/$organization.$tournament/admin.tsx | 6 +- .../$organization.$tournament/admin/index.tsx | 262 ++++++++++++++++++ .../$organization.$tournament/admin/start.tsx | 23 ++ prisma/seed/script.ts | 4 +- 5 files changed, 385 insertions(+), 3 deletions(-) create mode 100644 app/routes/to/$organization.$tournament/admin/index.tsx create mode 100644 app/routes/to/$organization.$tournament/admin/start.tsx diff --git a/app/core/tournament/utils.ts b/app/core/tournament/utils.ts index 53dc21493..f67b4e345 100644 --- a/app/core/tournament/utils.ts +++ b/app/core/tournament/utils.ts @@ -1,3 +1,4 @@ +import invariant from "tiny-invariant"; import { Bracket } from "./bracket"; export function checkInHasStarted(checkInStartTime: string) { @@ -28,6 +29,98 @@ export function sortTeamsBySeed(seeds: string[]) { }; } +export function roundNamesWithDefaultBestOf(bracket: Bracket): { + winners: { + name: string; + bestOf: number; + }[]; + losers: { + name: string; + bestOf: number; + }[]; +} { + const { winners: winnersRoundNames, losers: losersRoundNames } = + roundNames(bracket); + const { winners: winnersDefaultBestOf, losers: losersDefaultBestOf } = + roundDefaultBestOf(bracket); + + invariant( + winnersRoundNames.length === winnersDefaultBestOf.length, + "Unexpected different length with winnersRoundNames and winnersDefaultBestOf" + ); + invariant( + losersRoundNames.length === losersDefaultBestOf.length, + "Unexpected different length with losersRoundNames and losersDefaultBestOf" + ); + + return { + winners: winnersRoundNames.map((roundName, i) => { + const bestOf = winnersDefaultBestOf[i]; + return { + name: roundName, + bestOf, + }; + }), + losers: losersRoundNames.map((roundName, i) => { + const bestOf = losersDefaultBestOf[i]; + return { + name: roundName, + bestOf, + }; + }), + }; +} + +const WINNERS_DEFAULT = 5; +const WINNERS_FIRST_TWO_DEFAULT = 3; +const GRAND_FINALS_DEFAULT = 7; +const LOSERS_DEFAULT = 3; +const LOSERS_FINALS_DEFAULT = 5; + +function roundDefaultBestOf(bracket: Bracket): { + winners: number[]; + losers: number[]; +} { + const { winners: winnersRoundCount, losers: losersRoundCount } = + countRounds(bracket); + + return { + winners: new Array(winnersRoundCount).fill(null).map((_, i) => { + if (i === 0) return WINNERS_FIRST_TWO_DEFAULT; + if (i === 1) return WINNERS_FIRST_TWO_DEFAULT; + if (i === winnersRoundCount - 1) return GRAND_FINALS_DEFAULT; + return WINNERS_DEFAULT; + }), + losers: new Array(losersRoundCount) + .fill(null) + .map((_, i) => + i === losersRoundCount - 1 ? LOSERS_FINALS_DEFAULT : LOSERS_DEFAULT + ), + }; +} + +function roundNames(bracket: Bracket): { + winners: string[]; + losers: string[]; +} { + const { winners: winnersRoundCount, losers: losersRoundCount } = + countRounds(bracket); + + return { + winners: new Array(winnersRoundCount).fill(null).map((_, i) => { + if (i === winnersRoundCount - 3) return "Winners' Semifinals"; + if (i === winnersRoundCount - 2) return "Winners' Finals"; + if (i === winnersRoundCount - 1) return "Grand Finals"; + return `Winners' Round ${i + 1}`; + }), + losers: new Array(losersRoundCount) + .fill(null) + .map((_, i) => + i === losersRoundCount - 1 ? "Losers' Finals" : `Losers' Round ${i + 1}` + ), + }; +} + export function countRounds(bracket: Bracket): { winners: number; losers: number; diff --git a/app/routes/to/$organization.$tournament/admin.tsx b/app/routes/to/$organization.$tournament/admin.tsx index c80b43728..5e46d24b2 100644 --- a/app/routes/to/$organization.$tournament/admin.tsx +++ b/app/routes/to/$organization.$tournament/admin.tsx @@ -1,6 +1,6 @@ import type { LinksFunction } from "remix"; +import { Outlet } from "remix"; import { Button } from "~/components/Button"; -import { AdminTeamControls } from "~/components/tournament/AdminTeamControls"; import styles from "~/styles/tournament-admin.css"; export const links: LinksFunction = () => { @@ -11,10 +11,12 @@ export default function AdminPage() { return ( <>
+ {JSON.stringify(
+ roundNamesWithDefaultBestOf(eliminationBracket(teamCount, "DE")),
+ null,
+ 2
+ )}
+
+ );
+}
diff --git a/prisma/seed/script.ts b/prisma/seed/script.ts
index 7b5e039f0..7092c446a 100644
--- a/prisma/seed/script.ts
+++ b/prisma/seed/script.ts
@@ -165,14 +165,16 @@ export async function seed(variation?: "check-in") {
}
for (const [mockTeamI, mockTeam] of mockTeams.entries()) {
+ const memberCount = (mockTeamI % 5) + 2;
const team = await prisma.tournamentTeam.create({
data: {
name: mockTeam,
tournamentId,
+ checkedInTime: memberCount >= 4 ? new Date() : undefined,
},
});
- for (let memberI = 0; memberI < (mockTeamI % 5) + 2; memberI++) {
+ for (let memberI = 0; memberI < memberCount; memberI++) {
const memberId = userIdsCopy.shift()!;
await prisma.tournamentTeamMember.create({
data: {