tods-competition-factory 2.2.19 → 2.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +8 -8
- package/dist/tods-competition-factory.d.ts +54 -29
- package/dist/tods-competition-factory.development.cjs.js +256 -124
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +17 -17
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function factoryVersion() {
|
|
6
|
-
return '2.2.
|
|
6
|
+
return '2.2.20';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const SINGLES_MATCHUP = 'SINGLES';
|
|
@@ -585,6 +585,10 @@ const MISSING_STRUCTURE = {
|
|
|
585
585
|
message: 'Missing structure',
|
|
586
586
|
code: 'ERR_MISSING_STRUCTURE',
|
|
587
587
|
};
|
|
588
|
+
const MISSING_MAIN_STRUCTURE = {
|
|
589
|
+
message: 'Missing MAIN structure',
|
|
590
|
+
code: 'ERR_MISSING_MAIN_STRUCTURE',
|
|
591
|
+
};
|
|
588
592
|
const UNLINKED_STRUCTURES = {
|
|
589
593
|
message: 'drawDefinition contains unlinked structures',
|
|
590
594
|
code: 'ERR_MISSING_STRUCTURE_LINKS',
|
|
@@ -873,6 +877,10 @@ const MISSING_PARTICIPANT_ID = {
|
|
|
873
877
|
message: 'Missing participantId',
|
|
874
878
|
code: 'ERR_MISSING_PARTICIPANT_ID',
|
|
875
879
|
};
|
|
880
|
+
const MISSING_QUALIFIED_PARTICIPANTS = {
|
|
881
|
+
message: 'Missing qualified participants',
|
|
882
|
+
code: 'ERR_MISSING_QUALIFIED_PARTICIPANTS',
|
|
883
|
+
};
|
|
876
884
|
const PARTICIPANT_NOT_FOUND = {
|
|
877
885
|
message: 'Participant Not Found',
|
|
878
886
|
code: 'ERR_NOT_FOUND_PARTICIPANT',
|
|
@@ -1241,6 +1249,7 @@ const errorConditionConstants = {
|
|
|
1241
1249
|
MISSING_DRAW_SIZE,
|
|
1242
1250
|
MISSING_ENTRIES,
|
|
1243
1251
|
MISSING_EVENT,
|
|
1252
|
+
MISSING_QUALIFIED_PARTICIPANTS,
|
|
1244
1253
|
MISSING_MATCHUP_FORMAT,
|
|
1245
1254
|
MISSING_MATCHUP_ID,
|
|
1246
1255
|
MISSING_MATCHUP_IDS,
|
|
@@ -1271,6 +1280,7 @@ const errorConditionConstants = {
|
|
|
1271
1280
|
MISSING_STAGE,
|
|
1272
1281
|
MISSING_STRUCTURE_ID,
|
|
1273
1282
|
MISSING_STRUCTURE,
|
|
1283
|
+
MISSING_MAIN_STRUCTURE,
|
|
1274
1284
|
MISSING_STRUCTURES,
|
|
1275
1285
|
MISSING_TARGET_LINK,
|
|
1276
1286
|
MISSING_TIE_FORMAT,
|
|
@@ -17436,22 +17446,6 @@ function swapAdHocRounds(params) {
|
|
|
17436
17446
|
return { ...SUCCESS };
|
|
17437
17447
|
}
|
|
17438
17448
|
|
|
17439
|
-
function qualifierDrawPositionAssignment$1({ qualifyingParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }) {
|
|
17440
|
-
return positionParticipantAction({
|
|
17441
|
-
positionActionName: 'qualifierDrawPositionAssignment',
|
|
17442
|
-
participantId: qualifyingParticipantId,
|
|
17443
|
-
isQualifierPosition: true,
|
|
17444
|
-
tournamentRecord,
|
|
17445
|
-
drawDefinition,
|
|
17446
|
-
drawPosition,
|
|
17447
|
-
structureId,
|
|
17448
|
-
});
|
|
17449
|
-
}
|
|
17450
|
-
|
|
17451
|
-
function qualifierDrawPositionAssignment(params) {
|
|
17452
|
-
return qualifierDrawPositionAssignment$1(params);
|
|
17453
|
-
}
|
|
17454
|
-
|
|
17455
17449
|
function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, event, }) {
|
|
17456
17450
|
return positionParticipantAction({
|
|
17457
17451
|
positionActionName: 'alternateDrawPositionAssignment',
|
|
@@ -17465,60 +17459,6 @@ function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRec
|
|
|
17465
17459
|
});
|
|
17466
17460
|
}
|
|
17467
17461
|
|
|
17468
|
-
function modifySeedAssignment({ validation = true, tournamentRecord, drawDefinition, participantId, structureId, seedValue, event, }) {
|
|
17469
|
-
if (!drawDefinition)
|
|
17470
|
-
return { error: MISSING_DRAW_DEFINITION };
|
|
17471
|
-
if (!structureId)
|
|
17472
|
-
return { error: MISSING_STRUCTURE_ID };
|
|
17473
|
-
const participant = (tournamentRecord?.participants ?? []).find((participant) => participant.participantId === participantId);
|
|
17474
|
-
if (tournamentRecord && !participant)
|
|
17475
|
-
return { error: INVALID_PARTICIPANT_ID };
|
|
17476
|
-
const { structure } = findStructure({ drawDefinition, structureId });
|
|
17477
|
-
if (!structure)
|
|
17478
|
-
return { error: STRUCTURE_NOT_FOUND };
|
|
17479
|
-
const validValue = !validation ||
|
|
17480
|
-
isNumeric(seedValue) ||
|
|
17481
|
-
seedValue === undefined ||
|
|
17482
|
-
seedValue === '' ||
|
|
17483
|
-
(typeof seedValue === 'string' && seedValue.split('-').every((v) => isNumeric(v) && ensureInt(v) > 0));
|
|
17484
|
-
if (!validValue)
|
|
17485
|
-
return { error: INVALID_VALUES };
|
|
17486
|
-
const { seedAssignments } = getStructureSeedAssignments({
|
|
17487
|
-
drawDefinition,
|
|
17488
|
-
structure,
|
|
17489
|
-
});
|
|
17490
|
-
const seedNumbers = seedAssignments?.map((assignment) => assignment.seedNumber);
|
|
17491
|
-
const existingAssginment = seedAssignments?.find((assignment) => assignment.participantId === participantId);
|
|
17492
|
-
if (existingAssginment) {
|
|
17493
|
-
const newValue = typeof seedValue === 'string'
|
|
17494
|
-
? (seedValue.includes('-') &&
|
|
17495
|
-
seedValue
|
|
17496
|
-
.split('-')
|
|
17497
|
-
.map((v) => parseInt(v))
|
|
17498
|
-
.join('-')) ||
|
|
17499
|
-
(parseInt(seedValue) > 0 && parseInt(seedValue)) ||
|
|
17500
|
-
''
|
|
17501
|
-
: (seedValue && seedValue > 0 && seedValue) || '';
|
|
17502
|
-
existingAssginment.seedValue = newValue;
|
|
17503
|
-
}
|
|
17504
|
-
else {
|
|
17505
|
-
const seedNumber = Math.max(0, ...(seedNumbers || [])) + 1;
|
|
17506
|
-
const seedAssignment = { seedNumber, participantId };
|
|
17507
|
-
if (seedValue)
|
|
17508
|
-
seedAssignment.seedValue = seedValue;
|
|
17509
|
-
if (!structure.seedAssignments)
|
|
17510
|
-
structure.seedAssignments = [];
|
|
17511
|
-
structure.seedAssignments.push(seedAssignment);
|
|
17512
|
-
}
|
|
17513
|
-
modifySeedAssignmentsNotice({
|
|
17514
|
-
tournamentId: tournamentRecord?.tournamentId,
|
|
17515
|
-
eventId: event?.eventId,
|
|
17516
|
-
drawDefinition,
|
|
17517
|
-
structure,
|
|
17518
|
-
});
|
|
17519
|
-
return { ...SUCCESS };
|
|
17520
|
-
}
|
|
17521
|
-
|
|
17522
17462
|
function getPlayoffStructures({ drawDefinition, structureId }) {
|
|
17523
17463
|
if (!drawDefinition)
|
|
17524
17464
|
return { error: MISSING_DRAW_DEFINITION };
|
|
@@ -18598,21 +18538,7 @@ function getStructurePositionedSeeds({ provisionalPositioning, drawDefinition, s
|
|
|
18598
18538
|
|
|
18599
18539
|
function getBlockSortedRandomDrawPositions({ orderedSortedFirstRoundSeededDrawPositions: strictOrder, validSeedBlocks, byesToPlace, }) {
|
|
18600
18540
|
const drawPositions = [];
|
|
18601
|
-
validSeedBlocks.forEach((seedBlock) =>
|
|
18602
|
-
const leftToPlace = byesToPlace - drawPositions.length;
|
|
18603
|
-
if (leftToPlace > seedBlock.drawPositions.length) {
|
|
18604
|
-
drawPositions.push(...seedBlock.drawPositions);
|
|
18605
|
-
}
|
|
18606
|
-
else {
|
|
18607
|
-
const nestedDrawPositions = nestArray(chunkArray(seedBlock.drawPositions, 2));
|
|
18608
|
-
let drawPosition;
|
|
18609
|
-
let desiredPosition = strictOrder[drawPositions.length];
|
|
18610
|
-
while ((drawPosition = popFromLargerSide(nestedDrawPositions, desiredPosition))) {
|
|
18611
|
-
drawPositions.push(drawPosition);
|
|
18612
|
-
desiredPosition = strictOrder[drawPositions.length];
|
|
18613
|
-
}
|
|
18614
|
-
}
|
|
18615
|
-
});
|
|
18541
|
+
validSeedBlocks.forEach((seedBlock) => processSeedBlock(seedBlock, byesToPlace, drawPositions, strictOrder));
|
|
18616
18542
|
const blockSortedRandom = drawPositions.map((p) => (Array.isArray(p) ? shuffleArray(p) : p)).flat(Infinity);
|
|
18617
18543
|
if (isOdd(byesToPlace)) {
|
|
18618
18544
|
const blockFirstSeedNumbers = validSeedBlocks.map((block) => block.seedNumbers[0]);
|
|
@@ -18621,14 +18547,38 @@ function getBlockSortedRandomDrawPositions({ orderedSortedFirstRoundSeededDrawPo
|
|
|
18621
18547
|
}
|
|
18622
18548
|
return blockSortedRandom;
|
|
18623
18549
|
}
|
|
18550
|
+
function processSeedBlock(seedBlock, byesToPlace, drawPositions, strictOrder) {
|
|
18551
|
+
const leftToPlace = byesToPlace - drawPositions.length;
|
|
18552
|
+
if (leftToPlace > seedBlock.drawPositions.length) {
|
|
18553
|
+
drawPositions.push(...seedBlock.drawPositions);
|
|
18554
|
+
}
|
|
18555
|
+
else {
|
|
18556
|
+
const nestedDrawPositions = nestArray(chunkArray(seedBlock.drawPositions, 2));
|
|
18557
|
+
placeDrawPositions(nestedDrawPositions, drawPositions, strictOrder);
|
|
18558
|
+
}
|
|
18559
|
+
}
|
|
18560
|
+
function placeDrawPositions(nestedDrawPositions, drawPositions, strictOrder) {
|
|
18561
|
+
let drawPosition;
|
|
18562
|
+
let desiredPosition = strictOrder[drawPositions.length];
|
|
18563
|
+
while ((drawPosition = popFromLargerSide(nestedDrawPositions, desiredPosition))) {
|
|
18564
|
+
drawPositions.push(drawPosition);
|
|
18565
|
+
desiredPosition = strictOrder[drawPositions.length];
|
|
18566
|
+
}
|
|
18567
|
+
}
|
|
18624
18568
|
function popFromLargerSide(arr, desiredPosition) {
|
|
18625
18569
|
if (Array.isArray(arr) && arr.length !== 2)
|
|
18626
18570
|
return arr.pop();
|
|
18627
18571
|
if (!Array.isArray(arr[0])) {
|
|
18628
|
-
|
|
18629
|
-
return arr.indexOf(desiredPosition) ? arr.pop() : arr.shift();
|
|
18630
|
-
return Math.round(Math.random()) ? arr.pop() : arr.shift();
|
|
18572
|
+
return handleNonNestedArray(arr, desiredPosition);
|
|
18631
18573
|
}
|
|
18574
|
+
return handleNestedArray(arr, desiredPosition);
|
|
18575
|
+
}
|
|
18576
|
+
function handleNonNestedArray(arr, desiredPosition) {
|
|
18577
|
+
if (arr.includes(desiredPosition))
|
|
18578
|
+
return arr.indexOf(desiredPosition) ? arr.pop() : arr.shift();
|
|
18579
|
+
return Math.round(Math.random()) ? arr.pop() : arr.shift();
|
|
18580
|
+
}
|
|
18581
|
+
function handleNestedArray(arr, desiredPosition) {
|
|
18632
18582
|
const side1 = arr[0].flat(Infinity).length;
|
|
18633
18583
|
const side2 = arr[1].flat(Infinity).length;
|
|
18634
18584
|
if (side1 === side2) {
|
|
@@ -19226,6 +19176,197 @@ function automatedPlayoffPositioning(params) {
|
|
|
19226
19176
|
return { ...SUCCESS, structurePositionAssignments, positioningReports };
|
|
19227
19177
|
}
|
|
19228
19178
|
|
|
19179
|
+
function modifySeedAssignment({ validation = true, tournamentRecord, drawDefinition, participantId, structureId, seedValue, event, }) {
|
|
19180
|
+
if (!drawDefinition)
|
|
19181
|
+
return { error: MISSING_DRAW_DEFINITION };
|
|
19182
|
+
if (!structureId)
|
|
19183
|
+
return { error: MISSING_STRUCTURE_ID };
|
|
19184
|
+
const participant = (tournamentRecord?.participants ?? []).find((participant) => participant.participantId === participantId);
|
|
19185
|
+
if (tournamentRecord && !participant)
|
|
19186
|
+
return { error: INVALID_PARTICIPANT_ID };
|
|
19187
|
+
const { structure } = findStructure({ drawDefinition, structureId });
|
|
19188
|
+
if (!structure)
|
|
19189
|
+
return { error: STRUCTURE_NOT_FOUND };
|
|
19190
|
+
const validValue = !validation ||
|
|
19191
|
+
isNumeric(seedValue) ||
|
|
19192
|
+
seedValue === undefined ||
|
|
19193
|
+
seedValue === '' ||
|
|
19194
|
+
(typeof seedValue === 'string' && seedValue.split('-').every((v) => isNumeric(v) && ensureInt(v) > 0));
|
|
19195
|
+
if (!validValue)
|
|
19196
|
+
return { error: INVALID_VALUES };
|
|
19197
|
+
const { seedAssignments } = getStructureSeedAssignments({
|
|
19198
|
+
drawDefinition,
|
|
19199
|
+
structure,
|
|
19200
|
+
});
|
|
19201
|
+
const seedNumbers = seedAssignments?.map((assignment) => assignment.seedNumber);
|
|
19202
|
+
const existingAssginment = seedAssignments?.find((assignment) => assignment.participantId === participantId);
|
|
19203
|
+
if (existingAssginment) {
|
|
19204
|
+
const newValue = typeof seedValue === 'string'
|
|
19205
|
+
? (seedValue.includes('-') &&
|
|
19206
|
+
seedValue
|
|
19207
|
+
.split('-')
|
|
19208
|
+
.map((v) => parseInt(v))
|
|
19209
|
+
.join('-')) ||
|
|
19210
|
+
(parseInt(seedValue) > 0 && parseInt(seedValue)) ||
|
|
19211
|
+
''
|
|
19212
|
+
: (seedValue && seedValue > 0 && seedValue) || '';
|
|
19213
|
+
existingAssginment.seedValue = newValue;
|
|
19214
|
+
}
|
|
19215
|
+
else {
|
|
19216
|
+
const seedNumber = Math.max(0, ...(seedNumbers || [])) + 1;
|
|
19217
|
+
const seedAssignment = { seedNumber, participantId };
|
|
19218
|
+
if (seedValue)
|
|
19219
|
+
seedAssignment.seedValue = seedValue;
|
|
19220
|
+
if (!structure.seedAssignments)
|
|
19221
|
+
structure.seedAssignments = [];
|
|
19222
|
+
structure.seedAssignments.push(seedAssignment);
|
|
19223
|
+
}
|
|
19224
|
+
modifySeedAssignmentsNotice({
|
|
19225
|
+
tournamentId: tournamentRecord?.tournamentId,
|
|
19226
|
+
eventId: event?.eventId,
|
|
19227
|
+
drawDefinition,
|
|
19228
|
+
structure,
|
|
19229
|
+
});
|
|
19230
|
+
return { ...SUCCESS };
|
|
19231
|
+
}
|
|
19232
|
+
|
|
19233
|
+
function qualifierDrawPositionAssignment({ qualifyingParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }) {
|
|
19234
|
+
return positionParticipantAction({
|
|
19235
|
+
positionActionName: 'qualifierDrawPositionAssignment',
|
|
19236
|
+
participantId: qualifyingParticipantId,
|
|
19237
|
+
isQualifierPosition: true,
|
|
19238
|
+
tournamentRecord,
|
|
19239
|
+
drawDefinition,
|
|
19240
|
+
drawPosition,
|
|
19241
|
+
structureId,
|
|
19242
|
+
});
|
|
19243
|
+
}
|
|
19244
|
+
|
|
19245
|
+
function getSourceStructureIdsAndRelevantLinks({ targetRoundNumber, finishingPosition, drawDefinition, structureId, linkType, }) {
|
|
19246
|
+
const { links } = getStructureLinks({
|
|
19247
|
+
drawDefinition,
|
|
19248
|
+
structureId,
|
|
19249
|
+
}) || {};
|
|
19250
|
+
const sourceLinks = (links?.target || [])
|
|
19251
|
+
.filter(({ linkType: structureLinkType }) => structureLinkType === linkType)
|
|
19252
|
+
.filter(({ target }) => !targetRoundNumber || targetRoundNumber === target.roundNumber);
|
|
19253
|
+
const relevantLinks = sourceLinks
|
|
19254
|
+
.map((link) => {
|
|
19255
|
+
const sourceStructureId = link.source.structureId;
|
|
19256
|
+
const { structure: sourceStructure } = findStructure({
|
|
19257
|
+
structureId: sourceStructureId,
|
|
19258
|
+
drawDefinition,
|
|
19259
|
+
});
|
|
19260
|
+
if (finishingPosition && sourceStructure?.finishingPosition !== finishingPosition)
|
|
19261
|
+
return undefined;
|
|
19262
|
+
return link;
|
|
19263
|
+
})
|
|
19264
|
+
.filter(Boolean);
|
|
19265
|
+
const sourceStructureIds = relevantLinks.map(({ source }) => source.structureId);
|
|
19266
|
+
return { sourceStructureIds, relevantLinks };
|
|
19267
|
+
}
|
|
19268
|
+
|
|
19269
|
+
function qualifierProgression({ targetRoundNumber = 1, tournamentRecord, drawDefinition, event, }) {
|
|
19270
|
+
const paramsCheck = checkRequiredParameters({ drawDefinition, event, tournamentRecord }, [
|
|
19271
|
+
{ [DRAW_DEFINITION]: true, [EVENT]: true, [TOURNAMENT_RECORD]: true },
|
|
19272
|
+
]);
|
|
19273
|
+
if (paramsCheck.error)
|
|
19274
|
+
return paramsCheck;
|
|
19275
|
+
const assignedParticipants = [];
|
|
19276
|
+
const qualifyingParticipantIds = [];
|
|
19277
|
+
const mainStructure = drawDefinition.structures?.find((structure) => structure.stage === MAIN && structure.stageSequence === 1);
|
|
19278
|
+
if (!mainStructure)
|
|
19279
|
+
return decorateResult({ result: { error: MISSING_MAIN_STRUCTURE } });
|
|
19280
|
+
const appliedPolicies = getAppliedPolicies({ tournamentRecord, drawDefinition, structure: mainStructure, event }).appliedPolicies ?? {};
|
|
19281
|
+
const policy = appliedPolicies[POLICY_TYPE_POSITION_ACTIONS];
|
|
19282
|
+
const requireCompletedStructures = policy?.requireCompletedStructures;
|
|
19283
|
+
const { qualifierPositions, positionAssignments } = structureAssignedDrawPositions({ structure: mainStructure });
|
|
19284
|
+
if (!qualifierPositions.length)
|
|
19285
|
+
return decorateResult({ result: { error: NO_DRAW_POSITIONS_AVAILABLE_FOR_QUALIFIERS } });
|
|
19286
|
+
const assignedParticipantIds = positionAssignments.map((assignment) => assignment.participantId).filter(Boolean);
|
|
19287
|
+
const { relevantLinks: eliminationSourceLinks } = getSourceStructureIdsAndRelevantLinks({
|
|
19288
|
+
structureId: mainStructure.structureId,
|
|
19289
|
+
targetRoundNumber,
|
|
19290
|
+
linkType: WINNER,
|
|
19291
|
+
drawDefinition,
|
|
19292
|
+
}) || {};
|
|
19293
|
+
const { relevantLinks: roundRobinSourceLinks } = getSourceStructureIdsAndRelevantLinks({
|
|
19294
|
+
structureId: mainStructure.structureId,
|
|
19295
|
+
targetRoundNumber,
|
|
19296
|
+
linkType: POSITION,
|
|
19297
|
+
drawDefinition,
|
|
19298
|
+
}) || {};
|
|
19299
|
+
for (const sourceLink of eliminationSourceLinks) {
|
|
19300
|
+
const structure = drawDefinition.structures?.find((structure) => structure.structureId === sourceLink.source.structureId);
|
|
19301
|
+
if (structure?.stage !== QUALIFYING)
|
|
19302
|
+
continue;
|
|
19303
|
+
const structureCompleted = isCompletedStructure({ structureId: sourceLink.source.structureId, drawDefinition });
|
|
19304
|
+
if (!requireCompletedStructures || structureCompleted) {
|
|
19305
|
+
const qualifyingRoundNumber = structure.qualifyingRoundNumber;
|
|
19306
|
+
const { matchUps } = getAllStructureMatchUps({
|
|
19307
|
+
matchUpFilters: {
|
|
19308
|
+
...(qualifyingRoundNumber && { roundNumbers: [qualifyingRoundNumber] }),
|
|
19309
|
+
hasWinningSide: true,
|
|
19310
|
+
},
|
|
19311
|
+
afterRecoveryTimes: false,
|
|
19312
|
+
inContext: true,
|
|
19313
|
+
structure,
|
|
19314
|
+
});
|
|
19315
|
+
for (const matchUp of matchUps) {
|
|
19316
|
+
const relevantSide = matchUp.matchUpStatus === BYE && matchUp.sides?.find(({ participantId }) => participantId);
|
|
19317
|
+
const winningSide = matchUp.sides.find((side) => side?.sideNumber === matchUp.winningSide);
|
|
19318
|
+
if (winningSide || relevantSide) {
|
|
19319
|
+
const { participantId } = winningSide || relevantSide || {};
|
|
19320
|
+
if (participantId && !assignedParticipantIds.includes(participantId)) {
|
|
19321
|
+
qualifyingParticipantIds.push(participantId);
|
|
19322
|
+
}
|
|
19323
|
+
}
|
|
19324
|
+
}
|
|
19325
|
+
}
|
|
19326
|
+
}
|
|
19327
|
+
for (const sourceLink of roundRobinSourceLinks) {
|
|
19328
|
+
const structure = drawDefinition?.structures?.find((structure) => structure.structureId === sourceLink.source.structureId);
|
|
19329
|
+
if (structure?.stage !== QUALIFYING)
|
|
19330
|
+
continue;
|
|
19331
|
+
const structureCompleted = isCompletedStructure({
|
|
19332
|
+
structureId: sourceLink.source.structureId,
|
|
19333
|
+
drawDefinition,
|
|
19334
|
+
});
|
|
19335
|
+
if (structureCompleted) {
|
|
19336
|
+
const { positionAssignments } = getPositionAssignments$1({ structure });
|
|
19337
|
+
const relevantParticipantIds = positionAssignments
|
|
19338
|
+
?.map((assignment) => {
|
|
19339
|
+
const participantId = assignment.participantId;
|
|
19340
|
+
const results = findExtension({ element: assignment, name: TALLY }).extension?.value;
|
|
19341
|
+
return results ? { participantId, groupOrder: results?.groupOrder } : {};
|
|
19342
|
+
})
|
|
19343
|
+
.filter(({ groupOrder, participantId }) => groupOrder === 1 && !assignedParticipantIds.includes(participantId))
|
|
19344
|
+
.map(({ participantId }) => participantId) ?? [];
|
|
19345
|
+
if (relevantParticipantIds)
|
|
19346
|
+
qualifyingParticipantIds.push(...relevantParticipantIds);
|
|
19347
|
+
}
|
|
19348
|
+
}
|
|
19349
|
+
if (!qualifyingParticipantIds.length)
|
|
19350
|
+
return decorateResult({ result: { error: MISSING_QUALIFIED_PARTICIPANTS } });
|
|
19351
|
+
qualifierPositions.forEach((position) => {
|
|
19352
|
+
const randomParticipantId = randomPop(qualifyingParticipantIds);
|
|
19353
|
+
if (randomParticipantId) {
|
|
19354
|
+
const positionAssignmentResult = qualifierDrawPositionAssignment({
|
|
19355
|
+
qualifyingParticipantId: randomParticipantId,
|
|
19356
|
+
structureId: mainStructure.structureId,
|
|
19357
|
+
drawPosition: position.drawPosition,
|
|
19358
|
+
tournamentRecord,
|
|
19359
|
+
drawDefinition,
|
|
19360
|
+
});
|
|
19361
|
+
positionAssignmentResult?.success &&
|
|
19362
|
+
assignedParticipants.push({ participantId: randomParticipantId, drawPosition: position.drawPosition });
|
|
19363
|
+
}
|
|
19364
|
+
});
|
|
19365
|
+
return decorateResult({
|
|
19366
|
+
result: definedAttributes({ ...SUCCESS, assignedParticipants }),
|
|
19367
|
+
});
|
|
19368
|
+
}
|
|
19369
|
+
|
|
19229
19370
|
function setStructureOrder({ drawDefinition, orderMap }) {
|
|
19230
19371
|
if (!drawDefinition)
|
|
19231
19372
|
return { error: MISSING_DRAW_DEFINITION };
|
|
@@ -21931,7 +22072,7 @@ function isGamesBased(based) {
|
|
|
21931
22072
|
return !isPointsBased(based);
|
|
21932
22073
|
}
|
|
21933
22074
|
|
|
21934
|
-
function calculatePercentages({ participantResults, matchUpFormat, tallyPolicy, perPlayer, totalSets }) {
|
|
22075
|
+
function calculatePercentages({ participantResults, groupingTotal, matchUpFormat, tallyPolicy, totalGames, perPlayer, totalSets, }) {
|
|
21935
22076
|
const parsedGroupMatchUpFormat = (matchUpFormat && parse(matchUpFormat)) || {};
|
|
21936
22077
|
const bestOfGames = parsedGroupMatchUpFormat.bestOf;
|
|
21937
22078
|
const bracketSetsToWin = (bestOfGames && Math.ceil(bestOfGames / 2)) || 1;
|
|
@@ -21940,7 +22081,7 @@ function calculatePercentages({ participantResults, matchUpFormat, tallyPolicy,
|
|
|
21940
22081
|
Object.keys(participantResults).forEach((participantId) => {
|
|
21941
22082
|
const setsWon = participantResults[participantId].setsWon;
|
|
21942
22083
|
const setsLost = participantResults[participantId].setsLost;
|
|
21943
|
-
const setsTotal = tallyPolicy?.groupTotalSetsPlayed
|
|
22084
|
+
const setsTotal = tallyPolicy?.groupTotalSetsPlayed || groupingTotal === 'setsPct'
|
|
21944
22085
|
? totalSets
|
|
21945
22086
|
: perPlayer * (bracketSetsToWin || 0) || setsWon + setsLost;
|
|
21946
22087
|
let setsPct = Math.round((setsWon / setsTotal) * precision) / precision;
|
|
@@ -21961,7 +22102,9 @@ function calculatePercentages({ participantResults, matchUpFormat, tallyPolicy,
|
|
|
21961
22102
|
const gamesWon = participantResults[participantId].gamesWon || 0;
|
|
21962
22103
|
const gamesLost = participantResults[participantId].gamesLost || 0;
|
|
21963
22104
|
const minimumExpectedGames = (perPlayer || 0) * (bracketSetsToWin || 0) * (bracketGamesForSet || 0);
|
|
21964
|
-
const gamesTotal =
|
|
22105
|
+
const gamesTotal = tallyPolicy?.groupTotalGamesPlayed || groupingTotal === 'gamesPct'
|
|
22106
|
+
? totalGames
|
|
22107
|
+
: Math.max(minimumExpectedGames, gamesWon + gamesLost);
|
|
21965
22108
|
let gamesPct = Math.round((gamesWon / gamesTotal) * precision) / precision;
|
|
21966
22109
|
if (gamesPct === Infinity || isNaN(gamesPct))
|
|
21967
22110
|
gamesPct = 0;
|
|
@@ -21984,7 +22127,7 @@ function calculatePercentages({ participantResults, matchUpFormat, tallyPolicy,
|
|
|
21984
22127
|
});
|
|
21985
22128
|
}
|
|
21986
22129
|
|
|
21987
|
-
function getParticipantResults({ participantIds, pressureRating, matchUpFormat, tallyPolicy, perPlayer, matchUps, }) {
|
|
22130
|
+
function getParticipantResults({ participantIds, pressureRating, groupingTotal, matchUpFormat, tallyPolicy, perPlayer, matchUps, }) {
|
|
21988
22131
|
const participantResults = {};
|
|
21989
22132
|
const excludeMatchUpStatuses = tallyPolicy?.excludeMatchUpStatuses || [];
|
|
21990
22133
|
const filteredMatchUps = matchUps?.filter((matchUp) => {
|
|
@@ -21992,12 +22135,19 @@ function getParticipantResults({ participantIds, pressureRating, matchUpFormat,
|
|
|
21992
22135
|
(!participantIds?.length ||
|
|
21993
22136
|
intersection(participantIds, [getSideId(matchUp, 0), getSideId(matchUp, 1)]).length === 2));
|
|
21994
22137
|
});
|
|
21995
|
-
const
|
|
22138
|
+
const allSetsCount = filteredMatchUps?.flatMap(({ score, tieMatchUps }) => tieMatchUps
|
|
21996
22139
|
? tieMatchUps
|
|
21997
22140
|
.filter(({ matchUpStatus }) => !excludeMatchUpStatuses.includes(matchUpStatus))
|
|
21998
22141
|
.flatMap(({ score }) => score?.sets?.length ?? 0)
|
|
21999
22142
|
: (score?.sets?.length ?? 0));
|
|
22000
|
-
const totalSets =
|
|
22143
|
+
const totalSets = allSetsCount?.reduce((a, b) => a + b, 0);
|
|
22144
|
+
const getGames = (score) => score?.sets?.reduce((total, set) => total + (set?.side1Score ?? 0) + (set?.side2Score ?? 0), 0) ?? 0;
|
|
22145
|
+
const allGamesCount = filteredMatchUps?.flatMap(({ score, tieMatchUps }) => tieMatchUps
|
|
22146
|
+
? tieMatchUps
|
|
22147
|
+
.filter(({ matchUpStatus }) => !excludeMatchUpStatuses.includes(matchUpStatus))
|
|
22148
|
+
.flatMap(({ score }) => getGames(score))
|
|
22149
|
+
: getGames(score));
|
|
22150
|
+
const totalGames = allGamesCount?.reduce((a, b) => a + b, 0);
|
|
22001
22151
|
for (const matchUp of filteredMatchUps ?? []) {
|
|
22002
22152
|
const { matchUpStatus, tieMatchUps, tieFormat, score, winningSide, sides } = matchUp;
|
|
22003
22153
|
const manualGamesOverride = tieFormat && matchUp._disableAutoCalc && tieFormat.collectionDefinitions.every(({ scoreValue }) => scoreValue);
|
|
@@ -22141,9 +22291,9 @@ function getParticipantResults({ participantIds, pressureRating, matchUpFormat,
|
|
|
22141
22291
|
});
|
|
22142
22292
|
}
|
|
22143
22293
|
}
|
|
22144
|
-
const gamesWonSide1 = score?.sets?.reduce((total, set) => total + (set?.side1Score ?? 0), 0);
|
|
22145
|
-
const gamesWonSide2 = score?.sets?.reduce((total, set) => total + (set.side2Score ?? 0), 0);
|
|
22146
22294
|
if (manualGamesOverride) {
|
|
22295
|
+
const gamesWonSide1 = score?.sets?.reduce((total, set) => total + (set?.side1Score ?? 0), 0);
|
|
22296
|
+
const gamesWonSide2 = score?.sets?.reduce((total, set) => total + (set.side2Score ?? 0), 0);
|
|
22147
22297
|
const side1participantId = sides?.find(({ sideNumber }) => sideNumber === 1)?.participantId;
|
|
22148
22298
|
const side2participantId = sides?.find(({ sideNumber }) => sideNumber === 2)?.participantId;
|
|
22149
22299
|
checkInitializeParticipant(participantResults, side1participantId);
|
|
@@ -22160,8 +22310,10 @@ function getParticipantResults({ participantIds, pressureRating, matchUpFormat,
|
|
|
22160
22310
|
}
|
|
22161
22311
|
calculatePercentages({
|
|
22162
22312
|
participantResults,
|
|
22313
|
+
groupingTotal,
|
|
22163
22314
|
matchUpFormat,
|
|
22164
22315
|
tallyPolicy,
|
|
22316
|
+
totalGames,
|
|
22165
22317
|
perPlayer,
|
|
22166
22318
|
totalSets,
|
|
22167
22319
|
});
|
|
@@ -22514,9 +22666,10 @@ function isComplete({ participantResults, participantsCount }) {
|
|
|
22514
22666
|
const participantsFinished = resultsArray.filter((r) => participantsCount - 1 === r.results.matchUpsWon + r.results.matchUpsLost + r.results.matchUpsCancelled);
|
|
22515
22667
|
return participantsCount === participantsFinished.length;
|
|
22516
22668
|
}
|
|
22517
|
-
function processAttribute({ disableHeadToHead, participantIds, matchUpFormat, tallyPolicy, attribute, idsFilter, matchUps, reversed, }) {
|
|
22669
|
+
function processAttribute({ disableHeadToHead, participantIds, matchUpFormat, groupTotals, tallyPolicy, attribute, idsFilter, matchUps, reversed, }) {
|
|
22518
22670
|
const { participantResults } = getParticipantResults({
|
|
22519
22671
|
participantIds: idsFilter && participantIds,
|
|
22672
|
+
groupingTotal: groupTotals && attribute,
|
|
22520
22673
|
matchUpFormat,
|
|
22521
22674
|
tallyPolicy,
|
|
22522
22675
|
matchUps,
|
|
@@ -22579,11 +22732,12 @@ function groupSubSort({ participantResults, disableHeadToHead, participantIds, m
|
|
|
22579
22732
|
});
|
|
22580
22733
|
if (excludedDirectives.length)
|
|
22581
22734
|
report.push({ excludedDirectives, participantIds });
|
|
22582
|
-
filteredDirectives.every(({ attribute, reversed, idsFilter, disableHeadToHead }) => {
|
|
22735
|
+
filteredDirectives.every(({ attribute, reversed, idsFilter, groupTotals, disableHeadToHead }) => {
|
|
22583
22736
|
result = processAttribute({
|
|
22584
22737
|
disableHeadToHead,
|
|
22585
22738
|
participantIds,
|
|
22586
22739
|
matchUpFormat,
|
|
22740
|
+
groupTotals,
|
|
22587
22741
|
tallyPolicy,
|
|
22588
22742
|
attribute,
|
|
22589
22743
|
idsFilter,
|
|
@@ -22646,8 +22800,8 @@ function tallyParticipantResults({ policyDefinitions, generateReport, pressureRa
|
|
|
22646
22800
|
participantResults,
|
|
22647
22801
|
participantsCount,
|
|
22648
22802
|
matchUpFormat,
|
|
22649
|
-
tallyPolicy,
|
|
22650
22803
|
subOrderMap,
|
|
22804
|
+
tallyPolicy,
|
|
22651
22805
|
});
|
|
22652
22806
|
if (pressureRating)
|
|
22653
22807
|
addPressureOrder({ participantResults });
|
|
@@ -25116,6 +25270,7 @@ var mutate$c = {
|
|
|
25116
25270
|
modifySeedAssignment: modifySeedAssignment,
|
|
25117
25271
|
pruneDrawDefinition: pruneDrawDefinition,
|
|
25118
25272
|
qualifierDrawPositionAssignment: qualifierDrawPositionAssignment,
|
|
25273
|
+
qualifierProgression: qualifierProgression,
|
|
25119
25274
|
removeDrawPositionAssignment: removeDrawPositionAssignment,
|
|
25120
25275
|
removeRoundMatchUps: removeRoundMatchUps,
|
|
25121
25276
|
removeSeededParticipant: removeSeededParticipant,
|
|
@@ -25402,30 +25557,6 @@ function publicFindDrawDefinition(params) {
|
|
|
25402
25557
|
return { drawDefinition: makeDeepCopy(drawDefinition) };
|
|
25403
25558
|
}
|
|
25404
25559
|
|
|
25405
|
-
function getSourceStructureIdsAndRelevantLinks({ targetRoundNumber, finishingPosition, drawDefinition, structureId, linkType, }) {
|
|
25406
|
-
const { links } = getStructureLinks({
|
|
25407
|
-
drawDefinition,
|
|
25408
|
-
structureId,
|
|
25409
|
-
}) || {};
|
|
25410
|
-
const sourceLinks = (links?.target || [])
|
|
25411
|
-
.filter(({ linkType: structureLinkType }) => structureLinkType === linkType)
|
|
25412
|
-
.filter(({ target }) => !targetRoundNumber || targetRoundNumber === target.roundNumber);
|
|
25413
|
-
const relevantLinks = sourceLinks
|
|
25414
|
-
.map((link) => {
|
|
25415
|
-
const sourceStructureId = link.source.structureId;
|
|
25416
|
-
const { structure: sourceStructure } = findStructure({
|
|
25417
|
-
structureId: sourceStructureId,
|
|
25418
|
-
drawDefinition,
|
|
25419
|
-
});
|
|
25420
|
-
if (finishingPosition && sourceStructure?.finishingPosition !== finishingPosition)
|
|
25421
|
-
return undefined;
|
|
25422
|
-
return link;
|
|
25423
|
-
})
|
|
25424
|
-
.filter(Boolean);
|
|
25425
|
-
const sourceStructureIds = relevantLinks.map(({ source }) => source.structureId);
|
|
25426
|
-
return { sourceStructureIds, relevantLinks };
|
|
25427
|
-
}
|
|
25428
|
-
|
|
25429
25560
|
function getValidModifyAssignedPairAction({ tournamentParticipants, returnParticipants, drawPosition, participant, drawId, event, }) {
|
|
25430
25561
|
const availableIndividualParticipantIds = event?.entries
|
|
25431
25562
|
?.filter(({ entryStatus }) => [UNGROUPED, UNPAIRED].includes(entryStatus))
|
|
@@ -38420,6 +38551,7 @@ var index$e = {
|
|
|
38420
38551
|
positionActions: positionActions,
|
|
38421
38552
|
pruneDrawDefinition: pruneDrawDefinition,
|
|
38422
38553
|
qualifierDrawPositionAssignment: qualifierDrawPositionAssignment,
|
|
38554
|
+
qualifierProgression: qualifierProgression,
|
|
38423
38555
|
query: query$b,
|
|
38424
38556
|
removeDrawPositionAssignment: removeDrawPositionAssignment,
|
|
38425
38557
|
removeRoundMatchUps: removeRoundMatchUps,
|