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.
@@ -13589,10 +13589,89 @@ function getSeedGroups({
13589
13589
  }
13590
13590
  }
13591
13591
 
13592
+ function getDivisions({ size }) {
13593
+ const divisions = [size];
13594
+ let division = size;
13595
+ while (division / 2 === Math.floor(division / 2)) {
13596
+ division = division / 2;
13597
+ divisions.push(division);
13598
+ }
13599
+ if (!divisions.includes(1))
13600
+ divisions.push(1);
13601
+ divisions.sort(numericSort);
13602
+ divisions.reverse();
13603
+ return divisions;
13604
+ }
13605
+ function getSubBlock({ blockPattern, index }) {
13606
+ let i = 0;
13607
+ for (const subBlock of blockPattern) {
13608
+ if (i === index)
13609
+ return subBlock;
13610
+ let j = 0;
13611
+ while (j < subBlock.length) {
13612
+ if (i === index)
13613
+ return subBlock;
13614
+ i += 1;
13615
+ j++;
13616
+ }
13617
+ }
13618
+ }
13619
+ function generateBlockPattern({
13620
+ positioning,
13621
+ size
13622
+ }) {
13623
+ const divisions = getDivisions({ size });
13624
+ const divisionGroupings = [];
13625
+ const selected = [];
13626
+ const firstMember = (arr) => arr[0];
13627
+ const lastMember = (arr) => arr[arr.length - 1];
13628
+ const getMember = (arr, i) => (positioning === CLUSTER && i % 2 ? lastMember(arr) : firstMember(arr)) || firstMember(arr);
13629
+ const noneSelected = (chunk, i) => {
13630
+ if (chunk.every((member) => !selected.includes(member))) {
13631
+ const member = getMember(chunk, i);
13632
+ selected.push(member);
13633
+ return member;
13634
+ }
13635
+ };
13636
+ const notSelected = (chunk) => {
13637
+ const notSelected2 = chunk.filter((member) => !selected.includes(member));
13638
+ if (notSelected2.length) {
13639
+ selected.push(...notSelected2);
13640
+ return notSelected2;
13641
+ }
13642
+ };
13643
+ const select = (chunk, i) => {
13644
+ const member = getMember(chunk, i);
13645
+ if (!selected.includes(member)) {
13646
+ selected.push(member);
13647
+ return member;
13648
+ }
13649
+ };
13650
+ const range = generateRange(1, size + 1);
13651
+ for (const division of divisions) {
13652
+ if (division === 1) {
13653
+ const chunks = chunkArray(range, 2);
13654
+ const positions = chunks.map(noneSelected).filter(Boolean);
13655
+ if (positions.length)
13656
+ divisionGroupings.push(positions);
13657
+ const lastPositions = chunks.flatMap(notSelected).filter(Boolean);
13658
+ if (lastPositions.length)
13659
+ divisionGroupings.push(lastPositions);
13660
+ } else {
13661
+ const chunks = chunkArray(range, division);
13662
+ const positions = chunks.map(select).filter(Boolean);
13663
+ if (positions.length)
13664
+ divisionGroupings.push(positions);
13665
+ }
13666
+ }
13667
+ return { divisions, divisionGroupings };
13668
+ }
13669
+
13592
13670
  function getValidSeedBlocks({
13593
13671
  provisionalPositioning,
13594
13672
  returnAllProxies,
13595
13673
  appliedPolicies,
13674
+ seedingProfile,
13596
13675
  drawDefinition,
13597
13676
  allPositions,
13598
13677
  structure
@@ -13626,7 +13705,7 @@ function getValidSeedBlocks({
13626
13705
  }).filter((f) => f.length).reverse();
13627
13706
  const firstRoundDrawPositions = uniqueDrawPositionsByRound.pop();
13628
13707
  const firstRoundDrawPositionOffset = firstRoundDrawPositions && Math.min(...firstRoundDrawPositions) - 1 || 0;
13629
- const seedingProfile = appliedPolicies?.seeding?.seedingProfile;
13708
+ seedingProfile = seedingProfile ?? appliedPolicies?.seeding?.seedingProfile;
13630
13709
  const baseDrawSize = firstRoundDrawPositions?.length || 0;
13631
13710
  const seedRangeDrawPositionBlocks = uniqueDrawPositionsByRound.filter(
13632
13711
  (block) => block.filter((drawPosition) => drawPosition <= seedsCount).length
@@ -13665,12 +13744,14 @@ function getValidSeedBlocks({
13665
13744
  );
13666
13745
  ({ validSeedBlocks } = getSeedBlockPattern({
13667
13746
  drawPositionBlocks: drawPositionChunks,
13747
+ nonRandom: seedingProfile?.nonRandom,
13668
13748
  positioning,
13669
13749
  seedGroups
13670
13750
  }));
13671
13751
  }
13672
13752
  } else if (isContainer) {
13673
13753
  const result = getContainerBlocks({
13754
+ nonRandom: seedingProfile?.nonRandom,
13674
13755
  seedingProfile,
13675
13756
  structure
13676
13757
  });
@@ -13720,7 +13801,7 @@ function getValidSeedBlocks({
13720
13801
  isFeedIn
13721
13802
  };
13722
13803
  }
13723
- function getContainerBlocks({ seedingProfile, structure }) {
13804
+ function getContainerBlocks({ seedingProfile, structure, nonRandom }) {
13724
13805
  const containedStructures = structure.structures || [];
13725
13806
  const roundRobinGroupsCount = containedStructures.length;
13726
13807
  const positionAssignments = getPositionAssignments({
@@ -13740,26 +13821,48 @@ function getContainerBlocks({ seedingProfile, structure }) {
13740
13821
  return getSeedBlockPattern({
13741
13822
  drawPositionBlocks,
13742
13823
  positioning,
13743
- seedGroups
13824
+ seedGroups,
13825
+ nonRandom
13744
13826
  });
13745
13827
  }
13746
- function getSeedBlockPattern({ positioning, seedGroups, drawPositionBlocks }) {
13828
+ function getSeedBlockPattern({
13829
+ drawPositionBlocks,
13830
+ positioning,
13831
+ seedGroups,
13832
+ nonRandom
13833
+ }) {
13747
13834
  const validSeedBlocks = [];
13748
- const topDown = (a, b) => a - b;
13749
- const bottomUp = (a, b) => b - a;
13835
+ const { divisionGroupings } = generateBlockPattern({
13836
+ size: seedGroups.length,
13837
+ positioning
13838
+ });
13750
13839
  const assignedPositions = [];
13751
13840
  seedGroups.forEach((seedGroup, i) => {
13752
- if (i && positioning !== WATERFALL) {
13753
- shuffleArray(seedGroup);
13754
- }
13841
+ const relativePositions = getSubBlock({
13842
+ blockPattern: divisionGroupings,
13843
+ index: i
13844
+ });
13755
13845
  seedGroup.forEach((seedNumber, j) => {
13756
13846
  const blockIndex = i % 2 ? drawPositionBlocks.length - j - 1 : j;
13757
- const drawPosition = drawPositionBlocks[blockIndex].sort(i % 2 ? bottomUp : topDown).find((drawPosition2) => !assignedPositions.includes(drawPosition2));
13758
- assignedPositions.push(drawPosition);
13759
- validSeedBlocks.push({
13760
- seedNumbers: [seedNumber],
13761
- drawPositions: [drawPosition]
13762
- });
13847
+ const block = drawPositionBlocks[blockIndex].slice();
13848
+ let consideredDrawPositions = block.filter(
13849
+ (drawPosition2, i2) => relativePositions.includes(i2 + 1) && drawPosition2
13850
+ );
13851
+ if (positioning !== WATERFALL) {
13852
+ consideredDrawPositions = nonRandom ? consideredDrawPositions : shuffleArray(consideredDrawPositions);
13853
+ } else if (i % 2) {
13854
+ consideredDrawPositions.reverse();
13855
+ }
13856
+ const drawPosition = consideredDrawPositions.find(
13857
+ (drawPosition2) => !assignedPositions.includes(drawPosition2)
13858
+ );
13859
+ if (drawPosition) {
13860
+ assignedPositions.push(drawPosition);
13861
+ validSeedBlocks.push({
13862
+ seedNumbers: [seedNumber],
13863
+ drawPositions: [drawPosition]
13864
+ });
13865
+ }
13763
13866
  });
13764
13867
  });
13765
13868
  return { validSeedBlocks };