tods-competition-factory 1.8.31 → 1.8.33

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) => {
@@ -12485,6 +12590,7 @@ function getSeedOrderByePositions({
12485
12590
  relevantMatchUps,
12486
12591
  appliedPolicies,
12487
12592
  drawDefinition,
12593
+ seedingProfile,
12488
12594
  seedBlockInfo,
12489
12595
  byesToPlace,
12490
12596
  structure
@@ -12494,6 +12600,7 @@ function getSeedOrderByePositions({
12494
12600
  provisionalPositioning,
12495
12601
  appliedPolicies,
12496
12602
  drawDefinition,
12603
+ seedingProfile,
12497
12604
  structure
12498
12605
  });
12499
12606
  }
@@ -12769,6 +12876,7 @@ function positionByes({
12769
12876
  appliedPolicies,
12770
12877
  drawDefinition,
12771
12878
  seedBlockInfo,
12879
+ seedingProfile,
12772
12880
  matchUpsMap,
12773
12881
  structureId,
12774
12882
  structure,
@@ -12801,6 +12909,7 @@ function positionByes({
12801
12909
  relevantMatchUps,
12802
12910
  appliedPolicies,
12803
12911
  drawDefinition,
12912
+ seedingProfile,
12804
12913
  seedBlockInfo,
12805
12914
  byesToPlace,
12806
12915
  structure
@@ -12976,6 +13085,7 @@ function positionSeedBlocks({
12976
13085
  provisionalPositioning,
12977
13086
  appliedPolicies,
12978
13087
  drawDefinition,
13088
+ seedingProfile,
12979
13089
  structure
12980
13090
  });
12981
13091
  if (result?.error)
@@ -13026,6 +13136,7 @@ function positionSeedBlock({
13026
13136
  provisionalPositioning,
13027
13137
  randomize: true,
13028
13138
  drawDefinition,
13139
+ seedingProfile,
13029
13140
  seedBlockInfo,
13030
13141
  structureId,
13031
13142
  event
@@ -13138,6 +13249,7 @@ function automatedPositioning$1({
13138
13249
  provisionalPositioning,
13139
13250
  appliedPolicies,
13140
13251
  drawDefinition,
13252
+ seedingProfile,
13141
13253
  structure
13142
13254
  });
13143
13255
  if (seedBlockInfo.error)
@@ -19104,7 +19216,7 @@ function getParticipantEntries(params) {
19104
19216
  const minutesDifference = Math.abs(
19105
19217
  consideredMinutes - scheduledMinutes
19106
19218
  );
19107
- const itemIsPrior = consideredMinutes > scheduledMinutes;
19219
+ const itemIsPrior = consideredMinutes >= scheduledMinutes;
19108
19220
  const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : itemIsPrior && timeStringMinutes(consideredItem.scheduledTime) < timeStringMinutes(notBeforeTime);
19109
19221
  if (timeOverlap && !(bothPotential && sameDraw) && itemIsPrior) {
19110
19222
  participantAggregator.scheduleConflicts.push({
@@ -23203,6 +23315,7 @@ function prepareStage(params) {
23203
23315
  provisionalPositioning,
23204
23316
  appliedPolicies,
23205
23317
  drawDefinition,
23318
+ seedingProfile,
23206
23319
  structure
23207
23320
  }) : void 0;
23208
23321
  const { seedLimit } = initializeStructureSeedAssignments({
@@ -23482,6 +23595,7 @@ function generateDrawDefinition(params) {
23482
23595
  ignoreStageSpace,
23483
23596
  tournamentRecord,
23484
23597
  qualifyingOnly,
23598
+ seedingProfile,
23485
23599
  tieFormatName,
23486
23600
  drawEntries,
23487
23601
  addToEvent,
@@ -23771,6 +23885,7 @@ function generateDrawDefinition(params) {
23771
23885
  // ooo!! If there is no drawSize then MAIN is not being generated
23772
23886
  appliedPolicies,
23773
23887
  drawDefinition,
23888
+ seedingProfile,
23774
23889
  participants,
23775
23890
  stage: MAIN,
23776
23891
  seedsCount,
@@ -23853,7 +23968,6 @@ function generateDrawDefinition(params) {
23853
23968
  seededParticipants,
23854
23969
  seedingScaleName,
23855
23970
  seedsCount: seedsCount2 = 0,
23856
- seedingProfile,
23857
23971
  seedByRanking,
23858
23972
  placeByes: placeByes2,
23859
23973
  drawSize: drawSize2
@@ -23861,6 +23975,7 @@ function generateDrawDefinition(params) {
23861
23975
  const qualifyingStageResult = prepareStage({
23862
23976
  ...drawTypeResult,
23863
23977
  ...params,
23978
+ seedingProfile: structureProfile.seedingProfile ?? seedingProfile,
23864
23979
  stageSequence: sequence,
23865
23980
  qualifyingRoundNumber,
23866
23981
  preparedStructureIds,
@@ -23871,7 +23986,6 @@ function generateDrawDefinition(params) {
23871
23986
  appliedPolicies,
23872
23987
  drawDefinition,
23873
23988
  qualifyingOnly,
23874
- seedingProfile,
23875
23989
  seedByRanking,
23876
23990
  participants,
23877
23991
  roundTarget,