tods-competition-factory 0.63.2 → 0.65.0

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.
@@ -16322,7 +16322,7 @@ function updateTieMatchUpScore({
16322
16322
  });
16323
16323
  if (result.error) return result;
16324
16324
  const matchUp = result.matchUp;
16325
- const tieFormat = matchUp.tieFormat || (structure === null || structure === void 0 ? void 0 : structure.tieFormat) || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat);
16325
+ const tieFormat = matchUp.tieFormat || (structure === null || structure === void 0 ? void 0 : structure.tieFormat) || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat) || undefined;
16326
16326
  const {
16327
16327
  winningSide,
16328
16328
  set,
@@ -18057,9 +18057,9 @@ function getAvailableAdHocParticipantIds({
18057
18057
  drawPosition,
18058
18058
  participantId
18059
18059
  }) => roundDrawPositions.includes(drawPosition) && participantId).map(getParticipantId);
18060
- const enteredParticipantIds = drawDefinition.entries.filter(({
18060
+ const enteredParticipantIds = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries.filter(({
18061
18061
  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
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
18063
18063
 
18064
18064
  const availableParticipantIds = enteredParticipantIds.filter(participantId => !roundAssignedParticipantIds.includes(participantId));
18065
18065
  return availableParticipantIds;
@@ -19900,7 +19900,7 @@ function setMatchUpStatus$2(params) {
19900
19900
  matchUpsMap,
19901
19901
  event
19902
19902
  });
19903
- const tieFormat = dualMatchUp.tieFormat || drawDefinition.tieFormat;
19903
+ const tieFormat = (dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.tieFormat) || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat) || undefined;
19904
19904
  const {
19905
19905
  projectedWinningSide
19906
19906
  } = getProjectedDualWinningSide({
@@ -27550,9 +27550,6 @@ function bulkRescheduleMatchUps({
27550
27550
  matchUpIds,
27551
27551
  dryRun
27552
27552
  }) {
27553
- if (!tournamentRecords) return {
27554
- error: MISSING_TOURNAMENT_RECORDS
27555
- };
27556
27553
  if (!matchUpIds || !Array.isArray(matchUpIds)) return {
27557
27554
  error: MISSING_MATCHUP_IDS
27558
27555
  };
@@ -28043,7 +28040,7 @@ const scheduleGovernor$1 = {
28043
28040
  };
28044
28041
 
28045
28042
  function factoryVersion() {
28046
- return '0.63.2';
28043
+ return '0.65.0';
28047
28044
  }
28048
28045
 
28049
28046
  function attachPolicies$2({
@@ -32760,7 +32757,7 @@ function addPlayoffStructures$1(params) {
32760
32757
  }) => addedMatchUpIds.includes(matchUpId));
32761
32758
 
32762
32759
  if (addedMatchUps.length) {
32763
- const tieFormat = drawDefinition.tieFormat || (event === null || event === void 0 ? void 0 : event.tieFormat);
32760
+ const tieFormat = drawDefinition.tieFormat || (event === null || event === void 0 ? void 0 : event.tieFormat) || undefined;
32764
32761
 
32765
32762
  if (tieFormat) {
32766
32763
  addedMatchUps.forEach(matchUp => {
@@ -33882,17 +33879,17 @@ function generateDrawType(params = {}) {
33882
33879
  tieFormat,
33883
33880
  matchUpType
33884
33881
  } = params;
33885
- tieFormat = tieFormat || drawDefinition.tieFormat;
33882
+ tieFormat = tieFormat || drawDefinition.tieFormat || undefined;
33886
33883
  matchUpType = matchUpType || drawDefinition.matchUpType || SINGLES$1;
33887
33884
  const drawSize = getStageDrawPositionsCount({
33888
33885
  stage,
33889
33886
  drawDefinition
33890
33887
  });
33891
- Object.assign(params, {
33888
+ Object.assign(params, definedAttributes({
33892
33889
  drawSize,
33893
33890
  matchUpType,
33894
33891
  tieFormat
33895
- });
33892
+ }));
33896
33893
  const validDoubleEliminationSize = isPowerOf2(drawSize * 2 / 3); // check that drawSize is a valid value
33897
33894
 
33898
33895
  const invalidDrawSize = drawSize < 2 || !staggeredEntry && ![FEED_IN$1, AD_HOC].includes(drawType) && (drawType === ROUND_ROBIN && drawSize < 3 || drawType === DOUBLE_ELIMINATION && !validDoubleEliminationSize || ![ROUND_ROBIN, DOUBLE_ELIMINATION, ROUND_ROBIN_WITH_PLAYOFF].includes(drawType) && !isPowerOf2(drawSize));
@@ -34636,7 +34633,7 @@ function getAssignedParticipantIds({
34636
34633
  function refreshEntryPositions({
34637
34634
  entries = []
34638
34635
  } = {}) {
34639
- const stagedEntries = entries.reduce((stages, entry) => {
34636
+ const stagedEntries = entries.filter(Boolean).reduce((stages, entry) => {
34640
34637
  const {
34641
34638
  entryStage,
34642
34639
  entryStatus
@@ -34848,6 +34845,8 @@ function modifyEntriesStatus({
34848
34845
  return true;
34849
34846
  });
34850
34847
  (_event$drawDefinition4 = event.drawDefinitions) === null || _event$drawDefinition4 === void 0 ? void 0 : _event$drawDefinition4.every(drawDefinition => {
34848
+ var _drawDefinition$entri2;
34849
+
34851
34850
  const result = updateEntryStatus(drawDefinition.entries);
34852
34851
 
34853
34852
  if (result.error) {
@@ -34855,7 +34854,7 @@ function modifyEntriesStatus({
34855
34854
  return false;
34856
34855
  }
34857
34856
 
34858
- drawDefinition.entries = drawDefinition.entries.filter(({
34857
+ drawDefinition.entries = (_drawDefinition$entri2 = drawDefinition.entries) === null || _drawDefinition$entri2 === void 0 ? void 0 : _drawDefinition$entri2.filter(({
34859
34858
  participantId
34860
34859
  }) => !participantIds.includes(participantId));
34861
34860
  return true;
@@ -35192,8 +35191,8 @@ function participantInEntries({
35192
35191
  function addDrawEntry({
35193
35192
  entryStatus = DIRECT_ACCEPTANCE,
35194
35193
  entryStage = MAIN,
35195
- entryPosition,
35196
35194
  drawDefinition,
35195
+ entryPosition,
35197
35196
  participantId,
35198
35197
  participant
35199
35198
  }) {
@@ -35225,7 +35224,7 @@ function addDrawEntry({
35225
35224
  };
35226
35225
  }
35227
35226
 
35228
- participantId = participantId || participant && participant.participantId;
35227
+ participantId = participantId || (participant === null || participant === void 0 ? void 0 : participant.participantId);
35229
35228
  if (!participantId) return {
35230
35229
  error: MISSING_PARTICIPANT_ID
35231
35230
  };
@@ -35347,7 +35346,7 @@ function addDrawEntries$1({
35347
35346
  };
35348
35347
  }
35349
35348
 
35350
- participantIds.forEach(participantId => {
35349
+ participantIds.filter(Boolean).forEach(participantId => {
35351
35350
  const entry = Object.assign({
35352
35351
  participantId
35353
35352
  }, {
@@ -42665,7 +42664,7 @@ function getTieMatchUpContext({
42665
42664
  drawDefinition,
42666
42665
  matchUpsMap
42667
42666
  });
42668
- const tieFormat = dualMatchUp.tieFormat || structure.tieFormat || drawDefinition.tieFormat || event.tieFormat;
42667
+ const tieFormat = dualMatchUp.tieFormat || structure.tieFormat || drawDefinition.tieFormat || event.tieFormat || undefined;
42669
42668
  return {
42670
42669
  relevantAssignments,
42671
42670
  collectionPosition,
@@ -45705,7 +45704,7 @@ function getTieFormat({
45705
45704
  const structureDefaultTieFormat = (_structure = structure) === null || _structure === void 0 ? void 0 : _structure.tieFormat;
45706
45705
  const drawDefaultTieFormat = (_drawDefinition = drawDefinition) === null || _drawDefinition === void 0 ? void 0 : _drawDefinition.tieFormat;
45707
45706
  const eventDefaultTieFormat = event === null || event === void 0 ? void 0 : event.tieFormat;
45708
- const tieFormat = (matchUpResult === null || matchUpResult === void 0 ? void 0 : (_matchUpResult$matchU = matchUpResult.matchUp) === null || _matchUpResult$matchU === void 0 ? void 0 : _matchUpResult$matchU.tieFormat) || structureDefaultTieFormat || drawDefaultTieFormat || eventDefaultTieFormat;
45707
+ const tieFormat = (matchUpResult === null || matchUpResult === void 0 ? void 0 : (_matchUpResult$matchU = matchUpResult.matchUp) === null || _matchUpResult$matchU === void 0 ? void 0 : _matchUpResult$matchU.tieFormat) || structureDefaultTieFormat || drawDefaultTieFormat || eventDefaultTieFormat || undefined;
45709
45708
  return {
45710
45709
  structureDefaultTieFormat,
45711
45710
  eventDefaultTieFormat,
@@ -49827,10 +49826,12 @@ function completeDrawMatchUps({
49827
49826
  completeAllMatchUps,
49828
49827
  randomWinningSide,
49829
49828
  drawDefinition,
49829
+ completionGoal,
49830
49830
  matchUpFormat,
49831
49831
  event
49832
49832
  }) {
49833
- const sortedStructures = drawDefinition.structures.slice().sort(structureSort); // to support legacy tests it is possible to use completeAllMatchUps
49833
+ const sortedStructures = drawDefinition.structures.slice().sort(structureSort);
49834
+ let completedCount = 0; // to support legacy tests it is possible to use completeAllMatchUps
49834
49835
  // to pass a score string that will be applied to all matchUps
49835
49836
 
49836
49837
  const scoreString = typeof completeAllMatchUps === 'string' && completeAllMatchUps;
@@ -49854,6 +49855,7 @@ function completeDrawMatchUps({
49854
49855
  }) => !winningSide).sort(matchUpSort).map(getMatchUpId$1);
49855
49856
 
49856
49857
  for (const matchUpId of sortedMatchUpIds) {
49858
+ if (!isNaN(completionGoal) && completedCount >= completionGoal) break;
49857
49859
  const {
49858
49860
  matchUps
49859
49861
  } = getAllStructureMatchUps({
@@ -49877,11 +49879,13 @@ function completeDrawMatchUps({
49877
49879
  scoreString
49878
49880
  });
49879
49881
  if (result.error) return result;
49882
+ completedCount += 1;
49880
49883
  }
49881
49884
  }
49882
49885
  }
49883
49886
 
49884
- return { ...SUCCESS
49887
+ return { ...SUCCESS,
49888
+ completedCount
49885
49889
  };
49886
49890
  }
49887
49891
  function completeDrawMatchUp({
@@ -50061,18 +50065,21 @@ function generateFlightDrawDefinitions({
50061
50065
  } // TODO: enable { outcomes: [] } in eventProfile: { drawProfiles }
50062
50066
 
50063
50067
 
50068
+ const completionGoal = drawProfile === null || drawProfile === void 0 ? void 0 : drawProfile.completionGoal;
50064
50069
  const manual = (drawProfile === null || drawProfile === void 0 ? void 0 : drawProfile.automated) === false;
50065
50070
 
50066
- if (!manual && completeAllMatchUps) {
50071
+ if (!manual && (completeAllMatchUps || completionGoal)) {
50067
50072
  const matchUpFormat = drawProfile === null || drawProfile === void 0 ? void 0 : drawProfile.matchUpFormat;
50068
50073
  const result = completeDrawMatchUps({
50069
50074
  matchUpStatusProfile,
50070
- completeAllMatchUps,
50075
+ completeAllMatchUps: !completionGoal && completeAllMatchUps,
50071
50076
  randomWinningSide,
50077
+ completionGoal,
50072
50078
  drawDefinition,
50073
50079
  matchUpFormat
50074
50080
  });
50075
50081
  if (result.error) return result;
50082
+ const completedCount = result.completedCount;
50076
50083
 
50077
50084
  if ((drawProfile === null || drawProfile === void 0 ? void 0 : drawProfile.drawType) === ROUND_ROBIN_WITH_PLAYOFF) {
50078
50085
  const mainStructure = drawDefinition.structures.find(structure => structure.stage === MAIN);
@@ -50083,12 +50090,14 @@ function generateFlightDrawDefinitions({
50083
50090
  event
50084
50091
  });
50085
50092
  if (result.error) return result;
50093
+ const playoffCompletionGoal = completionGoal ? completionGoal - completedCount : undefined;
50086
50094
  result = completeDrawMatchUps({
50087
- completeAllMatchUps,
50095
+ completeAllMatchUps: !completionGoal && completeAllMatchUps,
50096
+ completionGoal: completionGoal ? playoffCompletionGoal : undefined,
50088
50097
  matchUpStatusProfile,
50089
50098
  randomWinningSide,
50090
- matchUpFormat,
50091
- drawDefinition
50099
+ drawDefinition,
50100
+ matchUpFormat
50092
50101
  });
50093
50102
  if (result.error) return result;
50094
50103
  }
@@ -50395,6 +50404,258 @@ function addScaleItem({
50395
50404
  }
50396
50405
  }
50397
50406
 
50407
+ function processTieFormat({
50408
+ tieFormat,
50409
+ tieFormatName,
50410
+ drawSize,
50411
+ alternatesCount = 0
50412
+ }) {
50413
+ var _tieFormat, _tieFormat$collection;
50414
+
50415
+ let maxDoublesCount = 0,
50416
+ maxSinglesCount = 0;
50417
+ tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
50418
+ namedFormat: tieFormatName
50419
+ });
50420
+ (_tieFormat = tieFormat) === null || _tieFormat === void 0 ? void 0 : (_tieFormat$collection = _tieFormat.collectionDefinitions) === null || _tieFormat$collection === void 0 ? void 0 : _tieFormat$collection.forEach(collectionDefinition => {
50421
+ // ensure every collectionDefinition has a collectionId
50422
+ if (!collectionDefinition.collectionId) collectionDefinition.collectionId = UUID();
50423
+
50424
+ if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === DOUBLES$1) {
50425
+ const doublesCount = collectionDefinition.matchUpCount;
50426
+ maxDoublesCount = Math.max(maxDoublesCount, doublesCount);
50427
+ }
50428
+
50429
+ if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === SINGLES$1) {
50430
+ const singlescount = collectionDefinition.matchUpCount;
50431
+ maxSinglesCount = Math.max(maxSinglesCount, singlescount);
50432
+ }
50433
+ });
50434
+ const teamSize = Math.max(maxSinglesCount, maxDoublesCount * 2);
50435
+ const maxDoublesDraw = maxDoublesCount * (drawSize + alternatesCount);
50436
+ const maxSinglesDraw = maxSinglesCount * (drawSize + alternatesCount);
50437
+ return {
50438
+ maxDoublesDraw,
50439
+ maxSinglesDraw,
50440
+ teamSize
50441
+ };
50442
+ }
50443
+
50444
+ function getParticipantsCount({
50445
+ participantsProfile,
50446
+ eventProfiles,
50447
+ drawProfiles
50448
+ }) {
50449
+ let {
50450
+ participantsCount,
50451
+ participantType = INDIVIDUAL$1
50452
+ } = participantsProfile || {};
50453
+ const specifiedParicipantsCount = participantsCount || 0; // capture this to ensure calculated participantsCount is not below
50454
+
50455
+ let largestDoublesDraw = 0,
50456
+ largestSinglesDraw = 0,
50457
+ largestTeamSize = 0,
50458
+ largestTeamDraw = 0,
50459
+ uniqueParticipantsCount = 0;
50460
+
50461
+ const processDrawProfile = ({
50462
+ alternatesCount = 0,
50463
+ uniqueParticipants,
50464
+ tieFormatName,
50465
+ drawSize = 0,
50466
+ eventType,
50467
+ tieFormat,
50468
+ category,
50469
+ gender,
50470
+ stage
50471
+ }) => {
50472
+ const isDoubles = eventType === DOUBLES;
50473
+ const isTeam = eventType === TEAM$2;
50474
+ const requiresUniqueParticipants = uniqueParticipants || stage === QUALIFYING || category || gender;
50475
+
50476
+ if (requiresUniqueParticipants) {
50477
+ if (isDoubles) {
50478
+ uniqueParticipantsCount += (drawSize + alternatesCount) * 2;
50479
+ } else {
50480
+ uniqueParticipantsCount += drawSize + alternatesCount;
50481
+ }
50482
+ } else {
50483
+ if (isTeam) {
50484
+ largestTeamDraw = Math.max(largestTeamDraw, drawSize + alternatesCount);
50485
+ tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
50486
+ namedFormat: tieFormatName
50487
+ });
50488
+ const {
50489
+ teamSize,
50490
+ maxDoublesDraw,
50491
+ maxSinglesDraw
50492
+ } = processTieFormat({
50493
+ alternatesCount,
50494
+ tieFormatName,
50495
+ tieFormat,
50496
+ drawSize
50497
+ });
50498
+ largestTeamSize = Math.max(largestTeamSize, teamSize);
50499
+ largestDoublesDraw = Math.max(largestDoublesDraw, maxDoublesDraw);
50500
+ largestSinglesDraw = Math.max(largestSinglesDraw, maxSinglesDraw);
50501
+ }
50502
+
50503
+ if (isDoubles && drawSize + alternatesCount && drawSize + alternatesCount > largestDoublesDraw) {
50504
+ largestDoublesDraw = drawSize + alternatesCount;
50505
+ }
50506
+
50507
+ if (!isDoubles && !isTeam && drawSize && drawSize > largestSinglesDraw) {
50508
+ largestSinglesDraw = drawSize + alternatesCount;
50509
+ }
50510
+ }
50511
+ };
50512
+
50513
+ eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
50514
+ const {
50515
+ tieFormatName: eventTieFormatName,
50516
+ tieFormat: eventTieFormat,
50517
+ drawProfiles,
50518
+ eventType,
50519
+ category,
50520
+ gender
50521
+ } = eventProfile;
50522
+
50523
+ if (drawProfiles) {
50524
+ for (const drawProfile of drawProfiles) {
50525
+ const {
50526
+ tieFormatName,
50527
+ tieFormat
50528
+ } = drawProfile;
50529
+ processDrawProfile({ ...drawProfile,
50530
+ tieFormatName: tieFormatName || eventTieFormatName,
50531
+ tieFormat: tieFormat || eventTieFormat,
50532
+ eventType,
50533
+ category,
50534
+ gender
50535
+ });
50536
+ }
50537
+ }
50538
+ });
50539
+
50540
+ if (drawProfiles) {
50541
+ for (const drawProfile of drawProfiles) {
50542
+ processDrawProfile(drawProfile);
50543
+ }
50544
+ }
50545
+
50546
+ const individualCompetitorsCount = Math.max(largestTeamDraw * largestTeamSize, largestDoublesDraw * 2, largestSinglesDraw);
50547
+ if (largestDoublesDraw) participantType = PAIR$1;
50548
+ if ((participantsCount || specifiedParicipantsCount) < individualCompetitorsCount) participantsCount = individualCompetitorsCount;
50549
+
50550
+ if (participantsCount && largestDoublesDraw && [PAIR$1, TEAM$2].includes(participantType)) {
50551
+ // if we are generating PAIRs or TEAMs...
50552
+ if (largestSinglesDraw && Math.floor(largestSinglesDraw / 2) > largestDoublesDraw) {
50553
+ // if the half the singles draw is still larger than doubles draw
50554
+ participantsCount = Math.floor(largestSinglesDraw / 2);
50555
+ } else if (!largestSinglesDraw || largestDoublesDraw * 2 >= largestSinglesDraw) {
50556
+ // otherwise participantsCount can be cut in half
50557
+ participantsCount = Math.ceil(participantsCount / 2);
50558
+ }
50559
+ } // if (participantsCount === undefined) participantsCount = 32;
50560
+
50561
+
50562
+ if (participantsCount === undefined) {
50563
+ participantsCount = !(eventProfiles !== null && eventProfiles !== void 0 && eventProfiles.length) && !(drawProfiles !== null && drawProfiles !== void 0 && drawProfiles.length) ? 32 : 0;
50564
+ }
50565
+
50566
+ if (participantsCount < specifiedParicipantsCount) participantsCount = specifiedParicipantsCount;
50567
+ return {
50568
+ largestTeamDraw,
50569
+ largestTeamSize,
50570
+ participantsCount,
50571
+ participantType,
50572
+ uniqueParticipantsCount
50573
+ };
50574
+ }
50575
+
50576
+ function addTournamentParticipants({
50577
+ participantsProfile,
50578
+ tournamentRecord,
50579
+ eventProfiles,
50580
+ drawProfiles,
50581
+ startDate,
50582
+ uuids
50583
+ }) {
50584
+ const {
50585
+ participantsCount,
50586
+ participantType,
50587
+ largestTeamDraw,
50588
+ largestTeamSize
50589
+ } = getParticipantsCount({
50590
+ participantsProfile,
50591
+ eventProfiles,
50592
+ drawProfiles
50593
+ });
50594
+ const {
50595
+ nationalityCodesCount,
50596
+ nationalityCodeType,
50597
+ valuesInstanceLimit,
50598
+ nationalityCodes,
50599
+ personExtensions,
50600
+ addressProps,
50601
+ personData,
50602
+ personIds,
50603
+ inContext,
50604
+ teamKey,
50605
+ sex
50606
+ } = participantsProfile || {};
50607
+ const {
50608
+ participants
50609
+ } = generateParticipants({
50610
+ consideredDate: startDate,
50611
+ valuesInstanceLimit,
50612
+ nationalityCodesCount,
50613
+ nationalityCodeType,
50614
+ nationalityCodes,
50615
+ personExtensions,
50616
+ addressProps,
50617
+ personData,
50618
+ sex,
50619
+ participantsCount,
50620
+ participantType,
50621
+ personIds,
50622
+ uuids,
50623
+ inContext
50624
+ });
50625
+ let result = addParticipants({
50626
+ tournamentRecord,
50627
+ participants
50628
+ });
50629
+ if (!result.success) return result;
50630
+
50631
+ if (teamKey) {
50632
+ const result = generateTeamsFromParticipantAttribute({
50633
+ tournamentRecord,
50634
+ ...teamKey
50635
+ });
50636
+ if (result.error) return result;
50637
+ } // generate Team participants
50638
+
50639
+
50640
+ const allIndividualParticipantIds = participants.filter(({
50641
+ participantType
50642
+ }) => participantType === INDIVIDUAL$1).map(getParticipantId);
50643
+ const teamParticipants = generateRange(0, largestTeamDraw).map(teamIndex => {
50644
+ const individualParticipantIds = allIndividualParticipantIds.slice(teamIndex * largestTeamSize, (teamIndex + 1) * largestTeamSize);
50645
+ return {
50646
+ participantName: `Team ${teamIndex + 1}`,
50647
+ participantRole: COMPETITOR,
50648
+ participantType: TEAM$1,
50649
+ participantId: UUID(),
50650
+ individualParticipantIds
50651
+ };
50652
+ });
50653
+ return addParticipants({
50654
+ tournamentRecord,
50655
+ participants: teamParticipants
50656
+ });
50657
+ }
50658
+
50398
50659
  function generateEventParticipants({
50399
50660
  uniqueParticipantsCount,
50400
50661
  participantsProfile,
@@ -50422,6 +50683,7 @@ function generateEventParticipants({
50422
50683
  const mainParticipantsCount = uniqueParticipantsCount[MAIN] || 0;
50423
50684
  const qualifyingParticipantsCount = uniqueParticipantsCount[QUALIFYING] || 0;
50424
50685
  const participantsCount = mainParticipantsCount + qualifyingParticipantsCount;
50686
+ const sex = [MALE, FEMALE].includes(gender) ? gender : undefined;
50425
50687
  const {
50426
50688
  participants: uniqueFlightParticipants
50427
50689
  } = generateParticipants({
@@ -50436,11 +50698,11 @@ function generateEventParticipants({
50436
50698
  ratingsParameters,
50437
50699
  nationalityCodes,
50438
50700
  addressProps,
50439
- sex: gender,
50440
50701
  personIds,
50441
50702
  inContext,
50442
50703
  category,
50443
- uuids
50704
+ uuids,
50705
+ sex
50444
50706
  });
50445
50707
  let result = addParticipants({
50446
50708
  participants: uniqueFlightParticipants,
@@ -50608,262 +50870,6 @@ function generateFlights({
50608
50870
  };
50609
50871
  }
50610
50872
 
50611
- function modifyTournamentRecord({
50612
- matchUpStatusProfile,
50613
- completeAllMatchUps,
50614
- participantsProfile,
50615
- autoEntryPositions,
50616
- randomWinningSide,
50617
- tournamentRecord,
50618
- eventProfiles,
50619
- uuids
50620
- }) {
50621
- if (!tournamentRecord) return {
50622
- error: MISSING_TOURNAMENT_RECORD
50623
- };
50624
- const allUniqueParticipantIds = [];
50625
- const drawIds = [];
50626
-
50627
- if (participantsProfile) {
50628
- const {
50629
- nationalityCodesCount,
50630
- nationalityCodeType,
50631
- valuesInstanceLimit,
50632
- participantsCount,
50633
- nationalityCodes,
50634
- personExtensions,
50635
- participantType,
50636
- addressProps,
50637
- personData,
50638
- personIds,
50639
- inContext,
50640
- teamKey,
50641
- uuids,
50642
- sex
50643
- } = participantsProfile || {};
50644
- const {
50645
- participants
50646
- } = generateParticipants({
50647
- consideredDate: tournamentRecord.startDate,
50648
- valuesInstanceLimit,
50649
- nationalityCodesCount,
50650
- nationalityCodeType,
50651
- nationalityCodes,
50652
- personExtensions,
50653
- addressProps,
50654
- personData,
50655
- sex,
50656
- participantsCount,
50657
- participantType,
50658
- personIds,
50659
- uuids,
50660
- inContext
50661
- });
50662
- let result = addParticipants({
50663
- tournamentRecord,
50664
- participants
50665
- });
50666
- if (result.error) return result;
50667
-
50668
- if (teamKey) {
50669
- const result = generateTeamsFromParticipantAttribute({
50670
- tournamentRecord,
50671
- ...teamKey
50672
- });
50673
- if (result.error) return result;
50674
- }
50675
- }
50676
-
50677
- if (eventProfiles) {
50678
- for (const eventProfile of eventProfiles) {
50679
- let {
50680
- ratingsParameters
50681
- } = eventProfile;
50682
- const event = tournamentRecord.events.find(event => eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
50683
- if (!event) return {
50684
- error: EVENT_NOT_FOUND
50685
- };
50686
- const {
50687
- gender,
50688
- category,
50689
- eventType
50690
- } = event;
50691
- const {
50692
- drawProfiles
50693
- } = eventProfile;
50694
- const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
50695
-
50696
- if (drawProfiles) {
50697
- const {
50698
- stageParticipantsCount,
50699
- uniqueParticipantsCount,
50700
- uniqueParticipantStages
50701
- } = getStageParticipantsCount({
50702
- drawProfiles,
50703
- category,
50704
- gender
50705
- });
50706
- const {
50707
- uniqueDrawParticipants = [],
50708
- uniqueParticipantIds = []
50709
- } = uniqueParticipantStages ? generateEventParticipants({
50710
- event: {
50711
- eventType,
50712
- category,
50713
- gender
50714
- },
50715
- uniqueParticipantsCount,
50716
- participantsProfile,
50717
- ratingsParameters,
50718
- tournamentRecord,
50719
- eventProfile,
50720
- uuids
50721
- }) : {};
50722
- allUniqueParticipantIds.push(...uniqueParticipantIds);
50723
- const {
50724
- stageParticipants
50725
- } = getStageParticipants({
50726
- targetParticipants: tournamentRecord.participants || [],
50727
- allUniqueParticipantIds,
50728
- stageParticipantsCount,
50729
- eventParticipantType
50730
- });
50731
- let result = generateFlights({
50732
- uniqueDrawParticipants,
50733
- autoEntryPositions,
50734
- stageParticipants,
50735
- tournamentRecord,
50736
- drawProfiles,
50737
- category,
50738
- gender,
50739
- event
50740
- });
50741
- if (result.error) return result;
50742
- result = generateFlightDrawDefinitions({
50743
- matchUpStatusProfile,
50744
- completeAllMatchUps,
50745
- randomWinningSide,
50746
- tournamentRecord,
50747
- drawProfiles,
50748
- event
50749
- });
50750
- if (result.error) return result;
50751
- drawIds.push(...result.drawIds);
50752
- }
50753
- }
50754
- }
50755
-
50756
- return { ...SUCCESS,
50757
- drawIds
50758
- };
50759
- }
50760
-
50761
- const amendsGovernor = {
50762
- anonymizeTournamentRecord,
50763
- modifyTournamentRecord
50764
- };
50765
-
50766
- function generateSchedulingProfile({
50767
- schedulingProfile,
50768
- tournamentRecord
50769
- }) {
50770
- if (typeof schedulingProfile !== 'object') return {
50771
- error: INVALID_VALUES
50772
- };
50773
- const containedStructures = getContainedStructures({
50774
- tournamentRecord
50775
- }).containedStructures;
50776
- const {
50777
- matchUps
50778
- } = allTournamentMatchUps({
50779
- tournamentRecord
50780
- });
50781
- const {
50782
- tournamentId
50783
- } = tournamentRecord;
50784
- const scheduledRounds = [];
50785
-
50786
- for (const dateProfile of schedulingProfile) {
50787
- const {
50788
- scheduleDate,
50789
- venues = []
50790
- } = dateProfile;
50791
-
50792
- for (const venue of venues) {
50793
- const {
50794
- rounds,
50795
- venueId
50796
- } = venue;
50797
-
50798
- for (const round of rounds) {
50799
- const {
50800
- drawId,
50801
- winnerFinishingPositionRange,
50802
- roundSegment
50803
- } = round;
50804
- const targetMatchUps = matchUps.filter(matchUp => {
50805
- var _matchUp$finishingPos;
50806
-
50807
- const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
50808
- const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
50809
- const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
50810
- return target;
50811
- });
50812
- const targetMatchUp = targetMatchUps[0];
50813
-
50814
- if (targetMatchUp) {
50815
- const {
50816
- eventId,
50817
- roundNumber,
50818
- drawName,
50819
- structureName,
50820
- roundName
50821
- } = targetMatchUp;
50822
- let structureId = targetMatchUp.structureId;
50823
-
50824
- if (roundNumber && !winnerFinishingPositionRange) {
50825
- structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
50826
- }
50827
-
50828
- const roundToSchedule = {
50829
- tournamentId,
50830
- eventId,
50831
- drawId,
50832
- structureId,
50833
- roundNumber,
50834
- roundSegment
50835
- };
50836
- let result = addSchedulingProfileRound({
50837
- tournamentRecords: {
50838
- [tournamentId]: tournamentRecord
50839
- },
50840
- scheduleDate,
50841
- venueId,
50842
- round: roundToSchedule
50843
- });
50844
- if (result.error) return result;
50845
- scheduledRounds.push({
50846
- drawName,
50847
- structureName,
50848
- roundName,
50849
- ...roundToSchedule
50850
- });
50851
- }
50852
- }
50853
- }
50854
- }
50855
-
50856
- return {
50857
- scheduledRounds
50858
- };
50859
- }
50860
-
50861
- // import { addDrawDefinition } from '../../tournamentEngine/governors/eventGovernor/drawDefinitions/addDrawDefinition';
50862
- // import {
50863
- // MAIN,
50864
- // ROUND_ROBIN_WITH_PLAYOFF,
50865
- // } from '../../constants/drawDefinitionConstants';
50866
-
50867
50873
  function generateEventWithFlights({
50868
50874
  allUniqueParticipantIds,
50869
50875
  matchUpStatusProfile,
@@ -50874,7 +50880,6 @@ function generateEventWithFlights({
50874
50880
  ratingsParameters,
50875
50881
  tournamentRecord,
50876
50882
  eventProfile,
50877
- // startDate,
50878
50883
  uuids
50879
50884
  }) {
50880
50885
  let gender = eventProfile.gender;
@@ -51003,120 +51008,6 @@ function generateEventWithFlights({
51003
51008
  });
51004
51009
  if (result.error) return result;
51005
51010
  const drawIds = result.drawIds;
51006
- /*
51007
- const drawIds = [];
51008
- const { flightProfile } = getFlightProfile({ event });
51009
- if (Array.isArray(flightProfile?.flights)) {
51010
- for (const [index, flight] of flightProfile.flights.entries()) {
51011
- const { drawId, stage, drawName, drawEntries } = flight;
51012
- drawIds.push(flight.drawId);
51013
- const drawProfile = drawProfiles[index];
51014
- const { seedsCount, generate = true } = drawProfile || {};
51015
- if (generate) {
51016
- const drawParticipantIds = drawEntries
51017
- .filter(hasParticipantId)
51018
- .map(getParticipantId);
51019
- const seedingScaleName = categoryName || eventName;
51020
- if (
51021
- tournamentRecord &&
51022
- seedsCount &&
51023
- seedsCount <= drawParticipantIds.length
51024
- ) {
51025
- const scaleValues = generateRange(1, seedsCount + 1);
51026
- scaleValues.forEach((scaleValue, index) => {
51027
- let scaleItem = {
51028
- scaleValue,
51029
- scaleName: seedingScaleName,
51030
- scaleType: SEEDING,
51031
- eventType,
51032
- scaleDate: startDate,
51033
- };
51034
- const participantId = drawParticipantIds[index];
51035
- setParticipantScaleItem({
51036
- tournamentRecord,
51037
- participantId,
51038
- scaleItem,
51039
- });
51040
- });
51041
- }
51042
- let result = generateDrawDefinition({
51043
- ...drawProfile,
51044
- matchUpType: eventType,
51045
- seedingScaleName,
51046
- tournamentRecord,
51047
- isMock: true,
51048
- drawEntries,
51049
- drawName,
51050
- drawId,
51051
- event,
51052
- stage,
51053
- });
51054
- const { drawDefinition, error } = result;
51055
- if (error) return { error };
51056
- const drawExtensions = drawProfiles[index]?.drawExtensions;
51057
- if (Array.isArray(drawExtensions)) {
51058
- drawExtensions
51059
- .filter(isValidExtension)
51060
- .forEach((extension) =>
51061
- addExtension({ element: drawDefinition, extension })
51062
- );
51063
- }
51064
- result = addDrawDefinition({
51065
- drawDefinition,
51066
- event,
51067
- });
51068
- if (result.error) return result;
51069
- if (drawProfile?.withPlayoffs) {
51070
- const structureId = drawDefinition.structures[0].structureId;
51071
- const result = addPlayoffStructures({
51072
- idPrefix: drawProfile.idPrefix,
51073
- ...drawProfile.withPlayoffs,
51074
- tournamentRecord,
51075
- drawDefinition,
51076
- isMock: true,
51077
- structureId,
51078
- event,
51079
- });
51080
- if (result?.error) return result;
51081
- }
51082
- // TODO: enable { outcomes: [] } in eventProfile: { drawProfiles }
51083
- const manual = drawProfile?.automated === false;
51084
- if (!manual && completeAllMatchUps) {
51085
- const matchUpFormat = drawProfile?.matchUpFormat;
51086
- const result = completeDrawMatchUps({
51087
- matchUpStatusProfile,
51088
- completeAllMatchUps,
51089
- randomWinningSide,
51090
- drawDefinition,
51091
- matchUpFormat,
51092
- });
51093
- if (result.error) return result;
51094
- if (drawProfile?.drawType === ROUND_ROBIN_WITH_PLAYOFF) {
51095
- const mainStructure = drawDefinition.structures.find(
51096
- (structure) => structure.stage === MAIN
51097
- );
51098
- let result = automatedPlayoffPositioning({
51099
- structureId: mainStructure.structureId,
51100
- tournamentRecord,
51101
- drawDefinition,
51102
- event,
51103
- });
51104
- if (result.error) return result;
51105
- result = completeDrawMatchUps({
51106
- completeAllMatchUps,
51107
- matchUpStatusProfile,
51108
- randomWinningSide,
51109
- matchUpFormat,
51110
- drawDefinition,
51111
- });
51112
- if (result.error) return result;
51113
- }
51114
- }
51115
- }
51116
- }
51117
- }
51118
- */
51119
-
51120
51011
  return {
51121
51012
  drawIds,
51122
51013
  eventId,
@@ -51124,43 +51015,6 @@ function generateEventWithFlights({
51124
51015
  };
51125
51016
  }
51126
51017
 
51127
- function processTieFormat({
51128
- tieFormat,
51129
- tieFormatName,
51130
- drawSize,
51131
- alternatesCount = 0
51132
- }) {
51133
- var _tieFormat, _tieFormat$collection;
51134
-
51135
- let maxDoublesCount = 0,
51136
- maxSinglesCount = 0;
51137
- tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
51138
- namedFormat: tieFormatName
51139
- });
51140
- (_tieFormat = tieFormat) === null || _tieFormat === void 0 ? void 0 : (_tieFormat$collection = _tieFormat.collectionDefinitions) === null || _tieFormat$collection === void 0 ? void 0 : _tieFormat$collection.forEach(collectionDefinition => {
51141
- // ensure every collectionDefinition has a collectionId
51142
- if (!collectionDefinition.collectionId) collectionDefinition.collectionId = UUID();
51143
-
51144
- if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === DOUBLES$1) {
51145
- const doublesCount = collectionDefinition.matchUpCount;
51146
- maxDoublesCount = Math.max(maxDoublesCount, doublesCount);
51147
- }
51148
-
51149
- if ((collectionDefinition === null || collectionDefinition === void 0 ? void 0 : collectionDefinition.matchUpType) === SINGLES$1) {
51150
- const singlescount = collectionDefinition.matchUpCount;
51151
- maxSinglesCount = Math.max(maxSinglesCount, singlescount);
51152
- }
51153
- });
51154
- const teamSize = Math.max(maxSinglesCount, maxDoublesCount * 2);
51155
- const maxDoublesDraw = maxDoublesCount * (drawSize + alternatesCount);
51156
- const maxSinglesDraw = maxSinglesCount * (drawSize + alternatesCount);
51157
- return {
51158
- maxDoublesDraw,
51159
- maxSinglesDraw,
51160
- teamSize
51161
- };
51162
- }
51163
-
51164
51018
  function generateEventWithDraw({
51165
51019
  allUniqueParticipantIds = [],
51166
51020
  matchUpStatusProfile,
@@ -51272,7 +51126,7 @@ function generateEventWithDraw({
51272
51126
  });
51273
51127
 
51274
51128
  if (tournamentRecord) {
51275
- let result = addParticipants({
51129
+ const result = addParticipants({
51276
51130
  tournamentRecord,
51277
51131
  participants: unique
51278
51132
  });
@@ -51332,22 +51186,26 @@ function generateEventWithDraw({
51332
51186
  participantId
51333
51187
  }) => !allUniqueParticipantIds.includes(participantId));
51334
51188
  const participantIds = consideredParticipants.slice(0, participantsCount).map(p => p.participantId);
51335
- let result = addEventEntries({
51336
- entryStage: stage,
51337
- autoEntryPositions,
51338
- tournamentRecord,
51339
- participantIds,
51340
- event
51341
- });
51342
- if (result.error) return result; // alternates can still be taken from existing participants
51189
+
51190
+ if (participantIds !== null && participantIds !== void 0 && participantIds.length) {
51191
+ const result = addEventEntries({
51192
+ autoEntryPositions,
51193
+ entryStage: stage,
51194
+ tournamentRecord,
51195
+ participantIds,
51196
+ event
51197
+ });
51198
+ if (result.error) return result;
51199
+ } // alternates can still be taken from existing participants
51343
51200
  // when unique participants are used for DIRECT_ACCEPTANCE entries
51344
51201
 
51202
+
51345
51203
  const alternatesParticipantIds = excessParticipantAlternates && (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : (_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.filter(({
51346
51204
  participantId
51347
51205
  }) => !participantIds.includes(participantId)).filter(isEventParticipantType).filter(isEventGender).slice(0, alternatesCount || drawSize - participantsCount).map(p => p.participantId));
51348
51206
 
51349
51207
  if (alternatesParticipantIds !== null && alternatesParticipantIds !== void 0 && alternatesParticipantIds.length) {
51350
- result = addEventEntries({
51208
+ const result = addEventEntries({
51351
51209
  participantIds: alternatesParticipantIds,
51352
51210
  autoEntryPositions: false,
51353
51211
  entryStatus: ALTERNATE,
@@ -51519,9 +51377,6 @@ function generateEventWithDraw({
51519
51377
  }
51520
51378
  }
51521
51379
 
51522
- if (result.error) return {
51523
- error: result.error
51524
- };
51525
51380
  return { ...SUCCESS,
51526
51381
  event: definedAttributes(event),
51527
51382
  uniqueParticipantIds,
@@ -51579,6 +51434,322 @@ function generateVenues({
51579
51434
  return venueIds;
51580
51435
  }
51581
51436
 
51437
+ function modifyTournamentRecord({
51438
+ ratingsParameters: ratingsParameters$1 = ratingsParameters,
51439
+ matchUpStatusProfile,
51440
+ completeAllMatchUps,
51441
+ participantsProfile,
51442
+ autoEntryPositions,
51443
+ randomWinningSide,
51444
+ schedulingProfile,
51445
+ tournamentRecord,
51446
+ eventProfiles,
51447
+ venueProfiles,
51448
+ autoSchedule,
51449
+ drawProfiles,
51450
+ goesTo,
51451
+ uuids
51452
+ }) {
51453
+ if (!tournamentRecord) return {
51454
+ error: MISSING_TOURNAMENT_RECORD
51455
+ };
51456
+ const allUniqueParticipantIds = [];
51457
+ const eventIds = [];
51458
+ const drawIds = [];
51459
+ eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
51460
+ 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);
51461
+
51462
+ if (event !== null && event !== void 0 && event.gender) {
51463
+ eventProfile.gender = event.gender;
51464
+ }
51465
+ });
51466
+ const result = addTournamentParticipants({
51467
+ startDate: tournamentRecord.startDate,
51468
+ participantsProfile,
51469
+ tournamentRecord,
51470
+ eventProfiles,
51471
+ drawProfiles,
51472
+ uuids
51473
+ });
51474
+ if (!result.success) return result;
51475
+
51476
+ if (eventProfiles) {
51477
+ for (const eventProfile of eventProfiles) {
51478
+ let {
51479
+ ratingsParameters
51480
+ } = eventProfile;
51481
+ 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);
51482
+
51483
+ if (!event) {
51484
+ const {
51485
+ error,
51486
+ eventId,
51487
+ drawIds: generatedDrawIds,
51488
+ uniqueParticipantIds
51489
+ } = generateEventWithFlights({
51490
+ startDate: tournamentRecord.startDate,
51491
+ allUniqueParticipantIds,
51492
+ matchUpStatusProfile,
51493
+ participantsProfile,
51494
+ completeAllMatchUps,
51495
+ autoEntryPositions,
51496
+ randomWinningSide,
51497
+ ratingsParameters,
51498
+ tournamentRecord,
51499
+ eventProfile,
51500
+ uuids
51501
+ });
51502
+ if (error) return {
51503
+ error
51504
+ };
51505
+ if (generatedDrawIds) drawIds.push(...generatedDrawIds);
51506
+ eventIds.push(eventId);
51507
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51508
+ } else {
51509
+ const {
51510
+ gender,
51511
+ category,
51512
+ eventType
51513
+ } = event;
51514
+ const {
51515
+ drawProfiles
51516
+ } = eventProfile;
51517
+ const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
51518
+
51519
+ if (drawProfiles) {
51520
+ const {
51521
+ stageParticipantsCount,
51522
+ uniqueParticipantsCount,
51523
+ uniqueParticipantStages
51524
+ } = getStageParticipantsCount({
51525
+ drawProfiles,
51526
+ category,
51527
+ gender
51528
+ });
51529
+ const {
51530
+ uniqueDrawParticipants = [],
51531
+ uniqueParticipantIds = []
51532
+ } = uniqueParticipantStages ? generateEventParticipants({
51533
+ event: {
51534
+ eventType,
51535
+ category,
51536
+ gender
51537
+ },
51538
+ uniqueParticipantsCount,
51539
+ participantsProfile,
51540
+ ratingsParameters,
51541
+ tournamentRecord,
51542
+ eventProfile,
51543
+ uuids
51544
+ }) : {};
51545
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
51546
+ const {
51547
+ stageParticipants
51548
+ } = getStageParticipants({
51549
+ targetParticipants: tournamentRecord.participants || [],
51550
+ allUniqueParticipantIds,
51551
+ stageParticipantsCount,
51552
+ eventParticipantType
51553
+ });
51554
+ let result = generateFlights({
51555
+ uniqueDrawParticipants,
51556
+ autoEntryPositions,
51557
+ stageParticipants,
51558
+ tournamentRecord,
51559
+ drawProfiles,
51560
+ category,
51561
+ gender,
51562
+ event
51563
+ });
51564
+ if (result.error) return result;
51565
+ result = generateFlightDrawDefinitions({
51566
+ matchUpStatusProfile,
51567
+ completeAllMatchUps,
51568
+ randomWinningSide,
51569
+ tournamentRecord,
51570
+ drawProfiles,
51571
+ event
51572
+ });
51573
+ if (result.error) return result;
51574
+ drawIds.push(...result.drawIds);
51575
+ }
51576
+ }
51577
+ }
51578
+ }
51579
+
51580
+ if (drawProfiles) {
51581
+ for (const drawProfile of drawProfiles) {
51582
+ const {
51583
+ drawId,
51584
+ eventId,
51585
+ event,
51586
+ error,
51587
+ uniqueParticipantIds
51588
+ } = generateEventWithDraw({
51589
+ startDate: tournamentRecord.startDate,
51590
+ allUniqueParticipantIds,
51591
+ matchUpStatusProfile,
51592
+ participantsProfile,
51593
+ completeAllMatchUps,
51594
+ autoEntryPositions,
51595
+ randomWinningSide,
51596
+ ratingsParameters: ratingsParameters$1,
51597
+ tournamentRecord,
51598
+ drawProfile,
51599
+ goesTo,
51600
+ uuids
51601
+ });
51602
+ if (error) return {
51603
+ error
51604
+ };
51605
+ const result = addEvent({
51606
+ tournamentRecord,
51607
+ event
51608
+ });
51609
+ if (result.error) return result;
51610
+ if (drawId) drawIds.push(drawId);
51611
+ eventIds.push(eventId);
51612
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51613
+ }
51614
+ }
51615
+
51616
+ const venueIds = venueProfiles !== null && venueProfiles !== void 0 && venueProfiles.length ? generateVenues({
51617
+ tournamentRecord,
51618
+ venueProfiles
51619
+ }) : [];
51620
+ let scheduledRounds;
51621
+ let schedulerResult = {};
51622
+
51623
+ if (schedulingProfile) {
51624
+ const result = generateScheduleTimes({
51625
+ schedulingProfile,
51626
+ tournamentRecord
51627
+ });
51628
+ if (result.error) return result;
51629
+ scheduledRounds = result.scheduledRounds;
51630
+
51631
+ if (autoSchedule) {
51632
+ const {
51633
+ tournamentId
51634
+ } = tournamentRecord;
51635
+ const tournamentRecords = {
51636
+ [tournamentId]: tournamentRecord
51637
+ };
51638
+ schedulerResult = scheduleProfileRounds({
51639
+ tournamentRecords
51640
+ });
51641
+ }
51642
+ }
51643
+
51644
+ return { ...SUCCESS,
51645
+ drawIds,
51646
+ eventIds,
51647
+ venueIds,
51648
+ scheduledRounds,
51649
+ schedulerResult
51650
+ };
51651
+ }
51652
+
51653
+ const amendsGovernor = {
51654
+ anonymizeTournamentRecord,
51655
+ modifyTournamentRecord
51656
+ };
51657
+
51658
+ function generateSchedulingProfile({
51659
+ schedulingProfile,
51660
+ tournamentRecord
51661
+ }) {
51662
+ if (typeof schedulingProfile !== 'object') return {
51663
+ error: INVALID_VALUES
51664
+ };
51665
+ const containedStructures = getContainedStructures({
51666
+ tournamentRecord
51667
+ }).containedStructures;
51668
+ const {
51669
+ matchUps
51670
+ } = allTournamentMatchUps({
51671
+ tournamentRecord
51672
+ });
51673
+ const {
51674
+ tournamentId
51675
+ } = tournamentRecord;
51676
+ const scheduledRounds = [];
51677
+
51678
+ for (const dateProfile of schedulingProfile) {
51679
+ const {
51680
+ scheduleDate,
51681
+ venues = []
51682
+ } = dateProfile;
51683
+
51684
+ for (const venue of venues) {
51685
+ const {
51686
+ rounds,
51687
+ venueId
51688
+ } = venue;
51689
+
51690
+ for (const round of rounds) {
51691
+ const {
51692
+ drawId,
51693
+ winnerFinishingPositionRange,
51694
+ roundSegment
51695
+ } = round;
51696
+ const targetMatchUps = matchUps.filter(matchUp => {
51697
+ var _matchUp$finishingPos;
51698
+
51699
+ const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
51700
+ const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
51701
+ const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
51702
+ return target;
51703
+ });
51704
+ const targetMatchUp = targetMatchUps[0];
51705
+
51706
+ if (targetMatchUp) {
51707
+ const {
51708
+ eventId,
51709
+ roundNumber,
51710
+ drawName,
51711
+ structureName,
51712
+ roundName
51713
+ } = targetMatchUp;
51714
+ let structureId = targetMatchUp.structureId;
51715
+
51716
+ if (roundNumber && !winnerFinishingPositionRange) {
51717
+ structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
51718
+ }
51719
+
51720
+ const roundToSchedule = {
51721
+ tournamentId,
51722
+ eventId,
51723
+ drawId,
51724
+ structureId,
51725
+ roundNumber,
51726
+ roundSegment
51727
+ };
51728
+ let result = addSchedulingProfileRound({
51729
+ tournamentRecords: {
51730
+ [tournamentId]: tournamentRecord
51731
+ },
51732
+ scheduleDate,
51733
+ venueId,
51734
+ round: roundToSchedule
51735
+ });
51736
+ if (result.error) return result;
51737
+ scheduledRounds.push({
51738
+ drawName,
51739
+ structureName,
51740
+ roundName,
51741
+ ...roundToSchedule
51742
+ });
51743
+ }
51744
+ }
51745
+ }
51746
+ }
51747
+
51748
+ return {
51749
+ scheduledRounds
51750
+ };
51751
+ }
51752
+
51582
51753
  /**
51583
51754
  *
51584
51755
  * Generate a complete tournamentRecord from the following attributes
@@ -51624,12 +51795,6 @@ function generateTournamentRecord({
51624
51795
  goesTo,
51625
51796
  uuids
51626
51797
  } = {}) {
51627
- let {
51628
- participantsCount,
51629
- participantType = INDIVIDUAL$1
51630
- } = participantsProfile || {};
51631
- const specifiedParicipantsCount = participantsCount || 0; // capture this to ensure calculated participantsCount is not below
51632
-
51633
51798
  if (startDate && !isValidDateString(startDate) || endDate && !isValidDateString(endDate)) return {
51634
51799
  error: INVALID_DATE
51635
51800
  };
@@ -51671,165 +51836,13 @@ function generateTournamentRecord({
51671
51836
  }
51672
51837
  }
51673
51838
 
51674
- let largestDoublesDraw = 0,
51675
- largestSinglesDraw = 0,
51676
- largestTeamSize = 0,
51677
- largestTeamDraw = 0;
51678
-
51679
- const processDrawProfile = ({
51680
- alternatesCount = 0,
51681
- uniqueParticipants,
51682
- tieFormatName,
51683
- drawSize = 0,
51684
- eventType,
51685
- tieFormat,
51686
- category,
51687
- gender,
51688
- stage
51689
- }) => {
51690
- const isDoubles = eventType === DOUBLES;
51691
- const isTeam = eventType === TEAM$2;
51692
- const requiresUniqueParticipants = uniqueParticipants || stage === QUALIFYING || category || gender;
51693
-
51694
- if (isTeam && !requiresUniqueParticipants) {
51695
- largestTeamDraw = Math.max(largestTeamDraw, drawSize + alternatesCount);
51696
- tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({
51697
- namedFormat: tieFormatName
51698
- });
51699
- const {
51700
- teamSize,
51701
- maxDoublesDraw,
51702
- maxSinglesDraw
51703
- } = processTieFormat({
51704
- alternatesCount,
51705
- tieFormatName,
51706
- tieFormat,
51707
- drawSize
51708
- });
51709
- largestTeamSize = Math.max(largestTeamSize, teamSize);
51710
- largestDoublesDraw = Math.max(largestDoublesDraw, maxDoublesDraw);
51711
- largestSinglesDraw = Math.max(largestSinglesDraw, maxSinglesDraw);
51712
- }
51713
-
51714
- if (isDoubles && drawSize + alternatesCount && drawSize + alternatesCount > largestDoublesDraw) {
51715
- largestDoublesDraw = drawSize + alternatesCount;
51716
- }
51717
-
51718
- if (!isDoubles && !isTeam && drawSize && drawSize > largestSinglesDraw) {
51719
- largestSinglesDraw = drawSize + alternatesCount;
51720
- }
51721
- };
51722
-
51723
- eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
51724
- const {
51725
- tieFormatName: eventTieFormatName,
51726
- tieFormat: eventTieFormat,
51727
- drawProfiles,
51728
- eventType,
51729
- category
51730
- } = eventProfile;
51731
-
51732
- if (drawProfiles) {
51733
- for (const drawProfile of drawProfiles) {
51734
- const {
51735
- tieFormatName,
51736
- tieFormat
51737
- } = drawProfile;
51738
- processDrawProfile({ ...drawProfile,
51739
- tieFormatName: tieFormatName || eventTieFormatName,
51740
- tieFormat: tieFormat || eventTieFormat,
51741
- eventType,
51742
- category
51743
- });
51744
- }
51745
- }
51746
- });
51747
-
51748
- if (drawProfiles) {
51749
- for (const drawProfile of drawProfiles) {
51750
- processDrawProfile(drawProfile);
51751
- }
51752
- }
51753
-
51754
- const individualCompetitorsCount = Math.max(largestTeamDraw * largestTeamSize, largestDoublesDraw * 2, largestSinglesDraw);
51755
- if (largestDoublesDraw) participantType = PAIR$1;
51756
- if ((participantsCount || specifiedParicipantsCount) < individualCompetitorsCount) participantsCount = individualCompetitorsCount;
51757
-
51758
- if (participantsCount && largestDoublesDraw && [PAIR$1, TEAM$2].includes(participantType)) {
51759
- // if we are generating PAIRs or TEAMs...
51760
- if (largestSinglesDraw && Math.floor(largestSinglesDraw / 2) > largestDoublesDraw) {
51761
- // if the half the singles draw is still larger than doubles draw
51762
- participantsCount = Math.floor(largestSinglesDraw / 2);
51763
- } else if (!largestSinglesDraw || largestDoublesDraw * 2 >= largestSinglesDraw) {
51764
- // otherwise participantsCount can be cut in half
51765
- participantsCount = Math.ceil(participantsCount / 2);
51766
- }
51767
- }
51768
-
51769
- if (participantsCount === undefined) participantsCount = 32;
51770
- if (participantsCount < specifiedParicipantsCount) participantsCount = specifiedParicipantsCount;
51771
- const {
51772
- nationalityCodesCount,
51773
- nationalityCodeType,
51774
- valuesInstanceLimit,
51775
- nationalityCodes,
51776
- personExtensions,
51777
- addressProps,
51778
- personData,
51779
- personIds,
51780
- inContext,
51781
- teamKey,
51782
- sex
51783
- } = participantsProfile || {};
51784
- const {
51785
- participants
51786
- } = generateParticipants({
51787
- consideredDate: startDate,
51788
- valuesInstanceLimit,
51789
- nationalityCodesCount,
51790
- nationalityCodeType,
51791
- nationalityCodes,
51792
- personExtensions,
51793
- addressProps,
51794
- personData,
51795
- sex,
51796
- participantsCount,
51797
- participantType,
51798
- personIds,
51799
- uuids,
51800
- inContext
51801
- });
51802
- let result = addParticipants({
51803
- tournamentRecord,
51804
- participants
51805
- });
51806
- if (!result.success) return result;
51807
-
51808
- if (teamKey) {
51809
- const result = generateTeamsFromParticipantAttribute({
51810
- tournamentRecord,
51811
- ...teamKey
51812
- });
51813
- if (result.error) return result;
51814
- } // generate Team participants
51815
-
51816
-
51817
- const allIndividualParticipantIds = participants.filter(({
51818
- participantType
51819
- }) => participantType === INDIVIDUAL$1).map(getParticipantId);
51820
- const teamParticipants = generateRange(0, largestTeamDraw).map(teamIndex => {
51821
- const individualParticipantIds = allIndividualParticipantIds.slice(teamIndex * largestTeamSize, (teamIndex + 1) * largestTeamSize);
51822
- return {
51823
- participantName: `Team ${teamIndex + 1}`,
51824
- participantRole: COMPETITOR,
51825
- participantType: TEAM$2,
51826
- participantId: UUID(),
51827
- individualParticipantIds
51828
- };
51829
- });
51830
- result = addParticipants({
51839
+ const result = addTournamentParticipants({
51840
+ participantsProfile,
51831
51841
  tournamentRecord,
51832
- participants: teamParticipants
51842
+ eventProfiles,
51843
+ drawProfiles,
51844
+ startDate,
51845
+ uuids
51833
51846
  });
51834
51847
  if (!result.success) return result;
51835
51848
  const drawIds = [],
@@ -51855,7 +51868,8 @@ function generateTournamentRecord({
51855
51868
  tournamentRecord,
51856
51869
  drawProfile,
51857
51870
  startDate,
51858
- goesTo
51871
+ goesTo,
51872
+ uuids
51859
51873
  });
51860
51874
  if (error) return {
51861
51875
  error
@@ -51888,7 +51902,8 @@ function generateTournamentRecord({
51888
51902
  ratingsParameters: ratingsParameters$1,
51889
51903
  tournamentRecord,
51890
51904
  eventProfile,
51891
- startDate
51905
+ startDate,
51906
+ uuids
51892
51907
  });
51893
51908
  if (error) return {
51894
51909
  error