-
Notifications
You must be signed in to change notification settings - Fork 0
CC-2: Improve Pairing Workflow #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,36 @@ | ||
| import { tournamentPairingConfig as config } from '@ianpaschal/combat-command-game-systems/common'; | ||
| import { TournamentPairingPolicy } from '@ianpaschal/combat-command-game-systems/common'; | ||
| import { createEnumSchema } from '@ianpaschal/combat-command-game-systems/utils'; | ||
| import { zodToConvex } from 'convex-helpers/server/zod'; | ||
| import { z } from 'zod'; | ||
|
|
||
| export const tournamentPairingConfig = zodToConvex(config.schema); | ||
| import { Id } from '../../_generated/dataModel'; | ||
|
|
||
| export const schema = z.object({ | ||
| orderBy: z.union([z.literal('ranking'), z.literal('random')]), | ||
| policies: z.object({ | ||
| sameAlignment: createEnumSchema(TournamentPairingPolicy), | ||
| repeat: createEnumSchema(TournamentPairingPolicy), | ||
| }), | ||
| tableCount: z.optional(z.number().min(1)), // TODO: REMOVE POST MIGRATION | ||
| }); | ||
|
|
||
| export const generationSchema = schema.extend({ | ||
| include: z.array(z.string()).transform((val): Id<'tournamentCompetitors'>[] => val as Id<'tournamentCompetitors'>[]), | ||
| }); | ||
|
|
||
| export type TournamentPairingConfig = z.infer<typeof schema>; | ||
|
|
||
| export type TournamentPairingPolicies = Partial<TournamentPairingConfig['policies']>; | ||
|
|
||
| export const defaultValues = { | ||
| orderBy: 'ranking', | ||
| policies: { | ||
| sameAlignment: TournamentPairingPolicy.Allow, | ||
| repeat: TournamentPairingPolicy.Block, | ||
| }, | ||
| tableCount: 1, | ||
| } satisfies TournamentPairingConfig; | ||
|
|
||
| export const tournamentPairingConfig = zodToConvex(schema); | ||
|
|
||
| export const tournamentPairingInput = zodToConvex(generationSchema); |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,7 @@ export const assignTables = ( | |||||||
| ); | ||||||||
| playedTablesMap.set(null, []); | ||||||||
|
|
||||||||
| const tableCount = (data.tournament?.competitorCount ?? 2) / 2; // TODO: Use actual table count | ||||||||
| const tableCount = data.tournament.pairingConfig.tableCount!; // TODO remove assertion post MIGRATION | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid hard dependency on migration completion here. At Line 23, removing the fallback and forcing Suggested fix- const tableCount = data.tournament.pairingConfig.tableCount!; // TODO remove assertion post MIGRATION
+ const tableCount = data.tournament.pairingConfig.tableCount
+ ?? Math.ceil((data.tournament.competitorCount ?? 2) / 2);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| const draftPairings = pairings.map((p) => ({ | ||||||||
| ...p, | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { DeepTournamentRegistration } from './deepenTournamentRegistration'; | ||
|
|
||
| export const sortTournamentRegistrationsByName = ( | ||
| a: DeepTournamentRegistration, | ||
| b: DeepTournamentRegistration, | ||
| ): number => a.displayName.localeCompare(b.displayName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Operator-precedence bug: division is only applied to the fallback, not to the override.
Due to JavaScript's operator precedence,
??binds less tightly than/, sooverrides?.maxCompetitors ?? 48 / 2is parsed asoverrides?.maxCompetitors ?? (48 / 2)— i.e.overrides?.maxCompetitors ?? 24. WhenmaxCompetitorsis supplied as an override (e.g.32),Math.ceil(32)=32, buttableCountshould beMath.ceil(32 / 2)=16. The trailing?? 1is also dead code sinceMath.ceilalways returns a number.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents