tods-competition-factory 0.64.1 → 0.65.2

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.
@@ -248,6 +248,10 @@ const matchUpFormatCode = {
248
248
  parse
249
249
  };
250
250
 
251
+ function factoryVersion() {
252
+ return '0.65.2';
253
+ }
254
+
251
255
  const FORMAT_STANDARD = 'SET3-S:6/TB7'; // Best of 3 Tiebreak Sets to 6
252
256
 
253
257
  const FORMAT_STANDARD_NOAD = 'SET3-S:6NOAD'; // Best of 3 NOAD Sets to 6 with deciding game at 5-5
@@ -11375,7 +11379,7 @@ function getAllStructureMatchUps({
11375
11379
  matchUp,
11376
11380
  event
11377
11381
  }) {
11378
- var _roundNamingProfile$r, _roundNamingProfile$r2;
11382
+ var _roundNamingProfile$r, _roundNamingProfile$r2, _roundProfile$roundNu, _roundProfile$roundNu2;
11379
11383
 
11380
11384
  const tieFormat = matchUp.tieFormat || structure.tieFormat || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat);
11381
11385
  const collectionDefinitions = tieFormat === null || tieFormat === void 0 ? void 0 : tieFormat.collectionDefinitions;
@@ -11415,7 +11419,8 @@ function getAllStructureMatchUps({
11415
11419
  });
11416
11420
  const roundName = roundNamingProfile && ((_roundNamingProfile$r = roundNamingProfile[roundNumber]) === null || _roundNamingProfile$r === void 0 ? void 0 : _roundNamingProfile$r.roundName) || additionalContext.roundName;
11417
11421
  const abbreviatedRoundName = roundNamingProfile && ((_roundNamingProfile$r2 = roundNamingProfile[roundNumber]) === null || _roundNamingProfile$r2 === void 0 ? void 0 : _roundNamingProfile$r2.abbreviatedRoundName) || additionalContext.abbreviatedRoundName;
11418
- const feedRound = roundProfile && roundProfile[roundNumber] && roundProfile[roundNumber].feedRound;
11422
+ const feedRound = roundProfile === null || roundProfile === void 0 ? void 0 : (_roundProfile$roundNu = roundProfile[roundNumber]) === null || _roundProfile$roundNu === void 0 ? void 0 : _roundProfile$roundNu.feedRound;
11423
+ const preFeedRound = roundProfile === null || roundProfile === void 0 ? void 0 : (_roundProfile$roundNu2 = roundProfile[roundNumber]) === null || _roundProfile$roundNu2 === void 0 ? void 0 : _roundProfile$roundNu2.preFeedRound;
11419
11424
  const drawPositionsRoundRanges = drawPositionsRanges && drawPositionsRanges[roundNumber];
11420
11425
  const drawPositionsRange = drawPositionsRoundRanges && drawPositionsRoundRanges[roundPosition];
11421
11426
  const sourceDrawPositionRoundRanges = sourceDrawPositionRanges && sourceDrawPositionRanges[roundNumber]; // order is important here as Round Robin matchUps already have inContext structureId
@@ -11433,6 +11438,7 @@ function getAllStructureMatchUps({
11433
11438
  drawPositions,
11434
11439
  matchUpStatus,
11435
11440
  matchUpTieId,
11441
+ preFeedRound,
11436
11442
  matchUpType,
11437
11443
  exitProfile,
11438
11444
  structureId,
@@ -18057,9 +18063,9 @@ function getAvailableAdHocParticipantIds({
18057
18063
  drawPosition,
18058
18064
  participantId
18059
18065
  }) => roundDrawPositions.includes(drawPosition) && participantId).map(getParticipantId);
18060
- const enteredParticipantIds = drawDefinition.entries.filter(({
18066
+ const enteredParticipantIds = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries.filter(({
18061
18067
  entryStatus
18062
- }) => [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId); // AdHoc available participants are those entered in the draw who are not assigned to the target round
18068
+ }) => [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId)) || []; // AdHoc available participants are those entered in the draw who are not assigned to the target round
18063
18069
 
18064
18070
  const availableParticipantIds = enteredParticipantIds.filter(participantId => !roundAssignedParticipantIds.includes(participantId));
18065
18071
  return availableParticipantIds;
@@ -28039,10 +28045,6 @@ const scheduleGovernor$1 = {
28039
28045
  removePersonRequests
28040
28046
  };
28041
28047
 
28042
- function factoryVersion() {
28043
- return '0.64.1';
28044
- }
28045
-
28046
28048
  function attachPolicies$2({
28047
28049
  tournamentRecord,
28048
28050
  policyDefinitions,
@@ -34633,7 +34635,7 @@ function getAssignedParticipantIds({
34633
34635
  function refreshEntryPositions({
34634
34636
  entries = []
34635
34637
  } = {}) {
34636
- const stagedEntries = entries.reduce((stages, entry) => {
34638
+ const stagedEntries = entries.filter(Boolean).reduce((stages, entry) => {
34637
34639
  const {
34638
34640
  entryStage,
34639
34641
  entryStatus
@@ -34845,6 +34847,8 @@ function modifyEntriesStatus({
34845
34847
  return true;
34846
34848
  });
34847
34849
  (_event$drawDefinition4 = event.drawDefinitions) === null || _event$drawDefinition4 === void 0 ? void 0 : _event$drawDefinition4.every(drawDefinition => {
34850
+ var _drawDefinition$entri2;
34851
+
34848
34852
  const result = updateEntryStatus(drawDefinition.entries);
34849
34853
 
34850
34854
  if (result.error) {
@@ -34852,7 +34856,7 @@ function modifyEntriesStatus({
34852
34856
  return false;
34853
34857
  }
34854
34858
 
34855
- drawDefinition.entries = drawDefinition.entries.filter(({
34859
+ drawDefinition.entries = (_drawDefinition$entri2 = drawDefinition.entries) === null || _drawDefinition$entri2 === void 0 ? void 0 : _drawDefinition$entri2.filter(({
34856
34860
  participantId
34857
34861
  }) => !participantIds.includes(participantId));
34858
34862
  return true;
@@ -35189,8 +35193,8 @@ function participantInEntries({
35189
35193
  function addDrawEntry({
35190
35194
  entryStatus = DIRECT_ACCEPTANCE,
35191
35195
  entryStage = MAIN,
35192
- entryPosition,
35193
35196
  drawDefinition,
35197
+ entryPosition,
35194
35198
  participantId,
35195
35199
  participant
35196
35200
  }) {
@@ -35222,7 +35226,7 @@ function addDrawEntry({
35222
35226
  };
35223
35227
  }
35224
35228
 
35225
- participantId = participantId || participant && participant.participantId;
35229
+ participantId = participantId || (participant === null || participant === void 0 ? void 0 : participant.participantId);
35226
35230
  if (!participantId) return {
35227
35231
  error: MISSING_PARTICIPANT_ID
35228
35232
  };
@@ -35344,7 +35348,7 @@ function addDrawEntries$1({
35344
35348
  };
35345
35349
  }
35346
35350
 
35347
- participantIds.forEach(participantId => {
35351
+ participantIds.filter(Boolean).forEach(participantId => {
35348
35352
  const entry = Object.assign({
35349
35353
  participantId
35350
35354
  }, {
@@ -36439,6 +36443,7 @@ function generateDrawMaticRound({
36439
36443
  const {
36440
36444
  participantIdPairings
36441
36445
  } = eventType === DOUBLES ? getDoublesPairings(params) : getSinglesPairings(params);
36446
+ console.log(participantIdPairings);
36442
36447
 
36443
36448
  for (const [index, matchUp] of roundMatchUps.entries()) {
36444
36449
  const drawPositions = matchUp.drawPositions;
@@ -36599,13 +36604,16 @@ function drawMatic$1({
36599
36604
  matchUpIds,
36600
36605
  scaleName,
36601
36606
  // custom rating name to seed dynamic ratings
36602
- eventType
36607
+ event
36603
36608
  }) {
36604
36609
  var _drawDefinition$struc2;
36605
36610
 
36606
36611
  if (typeof drawDefinition !== 'object') return {
36607
36612
  error: INVALID_DRAW_DEFINITION
36608
36613
  };
36614
+ const {
36615
+ eventType
36616
+ } = event || {};
36609
36617
  const enteredParticipantIds = drawDefinition.entries.filter(({
36610
36618
  entryStatus
36611
36619
  }) => !restrictEntryStatus || [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId);
@@ -50143,6 +50151,7 @@ function generateParticipants({
50143
50151
  participantsCount = 32,
50144
50152
  participantType,
50145
50153
  personIds,
50154
+ idPrefix,
50146
50155
  uuids,
50147
50156
  personExtensions,
50148
50157
  addressProps,
@@ -50272,12 +50281,18 @@ function generateParticipants({
50272
50281
  });
50273
50282
  const individualParticipantIds = individualParticipants.map(participant => participant.participantId);
50274
50283
  const pairName = individualParticipants.map(i => i.person.standardFamilyName).join('/');
50284
+ const participantType = doubles ? PAIR$1 : TEAM$1;
50275
50285
  const groupParticipant = {
50276
- participantId: (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID(),
50277
- participantType: doubles ? PAIR$1 : TEAM$1,
50286
+ participantId: genParticipantId({
50287
+ participantType,
50288
+ idPrefix,
50289
+ index: i,
50290
+ uuids
50291
+ }),
50278
50292
  participantRole: COMPETITOR,
50279
50293
  participantName: doubles ? pairName : teamNames[i],
50280
- individualParticipantIds
50294
+ individualParticipantIds,
50295
+ participantType
50281
50296
  };
50282
50297
  if (inContext) groupParticipant.individualParticipants = individualParticipants;
50283
50298
  return doubles || team ? [groupParticipant, ...individualParticipants] : individualParticipants;
@@ -50317,7 +50332,12 @@ function generateParticipants({
50317
50332
  nationalityCode
50318
50333
  });
50319
50334
  const participant = definedAttributes({
50320
- participantId: (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID(),
50335
+ participantId: genParticipantId({
50336
+ participantType: INDIVIDUAL$1,
50337
+ index: participantIndex,
50338
+ idPrefix,
50339
+ uuids
50340
+ }),
50321
50341
  extensions: participantExtensions,
50322
50342
  timeItems: participantTimeItems,
50323
50343
  participantRole: COMPETITOR,
@@ -50402,12 +50422,256 @@ function addScaleItem({
50402
50422
  }
50403
50423
  }
50404
50424
 
50425
+ function genParticipantId({
50426
+ idPrefix,
50427
+ participantType,
50428
+ index,
50429
+ uuids
50430
+ }) {
50431
+ const type = participantType === INDIVIDUAL$1 ? 'I' : 'P' ;
50432
+ return idPrefix ? `${idPrefix}-${type}-${index}` : (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID();
50433
+ }
50434
+
50435
+ function processTieFormat({
50436
+ tieFormat,
50437
+ tieFormatName,
50438
+ drawSize,
50439
+ alternatesCount = 0
50440
+ }) {
50441
+ var _tieFormat, _tieFormat$collection;
50442
+
50443
+ let maxDoublesCount = 0,
50444
+ maxSinglesCount = 0;
50445
+ tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
50446
+ namedFormat: tieFormatName
50447
+ });
50448
+ (_tieFormat = tieFormat) === null || _tieFormat === void 0 ? void 0 : (_tieFormat$collection = _tieFormat.collectionDefinitions) === null || _tieFormat$collection === void 0 ? void 0 : _tieFormat$collection.forEach(collectionDefinition => {
50449
+ // ensure every collectionDefinition has a collectionId
50450
+ if (!collectionDefinition.collectionId) collectionDefinition.collectionId = UUID();
50451
+
50452
+ if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === DOUBLES$1) {
50453
+ const doublesCount = collectionDefinition.matchUpCount;
50454
+ maxDoublesCount = Math.max(maxDoublesCount, doublesCount);
50455
+ }
50456
+
50457
+ if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === SINGLES$1) {
50458
+ const singlescount = collectionDefinition.matchUpCount;
50459
+ maxSinglesCount = Math.max(maxSinglesCount, singlescount);
50460
+ }
50461
+ });
50462
+ const teamSize = Math.max(maxSinglesCount, maxDoublesCount * 2);
50463
+ const maxDoublesDraw = maxDoublesCount * (drawSize + alternatesCount);
50464
+ const maxSinglesDraw = maxSinglesCount * (drawSize + alternatesCount);
50465
+ return {
50466
+ maxDoublesDraw,
50467
+ maxSinglesDraw,
50468
+ teamSize
50469
+ };
50470
+ }
50471
+
50472
+ function getParticipantsCount({
50473
+ participantsProfile,
50474
+ eventProfiles,
50475
+ drawProfiles
50476
+ }) {
50477
+ let {
50478
+ participantsCount,
50479
+ participantType = INDIVIDUAL$1
50480
+ } = participantsProfile || {};
50481
+ const specifiedParicipantsCount = participantsCount || 0; // capture this to ensure calculated participantsCount is not below
50482
+
50483
+ let largestDoublesDraw = 0,
50484
+ largestSinglesDraw = 0,
50485
+ largestTeamSize = 0,
50486
+ largestTeamDraw = 0,
50487
+ uniqueParticipantsCount = 0;
50488
+
50489
+ const processDrawProfile = ({
50490
+ alternatesCount = 0,
50491
+ uniqueParticipants,
50492
+ tieFormatName,
50493
+ drawSize = 0,
50494
+ eventType,
50495
+ tieFormat,
50496
+ category,
50497
+ gender,
50498
+ stage
50499
+ }) => {
50500
+ const isDoubles = eventType === DOUBLES;
50501
+ const isTeam = eventType === TEAM$2;
50502
+ const requiresUniqueParticipants = uniqueParticipants || stage === QUALIFYING || category || gender;
50503
+
50504
+ if (requiresUniqueParticipants) {
50505
+ if (isDoubles) {
50506
+ uniqueParticipantsCount += (drawSize + alternatesCount) * 2;
50507
+ } else {
50508
+ uniqueParticipantsCount += drawSize + alternatesCount;
50509
+ }
50510
+ } else {
50511
+ if (isTeam) {
50512
+ largestTeamDraw = Math.max(largestTeamDraw, drawSize + alternatesCount);
50513
+ tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
50514
+ namedFormat: tieFormatName
50515
+ });
50516
+ const {
50517
+ teamSize,
50518
+ maxDoublesDraw,
50519
+ maxSinglesDraw
50520
+ } = processTieFormat({
50521
+ alternatesCount,
50522
+ tieFormatName,
50523
+ tieFormat,
50524
+ drawSize
50525
+ });
50526
+ largestTeamSize = Math.max(largestTeamSize, teamSize);
50527
+ largestDoublesDraw = Math.max(largestDoublesDraw, maxDoublesDraw);
50528
+ largestSinglesDraw = Math.max(largestSinglesDraw, maxSinglesDraw);
50529
+ }
50530
+
50531
+ if (isDoubles && drawSize + alternatesCount && drawSize + alternatesCount > largestDoublesDraw) {
50532
+ largestDoublesDraw = drawSize + alternatesCount;
50533
+ }
50534
+
50535
+ if (!isDoubles && !isTeam && drawSize && drawSize > largestSinglesDraw) {
50536
+ largestSinglesDraw = drawSize + alternatesCount;
50537
+ }
50538
+ }
50539
+ };
50540
+
50541
+ eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
50542
+ const {
50543
+ tieFormatName: eventTieFormatName,
50544
+ tieFormat: eventTieFormat,
50545
+ drawProfiles,
50546
+ eventType,
50547
+ category,
50548
+ gender
50549
+ } = eventProfile;
50550
+
50551
+ if (drawProfiles) {
50552
+ for (const drawProfile of drawProfiles) {
50553
+ const {
50554
+ tieFormatName,
50555
+ tieFormat
50556
+ } = drawProfile;
50557
+ processDrawProfile({ ...drawProfile,
50558
+ tieFormatName: tieFormatName || eventTieFormatName,
50559
+ tieFormat: tieFormat || eventTieFormat,
50560
+ eventType,
50561
+ category,
50562
+ gender
50563
+ });
50564
+ }
50565
+ }
50566
+ });
50567
+
50568
+ if (drawProfiles) {
50569
+ for (const drawProfile of drawProfiles) {
50570
+ processDrawProfile(drawProfile);
50571
+ }
50572
+ }
50573
+
50574
+ const individualCompetitorsCount = Math.max(largestTeamDraw * largestTeamSize, largestDoublesDraw * 2, largestSinglesDraw);
50575
+ if (largestDoublesDraw) participantType = PAIR$1;
50576
+ if ((participantsCount || specifiedParicipantsCount) < individualCompetitorsCount) participantsCount = individualCompetitorsCount;
50577
+
50578
+ if (participantsCount && largestDoublesDraw && [PAIR$1, TEAM$2].includes(participantType)) {
50579
+ // if we are generating PAIRs or TEAMs...
50580
+ if (largestSinglesDraw && Math.floor(largestSinglesDraw / 2) > largestDoublesDraw) {
50581
+ // if the half the singles draw is still larger than doubles draw
50582
+ participantsCount = Math.floor(largestSinglesDraw / 2);
50583
+ } else if (!largestSinglesDraw || largestDoublesDraw * 2 >= largestSinglesDraw) {
50584
+ // otherwise participantsCount can be cut in half
50585
+ participantsCount = Math.ceil(participantsCount / 2);
50586
+ }
50587
+ } // if (participantsCount === undefined) participantsCount = 32;
50588
+
50589
+
50590
+ if (participantsCount === undefined) {
50591
+ participantsCount = !(eventProfiles !== null && eventProfiles !== void 0 && eventProfiles.length) && !(drawProfiles !== null && drawProfiles !== void 0 && drawProfiles.length) ? 32 : 0;
50592
+ }
50593
+
50594
+ if (participantsCount < specifiedParicipantsCount) participantsCount = specifiedParicipantsCount;
50595
+ return {
50596
+ largestTeamDraw,
50597
+ largestTeamSize,
50598
+ participantsCount,
50599
+ participantType,
50600
+ uniqueParticipantsCount
50601
+ };
50602
+ }
50603
+
50604
+ function addTournamentParticipants({
50605
+ participantsProfile = {},
50606
+ tournamentRecord,
50607
+ eventProfiles,
50608
+ drawProfiles,
50609
+ startDate,
50610
+ uuids
50611
+ }) {
50612
+ const {
50613
+ participantsCount,
50614
+ participantType,
50615
+ largestTeamDraw,
50616
+ largestTeamSize
50617
+ } = getParticipantsCount({
50618
+ participantsProfile,
50619
+ eventProfiles,
50620
+ drawProfiles
50621
+ });
50622
+ const {
50623
+ teamKey
50624
+ } = participantsProfile || {};
50625
+ const {
50626
+ participants
50627
+ } = generateParticipants({
50628
+ uuids,
50629
+ ...participantsProfile,
50630
+ consideredDate: startDate,
50631
+ participantsCount,
50632
+ participantType
50633
+ });
50634
+ let result = addParticipants({
50635
+ tournamentRecord,
50636
+ participants
50637
+ });
50638
+ if (!result.success) return result;
50639
+
50640
+ if (teamKey) {
50641
+ const result = generateTeamsFromParticipantAttribute({
50642
+ tournamentRecord,
50643
+ ...teamKey
50644
+ });
50645
+ if (result.error) return result;
50646
+ } // generate Team participants
50647
+
50648
+
50649
+ const allIndividualParticipantIds = participants.filter(({
50650
+ participantType
50651
+ }) => participantType === INDIVIDUAL$1).map(getParticipantId);
50652
+ const teamParticipants = generateRange(0, largestTeamDraw).map(teamIndex => {
50653
+ const individualParticipantIds = allIndividualParticipantIds.slice(teamIndex * largestTeamSize, (teamIndex + 1) * largestTeamSize);
50654
+ return {
50655
+ participantName: `Team ${teamIndex + 1}`,
50656
+ participantRole: COMPETITOR,
50657
+ participantType: TEAM$1,
50658
+ participantId: UUID(),
50659
+ individualParticipantIds
50660
+ };
50661
+ });
50662
+ return addParticipants({
50663
+ tournamentRecord,
50664
+ participants: teamParticipants
50665
+ });
50666
+ }
50667
+
50405
50668
  function generateEventParticipants({
50669
+ participantsProfile = {},
50406
50670
  uniqueParticipantsCount,
50407
- participantsProfile,
50408
50671
  ratingsParameters,
50409
50672
  tournamentRecord,
50410
50673
  eventProfile,
50674
+ eventIndex,
50411
50675
  event,
50412
50676
  uuids
50413
50677
  }) {
@@ -50416,38 +50680,26 @@ function generateEventParticipants({
50416
50680
  gender,
50417
50681
  eventType
50418
50682
  } = event;
50419
- const {
50420
- valuesInstanceLimit,
50421
- nationalityCodesCount,
50422
- nationalityCodeType,
50423
- nationalityCodes,
50424
- addressProps,
50425
- personIds,
50426
- inContext
50427
- } = participantsProfile || {};
50428
50683
  const eventParticipantType = eventType === SINGLES ? INDIVIDUAL$1 : eventType === DOUBLES ? PAIR$1 : eventType;
50429
50684
  const mainParticipantsCount = uniqueParticipantsCount[MAIN] || 0;
50430
50685
  const qualifyingParticipantsCount = uniqueParticipantsCount[QUALIFYING] || 0;
50431
50686
  const participantsCount = mainParticipantsCount + qualifyingParticipantsCount;
50687
+ const sex = [MALE, FEMALE].includes(gender) ? gender : undefined;
50688
+ const idPrefix = participantsProfile !== null && participantsProfile !== void 0 && participantsProfile.idPrefix ? `E-${eventIndex}-${participantsProfile === null || participantsProfile === void 0 ? void 0 : participantsProfile.idPrefix}` : undefined;
50432
50689
  const {
50433
50690
  participants: uniqueFlightParticipants
50434
50691
  } = generateParticipants({
50692
+ uuids: eventProfile.uuids || uuids,
50693
+ ...participantsProfile,
50435
50694
  scaledParticipantsCount: eventProfile.scaledParticipantsCount,
50436
50695
  consideredDate: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.startDate,
50437
50696
  rankingRange: eventProfile.rankingRange,
50438
50697
  participantType: eventParticipantType,
50439
- nationalityCodesCount,
50440
- nationalityCodeType,
50441
- valuesInstanceLimit,
50442
50698
  participantsCount,
50443
50699
  ratingsParameters,
50444
- nationalityCodes,
50445
- addressProps,
50446
- sex: gender,
50447
- personIds,
50448
- inContext,
50700
+ idPrefix,
50449
50701
  category,
50450
- uuids
50702
+ sex
50451
50703
  });
50452
50704
  let result = addParticipants({
50453
50705
  participants: uniqueFlightParticipants,
@@ -50615,262 +50867,6 @@ function generateFlights({
50615
50867
  };
50616
50868
  }
50617
50869
 
50618
- function modifyTournamentRecord({
50619
- matchUpStatusProfile,
50620
- completeAllMatchUps,
50621
- participantsProfile,
50622
- autoEntryPositions,
50623
- randomWinningSide,
50624
- tournamentRecord,
50625
- eventProfiles,
50626
- uuids
50627
- }) {
50628
- if (!tournamentRecord) return {
50629
- error: MISSING_TOURNAMENT_RECORD
50630
- };
50631
- const allUniqueParticipantIds = [];
50632
- const drawIds = [];
50633
-
50634
- if (participantsProfile) {
50635
- const {
50636
- nationalityCodesCount,
50637
- nationalityCodeType,
50638
- valuesInstanceLimit,
50639
- participantsCount,
50640
- nationalityCodes,
50641
- personExtensions,
50642
- participantType,
50643
- addressProps,
50644
- personData,
50645
- personIds,
50646
- inContext,
50647
- teamKey,
50648
- uuids,
50649
- sex
50650
- } = participantsProfile || {};
50651
- const {
50652
- participants
50653
- } = generateParticipants({
50654
- consideredDate: tournamentRecord.startDate,
50655
- valuesInstanceLimit,
50656
- nationalityCodesCount,
50657
- nationalityCodeType,
50658
- nationalityCodes,
50659
- personExtensions,
50660
- addressProps,
50661
- personData,
50662
- sex,
50663
- participantsCount,
50664
- participantType,
50665
- personIds,
50666
- uuids,
50667
- inContext
50668
- });
50669
- let result = addParticipants({
50670
- tournamentRecord,
50671
- participants
50672
- });
50673
- if (result.error) return result;
50674
-
50675
- if (teamKey) {
50676
- const result = generateTeamsFromParticipantAttribute({
50677
- tournamentRecord,
50678
- ...teamKey
50679
- });
50680
- if (result.error) return result;
50681
- }
50682
- }
50683
-
50684
- if (eventProfiles) {
50685
- for (const eventProfile of eventProfiles) {
50686
- let {
50687
- ratingsParameters
50688
- } = eventProfile;
50689
- const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
50690
- if (!event) return {
50691
- error: EVENT_NOT_FOUND
50692
- };
50693
- const {
50694
- gender,
50695
- category,
50696
- eventType
50697
- } = event;
50698
- const {
50699
- drawProfiles
50700
- } = eventProfile;
50701
- const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
50702
-
50703
- if (drawProfiles) {
50704
- const {
50705
- stageParticipantsCount,
50706
- uniqueParticipantsCount,
50707
- uniqueParticipantStages
50708
- } = getStageParticipantsCount({
50709
- drawProfiles,
50710
- category,
50711
- gender
50712
- });
50713
- const {
50714
- uniqueDrawParticipants = [],
50715
- uniqueParticipantIds = []
50716
- } = uniqueParticipantStages ? generateEventParticipants({
50717
- event: {
50718
- eventType,
50719
- category,
50720
- gender
50721
- },
50722
- uniqueParticipantsCount,
50723
- participantsProfile,
50724
- ratingsParameters,
50725
- tournamentRecord,
50726
- eventProfile,
50727
- uuids
50728
- }) : {};
50729
- allUniqueParticipantIds.push(...uniqueParticipantIds);
50730
- const {
50731
- stageParticipants
50732
- } = getStageParticipants({
50733
- targetParticipants: tournamentRecord.participants || [],
50734
- allUniqueParticipantIds,
50735
- stageParticipantsCount,
50736
- eventParticipantType
50737
- });
50738
- let result = generateFlights({
50739
- uniqueDrawParticipants,
50740
- autoEntryPositions,
50741
- stageParticipants,
50742
- tournamentRecord,
50743
- drawProfiles,
50744
- category,
50745
- gender,
50746
- event
50747
- });
50748
- if (result.error) return result;
50749
- result = generateFlightDrawDefinitions({
50750
- matchUpStatusProfile,
50751
- completeAllMatchUps,
50752
- randomWinningSide,
50753
- tournamentRecord,
50754
- drawProfiles,
50755
- event
50756
- });
50757
- if (result.error) return result;
50758
- drawIds.push(...result.drawIds);
50759
- }
50760
- }
50761
- }
50762
-
50763
- return { ...SUCCESS,
50764
- drawIds
50765
- };
50766
- }
50767
-
50768
- const amendsGovernor = {
50769
- anonymizeTournamentRecord,
50770
- modifyTournamentRecord
50771
- };
50772
-
50773
- function generateSchedulingProfile({
50774
- schedulingProfile,
50775
- tournamentRecord
50776
- }) {
50777
- if (typeof schedulingProfile !== 'object') return {
50778
- error: INVALID_VALUES
50779
- };
50780
- const containedStructures = getContainedStructures({
50781
- tournamentRecord
50782
- }).containedStructures;
50783
- const {
50784
- matchUps
50785
- } = allTournamentMatchUps({
50786
- tournamentRecord
50787
- });
50788
- const {
50789
- tournamentId
50790
- } = tournamentRecord;
50791
- const scheduledRounds = [];
50792
-
50793
- for (const dateProfile of schedulingProfile) {
50794
- const {
50795
- scheduleDate,
50796
- venues = []
50797
- } = dateProfile;
50798
-
50799
- for (const venue of venues) {
50800
- const {
50801
- rounds,
50802
- venueId
50803
- } = venue;
50804
-
50805
- for (const round of rounds) {
50806
- const {
50807
- drawId,
50808
- winnerFinishingPositionRange,
50809
- roundSegment
50810
- } = round;
50811
- const targetMatchUps = matchUps.filter(matchUp => {
50812
- var _matchUp$finishingPos;
50813
-
50814
- const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
50815
- const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
50816
- const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
50817
- return target;
50818
- });
50819
- const targetMatchUp = targetMatchUps[0];
50820
-
50821
- if (targetMatchUp) {
50822
- const {
50823
- eventId,
50824
- roundNumber,
50825
- drawName,
50826
- structureName,
50827
- roundName
50828
- } = targetMatchUp;
50829
- let structureId = targetMatchUp.structureId;
50830
-
50831
- if (roundNumber && !winnerFinishingPositionRange) {
50832
- structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
50833
- }
50834
-
50835
- const roundToSchedule = {
50836
- tournamentId,
50837
- eventId,
50838
- drawId,
50839
- structureId,
50840
- roundNumber,
50841
- roundSegment
50842
- };
50843
- let result = addSchedulingProfileRound({
50844
- tournamentRecords: {
50845
- [tournamentId]: tournamentRecord
50846
- },
50847
- scheduleDate,
50848
- venueId,
50849
- round: roundToSchedule
50850
- });
50851
- if (result.error) return result;
50852
- scheduledRounds.push({
50853
- drawName,
50854
- structureName,
50855
- roundName,
50856
- ...roundToSchedule
50857
- });
50858
- }
50859
- }
50860
- }
50861
- }
50862
-
50863
- return {
50864
- scheduledRounds
50865
- };
50866
- }
50867
-
50868
- // import { addDrawDefinition } from '../../tournamentEngine/governors/eventGovernor/drawDefinitions/addDrawDefinition';
50869
- // import {
50870
- // MAIN,
50871
- // ROUND_ROBIN_WITH_PLAYOFF,
50872
- // } from '../../constants/drawDefinitionConstants';
50873
-
50874
50870
  function generateEventWithFlights({
50875
50871
  allUniqueParticipantIds,
50876
50872
  matchUpStatusProfile,
@@ -50881,7 +50877,7 @@ function generateEventWithFlights({
50881
50877
  ratingsParameters,
50882
50878
  tournamentRecord,
50883
50879
  eventProfile,
50884
- // startDate,
50880
+ eventIndex,
50885
50881
  uuids
50886
50882
  }) {
50887
50883
  let gender = eventProfile.gender;
@@ -50931,6 +50927,7 @@ function generateEventWithFlights({
50931
50927
  ratingsParameters,
50932
50928
  tournamentRecord,
50933
50929
  eventProfile,
50930
+ eventIndex,
50934
50931
  uuids
50935
50932
  }) : {}; // Create event object -------------------------------------------------------
50936
50933
 
@@ -51010,120 +51007,6 @@ function generateEventWithFlights({
51010
51007
  });
51011
51008
  if (result.error) return result;
51012
51009
  const drawIds = result.drawIds;
51013
- /*
51014
- const drawIds = [];
51015
- const { flightProfile } = getFlightProfile({ event });
51016
- if (Array.isArray(flightProfile?.flights)) {
51017
- for (const [index, flight] of flightProfile.flights.entries()) {
51018
- const { drawId, stage, drawName, drawEntries } = flight;
51019
- drawIds.push(flight.drawId);
51020
- const drawProfile = drawProfiles[index];
51021
- const { seedsCount, generate = true } = drawProfile || {};
51022
- if (generate) {
51023
- const drawParticipantIds = drawEntries
51024
- .filter(hasParticipantId)
51025
- .map(getParticipantId);
51026
- const seedingScaleName = categoryName || eventName;
51027
- if (
51028
- tournamentRecord &&
51029
- seedsCount &&
51030
- seedsCount <= drawParticipantIds.length
51031
- ) {
51032
- const scaleValues = generateRange(1, seedsCount + 1);
51033
- scaleValues.forEach((scaleValue, index) => {
51034
- let scaleItem = {
51035
- scaleValue,
51036
- scaleName: seedingScaleName,
51037
- scaleType: SEEDING,
51038
- eventType,
51039
- scaleDate: startDate,
51040
- };
51041
- const participantId = drawParticipantIds[index];
51042
- setParticipantScaleItem({
51043
- tournamentRecord,
51044
- participantId,
51045
- scaleItem,
51046
- });
51047
- });
51048
- }
51049
- let result = generateDrawDefinition({
51050
- ...drawProfile,
51051
- matchUpType: eventType,
51052
- seedingScaleName,
51053
- tournamentRecord,
51054
- isMock: true,
51055
- drawEntries,
51056
- drawName,
51057
- drawId,
51058
- event,
51059
- stage,
51060
- });
51061
- const { drawDefinition, error } = result;
51062
- if (error) return { error };
51063
- const drawExtensions = drawProfiles[index]?.drawExtensions;
51064
- if (Array.isArray(drawExtensions)) {
51065
- drawExtensions
51066
- .filter(isValidExtension)
51067
- .forEach((extension) =>
51068
- addExtension({ element: drawDefinition, extension })
51069
- );
51070
- }
51071
- result = addDrawDefinition({
51072
- drawDefinition,
51073
- event,
51074
- });
51075
- if (result.error) return result;
51076
- if (drawProfile?.withPlayoffs) {
51077
- const structureId = drawDefinition.structures[0].structureId;
51078
- const result = addPlayoffStructures({
51079
- idPrefix: drawProfile.idPrefix,
51080
- ...drawProfile.withPlayoffs,
51081
- tournamentRecord,
51082
- drawDefinition,
51083
- isMock: true,
51084
- structureId,
51085
- event,
51086
- });
51087
- if (result?.error) return result;
51088
- }
51089
- // TODO: enable { outcomes: [] } in eventProfile: { drawProfiles }
51090
- const manual = drawProfile?.automated === false;
51091
- if (!manual && completeAllMatchUps) {
51092
- const matchUpFormat = drawProfile?.matchUpFormat;
51093
- const result = completeDrawMatchUps({
51094
- matchUpStatusProfile,
51095
- completeAllMatchUps,
51096
- randomWinningSide,
51097
- drawDefinition,
51098
- matchUpFormat,
51099
- });
51100
- if (result.error) return result;
51101
- if (drawProfile?.drawType === ROUND_ROBIN_WITH_PLAYOFF) {
51102
- const mainStructure = drawDefinition.structures.find(
51103
- (structure) => structure.stage === MAIN
51104
- );
51105
- let result = automatedPlayoffPositioning({
51106
- structureId: mainStructure.structureId,
51107
- tournamentRecord,
51108
- drawDefinition,
51109
- event,
51110
- });
51111
- if (result.error) return result;
51112
- result = completeDrawMatchUps({
51113
- completeAllMatchUps,
51114
- matchUpStatusProfile,
51115
- randomWinningSide,
51116
- matchUpFormat,
51117
- drawDefinition,
51118
- });
51119
- if (result.error) return result;
51120
- }
51121
- }
51122
- }
51123
- }
51124
- }
51125
- */
51126
-
51127
51010
  return {
51128
51011
  drawIds,
51129
51012
  eventId,
@@ -51131,47 +51014,10 @@ function generateEventWithFlights({
51131
51014
  };
51132
51015
  }
51133
51016
 
51134
- function processTieFormat({
51135
- tieFormat,
51136
- tieFormatName,
51137
- drawSize,
51138
- alternatesCount = 0
51139
- }) {
51140
- var _tieFormat, _tieFormat$collection;
51141
-
51142
- let maxDoublesCount = 0,
51143
- maxSinglesCount = 0;
51144
- tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
51145
- namedFormat: tieFormatName
51146
- });
51147
- (_tieFormat = tieFormat) === null || _tieFormat === void 0 ? void 0 : (_tieFormat$collection = _tieFormat.collectionDefinitions) === null || _tieFormat$collection === void 0 ? void 0 : _tieFormat$collection.forEach(collectionDefinition => {
51148
- // ensure every collectionDefinition has a collectionId
51149
- if (!collectionDefinition.collectionId) collectionDefinition.collectionId = UUID();
51150
-
51151
- if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === DOUBLES$1) {
51152
- const doublesCount = collectionDefinition.matchUpCount;
51153
- maxDoublesCount = Math.max(maxDoublesCount, doublesCount);
51154
- }
51155
-
51156
- if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === SINGLES$1) {
51157
- const singlescount = collectionDefinition.matchUpCount;
51158
- maxSinglesCount = Math.max(maxSinglesCount, singlescount);
51159
- }
51160
- });
51161
- const teamSize = Math.max(maxSinglesCount, maxDoublesCount * 2);
51162
- const maxDoublesDraw = maxDoublesCount * (drawSize + alternatesCount);
51163
- const maxSinglesDraw = maxSinglesCount * (drawSize + alternatesCount);
51164
- return {
51165
- maxDoublesDraw,
51166
- maxSinglesDraw,
51167
- teamSize
51168
- };
51169
- }
51170
-
51171
51017
  function generateEventWithDraw({
51172
51018
  allUniqueParticipantIds = [],
51019
+ participantsProfile = {},
51173
51020
  matchUpStatusProfile,
51174
- participantsProfile,
51175
51021
  completeAllMatchUps,
51176
51022
  autoEntryPositions,
51177
51023
  randomWinningSide,
@@ -51179,6 +51025,7 @@ function generateEventWithDraw({
51179
51025
  tournamentRecord,
51180
51026
  drawProfile,
51181
51027
  startDate,
51028
+ drawIndex,
51182
51029
  goesTo,
51183
51030
  uuids
51184
51031
  }) {
@@ -51247,39 +51094,25 @@ function generateEventWithDraw({
51247
51094
  individualParticipantsCount = teamSize * drawSize;
51248
51095
  }
51249
51096
 
51097
+ const idPrefix = participantsProfile !== null && participantsProfile !== void 0 && participantsProfile.idPrefix ? `D-${drawIndex}-${participantsProfile === null || participantsProfile === void 0 ? void 0 : participantsProfile.idPrefix}` : undefined;
51250
51098
  const participantType = eventType === DOUBLES ? PAIR$1 : INDIVIDUAL$1;
51251
- const {
51252
- valuesInstanceLimit,
51253
- nationalityCodesCount,
51254
- nationalityCodeType,
51255
- nationalityCodes,
51256
- addressProps,
51257
- personIds,
51258
- inContext
51259
- } = participantsProfile || {};
51260
51099
  const {
51261
51100
  participants: unique
51262
- } = generateParticipants({
51101
+ } = generateParticipants({ ...participantsProfile,
51263
51102
  scaledParticipantsCount: drawProfile.scaledParticipantsCount,
51264
51103
  participantsCount: individualParticipantsCount,
51265
51104
  consideredDate: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.startDate,
51266
51105
  sex: gender || (participantsProfile === null || participantsProfile === void 0 ? void 0 : participantsProfile.sex),
51267
51106
  rankingRange: drawProfile.rankingRange,
51268
51107
  uuids: drawProfile.uuids || uuids,
51269
- nationalityCodesCount,
51270
- nationalityCodeType,
51271
- valuesInstanceLimit,
51272
51108
  ratingsParameters,
51273
- nationalityCodes,
51274
51109
  participantType,
51275
- addressProps,
51276
- personIds,
51277
- inContext,
51110
+ idPrefix,
51278
51111
  category
51279
51112
  });
51280
51113
 
51281
51114
  if (tournamentRecord) {
51282
- let result = addParticipants({
51115
+ const result = addParticipants({
51283
51116
  tournamentRecord,
51284
51117
  participants: unique
51285
51118
  });
@@ -51339,22 +51172,26 @@ function generateEventWithDraw({
51339
51172
  participantId
51340
51173
  }) => !allUniqueParticipantIds.includes(participantId));
51341
51174
  const participantIds = consideredParticipants.slice(0, participantsCount).map(p => p.participantId);
51342
- let result = addEventEntries({
51343
- entryStage: stage,
51344
- autoEntryPositions,
51345
- tournamentRecord,
51346
- participantIds,
51347
- event
51348
- });
51349
- if (result.error) return result; // alternates can still be taken from existing participants
51175
+
51176
+ if (participantIds !== null && participantIds !== void 0 && participantIds.length) {
51177
+ const result = addEventEntries({
51178
+ autoEntryPositions,
51179
+ entryStage: stage,
51180
+ tournamentRecord,
51181
+ participantIds,
51182
+ event
51183
+ });
51184
+ if (result.error) return result;
51185
+ } // alternates can still be taken from existing participants
51350
51186
  // when unique participants are used for DIRECT_ACCEPTANCE entries
51351
51187
 
51188
+
51352
51189
  const alternatesParticipantIds = excessParticipantAlternates && (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : (_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.filter(({
51353
51190
  participantId
51354
51191
  }) => !participantIds.includes(participantId)).filter(isEventParticipantType).filter(isEventGender).slice(0, alternatesCount || drawSize - participantsCount).map(p => p.participantId));
51355
51192
 
51356
51193
  if (alternatesParticipantIds !== null && alternatesParticipantIds !== void 0 && alternatesParticipantIds.length) {
51357
- result = addEventEntries({
51194
+ const result = addEventEntries({
51358
51195
  participantIds: alternatesParticipantIds,
51359
51196
  autoEntryPositions: false,
51360
51197
  entryStatus: ALTERNATE,
@@ -51526,9 +51363,6 @@ function generateEventWithDraw({
51526
51363
  }
51527
51364
  }
51528
51365
 
51529
- if (result.error) return {
51530
- error: result.error
51531
- };
51532
51366
  return { ...SUCCESS,
51533
51367
  event: definedAttributes(event),
51534
51368
  uniqueParticipantIds,
@@ -51586,6 +51420,340 @@ function generateVenues({
51586
51420
  return venueIds;
51587
51421
  }
51588
51422
 
51423
+ function modifyTournamentRecord({
51424
+ ratingsParameters: ratingsParameters$1 = ratingsParameters,
51425
+ participantsProfile = {},
51426
+ matchUpStatusProfile,
51427
+ completeAllMatchUps,
51428
+ autoEntryPositions,
51429
+ randomWinningSide,
51430
+ schedulingProfile,
51431
+ tournamentRecord,
51432
+ eventProfiles,
51433
+ venueProfiles,
51434
+ autoSchedule,
51435
+ drawProfiles,
51436
+ goesTo,
51437
+ uuids
51438
+ }) {
51439
+ var _tournamentRecord$par;
51440
+
51441
+ if (!tournamentRecord) return {
51442
+ error: MISSING_TOURNAMENT_RECORD
51443
+ };
51444
+ const allUniqueParticipantIds = [];
51445
+ const eventIds = [];
51446
+ const drawIds = [];
51447
+ eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
51448
+ const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
51449
+
51450
+ if (event !== null && event !== void 0 && event.gender) {
51451
+ eventProfile.gender = event.gender;
51452
+ }
51453
+ });
51454
+ const participantsCount = ((_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.length) || undefined;
51455
+ if (participantsCount && participantsProfile !== null && participantsProfile !== void 0 && participantsProfile.idPrefix) participantsProfile.idPrefix = `${participantsProfile.idPrefix}-${participantsCount}`;
51456
+ const result = addTournamentParticipants({
51457
+ startDate: tournamentRecord.startDate,
51458
+ participantsProfile,
51459
+ tournamentRecord,
51460
+ eventProfiles,
51461
+ drawProfiles,
51462
+ uuids
51463
+ });
51464
+ if (!result.success) return result;
51465
+
51466
+ if (eventProfiles) {
51467
+ var _tournamentRecord$eve;
51468
+
51469
+ let eventIndex = ((_tournamentRecord$eve = tournamentRecord.events) === null || _tournamentRecord$eve === void 0 ? void 0 : _tournamentRecord$eve.length) || 0;
51470
+
51471
+ for (const eventProfile of eventProfiles) {
51472
+ let {
51473
+ ratingsParameters
51474
+ } = eventProfile;
51475
+ const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
51476
+
51477
+ if (!event) {
51478
+ const {
51479
+ error,
51480
+ eventId,
51481
+ drawIds: generatedDrawIds,
51482
+ uniqueParticipantIds
51483
+ } = generateEventWithFlights({
51484
+ startDate: tournamentRecord.startDate,
51485
+ allUniqueParticipantIds,
51486
+ matchUpStatusProfile,
51487
+ participantsProfile,
51488
+ completeAllMatchUps,
51489
+ autoEntryPositions,
51490
+ randomWinningSide,
51491
+ ratingsParameters,
51492
+ tournamentRecord,
51493
+ eventProfile,
51494
+ eventIndex,
51495
+ uuids
51496
+ });
51497
+ if (error) return {
51498
+ error
51499
+ };
51500
+ if (generatedDrawIds) drawIds.push(...generatedDrawIds);
51501
+ eventIds.push(eventId);
51502
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51503
+ eventIndex += 1;
51504
+ } else {
51505
+ const {
51506
+ gender,
51507
+ category,
51508
+ eventType
51509
+ } = event;
51510
+ const {
51511
+ drawProfiles
51512
+ } = eventProfile;
51513
+ const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
51514
+
51515
+ if (drawProfiles) {
51516
+ const {
51517
+ stageParticipantsCount,
51518
+ uniqueParticipantsCount,
51519
+ uniqueParticipantStages
51520
+ } = getStageParticipantsCount({
51521
+ drawProfiles,
51522
+ category,
51523
+ gender
51524
+ });
51525
+ const {
51526
+ uniqueDrawParticipants = [],
51527
+ uniqueParticipantIds = []
51528
+ } = uniqueParticipantStages ? generateEventParticipants({
51529
+ event: {
51530
+ eventType,
51531
+ category,
51532
+ gender
51533
+ },
51534
+ uniqueParticipantsCount,
51535
+ participantsProfile,
51536
+ ratingsParameters,
51537
+ tournamentRecord,
51538
+ eventProfile,
51539
+ uuids
51540
+ }) : {};
51541
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
51542
+ const {
51543
+ stageParticipants
51544
+ } = getStageParticipants({
51545
+ targetParticipants: tournamentRecord.participants || [],
51546
+ allUniqueParticipantIds,
51547
+ stageParticipantsCount,
51548
+ eventParticipantType
51549
+ });
51550
+ let result = generateFlights({
51551
+ uniqueDrawParticipants,
51552
+ autoEntryPositions,
51553
+ stageParticipants,
51554
+ tournamentRecord,
51555
+ drawProfiles,
51556
+ category,
51557
+ gender,
51558
+ event
51559
+ });
51560
+ if (result.error) return result;
51561
+ result = generateFlightDrawDefinitions({
51562
+ matchUpStatusProfile,
51563
+ completeAllMatchUps,
51564
+ randomWinningSide,
51565
+ tournamentRecord,
51566
+ drawProfiles,
51567
+ event
51568
+ });
51569
+ if (result.error) return result;
51570
+ drawIds.push(...result.drawIds);
51571
+ }
51572
+ }
51573
+ }
51574
+ }
51575
+
51576
+ if (drawProfiles) {
51577
+ let drawIndex = (tournamentRecord.events || []).map(event => {
51578
+ var _event$drawDefinition;
51579
+
51580
+ return ((_event$drawDefinition = event.drawDefinitions) === null || _event$drawDefinition === void 0 ? void 0 : _event$drawDefinition.map(() => 1)) || [];
51581
+ }).flat().reduce((a, b) => a + b, 0);
51582
+
51583
+ for (const drawProfile of drawProfiles) {
51584
+ const {
51585
+ drawId,
51586
+ eventId,
51587
+ event,
51588
+ error,
51589
+ uniqueParticipantIds
51590
+ } = generateEventWithDraw({
51591
+ startDate: tournamentRecord.startDate,
51592
+ allUniqueParticipantIds,
51593
+ matchUpStatusProfile,
51594
+ participantsProfile,
51595
+ completeAllMatchUps,
51596
+ autoEntryPositions,
51597
+ randomWinningSide,
51598
+ ratingsParameters: ratingsParameters$1,
51599
+ tournamentRecord,
51600
+ drawProfile,
51601
+ drawIndex,
51602
+ goesTo,
51603
+ uuids
51604
+ });
51605
+ if (error) return {
51606
+ error
51607
+ };
51608
+ const result = addEvent({
51609
+ tournamentRecord,
51610
+ event
51611
+ });
51612
+ if (result.error) return result;
51613
+ if (drawId) drawIds.push(drawId);
51614
+ eventIds.push(eventId);
51615
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51616
+ drawIndex += 1;
51617
+ }
51618
+ }
51619
+
51620
+ const venueIds = venueProfiles !== null && venueProfiles !== void 0 && venueProfiles.length ? generateVenues({
51621
+ tournamentRecord,
51622
+ venueProfiles
51623
+ }) : [];
51624
+ let scheduledRounds;
51625
+ let schedulerResult = {};
51626
+
51627
+ if (schedulingProfile) {
51628
+ const result = generateScheduleTimes({
51629
+ schedulingProfile,
51630
+ tournamentRecord
51631
+ });
51632
+ if (result.error) return result;
51633
+ scheduledRounds = result.scheduledRounds;
51634
+
51635
+ if (autoSchedule) {
51636
+ const {
51637
+ tournamentId
51638
+ } = tournamentRecord;
51639
+ const tournamentRecords = {
51640
+ [tournamentId]: tournamentRecord
51641
+ };
51642
+ schedulerResult = scheduleProfileRounds({
51643
+ tournamentRecords
51644
+ });
51645
+ }
51646
+ }
51647
+
51648
+ return { ...SUCCESS,
51649
+ drawIds,
51650
+ eventIds,
51651
+ venueIds,
51652
+ scheduledRounds,
51653
+ schedulerResult
51654
+ };
51655
+ }
51656
+
51657
+ const amendsGovernor = {
51658
+ anonymizeTournamentRecord,
51659
+ modifyTournamentRecord
51660
+ };
51661
+
51662
+ function generateSchedulingProfile({
51663
+ schedulingProfile,
51664
+ tournamentRecord
51665
+ }) {
51666
+ if (typeof schedulingProfile !== 'object') return {
51667
+ error: INVALID_VALUES
51668
+ };
51669
+ const containedStructures = getContainedStructures({
51670
+ tournamentRecord
51671
+ }).containedStructures;
51672
+ const {
51673
+ matchUps
51674
+ } = allTournamentMatchUps({
51675
+ tournamentRecord
51676
+ });
51677
+ const {
51678
+ tournamentId
51679
+ } = tournamentRecord;
51680
+ const scheduledRounds = [];
51681
+
51682
+ for (const dateProfile of schedulingProfile) {
51683
+ const {
51684
+ scheduleDate,
51685
+ venues = []
51686
+ } = dateProfile;
51687
+
51688
+ for (const venue of venues) {
51689
+ const {
51690
+ rounds,
51691
+ venueId
51692
+ } = venue;
51693
+
51694
+ for (const round of rounds) {
51695
+ const {
51696
+ drawId,
51697
+ winnerFinishingPositionRange,
51698
+ roundSegment
51699
+ } = round;
51700
+ const targetMatchUps = matchUps.filter(matchUp => {
51701
+ var _matchUp$finishingPos;
51702
+
51703
+ const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
51704
+ const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
51705
+ const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
51706
+ return target;
51707
+ });
51708
+ const targetMatchUp = targetMatchUps[0];
51709
+
51710
+ if (targetMatchUp) {
51711
+ const {
51712
+ eventId,
51713
+ roundNumber,
51714
+ drawName,
51715
+ structureName,
51716
+ roundName
51717
+ } = targetMatchUp;
51718
+ let structureId = targetMatchUp.structureId;
51719
+
51720
+ if (roundNumber && !winnerFinishingPositionRange) {
51721
+ structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
51722
+ }
51723
+
51724
+ const roundToSchedule = {
51725
+ tournamentId,
51726
+ eventId,
51727
+ drawId,
51728
+ structureId,
51729
+ roundNumber,
51730
+ roundSegment
51731
+ };
51732
+ let result = addSchedulingProfileRound({
51733
+ tournamentRecords: {
51734
+ [tournamentId]: tournamentRecord
51735
+ },
51736
+ scheduleDate,
51737
+ venueId,
51738
+ round: roundToSchedule
51739
+ });
51740
+ if (result.error) return result;
51741
+ scheduledRounds.push({
51742
+ drawName,
51743
+ structureName,
51744
+ roundName,
51745
+ ...roundToSchedule
51746
+ });
51747
+ }
51748
+ }
51749
+ }
51750
+ }
51751
+
51752
+ return {
51753
+ scheduledRounds
51754
+ };
51755
+ }
51756
+
51589
51757
  /**
51590
51758
  *
51591
51759
  * Generate a complete tournamentRecord from the following attributes
@@ -51631,12 +51799,6 @@ function generateTournamentRecord({
51631
51799
  goesTo,
51632
51800
  uuids
51633
51801
  } = {}) {
51634
- let {
51635
- participantsCount,
51636
- participantType = INDIVIDUAL$1
51637
- } = participantsProfile || {};
51638
- const specifiedParicipantsCount = participantsCount || 0; // capture this to ensure calculated participantsCount is not below
51639
-
51640
51802
  if (startDate && !isValidDateString(startDate) || endDate && !isValidDateString(endDate)) return {
51641
51803
  error: INVALID_DATE
51642
51804
  };
@@ -51678,165 +51840,13 @@ function generateTournamentRecord({
51678
51840
  }
51679
51841
  }
51680
51842
 
51681
- let largestDoublesDraw = 0,
51682
- largestSinglesDraw = 0,
51683
- largestTeamSize = 0,
51684
- largestTeamDraw = 0;
51685
-
51686
- const processDrawProfile = ({
51687
- alternatesCount = 0,
51688
- uniqueParticipants,
51689
- tieFormatName,
51690
- drawSize = 0,
51691
- eventType,
51692
- tieFormat,
51693
- category,
51694
- gender,
51695
- stage
51696
- }) => {
51697
- const isDoubles = eventType === DOUBLES;
51698
- const isTeam = eventType === TEAM$2;
51699
- const requiresUniqueParticipants = uniqueParticipants || stage === QUALIFYING || category || gender;
51700
-
51701
- if (isTeam && !requiresUniqueParticipants) {
51702
- largestTeamDraw = Math.max(largestTeamDraw, drawSize + alternatesCount);
51703
- tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
51704
- namedFormat: tieFormatName
51705
- });
51706
- const {
51707
- teamSize,
51708
- maxDoublesDraw,
51709
- maxSinglesDraw
51710
- } = processTieFormat({
51711
- alternatesCount,
51712
- tieFormatName,
51713
- tieFormat,
51714
- drawSize
51715
- });
51716
- largestTeamSize = Math.max(largestTeamSize, teamSize);
51717
- largestDoublesDraw = Math.max(largestDoublesDraw, maxDoublesDraw);
51718
- largestSinglesDraw = Math.max(largestSinglesDraw, maxSinglesDraw);
51719
- }
51720
-
51721
- if (isDoubles && drawSize + alternatesCount && drawSize + alternatesCount > largestDoublesDraw) {
51722
- largestDoublesDraw = drawSize + alternatesCount;
51723
- }
51724
-
51725
- if (!isDoubles && !isTeam && drawSize && drawSize > largestSinglesDraw) {
51726
- largestSinglesDraw = drawSize + alternatesCount;
51727
- }
51728
- };
51729
-
51730
- eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
51731
- const {
51732
- tieFormatName: eventTieFormatName,
51733
- tieFormat: eventTieFormat,
51734
- drawProfiles,
51735
- eventType,
51736
- category
51737
- } = eventProfile;
51738
-
51739
- if (drawProfiles) {
51740
- for (const drawProfile of drawProfiles) {
51741
- const {
51742
- tieFormatName,
51743
- tieFormat
51744
- } = drawProfile;
51745
- processDrawProfile({ ...drawProfile,
51746
- tieFormatName: tieFormatName || eventTieFormatName,
51747
- tieFormat: tieFormat || eventTieFormat,
51748
- eventType,
51749
- category
51750
- });
51751
- }
51752
- }
51753
- });
51754
-
51755
- if (drawProfiles) {
51756
- for (const drawProfile of drawProfiles) {
51757
- processDrawProfile(drawProfile);
51758
- }
51759
- }
51760
-
51761
- const individualCompetitorsCount = Math.max(largestTeamDraw * largestTeamSize, largestDoublesDraw * 2, largestSinglesDraw);
51762
- if (largestDoublesDraw) participantType = PAIR$1;
51763
- if ((participantsCount || specifiedParicipantsCount) < individualCompetitorsCount) participantsCount = individualCompetitorsCount;
51764
-
51765
- if (participantsCount && largestDoublesDraw && [PAIR$1, TEAM$2].includes(participantType)) {
51766
- // if we are generating PAIRs or TEAMs...
51767
- if (largestSinglesDraw && Math.floor(largestSinglesDraw / 2) > largestDoublesDraw) {
51768
- // if the half the singles draw is still larger than doubles draw
51769
- participantsCount = Math.floor(largestSinglesDraw / 2);
51770
- } else if (!largestSinglesDraw || largestDoublesDraw * 2 >= largestSinglesDraw) {
51771
- // otherwise participantsCount can be cut in half
51772
- participantsCount = Math.ceil(participantsCount / 2);
51773
- }
51774
- }
51775
-
51776
- if (participantsCount === undefined) participantsCount = 32;
51777
- if (participantsCount < specifiedParicipantsCount) participantsCount = specifiedParicipantsCount;
51778
- const {
51779
- nationalityCodesCount,
51780
- nationalityCodeType,
51781
- valuesInstanceLimit,
51782
- nationalityCodes,
51783
- personExtensions,
51784
- addressProps,
51785
- personData,
51786
- personIds,
51787
- inContext,
51788
- teamKey,
51789
- sex
51790
- } = participantsProfile || {};
51791
- const {
51792
- participants
51793
- } = generateParticipants({
51794
- consideredDate: startDate,
51795
- valuesInstanceLimit,
51796
- nationalityCodesCount,
51797
- nationalityCodeType,
51798
- nationalityCodes,
51799
- personExtensions,
51800
- addressProps,
51801
- personData,
51802
- sex,
51803
- participantsCount,
51804
- participantType,
51805
- personIds,
51806
- uuids,
51807
- inContext
51808
- });
51809
- let result = addParticipants({
51810
- tournamentRecord,
51811
- participants
51812
- });
51813
- if (!result.success) return result;
51814
-
51815
- if (teamKey) {
51816
- const result = generateTeamsFromParticipantAttribute({
51817
- tournamentRecord,
51818
- ...teamKey
51819
- });
51820
- if (result.error) return result;
51821
- } // generate Team participants
51822
-
51823
-
51824
- const allIndividualParticipantIds = participants.filter(({
51825
- participantType
51826
- }) => participantType === INDIVIDUAL$1).map(getParticipantId);
51827
- const teamParticipants = generateRange(0, largestTeamDraw).map(teamIndex => {
51828
- const individualParticipantIds = allIndividualParticipantIds.slice(teamIndex * largestTeamSize, (teamIndex + 1) * largestTeamSize);
51829
- return {
51830
- participantName: `Team ${teamIndex + 1}`,
51831
- participantRole: COMPETITOR,
51832
- participantType: TEAM$2,
51833
- participantId: UUID(),
51834
- individualParticipantIds
51835
- };
51836
- });
51837
- result = addParticipants({
51843
+ const result = addTournamentParticipants({
51844
+ participantsProfile,
51838
51845
  tournamentRecord,
51839
- participants: teamParticipants
51846
+ eventProfiles,
51847
+ drawProfiles,
51848
+ startDate,
51849
+ uuids
51840
51850
  });
51841
51851
  if (!result.success) return result;
51842
51852
  const drawIds = [],
@@ -51844,6 +51854,8 @@ function generateTournamentRecord({
51844
51854
  allUniqueParticipantIds = [];
51845
51855
 
51846
51856
  if (drawProfiles) {
51857
+ let drawIndex = 0;
51858
+
51847
51859
  for (const drawProfile of drawProfiles) {
51848
51860
  const {
51849
51861
  drawId,
@@ -51862,7 +51874,9 @@ function generateTournamentRecord({
51862
51874
  tournamentRecord,
51863
51875
  drawProfile,
51864
51876
  startDate,
51865
- goesTo
51877
+ drawIndex,
51878
+ goesTo,
51879
+ uuids
51866
51880
  });
51867
51881
  if (error) return {
51868
51882
  error
@@ -51875,10 +51889,13 @@ function generateTournamentRecord({
51875
51889
  if (drawId) drawIds.push(drawId);
51876
51890
  eventIds.push(eventId);
51877
51891
  if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51892
+ drawIndex += 1;
51878
51893
  }
51879
51894
  }
51880
51895
 
51881
51896
  if (eventProfiles) {
51897
+ let eventIndex = 0;
51898
+
51882
51899
  for (const eventProfile of eventProfiles) {
51883
51900
  const {
51884
51901
  error,
@@ -51895,7 +51912,9 @@ function generateTournamentRecord({
51895
51912
  ratingsParameters: ratingsParameters$1,
51896
51913
  tournamentRecord,
51897
51914
  eventProfile,
51898
- startDate
51915
+ eventIndex,
51916
+ startDate,
51917
+ uuids
51899
51918
  });
51900
51919
  if (error) return {
51901
51920
  error
@@ -51903,6 +51922,7 @@ function generateTournamentRecord({
51903
51922
  if (generatedDrawIds) drawIds.push(...generatedDrawIds);
51904
51923
  eventIds.push(eventId);
51905
51924
  if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51925
+ eventIndex += 1;
51906
51926
  }
51907
51927
  }
51908
51928
 
@@ -52158,4 +52178,5 @@ exports.tournamentEngine = tournamentEngine;
52158
52178
  exports.tournamentEngineAsync = tournamentEngineAsync;
52159
52179
  exports.utilities = utilities;
52160
52180
  exports.venueConstants = venueConstants;
52181
+ exports.version = factoryVersion;
52161
52182
  //# sourceMappingURL=tods-competition-factory.development.cjs.js.map