tods-competition-factory 1.8.30 → 1.8.32

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.
@@ -1335,6 +1335,7 @@ type ValidPolicyTypes = typeof POLICY_TYPE_VOLUNTARY_CONSOLATION | typeof POLICY
1335
1335
  type SeedingProfile = {
1336
1336
  groupSeedingThreshold?: number;
1337
1337
  positioning?: string;
1338
+ nonRandom?: boolean;
1338
1339
  };
1339
1340
  type ScaleAttributes = {
1340
1341
  eventType: TypeEnum;
@@ -1511,6 +1512,7 @@ type GenerateDrawDefinitionArgs = {
1511
1512
  ignoreAllowedDrawTypes?: boolean;
1512
1513
  qualifyingPlaceholder?: boolean;
1513
1514
  considerEventEntries?: boolean;
1515
+ seedingProfile?: SeedingProfile;
1514
1516
  hydrateCollections?: boolean;
1515
1517
  tournamentRecord: Tournament;
1516
1518
  drawTypeCoercion?: boolean;
@@ -5409,10 +5409,89 @@ function getSeedGroups({
5409
5409
  }
5410
5410
  }
5411
5411
 
5412
+ function getDivisions({ size }) {
5413
+ const divisions = [size];
5414
+ let division = size;
5415
+ while (division / 2 === Math.floor(division / 2)) {
5416
+ division = division / 2;
5417
+ divisions.push(division);
5418
+ }
5419
+ if (!divisions.includes(1))
5420
+ divisions.push(1);
5421
+ divisions.sort(numericSort);
5422
+ divisions.reverse();
5423
+ return divisions;
5424
+ }
5425
+ function getSubBlock({ blockPattern, index }) {
5426
+ let i = 0;
5427
+ for (const subBlock of blockPattern) {
5428
+ if (i === index)
5429
+ return subBlock;
5430
+ let j = 0;
5431
+ while (j < subBlock.length) {
5432
+ if (i === index)
5433
+ return subBlock;
5434
+ i += 1;
5435
+ j++;
5436
+ }
5437
+ }
5438
+ }
5439
+ function generateBlockPattern({
5440
+ positioning,
5441
+ size
5442
+ }) {
5443
+ const divisions = getDivisions({ size });
5444
+ const divisionGroupings = [];
5445
+ const selected = [];
5446
+ const firstMember = (arr) => arr[0];
5447
+ const lastMember = (arr) => arr[arr.length - 1];
5448
+ const getMember = (arr, i) => (positioning === CLUSTER && i % 2 ? lastMember(arr) : firstMember(arr)) || firstMember(arr);
5449
+ const noneSelected = (chunk, i) => {
5450
+ if (chunk.every((member) => !selected.includes(member))) {
5451
+ const member = getMember(chunk, i);
5452
+ selected.push(member);
5453
+ return member;
5454
+ }
5455
+ };
5456
+ const notSelected = (chunk) => {
5457
+ const notSelected2 = chunk.filter((member) => !selected.includes(member));
5458
+ if (notSelected2.length) {
5459
+ selected.push(...notSelected2);
5460
+ return notSelected2;
5461
+ }
5462
+ };
5463
+ const select = (chunk, i) => {
5464
+ const member = getMember(chunk, i);
5465
+ if (!selected.includes(member)) {
5466
+ selected.push(member);
5467
+ return member;
5468
+ }
5469
+ };
5470
+ const range = generateRange(1, size + 1);
5471
+ for (const division of divisions) {
5472
+ if (division === 1) {
5473
+ const chunks = chunkArray(range, 2);
5474
+ const positions = chunks.map(noneSelected).filter(Boolean);
5475
+ if (positions.length)
5476
+ divisionGroupings.push(positions);
5477
+ const lastPositions = chunks.flatMap(notSelected).filter(Boolean);
5478
+ if (lastPositions.length)
5479
+ divisionGroupings.push(lastPositions);
5480
+ } else {
5481
+ const chunks = chunkArray(range, division);
5482
+ const positions = chunks.map(select).filter(Boolean);
5483
+ if (positions.length)
5484
+ divisionGroupings.push(positions);
5485
+ }
5486
+ }
5487
+ return { divisions, divisionGroupings };
5488
+ }
5489
+
5412
5490
  function getValidSeedBlocks({
5413
5491
  provisionalPositioning,
5414
5492
  returnAllProxies,
5415
5493
  appliedPolicies,
5494
+ seedingProfile,
5416
5495
  drawDefinition,
5417
5496
  allPositions,
5418
5497
  structure
@@ -5446,7 +5525,7 @@ function getValidSeedBlocks({
5446
5525
  }).filter((f) => f.length).reverse();
5447
5526
  const firstRoundDrawPositions = uniqueDrawPositionsByRound.pop();
5448
5527
  const firstRoundDrawPositionOffset = firstRoundDrawPositions && Math.min(...firstRoundDrawPositions) - 1 || 0;
5449
- const seedingProfile = appliedPolicies?.seeding?.seedingProfile;
5528
+ seedingProfile = seedingProfile ?? appliedPolicies?.seeding?.seedingProfile;
5450
5529
  const baseDrawSize = firstRoundDrawPositions?.length || 0;
5451
5530
  const seedRangeDrawPositionBlocks = uniqueDrawPositionsByRound.filter(
5452
5531
  (block) => block.filter((drawPosition) => drawPosition <= seedsCount).length
@@ -5485,12 +5564,14 @@ function getValidSeedBlocks({
5485
5564
  );
5486
5565
  ({ validSeedBlocks } = getSeedBlockPattern({
5487
5566
  drawPositionBlocks: drawPositionChunks,
5567
+ nonRandom: seedingProfile?.nonRandom,
5488
5568
  positioning,
5489
5569
  seedGroups
5490
5570
  }));
5491
5571
  }
5492
5572
  } else if (isContainer) {
5493
5573
  const result = getContainerBlocks({
5574
+ nonRandom: seedingProfile?.nonRandom,
5494
5575
  seedingProfile,
5495
5576
  structure
5496
5577
  });
@@ -5540,7 +5621,7 @@ function getValidSeedBlocks({
5540
5621
  isFeedIn
5541
5622
  };
5542
5623
  }
5543
- function getContainerBlocks({ seedingProfile, structure }) {
5624
+ function getContainerBlocks({ seedingProfile, structure, nonRandom }) {
5544
5625
  const containedStructures = structure.structures || [];
5545
5626
  const roundRobinGroupsCount = containedStructures.length;
5546
5627
  const positionAssignments = getPositionAssignments({
@@ -5560,26 +5641,48 @@ function getContainerBlocks({ seedingProfile, structure }) {
5560
5641
  return getSeedBlockPattern({
5561
5642
  drawPositionBlocks,
5562
5643
  positioning,
5563
- seedGroups
5644
+ seedGroups,
5645
+ nonRandom
5564
5646
  });
5565
5647
  }
5566
- function getSeedBlockPattern({ positioning, seedGroups, drawPositionBlocks }) {
5648
+ function getSeedBlockPattern({
5649
+ drawPositionBlocks,
5650
+ positioning,
5651
+ seedGroups,
5652
+ nonRandom
5653
+ }) {
5567
5654
  const validSeedBlocks = [];
5568
- const topDown = (a, b) => a - b;
5569
- const bottomUp = (a, b) => b - a;
5655
+ const { divisionGroupings } = generateBlockPattern({
5656
+ size: seedGroups.length,
5657
+ positioning
5658
+ });
5570
5659
  const assignedPositions = [];
5571
5660
  seedGroups.forEach((seedGroup, i) => {
5572
- if (i && positioning !== WATERFALL) {
5573
- shuffleArray(seedGroup);
5574
- }
5661
+ const relativePositions = getSubBlock({
5662
+ blockPattern: divisionGroupings,
5663
+ index: i
5664
+ });
5575
5665
  seedGroup.forEach((seedNumber, j) => {
5576
5666
  const blockIndex = i % 2 ? drawPositionBlocks.length - j - 1 : j;
5577
- const drawPosition = drawPositionBlocks[blockIndex].sort(i % 2 ? bottomUp : topDown).find((drawPosition2) => !assignedPositions.includes(drawPosition2));
5578
- assignedPositions.push(drawPosition);
5579
- validSeedBlocks.push({
5580
- seedNumbers: [seedNumber],
5581
- drawPositions: [drawPosition]
5582
- });
5667
+ const block = drawPositionBlocks[blockIndex].slice();
5668
+ let consideredDrawPositions = block.filter(
5669
+ (drawPosition2, i2) => relativePositions.includes(i2 + 1) && drawPosition2
5670
+ );
5671
+ if (positioning !== WATERFALL) {
5672
+ consideredDrawPositions = nonRandom ? consideredDrawPositions : shuffleArray(consideredDrawPositions);
5673
+ } else if (i % 2) {
5674
+ consideredDrawPositions.reverse();
5675
+ }
5676
+ const drawPosition = consideredDrawPositions.find(
5677
+ (drawPosition2) => !assignedPositions.includes(drawPosition2)
5678
+ );
5679
+ if (drawPosition) {
5680
+ assignedPositions.push(drawPosition);
5681
+ validSeedBlocks.push({
5682
+ seedNumbers: [seedNumber],
5683
+ drawPositions: [drawPosition]
5684
+ });
5685
+ }
5583
5686
  });
5584
5687
  });
5585
5688
  return { validSeedBlocks };
@@ -5656,6 +5759,7 @@ function getNextSeedBlock(params) {
5656
5759
  const {
5657
5760
  provisionalPositioning,
5658
5761
  drawDefinition,
5762
+ seedingProfile,
5659
5763
  seedBlockInfo,
5660
5764
  structureId,
5661
5765
  randomize
@@ -5678,6 +5782,7 @@ function getNextSeedBlock(params) {
5678
5782
  provisionalPositioning,
5679
5783
  appliedPolicies,
5680
5784
  drawDefinition,
5785
+ seedingProfile,
5681
5786
  structure
5682
5787
  })?.validSeedBlocks;
5683
5788
  const unfilledSeedBlocks = (validSeedBlocks || []).filter((seedBlock) => {
@@ -5762,13 +5867,12 @@ function getSeedPattern(seedingProfile) {
5762
5867
 
5763
5868
  function addParticipantGroupings({
5764
5869
  participantsProfile,
5765
- participants = []
5870
+ participants = [],
5871
+ deepCopy
5872
+ // will skip deepCopy only if false
5766
5873
  }) {
5767
- const participantsWithGroupings = makeDeepCopy(
5768
- participants,
5769
- participantsProfile?.convertExtensions,
5770
- true
5771
- );
5874
+ const groupMap = /* @__PURE__ */ new Map();
5875
+ const participantsWithGroupings = deepCopy !== false ? makeDeepCopy(participants, participantsProfile?.convertExtensions, true) : participants;
5772
5876
  const teamParticipants = participantsWithGroupings.filter(
5773
5877
  (participant) => participant.participantType === TEAM
5774
5878
  );
@@ -5791,6 +5895,11 @@ function addParticipantGroupings({
5791
5895
  (individualParticipantId) => {
5792
5896
  if (individualParticipantId === participantId && !participant.teamParticipantIds?.includes(team.participantId)) {
5793
5897
  participant.teamParticipantIds.push(team.participantId);
5898
+ if (!groupMap.get(team.participantId))
5899
+ groupMap.set(team.participantId, {
5900
+ participantName: team.participantName,
5901
+ participantId: team.participantId
5902
+ });
5794
5903
  participant.teams.push({
5795
5904
  participantRoleResponsibilities: team.participantRoleResponsibilities,
5796
5905
  participantOtherName: team.participantOtherName,
@@ -5828,7 +5937,7 @@ function addParticipantGroupings({
5828
5937
  });
5829
5938
  }
5830
5939
  });
5831
- return participantsWithGroupings;
5940
+ return { participantsWithGroupings, groupInfo: Object.fromEntries(groupMap) };
5832
5941
  }
5833
5942
 
5834
5943
  const countries = [
@@ -7812,11 +7921,13 @@ function hydrateParticipants({
7812
7921
  participants.forEach(
7813
7922
  (participant) => addNationalityCode({ participant, ...participantsProfile })
7814
7923
  );
7924
+ let groupInfo;
7815
7925
  if ((inContext || participantsProfile?.withGroupings) && participants?.length) {
7816
- participants = addParticipantGroupings({
7926
+ ({ participantsWithGroupings: participants, groupInfo } = addParticipantGroupings({
7817
7927
  participantsProfile,
7928
+ deepCopy: false,
7818
7929
  participants
7819
- });
7930
+ }));
7820
7931
  }
7821
7932
  if (participantsProfile?.withScaleValues && participants?.length) {
7822
7933
  for (const participant of participants) {
@@ -7825,7 +7936,7 @@ function hydrateParticipants({
7825
7936
  participant.ratings = ratings;
7826
7937
  }
7827
7938
  }
7828
- return { participants };
7939
+ return { participants, groupInfo };
7829
7940
  }
7830
7941
 
7831
7942
  const extractor = (object) => (attr) => object[attr];
@@ -8519,13 +8630,14 @@ function getDrawMatchUps(params) {
8519
8630
  event
8520
8631
  });
8521
8632
  }
8633
+ let groupInfo;
8522
8634
  if (!tournamentParticipants?.length && tournamentRecord) {
8523
8635
  tournamentParticipants = tournamentRecord?.participants;
8524
8636
  if ((inContext || participantsProfile?.withGroupings) && tournamentParticipants?.length) {
8525
- tournamentParticipants = addParticipantGroupings({
8637
+ ({ participantsWithGroupings: tournamentParticipants, groupInfo } = addParticipantGroupings({
8526
8638
  participants: tournamentParticipants,
8527
8639
  participantsProfile
8528
- });
8640
+ }));
8529
8641
  }
8530
8642
  }
8531
8643
  const { structures } = getDrawStructures({ drawDefinition });
@@ -8586,14 +8698,15 @@ function getDrawMatchUps(params) {
8586
8698
  }
8587
8699
  return matchUps;
8588
8700
  };
8589
- const matchUpGroups = {
8701
+ const drawMatchUpsResult = {
8590
8702
  abandonedMatchUps: applyFilter(allAbandonedMatchUps),
8591
8703
  completedMatchUps: applyFilter(allCompletedMatchUps),
8592
8704
  upcomingMatchUps: applyFilter(allUpcomingMatchUps),
8593
8705
  pendingMatchUps: applyFilter(allPendingMatchUps),
8594
8706
  byeMatchUps: applyFilter(allByeMatchUps),
8595
8707
  matchUpsMap,
8596
- ...SUCCESS
8708
+ ...SUCCESS,
8709
+ groupInfo
8597
8710
  };
8598
8711
  if (nextMatchUps) {
8599
8712
  const nextFilter = typeof nextMatchUps === "object" || {
@@ -8616,7 +8729,7 @@ function getDrawMatchUps(params) {
8616
8729
  drawDefinition
8617
8730
  });
8618
8731
  }
8619
- return matchUpGroups;
8732
+ return drawMatchUpsResult;
8620
8733
  }
8621
8734
 
8622
8735
  function allTournamentMatchUps(params) {
@@ -8724,8 +8837,13 @@ function allDrawMatchUps(params) {
8724
8837
  surfaceCategory: event?.surfaceCategory ?? tournamentRecord?.surfaceCategory,
8725
8838
  endDate: event?.endDate
8726
8839
  };
8840
+ let groupInfo;
8727
8841
  if (!tournamentParticipants?.length && !participantMap && tournamentRecord) {
8728
- ({ participants: tournamentParticipants = [], participantMap } = hydrateParticipants({
8842
+ ({
8843
+ participants: tournamentParticipants = [],
8844
+ participantMap,
8845
+ groupInfo
8846
+ } = hydrateParticipants({
8729
8847
  participantsProfile,
8730
8848
  useParticipantMap,
8731
8849
  policyDefinitions,
@@ -8743,7 +8861,7 @@ function allDrawMatchUps(params) {
8743
8861
  event
8744
8862
  });
8745
8863
  }
8746
- return getAllDrawMatchUps({
8864
+ const allDrawMatchUpsResult = getAllDrawMatchUps({
8747
8865
  context: additionalContext,
8748
8866
  tournamentAppliedPolicies,
8749
8867
  scheduleVisibilityFilters,
@@ -8762,6 +8880,7 @@ function allDrawMatchUps(params) {
8762
8880
  inContext,
8763
8881
  event
8764
8882
  });
8883
+ return { ...allDrawMatchUpsResult, groupInfo };
8765
8884
  }
8766
8885
  function allEventMatchUps(params) {
8767
8886
  let { participants = [], contextContent, participantMap } = params;
@@ -8808,6 +8927,7 @@ function allEventMatchUps(params) {
8808
8927
  event
8809
8928
  });
8810
8929
  }
8930
+ let groupInfo;
8811
8931
  if (!participants?.length && !participantMap && tournamentRecord) {
8812
8932
  const hydratedParticipantResult = hydrateParticipants({
8813
8933
  participantsProfile,
@@ -8819,6 +8939,7 @@ function allEventMatchUps(params) {
8819
8939
  });
8820
8940
  participantMap = hydratedParticipantResult.participantMap;
8821
8941
  participants = hydratedParticipantResult.participants ?? [];
8942
+ groupInfo = hydratedParticipantResult.groupInfo;
8822
8943
  }
8823
8944
  const drawDefinitions = event.drawDefinitions ?? [];
8824
8945
  const scheduleTiming = getScheduleTiming({
@@ -8850,7 +8971,7 @@ function allEventMatchUps(params) {
8850
8971
  return matchUps2 ?? [];
8851
8972
  }
8852
8973
  );
8853
- return { matchUps };
8974
+ return { matchUps, groupInfo };
8854
8975
  }
8855
8976
 
8856
8977
  function addFinishingRounds({
@@ -12006,8 +12127,9 @@ function randomUnseededSeparation({
12006
12127
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
12007
12128
  const participantsWithGroupings = addParticipantGroupings({
12008
12129
  participantsProfile: { convertExtensions: true },
12130
+ deepCopy: false,
12009
12131
  participants
12010
- });
12132
+ }).participantsWithGroupings;
12011
12133
  const unassignedPositions = positionAssignments?.filter(
12012
12134
  (assignment) => !assignment.participantId
12013
12135
  );
@@ -12468,6 +12590,7 @@ function getSeedOrderByePositions({
12468
12590
  relevantMatchUps,
12469
12591
  appliedPolicies,
12470
12592
  drawDefinition,
12593
+ seedingProfile,
12471
12594
  seedBlockInfo,
12472
12595
  byesToPlace,
12473
12596
  structure
@@ -12477,6 +12600,7 @@ function getSeedOrderByePositions({
12477
12600
  provisionalPositioning,
12478
12601
  appliedPolicies,
12479
12602
  drawDefinition,
12603
+ seedingProfile,
12480
12604
  structure
12481
12605
  });
12482
12606
  }
@@ -12752,6 +12876,7 @@ function positionByes({
12752
12876
  appliedPolicies,
12753
12877
  drawDefinition,
12754
12878
  seedBlockInfo,
12879
+ seedingProfile,
12755
12880
  matchUpsMap,
12756
12881
  structureId,
12757
12882
  structure,
@@ -12784,6 +12909,7 @@ function positionByes({
12784
12909
  relevantMatchUps,
12785
12910
  appliedPolicies,
12786
12911
  drawDefinition,
12912
+ seedingProfile,
12787
12913
  seedBlockInfo,
12788
12914
  byesToPlace,
12789
12915
  structure
@@ -12959,6 +13085,7 @@ function positionSeedBlocks({
12959
13085
  provisionalPositioning,
12960
13086
  appliedPolicies,
12961
13087
  drawDefinition,
13088
+ seedingProfile,
12962
13089
  structure
12963
13090
  });
12964
13091
  if (result?.error)
@@ -13009,6 +13136,7 @@ function positionSeedBlock({
13009
13136
  provisionalPositioning,
13010
13137
  randomize: true,
13011
13138
  drawDefinition,
13139
+ seedingProfile,
13012
13140
  seedBlockInfo,
13013
13141
  structureId,
13014
13142
  event
@@ -13121,6 +13249,7 @@ function automatedPositioning$1({
13121
13249
  provisionalPositioning,
13122
13250
  appliedPolicies,
13123
13251
  drawDefinition,
13252
+ seedingProfile,
13124
13253
  structure
13125
13254
  });
13126
13255
  if (seedBlockInfo.error)
@@ -23186,6 +23315,7 @@ function prepareStage(params) {
23186
23315
  provisionalPositioning,
23187
23316
  appliedPolicies,
23188
23317
  drawDefinition,
23318
+ seedingProfile,
23189
23319
  structure
23190
23320
  }) : void 0;
23191
23321
  const { seedLimit } = initializeStructureSeedAssignments({
@@ -23465,6 +23595,7 @@ function generateDrawDefinition(params) {
23465
23595
  ignoreStageSpace,
23466
23596
  tournamentRecord,
23467
23597
  qualifyingOnly,
23598
+ seedingProfile,
23468
23599
  tieFormatName,
23469
23600
  drawEntries,
23470
23601
  addToEvent,
@@ -23754,6 +23885,7 @@ function generateDrawDefinition(params) {
23754
23885
  // ooo!! If there is no drawSize then MAIN is not being generated
23755
23886
  appliedPolicies,
23756
23887
  drawDefinition,
23888
+ seedingProfile,
23757
23889
  participants,
23758
23890
  stage: MAIN,
23759
23891
  seedsCount,
@@ -23836,7 +23968,6 @@ function generateDrawDefinition(params) {
23836
23968
  seededParticipants,
23837
23969
  seedingScaleName,
23838
23970
  seedsCount: seedsCount2 = 0,
23839
- seedingProfile,
23840
23971
  seedByRanking,
23841
23972
  placeByes: placeByes2,
23842
23973
  drawSize: drawSize2
@@ -23844,6 +23975,7 @@ function generateDrawDefinition(params) {
23844
23975
  const qualifyingStageResult = prepareStage({
23845
23976
  ...drawTypeResult,
23846
23977
  ...params,
23978
+ seedingProfile: structureProfile.seedingProfile ?? seedingProfile,
23847
23979
  stageSequence: sequence,
23848
23980
  qualifyingRoundNumber,
23849
23981
  preparedStructureIds,
@@ -23854,7 +23986,6 @@ function generateDrawDefinition(params) {
23854
23986
  appliedPolicies,
23855
23987
  drawDefinition,
23856
23988
  qualifyingOnly,
23857
- seedingProfile,
23858
23989
  seedByRanking,
23859
23990
  participants,
23860
23991
  roundTarget,