tods-competition-factory 0.70.2 → 0.70.3

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.
@@ -249,7 +249,7 @@ const matchUpFormatCode = {
249
249
  };
250
250
 
251
251
  function factoryVersion() {
252
- return '0.70.2';
252
+ return '0.70.3';
253
253
  }
254
254
 
255
255
  const FORMAT_STANDARD = 'SET3-S:6/TB7'; // Best of 3 Tiebreak Sets to 6
@@ -18389,20 +18389,30 @@ function getSeedBlocks({
18389
18389
  };
18390
18390
  }
18391
18391
 
18392
+ /**
18393
+ * A seedBlock is an object pairing an array of drawPositions with an array of seedNumbers { drawPositions: [], seedNumbers: []}
18394
+ * In an elimination structure The first seedBlock is { drawPositions: [1], seedNumbers: [1] }
18395
+ * In an elimination structure The second seedBlock is{ drawPositions: [drawSize], seedNumbers: [2] }
18396
+ * In an elimination structure the third seedBlock is { drawPositions: [a, b], seedNumbers: [3, 4] }
18397
+ * In an elimination structure the fourth seedBlock is { drawPositions: [w, x, y, z], seedNumbers: [5, 6, 7, 8] }
18398
+ * The calculations for the positioning of [a, b] and [w, x, y, z] are specific to seeding policies
18399
+ */
18400
+
18392
18401
  function getValidSeedBlocks({
18393
- drawDefinition,
18394
18402
  appliedPolicies,
18403
+ drawDefinition,
18395
18404
  allPositions,
18396
18405
  structure
18397
18406
  }) {
18398
18407
  var _appliedPolicies$seed;
18399
18408
 
18400
- let firstRoundSeedsCount,
18401
- fedSeedNumberOffset = 0;
18402
- let error,
18403
- isFeedIn,
18409
+ let fedSeedNumberOffset = 0,
18410
+ firstRoundSeedsCount,
18411
+ validSeedBlocks = [],
18404
18412
  isContainer,
18405
- validSeedBlocks = [];
18413
+ isFeedIn,
18414
+ isLucky,
18415
+ error;
18406
18416
  if (!structure) return {
18407
18417
  error: MISSING_STRUCTURE
18408
18418
  };
@@ -18471,40 +18481,53 @@ function getValidSeedBlocks({
18471
18481
  // should be equal fo firstRoundDrawPositionOffset
18472
18482
 
18473
18483
  fedSeedNumberOffset = fedSeedBlockPositions.length;
18484
+ } else if (firstRoundDrawPositions && !isPowerOf2(baseDrawSize)) {
18485
+ // if there are first round draw positions it is not AdHoc
18486
+ // if the baseDrawSize is not a power of 2 then it isLucky
18487
+ firstRoundSeedsCount = 0;
18488
+ isLucky = true;
18474
18489
  } else {
18475
18490
  firstRoundSeedsCount = countLimit;
18476
18491
  }
18477
18492
 
18478
- if (!isContainer) {
18493
+ if (!isContainer && !isLucky) {
18479
18494
  const {
18480
18495
  blocks,
18481
18496
  error
18482
18497
  } = constructPower2Blocks({
18483
- baseDrawSize,
18484
- seedingProfile,
18485
- seedCountGoal: firstRoundSeedsCount,
18498
+ drawPositionOffset: firstRoundDrawPositionOffset,
18486
18499
  seedNumberOffset: fedSeedNumberOffset,
18487
- drawPositionOffset: firstRoundDrawPositionOffset
18500
+ seedCountGoal: firstRoundSeedsCount,
18501
+ seedingProfile,
18502
+ baseDrawSize
18488
18503
  });
18489
18504
 
18490
18505
  if (error) {
18491
18506
  return {
18492
- error,
18493
18507
  validSeedBlocks: [],
18494
18508
  isContainer,
18495
- isFeedIn
18509
+ isFeedIn,
18510
+ error
18496
18511
  };
18497
18512
  }
18498
18513
 
18499
18514
  blocks.forEach(block => validSeedBlocks.push(block));
18500
18515
  }
18501
18516
 
18517
+ if (isLucky) {
18518
+ const blocks = chunkArray(firstRoundDrawPositions, 2).map((block, i) => ({
18519
+ drawPositions: [block[0]],
18520
+ seedNumbers: [i + 1]
18521
+ }));
18522
+ blocks.forEach(block => validSeedBlocks.push(block));
18523
+ }
18524
+
18502
18525
  const seedDrawPositions = [].concat(...validSeedBlocks.map(seedBlock => seedBlock.drawPositions));
18503
18526
  const validSeedPositions = seedDrawPositions.reduce((result, drawPosition) => {
18504
18527
  return (firstRoundDrawPositions === null || firstRoundDrawPositions === void 0 ? void 0 : firstRoundDrawPositions.includes(drawPosition)) && result;
18505
18528
  }, true);
18506
18529
 
18507
- if (!isFeedIn && !isContainer && !validSeedPositions) {
18530
+ if (!isLucky && !isFeedIn && !isContainer && !validSeedPositions) {
18508
18531
  return {
18509
18532
  error: INVALID_SEED_POSITION,
18510
18533
  validSeedBlocks: [],
@@ -18515,8 +18538,9 @@ function getValidSeedBlocks({
18515
18538
 
18516
18539
  return {
18517
18540
  validSeedBlocks,
18541
+ isContainer,
18518
18542
  isFeedIn,
18519
- isContainer
18543
+ isLucky
18520
18544
  };
18521
18545
  }
18522
18546
 
@@ -18620,11 +18644,11 @@ function constructContainerBlocks({
18620
18644
  }
18621
18645
 
18622
18646
  function constructPower2Blocks({
18623
- baseDrawSize,
18624
- seedCountGoal,
18625
- seedingProfile,
18626
18647
  drawPositionOffset = 0,
18627
- seedNumberOffset = 0
18648
+ seedNumberOffset = 0,
18649
+ seedingProfile,
18650
+ seedCountGoal,
18651
+ baseDrawSize
18628
18652
  }) {
18629
18653
  let count = 1;
18630
18654
  const blocks = [];
@@ -30531,14 +30555,15 @@ function getStructurePositionedSeeds({
30531
30555
  }
30532
30556
 
30533
30557
  function getSeedOrderByePositions({
30534
- structure,
30535
- drawDefinition,
30558
+ relevantMatchUps,
30536
30559
  appliedPolicies,
30537
- relevantMatchUps
30560
+ drawDefinition,
30561
+ structure
30538
30562
  }) {
30539
30563
  const {
30540
30564
  validSeedBlocks,
30541
30565
  isFeedIn,
30566
+ isLucky,
30542
30567
  isContainer
30543
30568
  } = getValidSeedBlocks({
30544
30569
  appliedPolicies,
@@ -30585,8 +30610,9 @@ function getSeedOrderByePositions({
30585
30610
  return {
30586
30611
  strictSeedOrderByePositions,
30587
30612
  blockSeedOrderByePositions,
30613
+ isContainer,
30588
30614
  isFeedIn,
30589
- isContainer
30615
+ isLucky
30590
30616
  };
30591
30617
  }
30592
30618
 
@@ -30611,9 +30637,10 @@ function getOrderedByePositions({
30611
30637
  }
30612
30638
 
30613
30639
  function getUnseededByePositions({
30614
- structure,
30615
30640
  appliedPolicies,
30616
- isFeedIn
30641
+ structure,
30642
+ isFeedIn,
30643
+ isLucky
30617
30644
  }) {
30618
30645
  var _appliedPolicies$seed;
30619
30646
 
@@ -30702,9 +30729,9 @@ function getUnseededByePositions({
30702
30729
  const {
30703
30730
  validSeedBlocks
30704
30731
  } = getValidSeedBlocks({
30705
- structure,
30732
+ allPositions: true,
30706
30733
  appliedPolicies,
30707
- allPositions: true
30734
+ structure
30708
30735
  });
30709
30736
  const validBlockDrawPositions = validSeedBlocks.map(block => {
30710
30737
  var _block$drawPositions;
@@ -30855,14 +30882,15 @@ function positionByes({
30855
30882
  drawDefinition
30856
30883
  });
30857
30884
  const {
30858
- isFeedIn,
30859
30885
  strictSeedOrderByePositions,
30860
- blockSeedOrderByePositions
30886
+ blockSeedOrderByePositions,
30887
+ isFeedIn,
30888
+ isLucky
30861
30889
  } = getSeedOrderByePositions({
30862
- structure,
30863
- drawDefinition,
30890
+ relevantMatchUps,
30864
30891
  appliedPolicies,
30865
- relevantMatchUps
30892
+ drawDefinition,
30893
+ structure
30866
30894
  });
30867
30895
  const seedOrderByePositions = blockOrdered ? blockSeedOrderByePositions : strictSeedOrderByePositions;
30868
30896
  const {
@@ -30870,9 +30898,10 @@ function positionByes({
30870
30898
  } = getUnseededByePositions({
30871
30899
  appliedPolicies,
30872
30900
  structure,
30873
- isFeedIn
30901
+ isFeedIn,
30902
+ isLucky
30874
30903
  }); // first add all drawPositions paired with sorted seeds drawPositions
30875
- // then add quarter separated dnd evenly distributed drawPositions
30904
+ // then add quarter separated and evenly distributed drawPositions
30876
30905
  // derived from theoretical seeding of firstRoundParticipants/2
30877
30906
 
30878
30907
  const byePositions = [].concat(...seedOrderByePositions, ...(seedsOnly ? [] : unseededByePositions)); // then take only the number of required byes
@@ -31087,6 +31116,7 @@ function automatedPositioning$1({
31087
31116
  structureId,
31088
31117
  matchUpsMap,
31089
31118
  seedsOnly,
31119
+ drawType,
31090
31120
  event
31091
31121
  }) {
31092
31122
  const {
@@ -31148,15 +31178,18 @@ function automatedPositioning$1({
31148
31178
  } else {
31149
31179
  // otherwise... seeds need to be placed first so that BYEs
31150
31180
  // can follow the seedValues of placed seeds
31151
- let result = positionSeedBlocks({
31152
- inContextDrawMatchUps,
31153
- drawDefinition,
31154
- participants,
31155
- matchUpsMap,
31156
- structure
31157
- });
31158
- if (result.error) return result;
31159
- result = positionByes({
31181
+ if (drawType !== LUCKY_DRAW) {
31182
+ let result = positionSeedBlocks({
31183
+ inContextDrawMatchUps,
31184
+ drawDefinition,
31185
+ participants,
31186
+ matchUpsMap,
31187
+ structure
31188
+ });
31189
+ if (result.error) return result;
31190
+ }
31191
+
31192
+ const result = positionByes({
31160
31193
  inContextDrawMatchUps,
31161
31194
  drawDefinition,
31162
31195
  matchUpsMap,
@@ -31171,12 +31204,12 @@ function automatedPositioning$1({
31171
31204
 
31172
31205
  if (!seedsOnly) {
31173
31206
  let result = positionUnseededParticipants({
31207
+ inContextDrawMatchUps,
31174
31208
  candidatesCount,
31175
31209
  drawDefinition,
31176
31210
  participants,
31177
- structure,
31178
31211
  matchUpsMap,
31179
- inContextDrawMatchUps
31212
+ structure
31180
31213
  });
31181
31214
  if (result.error) return result;
31182
31215
  if (result.conflicts) conflicts.unseededConflicts = result.conflicts;
@@ -44748,7 +44781,9 @@ function generateDrawDefinition(params) {
44748
44781
  seedsCount,
44749
44782
  event
44750
44783
  });
44751
- if (seedLimit && seedLimit < seedsCount) seedsCount = seedLimit;
44784
+ if (seedLimit && seedLimit < seedsCount) seedsCount = seedLimit; // temporary until seeding is supported in LUCKY_DRAW
44785
+
44786
+ if (drawType === LUCKY_DRAW) seedsCount = 0;
44752
44787
 
44753
44788
  if (seededParticipants) {
44754
44789
  seededParticipants.filter(({
@@ -44843,7 +44878,9 @@ function generateDrawDefinition(params) {
44843
44878
  participants,
44844
44879
  structureId,
44845
44880
  matchUpsMap,
44846
- seedsOnly
44881
+ seedsOnly,
44882
+ drawType,
44883
+ event
44847
44884
  }));
44848
44885
  }
44849
44886
 
@@ -51353,7 +51390,7 @@ function getParticipantsCount({
51353
51390
  }
51354
51391
  });
51355
51392
 
51356
- if (drawProfiles) {
51393
+ if (Array.isArray(drawProfiles)) {
51357
51394
  for (const drawProfile of drawProfiles) {
51358
51395
  processDrawProfile(drawProfile);
51359
51396
  }
@@ -52636,6 +52673,9 @@ function generateTournamentRecord({
52636
52673
  if (startDate && !isValidDateString(startDate) || endDate && !isValidDateString(endDate)) return {
52637
52674
  error: INVALID_DATE
52638
52675
  };
52676
+ if (eventProfiles && !Array.isArray(eventProfiles)) return {
52677
+ error: INVALID_VALUES
52678
+ };
52639
52679
 
52640
52680
  if (!startDate) {
52641
52681
  const tournamentDate = new Date();
@@ -52687,7 +52727,7 @@ function generateTournamentRecord({
52687
52727
  eventIds = [],
52688
52728
  allUniqueParticipantIds = [];
52689
52729
 
52690
- if (drawProfiles) {
52730
+ if (Array.isArray(drawProfiles)) {
52691
52731
  let drawIndex = 0;
52692
52732
 
52693
52733
  for (const drawProfile of drawProfiles) {