Skip to content

Commit c565186

Browse files
committed
Merge branch 'main-qualifying-tieformat'
2 parents b6e9a9e + 6f5c137 commit c565186

15 files changed

+430
-52
lines changed

documentation/docs/types/assets/drawDefinition.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,18 @@ export const drawDefinition = {
55
drawOrder: '{\\"type\\":\\"number\\",\\"required\\":\\"false\\"}',
66
drawRepresentativeIds:
77
'{\\"type\\":\\"string\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\",\\"note\\":\\"participantId array\\"}',
8-
drawStatus:
9-
'{\\"type\\":\\"enum\\",\\"enum\\": \\"\\",\\"required\\":\\"true\\"}',
10-
drawType:
11-
'{\\"type\\":\\"enum\\",\\"enum\\": \\"\\",\\"required\\":\\"false\\"}',
12-
entries:
13-
'{\\"type\\":\\"object\\",\\"object\\":\\"entry\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
14-
endDate:
15-
'{\\"type\\":\\"string\\",\\"required\\":\\"true\\",\\"note\\":\\"\'YYYY-MM-DD\'\\"}',
16-
links:
17-
'{\\"type\\":\\"object\\",\\"object\\":\\"link\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
18-
matchUps:
19-
'{\\"type\\":\\"object\\",\\"object\\":\\"matchUp\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
8+
drawStatus: '{\\"type\\":\\"enum\\",\\"enum\\": \\"\\",\\"required\\":\\"true\\"}',
9+
drawType: '{\\"type\\":\\"enum\\",\\"enum\\": \\"\\",\\"required\\":\\"false\\"}',
10+
entries: '{\\"type\\":\\"object\\",\\"object\\":\\"entry\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
11+
endDate: '{\\"type\\":\\"string\\",\\"required\\":\\"true\\",\\"note\\":\\"\'YYYY-MM-DD\'\\"}',
12+
links: '{\\"type\\":\\"object\\",\\"object\\":\\"link\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
13+
matchUps: '{\\"type\\":\\"object\\",\\"object\\":\\"matchUp\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
2014
matchUpFormat:
2115
'{\\"type\\":\\"string\\",\\"required\\":\\"false\\",\\"note\\":\\"TODS matchup format, e.g. \'SET3-S:6/TB7\'\\"}',
22-
startDate:
23-
'{\\"type\\":\\"string\\",\\"required\\":\\"true\\",\\"note\\":\\"\'YYYY-MM-DD\'\\"}',
16+
startDate: '{\\"type\\":\\"string\\",\\"required\\":\\"true\\",\\"note\\":\\"\'YYYY-MM-DD\'\\"}',
2417
structures:
2518
'{\\"type\\":\\"object\\",\\"object\\":\\"structure\\",\\"array\\":\\"true\\",\\"required\\":\\"false\\"}',
26-
tieFormat:
27-
'{\\"type\\":\\"object\\",\\"object\\":\\"tieFormat\\",\\"required\\":\\"false\\"}',
19+
tieFormat: '{\\"type\\":\\"object\\",\\"object\\":\\"tieFormat\\",\\"required\\":\\"false\\"}',
2820
};
2921

3022
export default drawDefinition;

src/assemblies/generators/drawDefinitions/drawTypes/eliminationTree.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { generateRange } from '@Tools/arrays';
21
import { addFinishingRounds } from '../addFinishingRounds';
2+
import { generateRange } from '@Tools/arrays';
33
import { isPowerOf2 } from '@Tools/math';
44
import { buildRound } from '../buildRound';
55

6+
// Types
67
import { MatchUp } from '@Types/tournamentTypes';
78

89
type TreeMatchUpsArgs = {

src/assemblies/generators/drawDefinitions/drawTypes/generateQualifyingStructure.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { generateQualifyingLink } from '@Generators/drawDefinitions/links/generateQualifyingLink';
22
import structureTemplate from '@Assemblies/generators/templates/structureTemplate';
3+
import { getAllStructureMatchUps } from '@Query/matchUps/getAllStructureMatchUps';
34
import { getStructureGroups } from '@Query/structure/getStructureGroups';
45
import { decorateResult } from '@Functions/global/decorateResult';
56
import { coerceEven, isConvertableInteger } from '@Tools/math';
67
import { addExtension } from '@Mutate/extensions/addExtension';
78
import { generateRoundRobin } from './roundRobin/roundRobin';
9+
import { generateTieMatchUps } from '../tieMatchUps';
810
import { constantToString } from '@Tools/strings';
911
import { treeMatchUps } from './eliminationTree';
1012

1113
// constants, fixtures and types
12-
import { DrawDefinition, DrawLink, DrawTypeUnion, Event, Structure } from '@Types/tournamentTypes';
14+
import { DrawDefinition, DrawLink, DrawTypeUnion, Event, Structure, TieFormat } from '@Types/tournamentTypes';
1315
import { POSITION, QUALIFYING, ROUND_ROBIN, WINNER } from '@Constants/drawDefinitionConstants';
1416
import POLICY_ROUND_NAMING_DEFAULT from '@Fixtures/policies/POLICY_ROUND_NAMING_DEFAULT';
1517
import { POLICY_TYPE_ROUND_NAMING } from '@Constants/policyConstants';
@@ -25,16 +27,19 @@ import {
2527
} from '@Constants/errorConditionConstants';
2628

2729
type GenerateQualifyingStructureArgs = {
30+
hasExistingDrawDefinition?: boolean;
2831
appliedPolicies?: PolicyDefinitions;
2932
qualifyingRoundNumber: number;
3033
drawDefinition: DrawDefinition;
3134
qualifyingPositions?: number;
3235
participantsCount?: number;
3336
targetStructureId: string;
37+
qualifyingOnly?: boolean;
3438
drawType?: DrawTypeUnion;
3539
structureOptions?: any;
3640
matchUpFormat?: string;
3741
structureName?: string;
42+
tieFormat?: TieFormat;
3843
structureId?: string;
3944
roundTarget: number;
4045
drawSize?: number;
@@ -73,16 +78,19 @@ export function generateQualifyingStructure(params: GenerateQualifyingStructureA
7378
let drawSize = params.drawSize ?? coerceEven(params.participantsCount);
7479

7580
const {
81+
hasExistingDrawDefinition,
7682
qualifyingRoundNumber,
7783
qualifyingPositions,
7884
targetStructureId,
7985
structureOptions,
8086
appliedPolicies,
87+
qualifyingOnly,
8188
drawDefinition,
8289
matchUpFormat,
8390
structureName,
8491
structureId,
8592
roundTarget,
93+
tieFormat,
8694
drawType,
8795
idPrefix,
8896
isMock,
@@ -139,12 +147,15 @@ export function generateQualifyingStructure(params: GenerateQualifyingStructureA
139147
const { maxRoundNumber /*, groupSize*/, structures, groupCount } = generateRoundRobin({
140148
structureName: structureName ?? qualifyingStructureName,
141149
structureId: structureId ?? uuids?.pop(),
150+
hasExistingDrawDefinition,
142151
stage: QUALIFYING,
143152
structureOptions,
144153
appliedPolicies,
154+
qualifyingOnly,
145155
stageSequence,
146156
matchUpType,
147157
roundTarget,
158+
tieFormat,
148159
idPrefix,
149160
drawSize,
150161
isMock,
@@ -202,6 +213,14 @@ export function generateQualifyingStructure(params: GenerateQualifyingStructureA
202213
linkType,
203214
})?.link;
204215

216+
if (tieFormat) {
217+
matchUps = getAllStructureMatchUps({ structure })?.matchUps || [];
218+
matchUps?.forEach((matchUp) => {
219+
const { tieMatchUps } = generateTieMatchUps({ tieFormat, matchUp, isMock });
220+
Object.assign(matchUp, { tieMatchUps, matchUpType });
221+
});
222+
}
223+
205224
return {
206225
qualifyingDrawPositionsCount: drawSize,
207226
qualifiersCount,

src/assemblies/generators/drawDefinitions/drawTypes/generateQualifyingStructures.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { generateQualifyingLink } from '@Generators/drawDefinitions/links/generateQualifyingLink';
2+
import { getAllStructureMatchUps } from '@Query/matchUps/getAllStructureMatchUps';
23
import structureTemplate from '@Generators/templates/structureTemplate';
34
import { decorateResult } from '@Functions/global/decorateResult';
45
import { coerceEven, isConvertableInteger } from '@Tools/math';
@@ -14,13 +15,15 @@ import { DrawLink, Structure, TieFormat } from '@Types/tournamentTypes';
1415
import { PolicyDefinitions, ResultType } from '@Types/factoryTypes';
1516
import { ROUND_TARGET } from '@Constants/extensionConstants';
1617
import { SUCCESS } from '@Constants/resultConstants';
18+
import { generateTieMatchUps } from '../tieMatchUps';
1719

1820
type GenerateQualifyingStructuresArgs = {
1921
hasExistingDrawDefinition?: boolean;
2022
appliedPolicies?: PolicyDefinitions;
2123
qualifyingProfiles: any[];
2224
qualifyingOnly?: boolean;
2325
tieFormat?: TieFormat;
26+
drawType?: string;
2427
idPrefix?: string;
2528
isMock?: boolean;
2629
uuids?: string[];
@@ -97,12 +100,15 @@ export function generateQualifyingStructures({
97100
structureName: structureProfile.structureName || qualifyingStructureName,
98101
structureId: structureId || uuids?.pop(),
99102
// qualifyingPositions,
103+
hasExistingDrawDefinition,
100104
stage: QUALIFYING,
101105
structureOptions,
102106
appliedPolicies,
107+
qualifyingOnly,
103108
stageSequence,
104109
matchUpType,
105110
roundTarget,
111+
tieFormat,
106112
drawSize,
107113
idPrefix,
108114
isMock,
@@ -171,6 +177,14 @@ export function generateQualifyingStructures({
171177
finalQualifyingStructureId = structure.structureId;
172178
finalQualifyingRoundNumber = roundLimit;
173179

180+
if (tieFormat) {
181+
matchUps = getAllStructureMatchUps({ structure })?.matchUps || [];
182+
matchUps?.forEach((matchUp) => {
183+
const { tieMatchUps } = generateTieMatchUps({ tieFormat, matchUp, isMock });
184+
Object.assign(matchUp, { tieMatchUps, matchUpType });
185+
});
186+
}
187+
174188
structures.push(structure);
175189
stageSequence += 1;
176190
}

src/assemblies/generators/drawDefinitions/drawTypes/roundRobin/roundRobin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ import { UUID } from '@Tools/UUID';
99
import { PlayoffAttributes, PolicyDefinitions, SeedingProfile, ResultType } from '@Types/factoryTypes';
1010
import { MAIN, ITEM, WIN_RATIO, CONTAINER } from '@Constants/drawDefinitionConstants';
1111
import { BYE, TO_BE_PLAYED } from '@Constants/matchUpStatusConstants';
12-
import { MatchUp, EventTypeUnion } from '@Types/tournamentTypes';
12+
import { MatchUp, EventTypeUnion, TieFormat } from '@Types/tournamentTypes';
1313
import { ROUND_TARGET } from '@Constants/extensionConstants';
1414
import { SUCCESS } from '@Constants/resultConstants';
1515
import { HydratedMatchUp } from '@Types/hydrated';
1616

1717
type GenerateRoundRobinArgs = {
1818
playoffAttributes?: PlayoffAttributes;
19+
hasExistingDrawDefinition?: boolean;
1920
appliedPolicies?: PolicyDefinitions;
2021
seedingProfile?: SeedingProfile;
22+
matchUpType?: EventTypeUnion;
23+
qualifyingOnly?: boolean;
2124
groupNameBase?: string;
2225
structureName?: string;
2326
stageSequence?: number;
2427
structureOptions?: any;
25-
matchUpType?: EventTypeUnion;
28+
tieFormat?: TieFormat;
2629
groupNames?: string[];
2730
roundTarget?: number;
2831
structureId?: string;
@@ -35,17 +38,20 @@ type GenerateRoundRobinArgs = {
3538

3639
export function generateRoundRobin(params: GenerateRoundRobinArgs) {
3740
const {
41+
hasExistingDrawDefinition,
3842
groupNameBase = 'Group',
3943
playoffAttributes,
4044
stageSequence = 1,
4145
structureOptions,
4246
appliedPolicies,
47+
qualifyingOnly,
4348
seedingProfile,
4449
stage = MAIN,
4550
matchUpType,
4651
roundTarget,
4752
structureId,
4853
groupNames,
54+
tieFormat,
4955
drawSize,
5056
idPrefix,
5157
isMock,
@@ -79,22 +85,27 @@ export function generateRoundRobin(params: GenerateRoundRobinArgs) {
7985

8086
return structureTemplate({
8187
structureId: uuids?.pop(),
88+
hasExistingDrawDefinition,
8289
structureType: ITEM,
8390
finishingPosition,
91+
qualifyingOnly,
8492
structureOrder,
8593
structureName,
94+
tieFormat,
8695
matchUps,
8796
});
8897
});
8998

9099
const structure = structureTemplate({
91100
structureId: structureId ?? uuids?.pop(),
101+
hasExistingDrawDefinition,
92102
structureType: CONTAINER,
93103
finishingPosition,
94104
seedingProfile,
95105
structureName,
96106
stageSequence,
97107
structures,
108+
tieFormat,
98109
stage,
99110
});
100111

src/assemblies/generators/drawDefinitions/generateAndPopulateRRplayoffStructures.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ export function generateAndPopulateRRplayoffStructures(params) {
7878

7979
if (tieFormat) {
8080
addedMatchUps.forEach((matchUp) => {
81-
const { tieMatchUps } = generateTieMatchUps({
82-
isMock: params.isMock,
83-
tieFormat,
84-
matchUp,
85-
});
81+
const { tieMatchUps } = generateTieMatchUps({ isMock: params.isMock, tieFormat, matchUp });
8682
Object.assign(matchUp, { tieMatchUps, matchUpType: TEAM_MATCHUP });
8783
});
8884
}

src/assemblies/generators/drawDefinitions/generateDrawDefinition/checkFormatScopeEquivalence.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { setMatchUpMatchUpFormat } from '@Mutate/matchUps/matchUpFormat/setMatch
22
import { checkTieFormat } from '@Mutate/tieFormat/checkTieFormat';
33

44
export function checkFormatScopeEquivalence({
5+
existingQualifyingStructures,
56
tournamentRecord,
67
drawDefinition,
78
matchUpFormat,
@@ -23,7 +24,11 @@ export function checkFormatScopeEquivalence({
2324
const result = checkTieFormat({ tieFormat });
2425
if (result.error) return result;
2526

26-
drawDefinition.tieFormat = result.tieFormat ?? tieFormat;
27+
const existingQualifyingTieFormats = existingQualifyingStructures?.every((structure) => structure.tieFormat);
28+
if (!existingQualifyingStructures?.length || existingQualifyingTieFormats) {
29+
// if there are no existing qualifying structures or if all existing qualifying structures have a tieFormat
30+
drawDefinition.tieFormat = result.tieFormat ?? tieFormat;
31+
}
2732
} else if (matchUpFormat) {
2833
const result = setMatchUpMatchUpFormat({
2934
tournamentRecord,

src/assemblies/generators/drawDefinitions/generateDrawDefinition/qualifyingGeneration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { POSITION, QUALIFYING } from '@Constants/drawDefinitionConstants';
1010
import { MISSING_VALUE } from '@Constants/errorConditionConstants';
1111
import { ResultType } from '@Types/factoryTypes';
1212

13+
// only does stage perparation unless no qualifyingProfiles are provided and a qualifyingPlaceholder is necessary
1314
export function qualifyingGeneration(params): ResultType & { qualifyingConflicts?: any[] } {
1415
const {
1516
qualifyingPlaceholder,

src/assemblies/generators/drawDefinitions/generateDrawDefinition/setUpDrawGeneration.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function setUpDrawGeneration(params): ResultType & {
1616
} {
1717
const {
1818
tournamentRecord,
19-
matchUpFormat,
20-
appliedPolicies,
2119
policyDefinitions,
20+
appliedPolicies,
21+
matchUpFormat,
2222
matchUpType,
2323
tieFormat,
2424
drawType,
@@ -30,6 +30,19 @@ export function setUpDrawGeneration(params): ResultType & {
3030
? (event?.drawDefinitions?.find((d) => d.drawId === params.drawId) as DrawDefinition)
3131
: undefined;
3232

33+
// find existing MAIN structureId if existingDrawDefinition
34+
const structureId = existingDrawDefinition?.structures?.find(
35+
(structure) => structure.stage === MAIN && structure.stageSequence === 1,
36+
)?.structureId;
37+
38+
const existingQualifyingStructures = existingDrawDefinition
39+
? existingDrawDefinition.structures?.filter((structure) => structure.stage === QUALIFYING)
40+
: [];
41+
const existingQualifyingPlaceholderStructureId =
42+
existingQualifyingStructures?.length === 1 &&
43+
!existingQualifyingStructures[0].matchUps?.length &&
44+
existingQualifyingStructures[0].structureId;
45+
3346
if (existingDrawDefinition && drawType !== existingDrawDefinition.drawType)
3447
existingDrawDefinition.drawType = drawType as DrawTypeUnion;
3548

@@ -42,6 +55,7 @@ export function setUpDrawGeneration(params): ResultType & {
4255
});
4356

4457
const equivalenceResult = checkFormatScopeEquivalence({
58+
existingQualifyingStructures,
4559
tournamentRecord,
4660
drawDefinition,
4761
matchUpFormat,
@@ -54,18 +68,5 @@ export function setUpDrawGeneration(params): ResultType & {
5468
const attachmentResult = policyAttachment({ appliedPolicies, policyDefinitions, drawDefinition, stack });
5569
if (attachmentResult.error) return attachmentResult;
5670

57-
// find existing MAIN structureId if existingDrawDefinition
58-
const structureId = existingDrawDefinition?.structures?.find(
59-
(structure) => structure.stage === MAIN && structure.stageSequence === 1,
60-
)?.structureId;
61-
62-
const existingQualifyingStructures = existingDrawDefinition
63-
? existingDrawDefinition.structures?.filter((structure) => structure.stage === QUALIFYING)
64-
: [];
65-
const existingQualifyingPlaceholderStructureId =
66-
existingQualifyingStructures?.length === 1 &&
67-
!existingQualifyingStructures[0].matchUps?.length &&
68-
existingQualifyingStructures[0].structureId;
69-
7071
return { drawDefinition, structureId, existingDrawDefinition, existingQualifyingPlaceholderStructureId };
7172
}

src/assemblies/generators/drawDefinitions/generateDrawTypeAndModifyDrawDefinition.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ export function generateDrawTypeAndModifyDrawDefinition(params: GenerateDrawType
151151
// if there were exiting matchUps, exclude them from this step
152152
matchUps?.forEach((matchUp) => {
153153
if (!existingMatchUpIds.includes(matchUp.matchUpId)) {
154-
const { tieMatchUps } = generateTieMatchUps({
155-
tieFormat,
156-
matchUp,
157-
isMock,
158-
});
154+
const { tieMatchUps } = generateTieMatchUps({ tieFormat, matchUp, isMock });
159155
Object.assign(matchUp, { tieMatchUps, matchUpType });
160156
}
161157
});

0 commit comments

Comments
 (0)