tods-competition-factory 2.1.10 → 2.1.11

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.1.10';
6
+ return '2.1.11';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -6353,6 +6353,651 @@ function getStructureSeedAssignments({ provisionalPositioning, returnAllProxies,
6353
6353
  };
6354
6354
  }
6355
6355
 
6356
+ function getObjectTieFormat(obj) {
6357
+ if (!obj)
6358
+ return;
6359
+ const { tieFormatId, tieFormats } = obj;
6360
+ if (obj.tieFormat) {
6361
+ return obj.tieFormat;
6362
+ }
6363
+ else if (tieFormatId && Array.isArray(tieFormats)) {
6364
+ return tieFormats.find((tf) => tf.tieFormatId === tieFormatId);
6365
+ }
6366
+ }
6367
+
6368
+ function getItemTieFormat({ item, drawDefinition, structure, event }) {
6369
+ if (!item)
6370
+ return;
6371
+ if (item.tieFormat)
6372
+ return item.tieFormat;
6373
+ if (item.tieFormatId) {
6374
+ if (drawDefinition.tieFormat)
6375
+ return drawDefinition.tieFormat;
6376
+ const tieFormat = drawDefinition.tieFormats?.find((tf) => item.tieFormatId === tf.tieFormatId);
6377
+ if (tieFormat)
6378
+ return tieFormat;
6379
+ if (event.tieFormat)
6380
+ return event.tieFormat;
6381
+ return event.tieFormats?.find((tf) => item.tieFormatId === tf.tieFormatId);
6382
+ }
6383
+ if (structure.tieFormat)
6384
+ return structure.tieFormat;
6385
+ if (structure.tieFormatId) {
6386
+ const structureTieFormat = drawDefinition.tieFormats?.find((tf) => structure.tieFormatId === tf.tieFormatId);
6387
+ if (structureTieFormat)
6388
+ return structureTieFormat;
6389
+ }
6390
+ }
6391
+
6392
+ function resolveTieFormat({ drawDefinition, structure, matchUp, event }) {
6393
+ return {
6394
+ tieFormat: getItemTieFormat({
6395
+ item: matchUp,
6396
+ drawDefinition,
6397
+ structure,
6398
+ event,
6399
+ }) ||
6400
+ getItemTieFormat({
6401
+ item: structure,
6402
+ drawDefinition,
6403
+ structure,
6404
+ event,
6405
+ }) ||
6406
+ getObjectTieFormat(drawDefinition) ||
6407
+ getObjectTieFormat(event),
6408
+ };
6409
+ }
6410
+
6411
+ function getCollectionPositionMatchUps({ matchUps }) {
6412
+ const collectionPositionMatchUpsArray = matchUps
6413
+ .reduce((collectionPositions, matchUp) => {
6414
+ return !matchUp.collectionPosition || collectionPositions.includes(matchUp.collectionPosition)
6415
+ ? collectionPositions
6416
+ : collectionPositions.concat(matchUp.collectionPosition);
6417
+ }, [])
6418
+ .map((collectionPosition) => {
6419
+ return {
6420
+ [collectionPosition]: matchUps.filter((matchUp) => matchUp.collectionPosition === collectionPosition),
6421
+ };
6422
+ });
6423
+ const collectionPositionMatchUps = Object.assign({}, ...collectionPositionMatchUpsArray);
6424
+ return { collectionPositionMatchUps };
6425
+ }
6426
+
6427
+ function getMatchUpsMap({ drawDefinition, structure }) {
6428
+ const mappedMatchUps = {};
6429
+ const drawMatchUps = [];
6430
+ (drawDefinition?.structures ?? [structure])
6431
+ .filter((structure) => structure && typeof structure === 'object')
6432
+ .forEach((structure) => {
6433
+ if (!structure)
6434
+ return;
6435
+ const { structureId, matchUps, structures } = structure;
6436
+ const isRoundRobin = Array.isArray(structures);
6437
+ if (!isRoundRobin) {
6438
+ const filteredMatchUps = matchUps;
6439
+ mappedMatchUps[structureId] = {
6440
+ matchUps: filteredMatchUps,
6441
+ itemStructureIds: [],
6442
+ };
6443
+ filteredMatchUps?.forEach((matchUp) => {
6444
+ drawMatchUps.push(matchUp);
6445
+ if (matchUp.tieMatchUps)
6446
+ drawMatchUps.push(...matchUp.tieMatchUps);
6447
+ });
6448
+ }
6449
+ else if (isRoundRobin) {
6450
+ structures.forEach((itemStructure) => {
6451
+ const { structureName } = itemStructure;
6452
+ const filteredMatchUps = itemStructure.matchUps;
6453
+ mappedMatchUps[itemStructure.structureId] = {
6454
+ matchUps: filteredMatchUps,
6455
+ itemStructureIds: [],
6456
+ structureName,
6457
+ };
6458
+ if (filteredMatchUps) {
6459
+ drawMatchUps.push(...filteredMatchUps);
6460
+ filteredMatchUps.forEach((matchUp) => {
6461
+ if (matchUp.tieMatchUps)
6462
+ drawMatchUps.push(...matchUp.tieMatchUps);
6463
+ });
6464
+ }
6465
+ if (!mappedMatchUps[structureId])
6466
+ mappedMatchUps[structureId] = {
6467
+ itemStructureIds: [],
6468
+ matchUps: [],
6469
+ };
6470
+ if (!mappedMatchUps[structureId].itemStructureIds)
6471
+ mappedMatchUps[structureId].itemStructureIds = [];
6472
+ mappedMatchUps[structureId].itemStructureIds.push(itemStructure.structureId);
6473
+ });
6474
+ }
6475
+ });
6476
+ return { mappedMatchUps, drawMatchUps };
6477
+ }
6478
+ function getMappedStructureMatchUps({ mappedMatchUps, matchUpsMap, structureId, inContext, }) {
6479
+ mappedMatchUps = matchUpsMap?.mappedMatchUps ?? mappedMatchUps;
6480
+ const structureMatchUpsMap = mappedMatchUps[structureId];
6481
+ const itemStructureMatchUps = (structureMatchUpsMap?.itemStructureIds || [])
6482
+ .map((itemStructureId) => {
6483
+ const { matchUps, structureName } = mappedMatchUps[itemStructureId];
6484
+ if (inContext) {
6485
+ return matchUps.map((matchUp) => {
6486
+ return Object.assign(makeDeepCopy(matchUp, true, true), {
6487
+ containerStructureId: structureId,
6488
+ structureId: itemStructureId,
6489
+ structureName,
6490
+ });
6491
+ });
6492
+ }
6493
+ else {
6494
+ return matchUps;
6495
+ }
6496
+ })
6497
+ .flat();
6498
+ return (structureMatchUpsMap?.matchUps || []).concat(...itemStructureMatchUps);
6499
+ }
6500
+
6501
+ function reduceGroupedOrder({ groupedOrder, roundPositionsCount }) {
6502
+ if (!groupedOrder || groupedOrder?.length <= roundPositionsCount) {
6503
+ return groupedOrder;
6504
+ }
6505
+ const groupChunks = chunkArray(groupedOrder, groupedOrder.length / roundPositionsCount);
6506
+ const chunkValues = groupChunks.map((chunk) => chunk.reduce((a, b) => a + b));
6507
+ const sortedChunks = chunkValues.slice().sort(numericSort);
6508
+ return chunkValues.map((chunkValue) => sortedChunks.indexOf(chunkValue) + 1);
6509
+ }
6510
+
6511
+ function validMatchUp(matchUp) {
6512
+ if (!isObject(matchUp))
6513
+ return false;
6514
+ const { matchUpId, drawPositions } = matchUp;
6515
+ const validMatchUpId = typeof matchUpId === 'string';
6516
+ const validDrawPositions = !drawPositions ||
6517
+ (Array.isArray(drawPositions) &&
6518
+ drawPositions.length <= 2 &&
6519
+ drawPositions.every((dp) => isConvertableInteger(dp) || dp === undefined || dp === null));
6520
+ return validMatchUpId && validDrawPositions;
6521
+ }
6522
+ function validMatchUps(matchUps) {
6523
+ if (!Array.isArray(matchUps))
6524
+ return false;
6525
+ return matchUps.every(validMatchUp);
6526
+ }
6527
+
6528
+ function getRoundMatchUps({ matchUps = [], interpolate }) {
6529
+ if (!validMatchUps(matchUps))
6530
+ return { roundMatchUps: [], error: INVALID_VALUES };
6531
+ const roundMatchUpsArray = matchUps
6532
+ .reduce((roundNumbers, matchUp) => {
6533
+ const roundNumber = typeof matchUp.roundNumber === 'string' ? ensureInt(matchUp.roundNumber) : matchUp.roundNumber;
6534
+ return !matchUp.roundNumber || roundNumbers.includes(roundNumber)
6535
+ ? roundNumbers
6536
+ : roundNumbers.concat(roundNumber);
6537
+ }, [])
6538
+ .sort(numericSort)
6539
+ .map((roundNumber) => {
6540
+ const roundMatchUps = matchUps.filter((matchUp) => matchUp.roundNumber === roundNumber);
6541
+ const hasTeamMatchUps = roundMatchUps.find(({ matchUpType }) => matchUpType === TEAM$1);
6542
+ const consideredMatchUps = hasTeamMatchUps
6543
+ ? roundMatchUps.filter(({ matchUpType }) => matchUpType === TEAM$1)
6544
+ : roundMatchUps;
6545
+ const getSorted = (items) => items.sort((a, b) => numericSort(a.roundPosition, b.roundPosition));
6546
+ return {
6547
+ [roundNumber]: getSorted(consideredMatchUps),
6548
+ };
6549
+ });
6550
+ const finishingRoundMap = matchUps.reduce((mapping, matchUp) => {
6551
+ const roundNumber = typeof matchUp.roundNumber === 'string' ? ensureInt(matchUp.roundNumber) : matchUp.roundNumber;
6552
+ if (!mapping[roundNumber])
6553
+ mapping[roundNumber] = definedAttributes({
6554
+ abbreviatedRoundName: matchUp.abbreviatedRoundName,
6555
+ finishingRound: matchUp.finishingRound,
6556
+ roundName: matchUp.roundName,
6557
+ });
6558
+ return mapping;
6559
+ }, {});
6560
+ const roundMatchUps = Object.assign({}, ...roundMatchUpsArray);
6561
+ if (interpolate) {
6562
+ const maxRoundNumber = Math.max(...Object.keys(roundMatchUps)
6563
+ .map((key) => ensureInt(key))
6564
+ .filter((f) => !isNaN(f)));
6565
+ const maxRoundMatchUpsCount = roundMatchUps[maxRoundNumber]?.length;
6566
+ if (maxRoundMatchUpsCount > 1 && isPowerOf2(maxRoundMatchUpsCount)) {
6567
+ const nextRound = maxRoundNumber + 1;
6568
+ const lastRound = nextRound + maxRoundMatchUpsCount / 2;
6569
+ const roundsToInterpolate = generateRange(nextRound, lastRound);
6570
+ roundsToInterpolate.forEach((roundNumber, i) => {
6571
+ roundMatchUps[roundNumber] = generateRange(0, maxRoundMatchUpsCount / (2 + i * 2)).map(() => ({}));
6572
+ });
6573
+ }
6574
+ }
6575
+ let maxMatchUpsCount = 0;
6576
+ const roundProfile = Object.assign({}, ...Object.keys(roundMatchUps).map((roundNumber) => {
6577
+ const matchUpsCount = roundMatchUps[roundNumber]?.length;
6578
+ const inactiveCount = roundMatchUps[roundNumber]?.filter((matchUp) => !completedMatchUpStatuses.includes(matchUp.matchUpStatus) && !matchUp.score?.scoreStringSide1)?.length;
6579
+ const inactiveRound = matchUpsCount && matchUpsCount === inactiveCount;
6580
+ maxMatchUpsCount = Math.max(maxMatchUpsCount, matchUpsCount);
6581
+ return { [roundNumber]: { matchUpsCount, inactiveCount, inactiveRound } };
6582
+ }));
6583
+ let roundIndex = 0;
6584
+ let feedRoundIndex = 0;
6585
+ const roundNumbers = Object.keys(roundMatchUps)
6586
+ .map((key) => ensureInt(key))
6587
+ .filter((f) => !isNaN(f));
6588
+ roundNumbers.forEach((roundNumber) => {
6589
+ const currentRoundMatchUps = roundMatchUps[roundNumber].sort((a, b) => a.roundPosition - b.roundPosition);
6590
+ const currentRoundDrawPositions = currentRoundMatchUps.map((matchUp) => matchUp?.drawPositions || []).flat();
6591
+ roundProfile[roundNumber].roundNumber = roundNumber;
6592
+ roundProfile[roundNumber].roundFactor = roundProfile[roundNumber].matchUpsCount
6593
+ ? maxMatchUpsCount / roundProfile[roundNumber].matchUpsCount
6594
+ : 1;
6595
+ roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber]?.finishingRound;
6596
+ roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber]?.roundName;
6597
+ roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber]?.abbreviatedRoundName;
6598
+ roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber]?.[0]?.finishingPositionRange;
6599
+ if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
6600
+ const orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
6601
+ const pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
6602
+ roundProfile[roundNumber].drawPositions = orderedDrawPositions;
6603
+ roundProfile[roundNumber].pairedDrawPositions = pairedDrawPositions;
6604
+ }
6605
+ else {
6606
+ const priorRound = roundProfile[roundNumber - 1];
6607
+ const priorRoundDrawPositions = priorRound.drawPositions;
6608
+ const chunkFactor = priorRound.matchUpsCount / roundProfile[roundNumber].matchUpsCount;
6609
+ const priorRoundDrawPositionChunks = chunkArray(priorRoundDrawPositions, chunkFactor);
6610
+ const roundDrawPositions = currentRoundMatchUps.map((matchUp) => {
6611
+ const { roundPosition } = matchUp;
6612
+ const drawPositions = [...(matchUp.drawPositions || []), undefined, undefined].slice(0, 2);
6613
+ if (!roundPosition)
6614
+ return drawPositions;
6615
+ const filteredDrawPositions = drawPositions?.filter(Boolean) || [];
6616
+ if (!filteredDrawPositions?.length)
6617
+ return [undefined, undefined];
6618
+ if (roundNumber < 3 && filteredDrawPositions?.length === 2) {
6619
+ return drawPositions?.slice().sort(numericSort);
6620
+ }
6621
+ const isFeedRound = intersection(priorRoundDrawPositions, filteredDrawPositions).length !== filteredDrawPositions?.length;
6622
+ if (filteredDrawPositions?.length && isFeedRound) {
6623
+ if (filteredDrawPositions?.length === 1) {
6624
+ return [filteredDrawPositions[0], undefined];
6625
+ }
6626
+ else {
6627
+ return drawPositions?.slice().sort(numericSort);
6628
+ }
6629
+ }
6630
+ const targetChunkIndex = (roundPosition - 1) * 2;
6631
+ const targetChunks = priorRoundDrawPositionChunks.slice(targetChunkIndex, targetChunkIndex + 2);
6632
+ return targetChunks.map((chunk) => {
6633
+ return filteredDrawPositions?.find((drawPosition) => chunk.includes(drawPosition));
6634
+ });
6635
+ });
6636
+ roundProfile[roundNumber].drawPositions = roundDrawPositions?.flat();
6637
+ roundProfile[roundNumber].pairedDrawPositions = roundDrawPositions;
6638
+ }
6639
+ if (roundProfile[roundNumber + 1] &&
6640
+ roundProfile[roundNumber + 1].matchUpsCount === roundProfile[roundNumber].matchUpsCount) {
6641
+ roundProfile[roundNumber + 1].feedRound = true;
6642
+ roundProfile[roundNumber + 1].feedRoundIndex = feedRoundIndex;
6643
+ roundProfile[roundNumber].preFeedRound = true;
6644
+ feedRoundIndex += 1;
6645
+ }
6646
+ if (roundProfile[roundNumber] && !roundProfile[roundNumber].feedRound) {
6647
+ roundProfile[roundNumber].roundIndex = roundIndex;
6648
+ roundIndex += 1;
6649
+ }
6650
+ });
6651
+ const roundsNotPowerOf2 = !!Object.values(roundProfile).find(({ matchUpsCount }) => !isPowerOf2(matchUpsCount));
6652
+ const hasNoRoundPositions = matchUps.some((matchUp) => !matchUp.roundPosition);
6653
+ return {
6654
+ hasNoRoundPositions,
6655
+ roundsNotPowerOf2,
6656
+ maxMatchUpsCount,
6657
+ roundMatchUps,
6658
+ roundNumbers,
6659
+ roundProfile,
6660
+ ...SUCCESS,
6661
+ };
6662
+ }
6663
+
6664
+ function getRangeString(arr) {
6665
+ if (!Array.isArray(arr))
6666
+ return '';
6667
+ const numericArray = arr.filter(isNumeric);
6668
+ if (!numericArray.length)
6669
+ return '';
6670
+ const range = unique([Math.min(...numericArray), Math.max(...numericArray)]);
6671
+ return range.join('-');
6672
+ }
6673
+
6674
+ function getSourceDrawPositionRanges({ drawDefinition, structureId, matchUpsMap }) {
6675
+ if (!drawDefinition)
6676
+ return { error: MISSING_DRAW_DEFINITION };
6677
+ if (!structureId)
6678
+ return { error: MISSING_STRUCTURE_ID };
6679
+ const { structure } = findStructure({ drawDefinition, structureId });
6680
+ if (structure?.stage !== CONSOLATION)
6681
+ return { error: INVALID_STAGE, info: 'Structure is not CONSOLATION stage' };
6682
+ const { links } = drawDefinition;
6683
+ const relevantLinks = links?.filter((link) => link.target.structureId === structureId) || [];
6684
+ const sourceStructureIds = relevantLinks?.reduce((sourceStructureIds, link) => {
6685
+ const { structureId: sourceStructureId } = link.source;
6686
+ return sourceStructureIds.includes(sourceStructureId)
6687
+ ? sourceStructureIds
6688
+ : sourceStructureIds.concat(sourceStructureId);
6689
+ }, []) || [];
6690
+ const sourceStructureProfiles = Object.assign({}, ...sourceStructureIds.map((sourceStructureId) => {
6691
+ const structureMatchUps = getMappedStructureMatchUps({
6692
+ structureId: sourceStructureId,
6693
+ matchUpsMap,
6694
+ });
6695
+ const roundMatchUpsResult = getRoundMatchUps({
6696
+ matchUps: structureMatchUps,
6697
+ });
6698
+ const roundProfile = roundMatchUpsResult.roundProfile;
6699
+ return { [sourceStructureId]: roundProfile };
6700
+ }));
6701
+ const structureMatchUps = getMappedStructureMatchUps({
6702
+ matchUpsMap,
6703
+ structureId,
6704
+ });
6705
+ const { roundProfile: targetStructureProfile } = getRoundMatchUps({
6706
+ matchUps: structureMatchUps,
6707
+ });
6708
+ const sourceDrawPositionRanges = {};
6709
+ relevantLinks?.forEach((link) => {
6710
+ const { structureId: sourceStructureId, roundNumber: sourceRoundNumber } = link.source;
6711
+ const { feedProfile, groupedOrder, positionInterleave, roundNumber: targetRoundNumber } = link.target;
6712
+ const sourceStructureProfile = sourceStructureProfiles[sourceStructureId];
6713
+ const firstRoundDrawPositions = sourceStructureProfile[1]?.drawPositions;
6714
+ const sourceRoundProfile = sourceStructureProfile[sourceRoundNumber];
6715
+ const sourceRoundMatchUpsCount = sourceRoundProfile?.matchUpsCount;
6716
+ if (!sourceRoundMatchUpsCount)
6717
+ return;
6718
+ const chunkSize = sourceRoundMatchUpsCount ? firstRoundDrawPositions.length / sourceRoundMatchUpsCount : 0;
6719
+ const targetRoundMatchUpsCount = firstRoundDrawPositions.length / chunkSize;
6720
+ let orderedPositions = firstRoundDrawPositions.slice();
6721
+ const sizedGroupOrder = reduceGroupedOrder({
6722
+ roundPositionsCount: targetRoundMatchUpsCount,
6723
+ groupedOrder,
6724
+ });
6725
+ const groupsCount = sizedGroupOrder?.length || 1;
6726
+ if (groupsCount <= targetRoundMatchUpsCount) {
6727
+ const groupSize = firstRoundDrawPositions.length / groupsCount;
6728
+ const groups = chunkArray(orderedPositions, groupSize);
6729
+ if (feedProfile === BOTTOM_UP)
6730
+ groups.forEach((group) => group.reverse());
6731
+ orderedPositions =
6732
+ (sizedGroupOrder?.length && sizedGroupOrder?.map((order) => groups[order - 1]).flat()) || orderedPositions;
6733
+ }
6734
+ let drawPositionBlocks = chunkArray(orderedPositions, chunkSize);
6735
+ if (positionInterleave) {
6736
+ const interleave = generateRange(0, positionInterleave.interleave).map(() => undefined);
6737
+ const offset = generateRange(0, positionInterleave.offset).map(() => undefined);
6738
+ drawPositionBlocks = drawPositionBlocks.map((block) => [block, ...interleave]);
6739
+ drawPositionBlocks.unshift(offset);
6740
+ drawPositionBlocks = drawPositionBlocks.flat(1);
6741
+ const targetLength = drawPositionBlocks.length - positionInterleave.offset;
6742
+ drawPositionBlocks = drawPositionBlocks.slice(0, targetLength);
6743
+ }
6744
+ if (!sourceDrawPositionRanges[targetRoundNumber])
6745
+ sourceDrawPositionRanges[targetRoundNumber] = {};
6746
+ const targetRoundProfile = targetStructureProfile?.[targetRoundNumber];
6747
+ const increment = targetRoundProfile?.feedRound ? 2 : 1;
6748
+ drawPositionBlocks.forEach((block, index) => {
6749
+ const columnPosition = 1 + index * increment;
6750
+ if (!sourceDrawPositionRanges[targetRoundNumber][columnPosition]) {
6751
+ sourceDrawPositionRanges[targetRoundNumber][columnPosition] = getRangeString(block);
6752
+ }
6753
+ });
6754
+ });
6755
+ return { sourceDrawPositionRanges };
6756
+ }
6757
+
6758
+ function getExitProfiles({ drawDefinition }) {
6759
+ if (typeof drawDefinition !== 'object')
6760
+ return { error: INVALID_DRAW_DEFINITION };
6761
+ const exitProfiles = {};
6762
+ const { structures = [], links = [] } = drawDefinition || {};
6763
+ const stageStructures = structures.reduce((stageStructures, structure) => {
6764
+ const { stage } = structure;
6765
+ if (!stageStructures[stage]) {
6766
+ stageStructures[stage] = [structure];
6767
+ }
6768
+ else {
6769
+ stageStructures[stage].push(structure);
6770
+ }
6771
+ return stageStructures;
6772
+ }, {});
6773
+ for (const stage of Object.keys(stageStructures)) {
6774
+ const initialStructure = stageStructures[stage].find(({ stageSequence }) => stageSequence === 1);
6775
+ if (!initialStructure)
6776
+ continue;
6777
+ const { structureId } = initialStructure;
6778
+ const exitProfile = '0';
6779
+ addExitProfiles({
6780
+ aggregator: {},
6781
+ targetRound: 0,
6782
+ exitProfiles,
6783
+ exitProfile,
6784
+ structureId,
6785
+ stage,
6786
+ });
6787
+ }
6788
+ return { exitProfiles };
6789
+ function addExitProfiles({ exitProfiles, exitProfile, structureId, targetRound, aggregator, stage }) {
6790
+ if (!exitProfiles[structureId])
6791
+ exitProfiles[structureId] = [];
6792
+ if (!(exitProfile === '0' && [CONSOLATION, PLAY_OFF].includes(stage)))
6793
+ exitProfiles[structureId].push(exitProfile);
6794
+ const relevantLinks = links.filter((link) => link.source.structureId === structureId && link.source.roundNumber >= targetRound);
6795
+ for (const link of relevantLinks) {
6796
+ const exitRound = link.source.roundNumber;
6797
+ const targetRound = link.target.roundNumber;
6798
+ const targetStructureId = link.target.structureId;
6799
+ const stage = structures.find((structure) => structure.structureId === targetStructureId).stage;
6800
+ const fp = [stage, targetStructureId, targetRound, exitRound].join('|');
6801
+ if (aggregator[fp])
6802
+ return;
6803
+ aggregator[fp] = true;
6804
+ addExitProfiles({
6805
+ exitProfile: `${exitProfile}-${exitRound}`,
6806
+ structureId: targetStructureId,
6807
+ exitProfiles,
6808
+ targetRound,
6809
+ aggregator,
6810
+ stage,
6811
+ });
6812
+ }
6813
+ }
6814
+ }
6815
+
6816
+ function getDrawPositionsRanges({ drawDefinition, roundProfile, structureId, matchUpsMap, }) {
6817
+ if (!drawDefinition)
6818
+ return { error: MISSING_DRAW_DEFINITION };
6819
+ if (!structureId)
6820
+ return { error: MISSING_STRUCTURE_ID };
6821
+ if (!roundProfile) {
6822
+ const structureMatchUps = getMappedStructureMatchUps({
6823
+ matchUpsMap,
6824
+ structureId,
6825
+ });
6826
+ ({ roundProfile } = getRoundMatchUps({
6827
+ matchUps: structureMatchUps,
6828
+ }));
6829
+ if (!roundProfile)
6830
+ return { error: MISSING_VALUE };
6831
+ }
6832
+ const firstRoundFirstDrawPosition = Math.min(...(roundProfile?.[1]?.drawPositions ?? []));
6833
+ const firstRoundFirstDrawPositionOffset = (firstRoundFirstDrawPosition || 1) - 1;
6834
+ const roundNumbers = Object.keys(roundProfile);
6835
+ const drawPositionsRanges = Object.assign({}, ...(roundNumbers || []).map((roundNumber) => {
6836
+ const matchUpsCount = roundProfile?.[roundNumber]?.matchUpsCount;
6837
+ const firstRoundDrawPositions = roundProfile?.[1]?.drawPositions ?? [];
6838
+ const firstRoundDrawPositionsChunks = chunkArray(firstRoundDrawPositions, firstRoundDrawPositions.length / matchUpsCount);
6839
+ const firstRoundDrawPositionsRanges = firstRoundDrawPositionsChunks.map(getRangeString);
6840
+ const firstRoundOffsetDrawPositionsRanges = firstRoundDrawPositionsChunks
6841
+ .map((drawPositions) => {
6842
+ return drawPositions.map((drawPosition) => drawPosition - firstRoundFirstDrawPositionOffset);
6843
+ })
6844
+ .map(getRangeString);
6845
+ const currentRoundDrawPositionChunks = roundNumbers
6846
+ .map((value) => {
6847
+ if (value > roundNumber)
6848
+ return undefined;
6849
+ const drawPositions = roundProfile?.[value]?.drawPositions ?? [];
6850
+ return chunkArray(drawPositions, drawPositions.length / matchUpsCount);
6851
+ })
6852
+ .filter(Boolean);
6853
+ const possibleDrawPositions = generateRange(0, matchUpsCount)
6854
+ .map((index) => {
6855
+ return currentRoundDrawPositionChunks
6856
+ .map((chunk) => chunk[index])
6857
+ .flat()
6858
+ .filter(Boolean)
6859
+ .sort(numericSort);
6860
+ })
6861
+ .map((possible) => unique(possible));
6862
+ const drawPositionsRanges = possibleDrawPositions.map((possible) => {
6863
+ return groupConsecutiveNumbers(possible).map(getRangeString).join(', ');
6864
+ });
6865
+ const roundPositionsMap = Object.assign({}, ...generateRange(0, matchUpsCount).map((index) => {
6866
+ const roundPosition = index + 1;
6867
+ return {
6868
+ [roundPosition]: {
6869
+ firstRoundDrawPositionsRange: firstRoundDrawPositionsRanges[index],
6870
+ firstRoundOffsetDrawPositionsRange: firstRoundOffsetDrawPositionsRanges[index],
6871
+ possibleDrawPositions: possibleDrawPositions[index],
6872
+ drawPositionsRange: drawPositionsRanges[index],
6873
+ },
6874
+ };
6875
+ }));
6876
+ return { [roundNumber]: roundPositionsMap };
6877
+ }));
6878
+ return { drawPositionsRanges };
6879
+ }
6880
+
6881
+ function isLucky({ roundsNotPowerOf2, drawDefinition, structure, matchUps }) {
6882
+ if (!structure)
6883
+ return false;
6884
+ matchUps = matchUps ?? structure.matchUps ?? [];
6885
+ roundsNotPowerOf2 = roundsNotPowerOf2 ?? getRoundMatchUps({ matchUps }).roundsNotPowerOf2;
6886
+ const hasDrawPositions = !!structure.positionAssignments?.find(({ drawPosition }) => drawPosition) ||
6887
+ !!matchUps?.find(({ drawPositions }) => drawPositions?.length);
6888
+ return ((!drawDefinition?.drawType || drawDefinition.drawType !== LUCKY_DRAW) &&
6889
+ !structure?.structures &&
6890
+ roundsNotPowerOf2 &&
6891
+ hasDrawPositions);
6892
+ }
6893
+
6894
+ function isAdHoc({ structure }) {
6895
+ if (!structure)
6896
+ return false;
6897
+ const matchUps = structure.matchUps || (structure.roundMatchUps && Object.values(structure.roundMatchUps).flat());
6898
+ const hasRoundPosition = !!matchUps?.find((matchUp) => matchUp?.roundPosition);
6899
+ const hasDrawPosition = !!matchUps?.find((matchUp) => matchUp?.drawPositions?.length);
6900
+ return (!structure?.structures &&
6901
+ structure?.stage !== VOLUNTARY_CONSOLATION &&
6902
+ (!matchUps.length || (!hasRoundPosition && !hasDrawPosition)));
6903
+ }
6904
+
6905
+ const POLICY_ROUND_NAMING_DEFAULT = {
6906
+ [POLICY_TYPE_ROUND_NAMING]: {
6907
+ policyName: 'Round Naming Default',
6908
+ namingConventions: {
6909
+ round: 'Round',
6910
+ pre: 'Pre',
6911
+ },
6912
+ qualifyingFinishMap: {
6913
+ 1: 'Final',
6914
+ },
6915
+ abbreviatedRoundNamingMap: {
6916
+ 1: 'F',
6917
+ 2: 'SF',
6918
+ 4: 'QF',
6919
+ },
6920
+ roundNamingMap: {
6921
+ 1: 'Final',
6922
+ 2: 'Semifinal',
6923
+ 4: 'Quarterfinal',
6924
+ },
6925
+ affixes: {
6926
+ roundNumber: 'R',
6927
+ preFeedRound: 'Q',
6928
+ preQualifying: 'P',
6929
+ },
6930
+ stageConstants: {
6931
+ [MAIN]: '',
6932
+ [PLAY_OFF]: 'P',
6933
+ [QUALIFYING]: 'Q',
6934
+ [CONSOLATION]: 'C',
6935
+ },
6936
+ },
6937
+ };
6938
+
6939
+ function getRoundContextProfile({ roundNamingPolicy, drawDefinition, structure, matchUps, }) {
6940
+ const { roundProfile, roundMatchUps } = getRoundMatchUps({ matchUps });
6941
+ const { structureAbbreviation, stage } = structure;
6942
+ const isAdHocStructure = isAdHoc({ structure });
6943
+ const isLuckyStructure = isLucky({ structure });
6944
+ const isRoundRobin = structure.structures;
6945
+ const roundNamingProfile = {};
6946
+ const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
6947
+ const isQualifying = structure.stage === QUALIFYING;
6948
+ const qualifyingStageSequences = isQualifying
6949
+ ? Math.max(...(drawDefinition?.structures ?? [])
6950
+ .filter((structure) => structure.stage === QUALIFYING)
6951
+ .map(({ stageSequence }) => stageSequence ?? 1), 0)
6952
+ : 0;
6953
+ const preQualifyingSequence = (structure.stageSequence ?? 1) < qualifyingStageSequences ? structure.stageSequence ?? 1 : '';
6954
+ const preQualifyingAffix = preQualifyingSequence
6955
+ ? roundNamingPolicy?.affixes?.preQualifying || defaultRoundNamingPolicy.affixes.preQualifying || ''
6956
+ : '';
6957
+ const roundNamingMap = roundNamingPolicy?.roundNamingMap || defaultRoundNamingPolicy.roundNamingMap || {};
6958
+ const abbreviatedRoundNamingMap = roundNamingPolicy?.abbreviatedRoundNamingMap || defaultRoundNamingPolicy.abbreviatedRoundNamingMap || {};
6959
+ const preFeedAffix = roundNamingPolicy?.affixes?.preFeedRound || defaultRoundNamingPolicy.affixes.preFeedRound;
6960
+ const roundNumberAffix = roundNamingPolicy?.affixes?.roundNumber || defaultRoundNamingPolicy.affixes.roundNumber;
6961
+ const namingConventions = roundNamingPolicy?.namingConventions || defaultRoundNamingPolicy.namingConventions;
6962
+ const roundNameFallback = namingConventions.round;
6963
+ const stageInitial = stage && stage !== MAIN ? stage[0] : '';
6964
+ const stageConstants = roundNamingPolicy?.stageConstants || defaultRoundNamingPolicy.stageConstants;
6965
+ const stageIndicator = (stage && stageConstants?.[stage]) || stageInitial;
6966
+ const stageConstant = `${preQualifyingAffix}${stageIndicator}${preQualifyingSequence}`;
6967
+ const roundProfileKeys = roundProfile ? Object.keys(roundProfile) : [];
6968
+ const qualifyingAffix = isQualifying && stageConstants?.[QUALIFYING] ? `${stageConstants?.[QUALIFYING]}-` : '';
6969
+ if (isRoundRobin || isAdHocStructure || isLuckyStructure) {
6970
+ Object.assign(roundNamingProfile, ...roundProfileKeys.map((key) => {
6971
+ const roundName = `${qualifyingAffix}${roundNameFallback} ${key}`;
6972
+ const abbreviatedRoundName = `${roundNumberAffix}${key}`;
6973
+ return { [key]: { roundName, abbreviatedRoundName } };
6974
+ }));
6975
+ }
6976
+ else {
6977
+ const qualifyingFinishgMap = isQualifying && (roundNamingPolicy?.qualifyingFinishMap || defaultRoundNamingPolicy?.qualifyingFinishMap || {});
6978
+ Object.assign(roundNamingProfile, ...roundProfileKeys.map((round) => {
6979
+ if (!roundProfile?.[round])
6980
+ return undefined;
6981
+ const { matchUpsCount, preFeedRound } = roundProfile[round];
6982
+ const participantsCount = matchUpsCount * 2;
6983
+ const sizedRoundName = qualifyingFinishgMap?.[roundProfile?.[round].finishingRound] ||
6984
+ (qualifyingFinishgMap && `${roundNumberAffix}${participantsCount}`) ||
6985
+ roundNamingMap[matchUpsCount] ||
6986
+ `${roundNumberAffix}${participantsCount}`;
6987
+ const suffix = preFeedRound ? `-${preFeedAffix}` : '';
6988
+ const profileRoundName = `${sizedRoundName}${suffix}`;
6989
+ const roundName = [stageConstant, structureAbbreviation, profileRoundName].filter(Boolean).join('-');
6990
+ const sizedAbbreviation = abbreviatedRoundNamingMap[matchUpsCount] || `${roundNumberAffix}${participantsCount}`;
6991
+ const profileAbbreviation = `${sizedAbbreviation}${suffix}`;
6992
+ const abbreviatedRoundName = [stageConstant, structureAbbreviation, profileAbbreviation]
6993
+ .filter(Boolean)
6994
+ .join('-');
6995
+ return { [round]: { abbreviatedRoundName, roundName } };
6996
+ }));
6997
+ }
6998
+ return { roundNamingProfile, roundProfile, roundMatchUps };
6999
+ }
7000
+
6356
7001
  const add = (a, b) => (a || 0) + (b || 0);
6357
7002
  function getBand(spread, bandProfiles) {
6358
7003
  const spreadValue = Array.isArray(spread) ? spread[0] : spread;
@@ -6907,6 +7552,21 @@ function matchUpCourtOrder({ visibilityThreshold, timeStamp, schedule, matchUp }
6907
7552
  : schedule;
6908
7553
  }
6909
7554
 
7555
+ function getHomeParticipantId(params) {
7556
+ const { visibilityThreshold, timeStamp, schedule, matchUp } = params;
7557
+ const paramsCheck = checkRequiredParameters(params, [{ [MATCHUP]: true }]);
7558
+ if (paramsCheck.error)
7559
+ return paramsCheck;
7560
+ const { itemValue: homeParticipantId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
7561
+ timeItems: matchUp?.timeItems || [],
7562
+ itemType: HOME_PARTICIPANT_ID,
7563
+ visibilityThreshold,
7564
+ });
7565
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
7566
+ ? { homeParticipantId }
7567
+ : schedule;
7568
+ }
7569
+
6910
7570
  function matchUpStartTime({ matchUp }) {
6911
7571
  const timeItems = matchUp?.timeItems || [];
6912
7572
  const getTimeStamp = (item) => (!item.createdAt ? 0 : new Date(item.createdAt).getTime());
@@ -7207,601 +7867,184 @@ function findEvent(params) {
7207
7867
  return {
7208
7868
  entries: flight.drawEntries,
7209
7869
  drawName: flight.drawName,
7210
- tournamentId,
7211
- drawId,
7212
- };
7213
- }
7214
- }
7215
- return targetDrawDefinition;
7216
- });
7217
- if (event)
7218
- return { event, drawDefinition, tournamentId };
7219
- }
7220
- if (eventId) {
7221
- const event = events.find((event) => event?.eventId === eventId);
7222
- if (!event) {
7223
- return {
7224
- event: undefined,
7225
- drawDefinition: undefined,
7226
- ...decorateResult({ result: { error: EVENT_NOT_FOUND }, stack }),
7227
- };
7228
- }
7229
- else {
7230
- tournamentId = eventIdsMap[event.eventId].tournamentId;
7231
- }
7232
- return { event, drawDefinition: undefined, tournamentId };
7233
- }
7234
- return {
7235
- event: undefined,
7236
- drawDefinition: undefined,
7237
- ...decorateResult({
7238
- result: { error: DRAW_DEFINITION_NOT_FOUND },
7239
- context: { drawId, eventId },
7240
- stack,
7241
- }),
7242
- };
7243
- }
7244
-
7245
- function getHomeParticipantId(params) {
7246
- const { visibilityThreshold, timeStamp, schedule, matchUp } = params;
7247
- const paramsCheck = checkRequiredParameters(params, [{ [MATCHUP]: true }]);
7248
- if (paramsCheck.error)
7249
- return paramsCheck;
7250
- const { itemValue: homeParticipantId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
7251
- timeItems: matchUp?.timeItems || [],
7252
- itemType: HOME_PARTICIPANT_ID,
7253
- visibilityThreshold,
7254
- });
7255
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
7256
- ? { homeParticipantId }
7257
- : schedule;
7258
- }
7259
-
7260
- function getMatchUpScheduleDetails(params) {
7261
- let event = params.event;
7262
- let matchUpType = params.matchUpType;
7263
- const { scheduleVisibilityFilters, afterRecoveryTimes, tournamentRecord, usePublishState, scheduleTiming, matchUpFormat, publishStatus, matchUp, } = params;
7264
- if (!matchUp)
7265
- return { error: MISSING_MATCHUP };
7266
- if (afterRecoveryTimes &&
7267
- !matchUp.matchUpType &&
7268
- !params.matchUpType &&
7269
- (event || tournamentRecord) &&
7270
- matchUp.drawId) {
7271
- let drawDefinition = event?.drawDefinitions?.find((drawDefinition) => drawDefinition.drawId === matchUp.drawId);
7272
- if (!drawDefinition && tournamentRecord) {
7273
- ({ drawDefinition, event } = findEvent({
7274
- tournamentRecord,
7275
- drawId: matchUp.drawId,
7276
- }));
7277
- }
7278
- const structure = matchUp.structureId && drawDefinition?.structures?.find(({ structureId }) => structureId === matchUp.structureId);
7279
- matchUpType =
7280
- params.matchUpType ||
7281
- structure?.matchUpType ||
7282
- drawDefinition?.matchUpType ||
7283
- (event?.eventType !== TEAM$2 && event?.eventType);
7284
- }
7285
- const { milliseconds, time } = matchUpDuration({ matchUp });
7286
- const { startTime } = matchUpStartTime({ matchUp });
7287
- const { endTime } = matchUpEndTime({ matchUp });
7288
- let schedule;
7289
- const { visibilityThreshold, eventIds, drawIds } = scheduleVisibilityFilters ?? {};
7290
- if ((!eventIds || eventIds.includes(matchUp.eventId)) && (!drawIds || drawIds.includes(matchUp.drawId))) {
7291
- const scheduleSource = { matchUp, visibilityThreshold };
7292
- const { allocatedCourts } = matchUpAllocatedCourts(scheduleSource);
7293
- const { homeParticipantId } = getHomeParticipantId(scheduleSource);
7294
- const { scheduledTime } = scheduledMatchUpTime(scheduleSource);
7295
- const { timeModifiers } = matchUpTimeModifiers(scheduleSource);
7296
- let { scheduledDate } = scheduledMatchUpDate(scheduleSource);
7297
- const { venueId } = matchUpAssignedVenueId(scheduleSource);
7298
- const { courtId } = matchUpAssignedCourtId(scheduleSource);
7299
- const { courtOrder } = matchUpCourtOrder(scheduleSource);
7300
- let timeAfterRecovery, averageMinutes, recoveryMinutes, typeChangeRecoveryMinutes, typeChangeTimeAfterRecovery;
7301
- const eventType = matchUp.matchUpType ?? matchUpType;
7302
- if (scheduleTiming && scheduledTime && afterRecoveryTimes && eventType) {
7303
- const timingDetails = {
7304
- matchUpFormat: matchUp.matchUpFormat ?? matchUpFormat,
7305
- ...scheduleTiming,
7306
- };
7307
- ({
7308
- averageMinutes = 0,
7309
- recoveryMinutes = 0,
7310
- typeChangeRecoveryMinutes = 0,
7311
- } = matchUpFormatTimes({
7312
- timingDetails,
7313
- eventType,
7314
- }));
7315
- if (averageMinutes || recoveryMinutes) {
7316
- timeAfterRecovery = endTime
7317
- ? addMinutesToTimeString(extractTime$1(endTime), recoveryMinutes)
7318
- : addMinutesToTimeString(scheduledTime, averageMinutes + recoveryMinutes);
7319
- }
7320
- if (typeChangeRecoveryMinutes) {
7321
- typeChangeTimeAfterRecovery = endTime
7322
- ? addMinutesToTimeString(extractTime$1(endTime), typeChangeRecoveryMinutes)
7323
- : addMinutesToTimeString(scheduledTime, averageMinutes + typeChangeRecoveryMinutes);
7324
- }
7325
- }
7326
- if (!scheduledDate && scheduledTime)
7327
- scheduledDate = extractDate(scheduledTime);
7328
- const isoDateString = getIsoDateString({ scheduledDate, scheduledTime });
7329
- const venueDataMap = {};
7330
- const venueData = (tournamentRecord && venueId && getVenueData({ tournamentRecord, venueId }))?.venueData || {};
7331
- if (venueId)
7332
- venueDataMap[venueId] = venueData;
7333
- const { venueName, venueAbbreviation, courtsInfo } = venueData;
7334
- const courtInfo = courtId && courtsInfo?.find((courtInfo) => courtInfo.courtId === courtId);
7335
- const courtName = courtInfo?.courtName;
7336
- for (const allocatedCourt of allocatedCourts || []) {
7337
- if (!tournamentRecord)
7338
- break;
7339
- if (allocatedCourt.venueId && !venueDataMap[allocatedCourt.venueid]) {
7340
- venueDataMap[allocatedCourt.venueId] = getVenueData({
7341
- venueId: allocatedCourt.venueId,
7342
- tournamentRecord,
7343
- })?.venueData;
7344
- }
7345
- const vData = venueDataMap[allocatedCourt.venueId];
7346
- allocatedCourt.venueName = vData?.venueName;
7347
- const courtInfo = vData?.courtsInfo?.find((courtInfo) => courtInfo.courtId === allocatedCourt.courtId);
7348
- allocatedCourt.courtName = courtInfo?.courtName;
7349
- }
7350
- schedule = definedAttributes({
7351
- typeChangeTimeAfterRecovery,
7352
- timeAfterRecovery,
7353
- scheduledDate,
7354
- scheduledTime,
7355
- isoDateString,
7356
- allocatedCourts,
7357
- homeParticipantId,
7358
- timeModifiers,
7359
- venueAbbreviation,
7360
- venueName,
7361
- venueId,
7362
- courtOrder,
7363
- courtName,
7364
- courtId,
7365
- typeChangeRecoveryMinutes,
7366
- recoveryMinutes,
7367
- averageMinutes,
7368
- milliseconds,
7369
- startTime,
7370
- endTime,
7371
- time,
7372
- });
7373
- }
7374
- else {
7375
- schedule = definedAttributes({
7376
- milliseconds,
7377
- startTime,
7378
- endTime,
7379
- time,
7380
- });
7381
- }
7382
- const { scheduledDate } = scheduledMatchUpDate({ matchUp });
7383
- const { scheduledTime } = scheduledMatchUpTime({ matchUp });
7384
- if (usePublishState && publishStatus?.displaySettings?.draws) {
7385
- const drawSettings = publishStatus.displaySettings.draws;
7386
- const scheduleDetails = (drawSettings?.[matchUp.drawId] ?? drawSettings?.default)?.scheduleDetails;
7387
- if (scheduleDetails) {
7388
- const scheduleAttributes = (scheduleDetails.find((details) => scheduledDate && details.dates?.includes(scheduledDate)) ??
7389
- scheduleDetails.find((details) => !details.dates?.length))?.attributes;
7390
- if (scheduleAttributes) {
7391
- const template = Object.assign({}, ...Object.keys(schedule).map((key) => ({ [key]: true })), scheduleAttributes);
7392
- schedule = attributeFilter({
7393
- source: schedule,
7394
- template,
7395
- });
7396
- }
7397
- }
7398
- }
7399
- const hasCompletedStatus = matchUp.matchUpStatus && completedMatchUpStatuses.includes(matchUp.matchUpStatus);
7400
- const endDate = (hasCompletedStatus && (extractDate(endTime) || extractDate(scheduledDate) || extractDate(scheduledTime))) ||
7401
- undefined;
7402
- return { schedule, endDate };
7403
- }
7404
-
7405
- function getObjectTieFormat(obj) {
7406
- if (!obj)
7407
- return;
7408
- const { tieFormatId, tieFormats } = obj;
7409
- if (obj.tieFormat) {
7410
- return obj.tieFormat;
7411
- }
7412
- else if (tieFormatId && Array.isArray(tieFormats)) {
7413
- return tieFormats.find((tf) => tf.tieFormatId === tieFormatId);
7414
- }
7415
- }
7416
-
7417
- function getItemTieFormat({ item, drawDefinition, structure, event }) {
7418
- if (!item)
7419
- return;
7420
- if (item.tieFormat)
7421
- return item.tieFormat;
7422
- if (item.tieFormatId) {
7423
- if (drawDefinition.tieFormat)
7424
- return drawDefinition.tieFormat;
7425
- const tieFormat = drawDefinition.tieFormats?.find((tf) => item.tieFormatId === tf.tieFormatId);
7426
- if (tieFormat)
7427
- return tieFormat;
7428
- if (event.tieFormat)
7429
- return event.tieFormat;
7430
- return event.tieFormats?.find((tf) => item.tieFormatId === tf.tieFormatId);
7431
- }
7432
- if (structure.tieFormat)
7433
- return structure.tieFormat;
7434
- if (structure.tieFormatId) {
7435
- const structureTieFormat = drawDefinition.tieFormats?.find((tf) => structure.tieFormatId === tf.tieFormatId);
7436
- if (structureTieFormat)
7437
- return structureTieFormat;
7438
- }
7439
- }
7440
-
7441
- function resolveTieFormat({ drawDefinition, structure, matchUp, event }) {
7442
- return {
7443
- tieFormat: getItemTieFormat({
7444
- item: matchUp,
7445
- drawDefinition,
7446
- structure,
7447
- event,
7448
- }) ||
7449
- getItemTieFormat({
7450
- item: structure,
7451
- drawDefinition,
7452
- structure,
7453
- event,
7454
- }) ||
7455
- getObjectTieFormat(drawDefinition) ||
7456
- getObjectTieFormat(event),
7457
- };
7458
- }
7459
-
7460
- function getCollectionPositionMatchUps({ matchUps }) {
7461
- const collectionPositionMatchUpsArray = matchUps
7462
- .reduce((collectionPositions, matchUp) => {
7463
- return !matchUp.collectionPosition || collectionPositions.includes(matchUp.collectionPosition)
7464
- ? collectionPositions
7465
- : collectionPositions.concat(matchUp.collectionPosition);
7466
- }, [])
7467
- .map((collectionPosition) => {
7468
- return {
7469
- [collectionPosition]: matchUps.filter((matchUp) => matchUp.collectionPosition === collectionPosition),
7470
- };
7471
- });
7472
- const collectionPositionMatchUps = Object.assign({}, ...collectionPositionMatchUpsArray);
7473
- return { collectionPositionMatchUps };
7474
- }
7475
-
7476
- function getMatchUpsMap({ drawDefinition, structure }) {
7477
- const mappedMatchUps = {};
7478
- const drawMatchUps = [];
7479
- (drawDefinition?.structures ?? [structure])
7480
- .filter((structure) => structure && typeof structure === 'object')
7481
- .forEach((structure) => {
7482
- if (!structure)
7483
- return;
7484
- const { structureId, matchUps, structures } = structure;
7485
- const isRoundRobin = Array.isArray(structures);
7486
- if (!isRoundRobin) {
7487
- const filteredMatchUps = matchUps;
7488
- mappedMatchUps[structureId] = {
7489
- matchUps: filteredMatchUps,
7490
- itemStructureIds: [],
7491
- };
7492
- filteredMatchUps?.forEach((matchUp) => {
7493
- drawMatchUps.push(matchUp);
7494
- if (matchUp.tieMatchUps)
7495
- drawMatchUps.push(...matchUp.tieMatchUps);
7496
- });
7497
- }
7498
- else if (isRoundRobin) {
7499
- structures.forEach((itemStructure) => {
7500
- const { structureName } = itemStructure;
7501
- const filteredMatchUps = itemStructure.matchUps;
7502
- mappedMatchUps[itemStructure.structureId] = {
7503
- matchUps: filteredMatchUps,
7504
- itemStructureIds: [],
7505
- structureName,
7506
- };
7507
- if (filteredMatchUps) {
7508
- drawMatchUps.push(...filteredMatchUps);
7509
- filteredMatchUps.forEach((matchUp) => {
7510
- if (matchUp.tieMatchUps)
7511
- drawMatchUps.push(...matchUp.tieMatchUps);
7512
- });
7513
- }
7514
- if (!mappedMatchUps[structureId])
7515
- mappedMatchUps[structureId] = {
7516
- itemStructureIds: [],
7517
- matchUps: [],
7518
- };
7519
- if (!mappedMatchUps[structureId].itemStructureIds)
7520
- mappedMatchUps[structureId].itemStructureIds = [];
7521
- mappedMatchUps[structureId].itemStructureIds.push(itemStructure.structureId);
7522
- });
7523
- }
7524
- });
7525
- return { mappedMatchUps, drawMatchUps };
7526
- }
7527
- function getMappedStructureMatchUps({ mappedMatchUps, matchUpsMap, structureId, inContext, }) {
7528
- mappedMatchUps = matchUpsMap?.mappedMatchUps ?? mappedMatchUps;
7529
- const structureMatchUpsMap = mappedMatchUps[structureId];
7530
- const itemStructureMatchUps = (structureMatchUpsMap?.itemStructureIds || [])
7531
- .map((itemStructureId) => {
7532
- const { matchUps, structureName } = mappedMatchUps[itemStructureId];
7533
- if (inContext) {
7534
- return matchUps.map((matchUp) => {
7535
- return Object.assign(makeDeepCopy(matchUp, true, true), {
7536
- containerStructureId: structureId,
7537
- structureId: itemStructureId,
7538
- structureName,
7539
- });
7540
- });
7541
- }
7542
- else {
7543
- return matchUps;
7544
- }
7545
- })
7546
- .flat();
7547
- return (structureMatchUpsMap?.matchUps || []).concat(...itemStructureMatchUps);
7548
- }
7549
-
7550
- function reduceGroupedOrder({ groupedOrder, roundPositionsCount }) {
7551
- if (!groupedOrder || groupedOrder?.length <= roundPositionsCount) {
7552
- return groupedOrder;
7553
- }
7554
- const groupChunks = chunkArray(groupedOrder, groupedOrder.length / roundPositionsCount);
7555
- const chunkValues = groupChunks.map((chunk) => chunk.reduce((a, b) => a + b));
7556
- const sortedChunks = chunkValues.slice().sort(numericSort);
7557
- return chunkValues.map((chunkValue) => sortedChunks.indexOf(chunkValue) + 1);
7558
- }
7559
-
7560
- function validMatchUp(matchUp) {
7561
- if (!isObject(matchUp))
7562
- return false;
7563
- const { matchUpId, drawPositions } = matchUp;
7564
- const validMatchUpId = typeof matchUpId === 'string';
7565
- const validDrawPositions = !drawPositions ||
7566
- (Array.isArray(drawPositions) &&
7567
- drawPositions.length <= 2 &&
7568
- drawPositions.every((dp) => isConvertableInteger(dp) || dp === undefined || dp === null));
7569
- return validMatchUpId && validDrawPositions;
7570
- }
7571
- function validMatchUps(matchUps) {
7572
- if (!Array.isArray(matchUps))
7573
- return false;
7574
- return matchUps.every(validMatchUp);
7575
- }
7576
-
7577
- function getRoundMatchUps({ matchUps = [], interpolate }) {
7578
- if (!validMatchUps(matchUps))
7579
- return { roundMatchUps: [], error: INVALID_VALUES };
7580
- const roundMatchUpsArray = matchUps
7581
- .reduce((roundNumbers, matchUp) => {
7582
- const roundNumber = typeof matchUp.roundNumber === 'string' ? ensureInt(matchUp.roundNumber) : matchUp.roundNumber;
7583
- return !matchUp.roundNumber || roundNumbers.includes(roundNumber)
7584
- ? roundNumbers
7585
- : roundNumbers.concat(roundNumber);
7586
- }, [])
7587
- .sort(numericSort)
7588
- .map((roundNumber) => {
7589
- const roundMatchUps = matchUps.filter((matchUp) => matchUp.roundNumber === roundNumber);
7590
- const hasTeamMatchUps = roundMatchUps.find(({ matchUpType }) => matchUpType === TEAM$1);
7591
- const consideredMatchUps = hasTeamMatchUps
7592
- ? roundMatchUps.filter(({ matchUpType }) => matchUpType === TEAM$1)
7593
- : roundMatchUps;
7594
- const getSorted = (items) => items.sort((a, b) => numericSort(a.roundPosition, b.roundPosition));
7595
- return {
7596
- [roundNumber]: getSorted(consideredMatchUps),
7597
- };
7598
- });
7599
- const finishingRoundMap = matchUps.reduce((mapping, matchUp) => {
7600
- const roundNumber = typeof matchUp.roundNumber === 'string' ? ensureInt(matchUp.roundNumber) : matchUp.roundNumber;
7601
- if (!mapping[roundNumber])
7602
- mapping[roundNumber] = definedAttributes({
7603
- abbreviatedRoundName: matchUp.abbreviatedRoundName,
7604
- finishingRound: matchUp.finishingRound,
7605
- roundName: matchUp.roundName,
7606
- });
7607
- return mapping;
7608
- }, {});
7609
- const roundMatchUps = Object.assign({}, ...roundMatchUpsArray);
7610
- if (interpolate) {
7611
- const maxRoundNumber = Math.max(...Object.keys(roundMatchUps)
7612
- .map((key) => ensureInt(key))
7613
- .filter((f) => !isNaN(f)));
7614
- const maxRoundMatchUpsCount = roundMatchUps[maxRoundNumber]?.length;
7615
- if (maxRoundMatchUpsCount > 1 && isPowerOf2(maxRoundMatchUpsCount)) {
7616
- const nextRound = maxRoundNumber + 1;
7617
- const lastRound = nextRound + maxRoundMatchUpsCount / 2;
7618
- const roundsToInterpolate = generateRange(nextRound, lastRound);
7619
- roundsToInterpolate.forEach((roundNumber, i) => {
7620
- roundMatchUps[roundNumber] = generateRange(0, maxRoundMatchUpsCount / (2 + i * 2)).map(() => ({}));
7621
- });
7622
- }
7623
- }
7624
- let maxMatchUpsCount = 0;
7625
- const roundProfile = Object.assign({}, ...Object.keys(roundMatchUps).map((roundNumber) => {
7626
- const matchUpsCount = roundMatchUps[roundNumber]?.length;
7627
- const inactiveCount = roundMatchUps[roundNumber]?.filter((matchUp) => !completedMatchUpStatuses.includes(matchUp.matchUpStatus) && !matchUp.score?.scoreStringSide1)?.length;
7628
- const inactiveRound = matchUpsCount && matchUpsCount === inactiveCount;
7629
- maxMatchUpsCount = Math.max(maxMatchUpsCount, matchUpsCount);
7630
- return { [roundNumber]: { matchUpsCount, inactiveCount, inactiveRound } };
7631
- }));
7632
- let roundIndex = 0;
7633
- let feedRoundIndex = 0;
7634
- const roundNumbers = Object.keys(roundMatchUps)
7635
- .map((key) => ensureInt(key))
7636
- .filter((f) => !isNaN(f));
7637
- roundNumbers.forEach((roundNumber) => {
7638
- const currentRoundMatchUps = roundMatchUps[roundNumber].sort((a, b) => a.roundPosition - b.roundPosition);
7639
- const currentRoundDrawPositions = currentRoundMatchUps.map((matchUp) => matchUp?.drawPositions || []).flat();
7640
- roundProfile[roundNumber].roundNumber = roundNumber;
7641
- roundProfile[roundNumber].roundFactor = roundProfile[roundNumber].matchUpsCount
7642
- ? maxMatchUpsCount / roundProfile[roundNumber].matchUpsCount
7643
- : 1;
7644
- roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber]?.finishingRound;
7645
- roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber]?.roundName;
7646
- roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber]?.abbreviatedRoundName;
7647
- roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber]?.[0]?.finishingPositionRange;
7648
- if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
7649
- const orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
7650
- const pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
7651
- roundProfile[roundNumber].drawPositions = orderedDrawPositions;
7652
- roundProfile[roundNumber].pairedDrawPositions = pairedDrawPositions;
7653
- }
7654
- else {
7655
- const priorRound = roundProfile[roundNumber - 1];
7656
- const priorRoundDrawPositions = priorRound.drawPositions;
7657
- const chunkFactor = priorRound.matchUpsCount / roundProfile[roundNumber].matchUpsCount;
7658
- const priorRoundDrawPositionChunks = chunkArray(priorRoundDrawPositions, chunkFactor);
7659
- const roundDrawPositions = currentRoundMatchUps.map((matchUp) => {
7660
- const { roundPosition } = matchUp;
7661
- const drawPositions = [...(matchUp.drawPositions || []), undefined, undefined].slice(0, 2);
7662
- if (!roundPosition)
7663
- return drawPositions;
7664
- const filteredDrawPositions = drawPositions?.filter(Boolean) || [];
7665
- if (!filteredDrawPositions?.length)
7666
- return [undefined, undefined];
7667
- if (roundNumber < 3 && filteredDrawPositions?.length === 2) {
7668
- return drawPositions?.slice().sort(numericSort);
7669
- }
7670
- const isFeedRound = intersection(priorRoundDrawPositions, filteredDrawPositions).length !== filteredDrawPositions?.length;
7671
- if (filteredDrawPositions?.length && isFeedRound) {
7672
- if (filteredDrawPositions?.length === 1) {
7673
- return [filteredDrawPositions[0], undefined];
7674
- }
7675
- else {
7676
- return drawPositions?.slice().sort(numericSort);
7677
- }
7678
- }
7679
- const targetChunkIndex = (roundPosition - 1) * 2;
7680
- const targetChunks = priorRoundDrawPositionChunks.slice(targetChunkIndex, targetChunkIndex + 2);
7681
- return targetChunks.map((chunk) => {
7682
- return filteredDrawPositions?.find((drawPosition) => chunk.includes(drawPosition));
7683
- });
7684
- });
7685
- roundProfile[roundNumber].drawPositions = roundDrawPositions?.flat();
7686
- roundProfile[roundNumber].pairedDrawPositions = roundDrawPositions;
7687
- }
7688
- if (roundProfile[roundNumber + 1] &&
7689
- roundProfile[roundNumber + 1].matchUpsCount === roundProfile[roundNumber].matchUpsCount) {
7690
- roundProfile[roundNumber + 1].feedRound = true;
7691
- roundProfile[roundNumber + 1].feedRoundIndex = feedRoundIndex;
7692
- roundProfile[roundNumber].preFeedRound = true;
7693
- feedRoundIndex += 1;
7870
+ tournamentId,
7871
+ drawId,
7872
+ };
7873
+ }
7874
+ }
7875
+ return targetDrawDefinition;
7876
+ });
7877
+ if (event)
7878
+ return { event, drawDefinition, tournamentId };
7879
+ }
7880
+ if (eventId) {
7881
+ const event = events.find((event) => event?.eventId === eventId);
7882
+ if (!event) {
7883
+ return {
7884
+ event: undefined,
7885
+ drawDefinition: undefined,
7886
+ ...decorateResult({ result: { error: EVENT_NOT_FOUND }, stack }),
7887
+ };
7694
7888
  }
7695
- if (roundProfile[roundNumber] && !roundProfile[roundNumber].feedRound) {
7696
- roundProfile[roundNumber].roundIndex = roundIndex;
7697
- roundIndex += 1;
7889
+ else {
7890
+ tournamentId = eventIdsMap[event.eventId].tournamentId;
7698
7891
  }
7699
- });
7700
- const roundsNotPowerOf2 = !!Object.values(roundProfile).find(({ matchUpsCount }) => !isPowerOf2(matchUpsCount));
7701
- const hasNoRoundPositions = matchUps.some((matchUp) => !matchUp.roundPosition);
7892
+ return { event, drawDefinition: undefined, tournamentId };
7893
+ }
7702
7894
  return {
7703
- hasNoRoundPositions,
7704
- roundsNotPowerOf2,
7705
- maxMatchUpsCount,
7706
- roundMatchUps,
7707
- roundNumbers,
7708
- roundProfile,
7709
- ...SUCCESS,
7895
+ event: undefined,
7896
+ drawDefinition: undefined,
7897
+ ...decorateResult({
7898
+ result: { error: DRAW_DEFINITION_NOT_FOUND },
7899
+ context: { drawId, eventId },
7900
+ stack,
7901
+ }),
7710
7902
  };
7711
7903
  }
7712
7904
 
7713
- function getRangeString(arr) {
7714
- if (!Array.isArray(arr))
7715
- return '';
7716
- const numericArray = arr.filter(isNumeric);
7717
- if (!numericArray.length)
7718
- return '';
7719
- const range = unique([Math.min(...numericArray), Math.max(...numericArray)]);
7720
- return range.join('-');
7721
- }
7722
-
7723
- function getSourceDrawPositionRanges({ drawDefinition, structureId, matchUpsMap }) {
7724
- if (!drawDefinition)
7725
- return { error: MISSING_DRAW_DEFINITION };
7726
- if (!structureId)
7727
- return { error: MISSING_STRUCTURE_ID };
7728
- const { structure } = findStructure({ drawDefinition, structureId });
7729
- if (structure?.stage !== CONSOLATION)
7730
- return { error: INVALID_STAGE, info: 'Structure is not CONSOLATION stage' };
7731
- const { links } = drawDefinition;
7732
- const relevantLinks = links?.filter((link) => link.target.structureId === structureId) || [];
7733
- const sourceStructureIds = relevantLinks?.reduce((sourceStructureIds, link) => {
7734
- const { structureId: sourceStructureId } = link.source;
7735
- return sourceStructureIds.includes(sourceStructureId)
7736
- ? sourceStructureIds
7737
- : sourceStructureIds.concat(sourceStructureId);
7738
- }, []) || [];
7739
- const sourceStructureProfiles = Object.assign({}, ...sourceStructureIds.map((sourceStructureId) => {
7740
- const structureMatchUps = getMappedStructureMatchUps({
7741
- structureId: sourceStructureId,
7742
- matchUpsMap,
7743
- });
7744
- const roundMatchUpsResult = getRoundMatchUps({
7745
- matchUps: structureMatchUps,
7746
- });
7747
- const roundProfile = roundMatchUpsResult.roundProfile;
7748
- return { [sourceStructureId]: roundProfile };
7749
- }));
7750
- const structureMatchUps = getMappedStructureMatchUps({
7751
- matchUpsMap,
7752
- structureId,
7753
- });
7754
- const { roundProfile: targetStructureProfile } = getRoundMatchUps({
7755
- matchUps: structureMatchUps,
7756
- });
7757
- const sourceDrawPositionRanges = {};
7758
- relevantLinks?.forEach((link) => {
7759
- const { structureId: sourceStructureId, roundNumber: sourceRoundNumber } = link.source;
7760
- const { feedProfile, groupedOrder, positionInterleave, roundNumber: targetRoundNumber } = link.target;
7761
- const sourceStructureProfile = sourceStructureProfiles[sourceStructureId];
7762
- const firstRoundDrawPositions = sourceStructureProfile[1]?.drawPositions;
7763
- const sourceRoundProfile = sourceStructureProfile[sourceRoundNumber];
7764
- const sourceRoundMatchUpsCount = sourceRoundProfile?.matchUpsCount;
7765
- if (!sourceRoundMatchUpsCount)
7766
- return;
7767
- const chunkSize = sourceRoundMatchUpsCount ? firstRoundDrawPositions.length / sourceRoundMatchUpsCount : 0;
7768
- const targetRoundMatchUpsCount = firstRoundDrawPositions.length / chunkSize;
7769
- let orderedPositions = firstRoundDrawPositions.slice();
7770
- const sizedGroupOrder = reduceGroupedOrder({
7771
- roundPositionsCount: targetRoundMatchUpsCount,
7772
- groupedOrder,
7773
- });
7774
- const groupsCount = sizedGroupOrder?.length || 1;
7775
- if (groupsCount <= targetRoundMatchUpsCount) {
7776
- const groupSize = firstRoundDrawPositions.length / groupsCount;
7777
- const groups = chunkArray(orderedPositions, groupSize);
7778
- if (feedProfile === BOTTOM_UP)
7779
- groups.forEach((group) => group.reverse());
7780
- orderedPositions =
7781
- (sizedGroupOrder?.length && sizedGroupOrder?.map((order) => groups[order - 1]).flat()) || orderedPositions;
7905
+ function getMatchUpScheduleDetails(params) {
7906
+ let event = params.event;
7907
+ let matchUpType = params.matchUpType;
7908
+ const { scheduleVisibilityFilters, afterRecoveryTimes, tournamentRecord, usePublishState, scheduleTiming, matchUpFormat, publishStatus, matchUp, } = params;
7909
+ if (!matchUp)
7910
+ return { error: MISSING_MATCHUP };
7911
+ if (afterRecoveryTimes &&
7912
+ !matchUp.matchUpType &&
7913
+ !params.matchUpType &&
7914
+ (event || tournamentRecord) &&
7915
+ matchUp.drawId) {
7916
+ let drawDefinition = event?.drawDefinitions?.find((drawDefinition) => drawDefinition.drawId === matchUp.drawId);
7917
+ if (!drawDefinition && tournamentRecord) {
7918
+ ({ drawDefinition, event } = findEvent({
7919
+ tournamentRecord,
7920
+ drawId: matchUp.drawId,
7921
+ }));
7782
7922
  }
7783
- let drawPositionBlocks = chunkArray(orderedPositions, chunkSize);
7784
- if (positionInterleave) {
7785
- const interleave = generateRange(0, positionInterleave.interleave).map(() => undefined);
7786
- const offset = generateRange(0, positionInterleave.offset).map(() => undefined);
7787
- drawPositionBlocks = drawPositionBlocks.map((block) => [block, ...interleave]);
7788
- drawPositionBlocks.unshift(offset);
7789
- drawPositionBlocks = drawPositionBlocks.flat(1);
7790
- const targetLength = drawPositionBlocks.length - positionInterleave.offset;
7791
- drawPositionBlocks = drawPositionBlocks.slice(0, targetLength);
7923
+ const structure = matchUp.structureId && drawDefinition?.structures?.find(({ structureId }) => structureId === matchUp.structureId);
7924
+ matchUpType =
7925
+ params.matchUpType ||
7926
+ structure?.matchUpType ||
7927
+ drawDefinition?.matchUpType ||
7928
+ (event?.eventType !== TEAM$2 && event?.eventType);
7929
+ }
7930
+ const { milliseconds, time } = matchUpDuration({ matchUp });
7931
+ const { startTime } = matchUpStartTime({ matchUp });
7932
+ const { endTime } = matchUpEndTime({ matchUp });
7933
+ let schedule;
7934
+ const { visibilityThreshold, eventIds, drawIds } = scheduleVisibilityFilters ?? {};
7935
+ if ((!eventIds || eventIds.includes(matchUp.eventId)) && (!drawIds || drawIds.includes(matchUp.drawId))) {
7936
+ const scheduleSource = { matchUp, visibilityThreshold };
7937
+ const { allocatedCourts } = matchUpAllocatedCourts(scheduleSource);
7938
+ const { homeParticipantId } = getHomeParticipantId(scheduleSource);
7939
+ const { scheduledTime } = scheduledMatchUpTime(scheduleSource);
7940
+ const { timeModifiers } = matchUpTimeModifiers(scheduleSource);
7941
+ let { scheduledDate } = scheduledMatchUpDate(scheduleSource);
7942
+ const { venueId } = matchUpAssignedVenueId(scheduleSource);
7943
+ const { courtId } = matchUpAssignedCourtId(scheduleSource);
7944
+ const { courtOrder } = matchUpCourtOrder(scheduleSource);
7945
+ let timeAfterRecovery, averageMinutes, recoveryMinutes, typeChangeRecoveryMinutes, typeChangeTimeAfterRecovery;
7946
+ const eventType = matchUp.matchUpType ?? matchUpType;
7947
+ if (scheduleTiming && scheduledTime && afterRecoveryTimes && eventType) {
7948
+ const timingDetails = {
7949
+ matchUpFormat: matchUp.matchUpFormat ?? matchUpFormat,
7950
+ ...scheduleTiming,
7951
+ };
7952
+ ({
7953
+ averageMinutes = 0,
7954
+ recoveryMinutes = 0,
7955
+ typeChangeRecoveryMinutes = 0,
7956
+ } = matchUpFormatTimes({
7957
+ timingDetails,
7958
+ eventType,
7959
+ }));
7960
+ if (averageMinutes || recoveryMinutes) {
7961
+ timeAfterRecovery = endTime
7962
+ ? addMinutesToTimeString(extractTime$1(endTime), recoveryMinutes)
7963
+ : addMinutesToTimeString(scheduledTime, averageMinutes + recoveryMinutes);
7964
+ }
7965
+ if (typeChangeRecoveryMinutes) {
7966
+ typeChangeTimeAfterRecovery = endTime
7967
+ ? addMinutesToTimeString(extractTime$1(endTime), typeChangeRecoveryMinutes)
7968
+ : addMinutesToTimeString(scheduledTime, averageMinutes + typeChangeRecoveryMinutes);
7969
+ }
7792
7970
  }
7793
- if (!sourceDrawPositionRanges[targetRoundNumber])
7794
- sourceDrawPositionRanges[targetRoundNumber] = {};
7795
- const targetRoundProfile = targetStructureProfile?.[targetRoundNumber];
7796
- const increment = targetRoundProfile?.feedRound ? 2 : 1;
7797
- drawPositionBlocks.forEach((block, index) => {
7798
- const columnPosition = 1 + index * increment;
7799
- if (!sourceDrawPositionRanges[targetRoundNumber][columnPosition]) {
7800
- sourceDrawPositionRanges[targetRoundNumber][columnPosition] = getRangeString(block);
7971
+ if (!scheduledDate && scheduledTime)
7972
+ scheduledDate = extractDate(scheduledTime);
7973
+ const isoDateString = getIsoDateString({ scheduledDate, scheduledTime });
7974
+ const venueDataMap = {};
7975
+ const venueData = (tournamentRecord && venueId && getVenueData({ tournamentRecord, venueId }))?.venueData || {};
7976
+ if (venueId)
7977
+ venueDataMap[venueId] = venueData;
7978
+ const { venueName, venueAbbreviation, courtsInfo } = venueData;
7979
+ const courtInfo = courtId && courtsInfo?.find((courtInfo) => courtInfo.courtId === courtId);
7980
+ const courtName = courtInfo?.courtName;
7981
+ for (const allocatedCourt of allocatedCourts || []) {
7982
+ if (!tournamentRecord)
7983
+ break;
7984
+ if (allocatedCourt.venueId && !venueDataMap[allocatedCourt.venueid]) {
7985
+ venueDataMap[allocatedCourt.venueId] = getVenueData({
7986
+ venueId: allocatedCourt.venueId,
7987
+ tournamentRecord,
7988
+ })?.venueData;
7801
7989
  }
7990
+ const vData = venueDataMap[allocatedCourt.venueId];
7991
+ allocatedCourt.venueName = vData?.venueName;
7992
+ const courtInfo = vData?.courtsInfo?.find((courtInfo) => courtInfo.courtId === allocatedCourt.courtId);
7993
+ allocatedCourt.courtName = courtInfo?.courtName;
7994
+ }
7995
+ schedule = definedAttributes({
7996
+ typeChangeTimeAfterRecovery,
7997
+ timeAfterRecovery,
7998
+ scheduledDate,
7999
+ scheduledTime,
8000
+ isoDateString,
8001
+ allocatedCourts,
8002
+ homeParticipantId,
8003
+ timeModifiers,
8004
+ venueAbbreviation,
8005
+ venueName,
8006
+ venueId,
8007
+ courtOrder,
8008
+ courtName,
8009
+ courtId,
8010
+ typeChangeRecoveryMinutes,
8011
+ recoveryMinutes,
8012
+ averageMinutes,
8013
+ milliseconds,
8014
+ startTime,
8015
+ endTime,
8016
+ time,
7802
8017
  });
7803
- });
7804
- return { sourceDrawPositionRanges };
8018
+ }
8019
+ else {
8020
+ schedule = definedAttributes({
8021
+ milliseconds,
8022
+ startTime,
8023
+ endTime,
8024
+ time,
8025
+ });
8026
+ }
8027
+ const { scheduledDate } = scheduledMatchUpDate({ matchUp });
8028
+ const { scheduledTime } = scheduledMatchUpTime({ matchUp });
8029
+ if (usePublishState && publishStatus?.displaySettings?.draws) {
8030
+ const drawSettings = publishStatus.displaySettings.draws;
8031
+ const scheduleDetails = (drawSettings?.[matchUp.drawId] ?? drawSettings?.default)?.scheduleDetails;
8032
+ if (scheduleDetails) {
8033
+ const scheduleAttributes = (scheduleDetails.find((details) => scheduledDate && details.dates?.includes(scheduledDate)) ??
8034
+ scheduleDetails.find((details) => !details.dates?.length))?.attributes;
8035
+ if (scheduleAttributes) {
8036
+ const template = Object.assign({}, ...Object.keys(schedule).map((key) => ({ [key]: true })), scheduleAttributes);
8037
+ schedule = attributeFilter({
8038
+ source: schedule,
8039
+ template,
8040
+ });
8041
+ }
8042
+ }
8043
+ }
8044
+ const hasCompletedStatus = matchUp.matchUpStatus && completedMatchUpStatuses.includes(matchUp.matchUpStatus);
8045
+ const endDate = (hasCompletedStatus && (extractDate(endTime) || extractDate(scheduledDate) || extractDate(scheduledTime))) ||
8046
+ undefined;
8047
+ return { schedule, endDate };
7805
8048
  }
7806
8049
 
7807
8050
  function getOrderedDrawPositions({ drawPositions, roundProfile, roundNumber }) {
@@ -7965,249 +8208,6 @@ function getCollectionAssignment({ tournamentParticipants, positionAssignments,
7965
8208
  return { drawPositionCollectionAssignment: Object.assign({}, ...drawPositionCollectionAssignment) };
7966
8209
  }
7967
8210
 
7968
- function getExitProfiles({ drawDefinition }) {
7969
- if (typeof drawDefinition !== 'object')
7970
- return { error: INVALID_DRAW_DEFINITION };
7971
- const exitProfiles = {};
7972
- const { structures = [], links = [] } = drawDefinition || {};
7973
- const stageStructures = structures.reduce((stageStructures, structure) => {
7974
- const { stage } = structure;
7975
- if (!stageStructures[stage]) {
7976
- stageStructures[stage] = [structure];
7977
- }
7978
- else {
7979
- stageStructures[stage].push(structure);
7980
- }
7981
- return stageStructures;
7982
- }, {});
7983
- for (const stage of Object.keys(stageStructures)) {
7984
- const initialStructure = stageStructures[stage].find(({ stageSequence }) => stageSequence === 1);
7985
- if (!initialStructure)
7986
- continue;
7987
- const { structureId } = initialStructure;
7988
- const exitProfile = '0';
7989
- addExitProfiles({
7990
- aggregator: {},
7991
- targetRound: 0,
7992
- exitProfiles,
7993
- exitProfile,
7994
- structureId,
7995
- stage,
7996
- });
7997
- }
7998
- return { exitProfiles };
7999
- function addExitProfiles({ exitProfiles, exitProfile, structureId, targetRound, aggregator, stage }) {
8000
- if (!exitProfiles[structureId])
8001
- exitProfiles[structureId] = [];
8002
- if (!(exitProfile === '0' && [CONSOLATION, PLAY_OFF].includes(stage)))
8003
- exitProfiles[structureId].push(exitProfile);
8004
- const relevantLinks = links.filter((link) => link.source.structureId === structureId && link.source.roundNumber >= targetRound);
8005
- for (const link of relevantLinks) {
8006
- const exitRound = link.source.roundNumber;
8007
- const targetRound = link.target.roundNumber;
8008
- const targetStructureId = link.target.structureId;
8009
- const stage = structures.find((structure) => structure.structureId === targetStructureId).stage;
8010
- const fp = [stage, targetStructureId, targetRound, exitRound].join('|');
8011
- if (aggregator[fp])
8012
- return;
8013
- aggregator[fp] = true;
8014
- addExitProfiles({
8015
- exitProfile: `${exitProfile}-${exitRound}`,
8016
- structureId: targetStructureId,
8017
- exitProfiles,
8018
- targetRound,
8019
- aggregator,
8020
- stage,
8021
- });
8022
- }
8023
- }
8024
- }
8025
-
8026
- function getDrawPositionsRanges({ drawDefinition, roundProfile, structureId, matchUpsMap, }) {
8027
- if (!drawDefinition)
8028
- return { error: MISSING_DRAW_DEFINITION };
8029
- if (!structureId)
8030
- return { error: MISSING_STRUCTURE_ID };
8031
- if (!roundProfile) {
8032
- const structureMatchUps = getMappedStructureMatchUps({
8033
- matchUpsMap,
8034
- structureId,
8035
- });
8036
- ({ roundProfile } = getRoundMatchUps({
8037
- matchUps: structureMatchUps,
8038
- }));
8039
- if (!roundProfile)
8040
- return { error: MISSING_VALUE };
8041
- }
8042
- const firstRoundFirstDrawPosition = Math.min(...(roundProfile?.[1]?.drawPositions ?? []));
8043
- const firstRoundFirstDrawPositionOffset = (firstRoundFirstDrawPosition || 1) - 1;
8044
- const roundNumbers = Object.keys(roundProfile);
8045
- const drawPositionsRanges = Object.assign({}, ...(roundNumbers || []).map((roundNumber) => {
8046
- const matchUpsCount = roundProfile?.[roundNumber]?.matchUpsCount;
8047
- const firstRoundDrawPositions = roundProfile?.[1]?.drawPositions ?? [];
8048
- const firstRoundDrawPositionsChunks = chunkArray(firstRoundDrawPositions, firstRoundDrawPositions.length / matchUpsCount);
8049
- const firstRoundDrawPositionsRanges = firstRoundDrawPositionsChunks.map(getRangeString);
8050
- const firstRoundOffsetDrawPositionsRanges = firstRoundDrawPositionsChunks
8051
- .map((drawPositions) => {
8052
- return drawPositions.map((drawPosition) => drawPosition - firstRoundFirstDrawPositionOffset);
8053
- })
8054
- .map(getRangeString);
8055
- const currentRoundDrawPositionChunks = roundNumbers
8056
- .map((value) => {
8057
- if (value > roundNumber)
8058
- return undefined;
8059
- const drawPositions = roundProfile?.[value]?.drawPositions ?? [];
8060
- return chunkArray(drawPositions, drawPositions.length / matchUpsCount);
8061
- })
8062
- .filter(Boolean);
8063
- const possibleDrawPositions = generateRange(0, matchUpsCount)
8064
- .map((index) => {
8065
- return currentRoundDrawPositionChunks
8066
- .map((chunk) => chunk[index])
8067
- .flat()
8068
- .filter(Boolean)
8069
- .sort(numericSort);
8070
- })
8071
- .map((possible) => unique(possible));
8072
- const drawPositionsRanges = possibleDrawPositions.map((possible) => {
8073
- return groupConsecutiveNumbers(possible).map(getRangeString).join(', ');
8074
- });
8075
- const roundPositionsMap = Object.assign({}, ...generateRange(0, matchUpsCount).map((index) => {
8076
- const roundPosition = index + 1;
8077
- return {
8078
- [roundPosition]: {
8079
- firstRoundDrawPositionsRange: firstRoundDrawPositionsRanges[index],
8080
- firstRoundOffsetDrawPositionsRange: firstRoundOffsetDrawPositionsRanges[index],
8081
- possibleDrawPositions: possibleDrawPositions[index],
8082
- drawPositionsRange: drawPositionsRanges[index],
8083
- },
8084
- };
8085
- }));
8086
- return { [roundNumber]: roundPositionsMap };
8087
- }));
8088
- return { drawPositionsRanges };
8089
- }
8090
-
8091
- function isLucky({ roundsNotPowerOf2, drawDefinition, structure, matchUps }) {
8092
- if (!structure)
8093
- return false;
8094
- matchUps = matchUps ?? structure.matchUps ?? [];
8095
- roundsNotPowerOf2 = roundsNotPowerOf2 ?? getRoundMatchUps({ matchUps }).roundsNotPowerOf2;
8096
- const hasDrawPositions = !!structure.positionAssignments?.find(({ drawPosition }) => drawPosition) ||
8097
- !!matchUps?.find(({ drawPositions }) => drawPositions?.length);
8098
- return ((!drawDefinition?.drawType || drawDefinition.drawType !== LUCKY_DRAW) &&
8099
- !structure?.structures &&
8100
- roundsNotPowerOf2 &&
8101
- hasDrawPositions);
8102
- }
8103
-
8104
- function isAdHoc({ structure }) {
8105
- if (!structure)
8106
- return false;
8107
- const matchUps = structure.matchUps || (structure.roundMatchUps && Object.values(structure.roundMatchUps).flat());
8108
- const hasRoundPosition = !!matchUps?.find((matchUp) => matchUp?.roundPosition);
8109
- const hasDrawPosition = !!matchUps?.find((matchUp) => matchUp?.drawPositions?.length);
8110
- return (!structure?.structures &&
8111
- structure?.stage !== VOLUNTARY_CONSOLATION &&
8112
- (!matchUps.length || (!hasRoundPosition && !hasDrawPosition)));
8113
- }
8114
-
8115
- const POLICY_ROUND_NAMING_DEFAULT = {
8116
- [POLICY_TYPE_ROUND_NAMING]: {
8117
- policyName: 'Round Naming Default',
8118
- namingConventions: {
8119
- round: 'Round',
8120
- pre: 'Pre',
8121
- },
8122
- qualifyingFinishMap: {
8123
- 1: 'Final',
8124
- },
8125
- abbreviatedRoundNamingMap: {
8126
- 1: 'F',
8127
- 2: 'SF',
8128
- 4: 'QF',
8129
- },
8130
- roundNamingMap: {
8131
- 1: 'Final',
8132
- 2: 'Semifinal',
8133
- 4: 'Quarterfinal',
8134
- },
8135
- affixes: {
8136
- roundNumber: 'R',
8137
- preFeedRound: 'Q',
8138
- preQualifying: 'P',
8139
- },
8140
- stageConstants: {
8141
- [MAIN]: '',
8142
- [PLAY_OFF]: 'P',
8143
- [QUALIFYING]: 'Q',
8144
- [CONSOLATION]: 'C',
8145
- },
8146
- },
8147
- };
8148
-
8149
- function getRoundContextProfile({ roundNamingPolicy, drawDefinition, structure, matchUps, }) {
8150
- const { roundProfile, roundMatchUps } = getRoundMatchUps({ matchUps });
8151
- const { structureAbbreviation, stage } = structure;
8152
- const isAdHocStructure = isAdHoc({ structure });
8153
- const isLuckyStructure = isLucky({ structure });
8154
- const isRoundRobin = structure.structures;
8155
- const roundNamingProfile = {};
8156
- const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
8157
- const isQualifying = structure.stage === QUALIFYING;
8158
- const qualifyingStageSequences = isQualifying
8159
- ? Math.max(...(drawDefinition?.structures ?? [])
8160
- .filter((structure) => structure.stage === QUALIFYING)
8161
- .map(({ stageSequence }) => stageSequence ?? 1), 0)
8162
- : 0;
8163
- const preQualifyingSequence = (structure.stageSequence ?? 1) < qualifyingStageSequences ? structure.stageSequence ?? 1 : '';
8164
- const preQualifyingAffix = preQualifyingSequence
8165
- ? roundNamingPolicy?.affixes?.preQualifying || defaultRoundNamingPolicy.affixes.preQualifying || ''
8166
- : '';
8167
- const roundNamingMap = roundNamingPolicy?.roundNamingMap || defaultRoundNamingPolicy.roundNamingMap || {};
8168
- const abbreviatedRoundNamingMap = roundNamingPolicy?.abbreviatedRoundNamingMap || defaultRoundNamingPolicy.abbreviatedRoundNamingMap || {};
8169
- const preFeedAffix = roundNamingPolicy?.affixes?.preFeedRound || defaultRoundNamingPolicy.affixes.preFeedRound;
8170
- const roundNumberAffix = roundNamingPolicy?.affixes?.roundNumber || defaultRoundNamingPolicy.affixes.roundNumber;
8171
- const namingConventions = roundNamingPolicy?.namingConventions || defaultRoundNamingPolicy.namingConventions;
8172
- const roundNameFallback = namingConventions.round;
8173
- const stageInitial = stage && stage !== MAIN ? stage[0] : '';
8174
- const stageConstants = roundNamingPolicy?.stageConstants || defaultRoundNamingPolicy.stageConstants;
8175
- const stageIndicator = (stage && stageConstants?.[stage]) || stageInitial;
8176
- const stageConstant = `${preQualifyingAffix}${stageIndicator}${preQualifyingSequence}`;
8177
- const roundProfileKeys = roundProfile ? Object.keys(roundProfile) : [];
8178
- const qualifyingAffix = isQualifying && stageConstants?.[QUALIFYING] ? `${stageConstants?.[QUALIFYING]}-` : '';
8179
- if (isRoundRobin || isAdHocStructure || isLuckyStructure) {
8180
- Object.assign(roundNamingProfile, ...roundProfileKeys.map((key) => {
8181
- const roundName = `${qualifyingAffix}${roundNameFallback} ${key}`;
8182
- const abbreviatedRoundName = `${roundNumberAffix}${key}`;
8183
- return { [key]: { roundName, abbreviatedRoundName } };
8184
- }));
8185
- }
8186
- else {
8187
- const qualifyingFinishgMap = isQualifying && (roundNamingPolicy?.qualifyingFinishMap || defaultRoundNamingPolicy?.qualifyingFinishMap || {});
8188
- Object.assign(roundNamingProfile, ...roundProfileKeys.map((round) => {
8189
- if (!roundProfile?.[round])
8190
- return;
8191
- const { matchUpsCount, preFeedRound } = roundProfile[round];
8192
- const participantsCount = matchUpsCount * 2;
8193
- const sizedRoundName = qualifyingFinishgMap?.[roundProfile?.[round].finishingRound] ||
8194
- (qualifyingFinishgMap && `${roundNumberAffix}${participantsCount}`) ||
8195
- roundNamingMap[matchUpsCount] ||
8196
- `${roundNumberAffix}${participantsCount}`;
8197
- const suffix = preFeedRound ? `-${preFeedAffix}` : '';
8198
- const profileRoundName = `${sizedRoundName}${suffix}`;
8199
- const roundName = [stageConstant, structureAbbreviation, profileRoundName].filter(Boolean).join('-');
8200
- const sizedAbbreviation = abbreviatedRoundNamingMap[matchUpsCount] || `${roundNumberAffix}${participantsCount}`;
8201
- const profileAbbreviation = `${sizedAbbreviation}${suffix}`;
8202
- const abbreviatedRoundName = [stageConstant, structureAbbreviation, profileAbbreviation]
8203
- .filter(Boolean)
8204
- .join('-');
8205
- return { [round]: { abbreviatedRoundName, roundName } };
8206
- }));
8207
- }
8208
- return { roundNamingProfile, roundProfile, roundMatchUps };
8209
- }
8210
-
8211
8211
  function getMatchUpType(params) {
8212
8212
  const paramCheck = checkRequiredParameters(params, [{ [MATCHUP]: true }]);
8213
8213
  if (paramCheck.error)
@@ -8380,6 +8380,394 @@ function getNumber$1(formatstring) {
8380
8380
  return !isNaN(Number(formatstring)) ? Number(formatstring) : 0;
8381
8381
  }
8382
8382
 
8383
+ function getSide({ drawPositionCollectionAssignment, sideNumberCollectionAssignment, positionAssignments, displaySideNumber, seedAssignments, drawPosition, isFeedRound, sideNumber, }) {
8384
+ const assignment = positionAssignments.find((assignment) => assignment.drawPosition && assignment.drawPosition === drawPosition);
8385
+ const dpc = drawPosition && drawPositionCollectionAssignment;
8386
+ const snc = sideNumber && sideNumberCollectionAssignment;
8387
+ const participantId = dpc ? dpc[drawPosition]?.participantId : assignment?.participantId;
8388
+ const sideValue = assignment
8389
+ ? getSideValue$1({
8390
+ displaySideNumber,
8391
+ seedAssignments,
8392
+ participantId,
8393
+ assignment,
8394
+ sideNumber,
8395
+ })
8396
+ : { ...snc?.[sideNumber] };
8397
+ if (isFeedRound) {
8398
+ if (sideNumber === 1) {
8399
+ Object.assign(sideValue, { participantFed: true });
8400
+ }
8401
+ else {
8402
+ Object.assign(sideValue, { participantAdvanced: true });
8403
+ }
8404
+ }
8405
+ if (drawPosition && dpc) {
8406
+ const teamParticipant = dpc[drawPosition]?.teamParticipant;
8407
+ const participant = dpc[drawPosition]?.participant;
8408
+ const substitutions = dpc[drawPosition]?.substitutions;
8409
+ if (participant)
8410
+ sideValue.participant = participant;
8411
+ if (substitutions)
8412
+ sideValue.substitutions = substitutions;
8413
+ if (teamParticipant)
8414
+ sideValue.teamParticipant = teamParticipant;
8415
+ }
8416
+ return sideValue;
8417
+ }
8418
+ function getSideValue$1({ displaySideNumber, seedAssignments, participantId, assignment, sideNumber }) {
8419
+ const side = {
8420
+ drawPosition: assignment.drawPosition,
8421
+ displaySideNumber,
8422
+ sideNumber,
8423
+ };
8424
+ if (participantId) {
8425
+ const seeding = getSeeding({ seedAssignments, participantId });
8426
+ Object.assign(side, seeding, { participantId });
8427
+ }
8428
+ else if (assignment.bye) {
8429
+ Object.assign(side, { bye: true });
8430
+ }
8431
+ if (assignment.qualifier) {
8432
+ Object.assign(side, { qualifier: true });
8433
+ }
8434
+ return side;
8435
+ }
8436
+ function getSeeding({ seedAssignments, participantId }) {
8437
+ return seedAssignments?.find((assignment) => !assignment.seedProxy && assignment.participantId === participantId);
8438
+ }
8439
+
8440
+ const ANY = 'ANY';
8441
+ const MALE = 'MALE';
8442
+ const MIXED = 'MIXED';
8443
+ const OTHER$2 = 'OTHER';
8444
+ const FEMALE = 'FEMALE';
8445
+ const genderConstants = {
8446
+ ANY,
8447
+ MALE,
8448
+ FEMALE,
8449
+ MIXED,
8450
+ OTHER: OTHER$2,
8451
+ };
8452
+
8453
+ function addMatchUpContext({ scheduleVisibilityFilters, sourceDrawPositionRanges, tournamentParticipants, positionAssignments, drawPositionsRanges, afterRecoveryTimes, initialRoundOfPlay, additionalContext, roundNamingProfile, tournamentRecord, tieDrawPositions, appliedPolicies, isCollectionBye, seedAssignments, usePublishState, participantMap, contextContent, scheduleTiming, contextProfile, drawDefinition, publishStatus, scoringActive, matchUpTieId, isRoundRobin, roundProfile, sideLineUps, structure, context, matchUp, event, }) {
8454
+ additionalContext = additionalContext ?? {};
8455
+ const tieFormat = resolveTieFormat({
8456
+ drawDefinition,
8457
+ structure,
8458
+ matchUp,
8459
+ event,
8460
+ })?.tieFormat;
8461
+ const { roundOffset, structureId, structureName, stage, stageSequence } = structure;
8462
+ const { drawId, drawName, drawType } = drawDefinition ?? {};
8463
+ const collectionDefinitions = tieFormat?.collectionDefinitions;
8464
+ const collectionDefinition = matchUp.collectionId &&
8465
+ collectionDefinitions?.find((definition) => definition.collectionId === matchUp.collectionId);
8466
+ const matchUpFormat = matchUp.collectionId
8467
+ ? collectionDefinition?.matchUpFormat
8468
+ : matchUp.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
8469
+ const matchUpType = matchUp.matchUpType ||
8470
+ collectionDefinition?.matchUpType ||
8471
+ structure?.matchUpType ||
8472
+ drawDefinition?.matchUpType ||
8473
+ (!isMatchUpEventType(TEAM$2)(event?.eventType) && event?.eventType);
8474
+ const matchUpStatus = isCollectionBye ? BYE : matchUp.matchUpStatus;
8475
+ const { schedule, endDate } = getMatchUpScheduleDetails({
8476
+ scheduleVisibilityFilters,
8477
+ afterRecoveryTimes,
8478
+ tournamentRecord,
8479
+ usePublishState,
8480
+ scheduleTiming,
8481
+ matchUpFormat,
8482
+ publishStatus,
8483
+ matchUpType,
8484
+ matchUp,
8485
+ event,
8486
+ });
8487
+ const drawPositions = tieDrawPositions ?? matchUp.drawPositions ?? [];
8488
+ const { collectionPosition, collectionId, roundPosition } = matchUp;
8489
+ const roundNumber = matchUp.roundNumber ?? additionalContext.roundNumber;
8490
+ const collectionAssignmentDetail = collectionId
8491
+ ? getCollectionAssignment({
8492
+ tournamentParticipants,
8493
+ positionAssignments,
8494
+ collectionPosition,
8495
+ participantMap,
8496
+ drawDefinition,
8497
+ drawPositions,
8498
+ collectionId,
8499
+ sideLineUps,
8500
+ matchUpType,
8501
+ })
8502
+ : undefined;
8503
+ const roundName = roundNamingProfile?.[roundNumber]?.roundName || additionalContext.roundName;
8504
+ const abbreviatedRoundName = roundNamingProfile?.[roundNumber]?.abbreviatedRoundName || additionalContext.abbreviatedRoundName;
8505
+ const feedRound = roundProfile?.[roundNumber]?.feedRound;
8506
+ const preFeedRound = roundProfile?.[roundNumber]?.preFeedRound;
8507
+ const roundFactor = roundProfile?.[roundNumber]?.roundFactor;
8508
+ const drawPositionsRoundRanges = drawPositionsRanges?.[roundNumber];
8509
+ const drawPositionsRange = roundPosition ? drawPositionsRoundRanges?.[roundPosition] : undefined;
8510
+ const sourceDrawPositionRoundRanges = sourceDrawPositionRanges?.[roundNumber];
8511
+ const matchUpCategory = collectionDefinition?.category
8512
+ ? {
8513
+ ...(context?.category || {}),
8514
+ ...collectionDefinition.category,
8515
+ }
8516
+ : context?.category ?? event?.category;
8517
+ const processCodes = (matchUp.processCodes?.length && matchUp.processCodes) ||
8518
+ (collectionDefinition?.processCodes?.length && collectionDefinition?.processCodes) ||
8519
+ (structure?.processCodes?.length && structure?.processCodes) ||
8520
+ (drawDefinition?.processCodes?.length && drawDefinition?.processCodes) ||
8521
+ (event?.processCodes?.length && event?.processCodes) ||
8522
+ tournamentRecord?.processCodes;
8523
+ const competitiveProfile = contextProfile?.withCompetitiveness && getMatchUpCompetitiveProfile({ ...contextContent, matchUp });
8524
+ const finishingPositionRange = matchUp.finishingPositionRange ?? additionalContext.finishingPositionRange;
8525
+ const onlyDefined = (obj) => definedAttributes(obj, undefined, true);
8526
+ const matchUpWithContext = {
8527
+ ...onlyDefined(context),
8528
+ ...onlyDefined({
8529
+ matchUpFormat: matchUp.matchUpType === TEAM$2 ? undefined : matchUpFormat,
8530
+ tieFormat: matchUp.matchUpType !== TEAM$2 ? undefined : tieFormat,
8531
+ gender: collectionDefinition?.gender ?? event?.gender,
8532
+ roundOfPlay: stage !== QUALIFYING && isConvertableInteger(initialRoundOfPlay) && initialRoundOfPlay + (roundNumber || 0),
8533
+ endDate: matchUp.endDate ?? endDate,
8534
+ discipline: event?.discipline,
8535
+ category: matchUpCategory,
8536
+ finishingPositionRange,
8537
+ abbreviatedRoundName,
8538
+ drawPositionsRange,
8539
+ competitiveProfile,
8540
+ structureName,
8541
+ stageSequence,
8542
+ drawPositions,
8543
+ matchUpStatus,
8544
+ processCodes,
8545
+ isRoundRobin,
8546
+ matchUpTieId,
8547
+ preFeedRound,
8548
+ matchUpType,
8549
+ roundFactor,
8550
+ roundOffset,
8551
+ structureId,
8552
+ roundNumber,
8553
+ feedRound,
8554
+ roundName,
8555
+ drawName,
8556
+ drawType,
8557
+ schedule,
8558
+ drawId,
8559
+ stage,
8560
+ }),
8561
+ ...makeDeepCopy(onlyDefined(matchUp), true, true),
8562
+ };
8563
+ if (matchUpFormat && matchUp.score?.scoreStringSide1) {
8564
+ const parsedFormat = parse(matchUpFormat);
8565
+ const { bestOf, finalSetFormat, setFormat } = parsedFormat ?? {};
8566
+ if (finalSetFormat?.tiebreakSet || setFormat?.tiebreakSet || setFormat?.timed) {
8567
+ matchUpWithContext.score.sets = matchUpWithContext.score.sets
8568
+ .sort((a, b) => a.setNumber - b.setNumber)
8569
+ .map((set, i) => {
8570
+ const setNumber = i + 1;
8571
+ if (setNumber === bestOf) {
8572
+ if (finalSetFormat?.tiebreakSet || finalSetFormat?.timed)
8573
+ set.tiebreakSet = true;
8574
+ }
8575
+ else if (setFormat?.tiebreakSet || setFormat?.timed) {
8576
+ set.tiebreakSet = true;
8577
+ }
8578
+ return set;
8579
+ });
8580
+ }
8581
+ }
8582
+ if (Array.isArray(drawPositions)) {
8583
+ const { orderedDrawPositions, displayOrder } = getOrderedDrawPositions({
8584
+ drawPositions,
8585
+ roundProfile,
8586
+ roundNumber,
8587
+ });
8588
+ const isFeedRound = roundProfile?.[roundNumber]?.feedRound;
8589
+ const reversedDisplayOrder = displayOrder[0] !== orderedDrawPositions[0];
8590
+ const sideDrawPositions = orderedDrawPositions.concat(undefined, undefined).slice(0, 2);
8591
+ const sides = sideDrawPositions.map((drawPosition, index) => {
8592
+ const sideNumber = index + 1;
8593
+ const displaySideNumber = reversedDisplayOrder ? 3 - sideNumber : sideNumber;
8594
+ const side = getSide({
8595
+ ...collectionAssignmentDetail,
8596
+ positionAssignments,
8597
+ displaySideNumber,
8598
+ seedAssignments,
8599
+ drawPosition,
8600
+ isFeedRound,
8601
+ sideNumber,
8602
+ });
8603
+ const existingSide = matchUp.sides?.find((existing) => existing.sideNumber === sideNumber);
8604
+ const columnPosition = roundPosition ? (roundPosition - 1) * 2 + index + 1 : undefined;
8605
+ const sourceDrawPositionRange = columnPosition ? sourceDrawPositionRoundRanges?.[columnPosition] : undefined;
8606
+ return onlyDefined({
8607
+ sourceDrawPositionRange,
8608
+ ...existingSide,
8609
+ ...side,
8610
+ });
8611
+ });
8612
+ Object.assign(matchUpWithContext, makeDeepCopy({ sides }, true, true));
8613
+ }
8614
+ if (tournamentParticipants && matchUpWithContext.sides) {
8615
+ const participantAttributes = appliedPolicies?.[POLICY_TYPE_PARTICIPANT];
8616
+ const getMappedParticipant = (participantId) => {
8617
+ const participant = participantMap?.[participantId]?.participant;
8618
+ return (participant &&
8619
+ attributeFilter({
8620
+ template: participantAttributes?.participant,
8621
+ source: participant,
8622
+ }));
8623
+ };
8624
+ matchUpWithContext.sides.filter(Boolean).forEach((side) => {
8625
+ if (side.participantId) {
8626
+ const participant = makeDeepCopy(getMappedParticipant(side.participantId) ||
8627
+ (tournamentParticipants
8628
+ ? findParticipant({
8629
+ policyDefinitions: appliedPolicies,
8630
+ participantId: side.participantId,
8631
+ tournamentParticipants,
8632
+ internalUse: true,
8633
+ contextProfile,
8634
+ })
8635
+ : undefined), undefined, true);
8636
+ if (participant) {
8637
+ if (drawDefinition?.entries) {
8638
+ const entry = drawDefinition.entries.find((entry) => entry.participantId === side.participantId);
8639
+ if (entry?.entryStatus) {
8640
+ participant.entryStatus = entry.entryStatus;
8641
+ }
8642
+ if (entry?.entryStage) {
8643
+ participant.entryStage = entry.entryStage;
8644
+ }
8645
+ }
8646
+ Object.assign(side, { participant });
8647
+ }
8648
+ }
8649
+ if (side?.participant?.individualParticipantIds?.length && !side.participant.individualParticipants?.length) {
8650
+ const individualParticipants = side.participant.individualParticipantIds.map((participantId) => {
8651
+ return (getMappedParticipant(participantId) ||
8652
+ (tournamentParticipants
8653
+ ? findParticipant({
8654
+ policyDefinitions: appliedPolicies,
8655
+ tournamentParticipants,
8656
+ internalUse: true,
8657
+ contextProfile,
8658
+ participantId,
8659
+ })
8660
+ : undefined));
8661
+ });
8662
+ Object.assign(side.participant, { individualParticipants });
8663
+ }
8664
+ });
8665
+ if (!matchUpWithContext.matchUpType) {
8666
+ const { matchUpType } = getMatchUpType({ matchUp: matchUpWithContext });
8667
+ if (matchUpType)
8668
+ Object.assign(matchUpWithContext, { matchUpType });
8669
+ }
8670
+ const inferGender = contextProfile?.inferGender &&
8671
+ (!matchUpWithContext.gender || matchUpWithContext.gender === MIXED) &&
8672
+ matchUpWithContext.sides?.length === 2 &&
8673
+ matchUpWithContext.matchUpType !== TEAM$2;
8674
+ if (inferGender) {
8675
+ const sideGenders = matchUpWithContext.sides.map((side) => {
8676
+ if (isMatchUpEventType(SINGLES)(matchUpWithContext.matchUpType))
8677
+ return side.participant?.person?.sex;
8678
+ if (side.participant?.individualParticipants?.length === 2) {
8679
+ const pairGenders = unique(side.participant.individualParticipants.map((participant) => participant.person?.sex)).filter(Boolean);
8680
+ if (pairGenders.length === 1)
8681
+ return pairGenders[0];
8682
+ }
8683
+ return undefined;
8684
+ });
8685
+ if (sideGenders.filter(Boolean).length === 2 && unique(sideGenders).length === 1) {
8686
+ const inferredGender = sideGenders[0];
8687
+ matchUpWithContext.inferredGender = inferredGender;
8688
+ }
8689
+ }
8690
+ }
8691
+ if (matchUpWithContext.tieMatchUps) {
8692
+ const isCollectionBye = matchUpWithContext.matchUpStatus === BYE;
8693
+ const lineUps = matchUpWithContext.sides?.map(({ participant, drawPosition, sideNumber, lineUp }) => {
8694
+ const teamParticipant = participant?.participantType === TEAM$2 && participant;
8695
+ const teamParticipantValues = teamParticipant &&
8696
+ definedAttributes({
8697
+ participantRoleResponsibilities: teamParticipant.participantRoleResponsibilities,
8698
+ participantOtherName: teamParticipant.participanOthertName,
8699
+ participantName: teamParticipant.participantName,
8700
+ participantId: teamParticipant.participantId,
8701
+ teamId: teamParticipant.teamId,
8702
+ });
8703
+ return {
8704
+ teamParticipant: teamParticipantValues,
8705
+ drawPosition,
8706
+ sideNumber,
8707
+ lineUp,
8708
+ };
8709
+ });
8710
+ matchUpWithContext.tieMatchUps = matchUpWithContext.tieMatchUps.map((matchUp) => {
8711
+ const matchUpTieId = matchUpWithContext.matchUpId;
8712
+ const finishingPositionRange = matchUpWithContext.finishingPositionRange;
8713
+ const additionalContext = {
8714
+ finishingPositionRange,
8715
+ abbreviatedRoundName,
8716
+ roundNumber,
8717
+ roundName,
8718
+ };
8719
+ return addMatchUpContext({
8720
+ tieDrawPositions: drawPositions,
8721
+ scheduleVisibilityFilters,
8722
+ sourceDrawPositionRanges,
8723
+ sideLineUps: lineUps,
8724
+ drawPositionsRanges,
8725
+ initialRoundOfPlay,
8726
+ roundNamingProfile,
8727
+ additionalContext,
8728
+ appliedPolicies,
8729
+ isCollectionBye,
8730
+ usePublishState,
8731
+ publishStatus,
8732
+ matchUpTieId,
8733
+ isRoundRobin,
8734
+ roundProfile,
8735
+ matchUp,
8736
+ event,
8737
+ tournamentParticipants,
8738
+ positionAssignments,
8739
+ tournamentRecord,
8740
+ seedAssignments,
8741
+ participantMap,
8742
+ contextContent,
8743
+ scheduleTiming,
8744
+ contextProfile,
8745
+ drawDefinition,
8746
+ scoringActive,
8747
+ structure,
8748
+ context,
8749
+ });
8750
+ });
8751
+ }
8752
+ const hasParticipants = matchUpWithContext.sides && matchUpWithContext.sides.filter((side) => side?.participantId).length === 2;
8753
+ const hasNoWinner = !matchUpWithContext.winningSide;
8754
+ const readyToScore = scoringActive && hasParticipants && hasNoWinner;
8755
+ Object.assign(matchUpWithContext, { readyToScore, hasContext: true });
8756
+ if (hasParticipants) {
8757
+ const { allParticipantsCheckedIn, checkedInParticipantIds } = getCheckedInParticipantIds({
8758
+ matchUp: matchUpWithContext,
8759
+ });
8760
+ Object.assign(matchUpWithContext, {
8761
+ allParticipantsCheckedIn,
8762
+ checkedInParticipantIds,
8763
+ });
8764
+ }
8765
+ if (Array.isArray(contextProfile?.exclude)) {
8766
+ contextProfile?.exclude.forEach((attribute) => delete matchUpWithContext[attribute]);
8767
+ }
8768
+ return matchUpWithContext;
8769
+ }
8770
+
8383
8771
  function includesMatchUpEventType(types, matchUpEventType) {
8384
8772
  if (!Array.isArray(types) || !isString(matchUpEventType))
8385
8773
  return false;
@@ -8524,79 +8912,10 @@ function filterMatchUps(params) {
8524
8912
  });
8525
8913
  }
8526
8914
 
8527
- function getSide({ drawPositionCollectionAssignment, sideNumberCollectionAssignment, positionAssignments, displaySideNumber, seedAssignments, drawPosition, isFeedRound, sideNumber, }) {
8528
- const assignment = positionAssignments.find((assignment) => assignment.drawPosition && assignment.drawPosition === drawPosition);
8529
- const dpc = drawPosition && drawPositionCollectionAssignment;
8530
- const snc = sideNumber && sideNumberCollectionAssignment;
8531
- const participantId = dpc ? dpc[drawPosition]?.participantId : assignment?.participantId;
8532
- const sideValue = assignment
8533
- ? getSideValue$1({
8534
- displaySideNumber,
8535
- seedAssignments,
8536
- participantId,
8537
- assignment,
8538
- sideNumber,
8539
- })
8540
- : { ...snc?.[sideNumber] };
8541
- if (isFeedRound) {
8542
- if (sideNumber === 1) {
8543
- Object.assign(sideValue, { participantFed: true });
8544
- }
8545
- else {
8546
- Object.assign(sideValue, { participantAdvanced: true });
8547
- }
8548
- }
8549
- if (drawPosition && dpc) {
8550
- const teamParticipant = dpc[drawPosition]?.teamParticipant;
8551
- const participant = dpc[drawPosition]?.participant;
8552
- const substitutions = dpc[drawPosition]?.substitutions;
8553
- if (participant)
8554
- sideValue.participant = participant;
8555
- if (substitutions)
8556
- sideValue.substitutions = substitutions;
8557
- if (teamParticipant)
8558
- sideValue.teamParticipant = teamParticipant;
8559
- }
8560
- return sideValue;
8561
- }
8562
- function getSideValue$1({ displaySideNumber, seedAssignments, participantId, assignment, sideNumber }) {
8563
- const side = {
8564
- drawPosition: assignment.drawPosition,
8565
- displaySideNumber,
8566
- sideNumber,
8567
- };
8568
- if (participantId) {
8569
- const seeding = getSeeding({ seedAssignments, participantId });
8570
- Object.assign(side, seeding, { participantId });
8571
- }
8572
- else if (assignment.bye) {
8573
- Object.assign(side, { bye: true });
8574
- }
8575
- if (assignment.qualifier) {
8576
- Object.assign(side, { qualifier: true });
8577
- }
8578
- return side;
8579
- }
8580
- function getSeeding({ seedAssignments, participantId }) {
8581
- return seedAssignments?.find((assignment) => !assignment.seedProxy && assignment.participantId === participantId);
8582
- }
8583
-
8584
- const ANY = 'ANY';
8585
- const MALE = 'MALE';
8586
- const MIXED = 'MIXED';
8587
- const OTHER$2 = 'OTHER';
8588
- const FEMALE = 'FEMALE';
8589
- const genderConstants = {
8590
- ANY,
8591
- MALE,
8592
- FEMALE,
8593
- MIXED,
8594
- OTHER: OTHER$2,
8595
- };
8596
-
8597
- function getAllStructureMatchUps({ scheduleVisibilityFilters, tournamentAppliedPolicies, provisionalPositioning, tournamentParticipants, afterRecoveryTimes, policyDefinitions, tournamentRecord, seedAssignments, usePublishState, contextFilters, contextContent, matchUpFilters, participantMap, scheduleTiming, contextProfile, drawDefinition, publishStatus, context = {}, exitProfiles, matchUpsMap, structure, inContext, event, }) {
8915
+ function getAllStructureMatchUps(params) {
8916
+ const { provisionalPositioning, tournamentRecord, contextFilters, matchUpFilters, contextProfile, drawDefinition, context = {}, structure, inContext, event, } = params;
8917
+ let { seedAssignments, contextContent, exitProfiles, matchUpsMap } = params;
8598
8918
  let collectionPositionMatchUps = {}, roundMatchUps = {};
8599
- tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants;
8600
8919
  if (!structure) {
8601
8920
  return {
8602
8921
  collectionPositionMatchUps,
@@ -8630,13 +8949,11 @@ function getAllStructureMatchUps({ scheduleVisibilityFilters, tournamentAppliedP
8630
8949
  drawDefinition,
8631
8950
  });
8632
8951
  }
8633
- const { appliedPolicies: drawAppliedPolicies } = getAppliedPolicies({
8634
- drawDefinition,
8635
- });
8952
+ const { appliedPolicies: drawAppliedPolicies } = getAppliedPolicies({ drawDefinition });
8636
8953
  const appliedPolicies = {
8637
- ...tournamentAppliedPolicies,
8954
+ ...params.tournamentAppliedPolicies,
8638
8955
  ...drawAppliedPolicies,
8639
- ...policyDefinitions,
8956
+ ...params.policyDefinitions,
8640
8957
  };
8641
8958
  const structureScoringPolicies = appliedPolicies?.scoring?.structures;
8642
8959
  const stageSpecificPolicies = structure.stage && structureScoringPolicies?.stage && structureScoringPolicies?.stage[structure.stage];
@@ -8657,8 +8974,7 @@ function getAllStructureMatchUps({ scheduleVisibilityFilters, tournamentAppliedP
8657
8974
  structure,
8658
8975
  });
8659
8976
  seedAssignments = seedAssignments ?? structureSeedAssignments;
8660
- const { roundOffset, structureId, structureName, stage, stageSequence } = structure;
8661
- const { drawId, drawName, drawType } = drawDefinition ?? {};
8977
+ const { structureId } = structure;
8662
8978
  exitProfiles = exitProfiles || (drawDefinition && getExitProfiles({ drawDefinition }).exitProfiles);
8663
8979
  const exitProfile = exitProfiles?.[structureId];
8664
8980
  const initialRoundOfPlay = exitProfile?.length &&
@@ -8706,16 +9022,29 @@ function getAllStructureMatchUps({ scheduleVisibilityFilters, tournamentAppliedP
8706
9022
  : undefined;
8707
9023
  matchUps = matchUps.map((matchUp) => {
8708
9024
  return addMatchUpContext({
8709
- scheduleVisibilityFilters,
9025
+ tournamentParticipants: params.tournamentParticipants ?? tournamentRecord?.participants,
9026
+ scheduleVisibilityFilters: params.scheduleVisibilityFilters,
9027
+ afterRecoveryTimes: params.afterRecoveryTimes,
9028
+ usePublishState: params.usePublishState,
9029
+ participantMap: params.participantMap,
9030
+ scheduleTiming: params.scheduleTiming,
9031
+ publishStatus: params.publishStatus,
8710
9032
  sourceDrawPositionRanges,
9033
+ positionAssignments,
8711
9034
  drawPositionsRanges,
8712
- roundNamingProfile,
8713
9035
  initialRoundOfPlay,
9036
+ roundNamingProfile,
9037
+ tournamentRecord,
8714
9038
  appliedPolicies,
8715
- usePublishState,
8716
- publishStatus,
9039
+ seedAssignments,
9040
+ contextContent,
9041
+ contextProfile,
9042
+ drawDefinition,
9043
+ scoringActive,
8717
9044
  isRoundRobin,
8718
9045
  roundProfile,
9046
+ structure,
9047
+ context,
8719
9048
  matchUp,
8720
9049
  event,
8721
9050
  });
@@ -8771,306 +9100,6 @@ function getAllStructureMatchUps({ scheduleVisibilityFilters, tournamentAppliedP
8771
9100
  matchUpsMap,
8772
9101
  matchUps,
8773
9102
  };
8774
- function addMatchUpContext({ scheduleVisibilityFilters, sourceDrawPositionRanges, drawPositionsRanges, initialRoundOfPlay, additionalContext, roundNamingProfile, tieDrawPositions, appliedPolicies, isCollectionBye, usePublishState, publishStatus, matchUpTieId, isRoundRobin, roundProfile, sideLineUps, matchUp, event, }) {
8775
- additionalContext = additionalContext ?? {};
8776
- const tieFormat = resolveTieFormat({
8777
- drawDefinition,
8778
- structure,
8779
- matchUp,
8780
- event,
8781
- })?.tieFormat;
8782
- const collectionDefinitions = tieFormat?.collectionDefinitions;
8783
- const collectionDefinition = matchUp.collectionId &&
8784
- collectionDefinitions?.find((definition) => definition.collectionId === matchUp.collectionId);
8785
- const matchUpFormat = matchUp.collectionId
8786
- ? collectionDefinition?.matchUpFormat
8787
- : matchUp.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
8788
- const matchUpType = matchUp.matchUpType ||
8789
- collectionDefinition?.matchUpType ||
8790
- structure?.matchUpType ||
8791
- drawDefinition?.matchUpType ||
8792
- (!isMatchUpEventType(TEAM$2)(event?.eventType) && event?.eventType);
8793
- const matchUpStatus = isCollectionBye ? BYE : matchUp.matchUpStatus;
8794
- const { schedule, endDate } = getMatchUpScheduleDetails({
8795
- scheduleVisibilityFilters,
8796
- afterRecoveryTimes,
8797
- tournamentRecord,
8798
- usePublishState,
8799
- scheduleTiming,
8800
- matchUpFormat,
8801
- publishStatus,
8802
- matchUpType,
8803
- matchUp,
8804
- event,
8805
- });
8806
- const drawPositions = tieDrawPositions ?? matchUp.drawPositions ?? [];
8807
- const { collectionPosition, collectionId, roundPosition } = matchUp;
8808
- const roundNumber = matchUp.roundNumber ?? additionalContext.roundNumber;
8809
- const collectionAssignmentDetail = collectionId
8810
- ? getCollectionAssignment({
8811
- tournamentParticipants,
8812
- positionAssignments,
8813
- collectionPosition,
8814
- drawDefinition,
8815
- participantMap,
8816
- drawPositions,
8817
- collectionId,
8818
- sideLineUps,
8819
- matchUpType,
8820
- })
8821
- : undefined;
8822
- const roundName = roundNamingProfile?.[roundNumber]?.roundName || additionalContext.roundName;
8823
- const abbreviatedRoundName = roundNamingProfile?.[roundNumber]?.abbreviatedRoundName || additionalContext.abbreviatedRoundName;
8824
- const feedRound = roundProfile?.[roundNumber]?.feedRound;
8825
- const preFeedRound = roundProfile?.[roundNumber]?.preFeedRound;
8826
- const roundFactor = roundProfile?.[roundNumber]?.roundFactor;
8827
- const drawPositionsRoundRanges = drawPositionsRanges?.[roundNumber];
8828
- const drawPositionsRange = roundPosition ? drawPositionsRoundRanges?.[roundPosition] : undefined;
8829
- const sourceDrawPositionRoundRanges = sourceDrawPositionRanges?.[roundNumber];
8830
- const matchUpCategory = collectionDefinition?.category
8831
- ? {
8832
- ...(context?.category || {}),
8833
- ...collectionDefinition.category,
8834
- }
8835
- : context?.category ?? event?.category;
8836
- const processCodes = (matchUp.processCodes?.length && matchUp.processCodes) ||
8837
- (collectionDefinition?.processCodes?.length && collectionDefinition?.processCodes) ||
8838
- (structure?.processCodes?.length && structure?.processCodes) ||
8839
- (drawDefinition?.processCodes?.length && drawDefinition?.processCodes) ||
8840
- (event?.processCodes?.length && event?.processCodes) ||
8841
- tournamentRecord?.processCodes;
8842
- const competitiveProfile = contextProfile?.withCompetitiveness && getMatchUpCompetitiveProfile({ ...contextContent, matchUp });
8843
- const finishingPositionRange = matchUp.finishingPositionRange ?? additionalContext.finishingPositionRange;
8844
- const onlyDefined = (obj) => definedAttributes(obj, undefined, true);
8845
- const matchUpWithContext = {
8846
- ...onlyDefined(context),
8847
- ...onlyDefined({
8848
- matchUpFormat: matchUp.matchUpType === TEAM$2 ? undefined : matchUpFormat,
8849
- tieFormat: matchUp.matchUpType !== TEAM$2 ? undefined : tieFormat,
8850
- gender: collectionDefinition?.gender ?? event?.gender,
8851
- roundOfPlay: stage !== QUALIFYING && isConvertableInteger(initialRoundOfPlay) && initialRoundOfPlay + (roundNumber || 0),
8852
- endDate: matchUp.endDate ?? endDate,
8853
- discipline: event?.discipline,
8854
- category: matchUpCategory,
8855
- finishingPositionRange,
8856
- abbreviatedRoundName,
8857
- drawPositionsRange,
8858
- competitiveProfile,
8859
- structureName,
8860
- stageSequence,
8861
- drawPositions,
8862
- matchUpStatus,
8863
- processCodes,
8864
- isRoundRobin,
8865
- matchUpTieId,
8866
- preFeedRound,
8867
- matchUpType,
8868
- roundFactor,
8869
- roundOffset,
8870
- structureId,
8871
- roundNumber,
8872
- feedRound,
8873
- roundName,
8874
- drawName,
8875
- drawType,
8876
- schedule,
8877
- drawId,
8878
- stage,
8879
- }),
8880
- ...makeDeepCopy(onlyDefined(matchUp), true, true),
8881
- };
8882
- if (matchUpFormat && matchUp.score?.scoreStringSide1) {
8883
- const parsedFormat = parse(matchUpFormat);
8884
- const { bestOf, finalSetFormat, setFormat } = parsedFormat ?? {};
8885
- if (finalSetFormat?.tiebreakSet || setFormat?.tiebreakSet || setFormat?.timed) {
8886
- matchUpWithContext.score.sets = matchUpWithContext.score.sets
8887
- .sort((a, b) => a.setNumber - b.setNumber)
8888
- .map((set, i) => {
8889
- const setNumber = i + 1;
8890
- if (setNumber === bestOf) {
8891
- if (finalSetFormat?.tiebreakSet || finalSetFormat?.timed)
8892
- set.tiebreakSet = true;
8893
- }
8894
- else if (setFormat?.tiebreakSet || setFormat?.timed) {
8895
- set.tiebreakSet = true;
8896
- }
8897
- return set;
8898
- });
8899
- }
8900
- }
8901
- if (Array.isArray(drawPositions)) {
8902
- const { orderedDrawPositions, displayOrder } = getOrderedDrawPositions({
8903
- drawPositions,
8904
- roundProfile,
8905
- roundNumber,
8906
- });
8907
- const isFeedRound = roundProfile?.[roundNumber]?.feedRound;
8908
- const reversedDisplayOrder = displayOrder[0] !== orderedDrawPositions[0];
8909
- const sideDrawPositions = orderedDrawPositions.concat(undefined, undefined).slice(0, 2);
8910
- const sides = sideDrawPositions.map((drawPosition, index) => {
8911
- const sideNumber = index + 1;
8912
- const displaySideNumber = reversedDisplayOrder ? 3 - sideNumber : sideNumber;
8913
- const side = getSide({
8914
- ...collectionAssignmentDetail,
8915
- positionAssignments,
8916
- displaySideNumber,
8917
- seedAssignments,
8918
- drawPosition,
8919
- isFeedRound,
8920
- sideNumber,
8921
- });
8922
- const existingSide = matchUp.sides?.find((existing) => existing.sideNumber === sideNumber);
8923
- const columnPosition = roundPosition ? (roundPosition - 1) * 2 + index + 1 : undefined;
8924
- const sourceDrawPositionRange = columnPosition ? sourceDrawPositionRoundRanges?.[columnPosition] : undefined;
8925
- return onlyDefined({
8926
- sourceDrawPositionRange,
8927
- ...existingSide,
8928
- ...side,
8929
- });
8930
- });
8931
- Object.assign(matchUpWithContext, makeDeepCopy({ sides }, true, true));
8932
- }
8933
- if (tournamentParticipants && matchUpWithContext.sides) {
8934
- const participantAttributes = appliedPolicies?.[POLICY_TYPE_PARTICIPANT];
8935
- const getMappedParticipant = (participantId) => {
8936
- const participant = participantMap?.[participantId]?.participant;
8937
- return (participant &&
8938
- attributeFilter({
8939
- template: participantAttributes?.participant,
8940
- source: participant,
8941
- }));
8942
- };
8943
- matchUpWithContext.sides.filter(Boolean).forEach((side) => {
8944
- if (side.participantId) {
8945
- const participant = makeDeepCopy(getMappedParticipant(side.participantId) ||
8946
- (tournamentParticipants &&
8947
- findParticipant({
8948
- policyDefinitions: appliedPolicies,
8949
- participantId: side.participantId,
8950
- tournamentParticipants,
8951
- internalUse: true,
8952
- contextProfile,
8953
- })), undefined, true);
8954
- if (participant) {
8955
- if (drawDefinition?.entries) {
8956
- const entry = drawDefinition.entries.find((entry) => entry.participantId === side.participantId);
8957
- if (entry?.entryStatus) {
8958
- participant.entryStatus = entry.entryStatus;
8959
- }
8960
- if (entry?.entryStage) {
8961
- participant.entryStage = entry.entryStage;
8962
- }
8963
- }
8964
- Object.assign(side, { participant });
8965
- }
8966
- }
8967
- if (side?.participant?.individualParticipantIds?.length && !side.participant.individualParticipants?.length) {
8968
- const individualParticipants = side.participant.individualParticipantIds.map((participantId) => {
8969
- return (getMappedParticipant(participantId) ||
8970
- (tournamentParticipants &&
8971
- findParticipant({
8972
- policyDefinitions: appliedPolicies,
8973
- tournamentParticipants,
8974
- internalUse: true,
8975
- contextProfile,
8976
- participantId,
8977
- })));
8978
- });
8979
- Object.assign(side.participant, { individualParticipants });
8980
- }
8981
- });
8982
- if (!matchUpWithContext.matchUpType) {
8983
- const { matchUpType } = getMatchUpType({ matchUp: matchUpWithContext });
8984
- if (matchUpType)
8985
- Object.assign(matchUpWithContext, { matchUpType });
8986
- }
8987
- const inferGender = contextProfile?.inferGender &&
8988
- (!matchUpWithContext.gender || matchUpWithContext.gender === MIXED) &&
8989
- matchUpWithContext.sides?.length === 2 &&
8990
- matchUpWithContext.matchUpType !== TEAM$2;
8991
- if (inferGender) {
8992
- const sideGenders = matchUpWithContext.sides.map((side) => {
8993
- if (isMatchUpEventType(SINGLES)(matchUpWithContext.matchUpType))
8994
- return side.participant?.person?.sex;
8995
- if (side.participant?.individualParticipants?.length === 2) {
8996
- const pairGenders = unique(side.participant.individualParticipants.map((participant) => participant.person?.sex)).filter(Boolean);
8997
- if (pairGenders.length === 1)
8998
- return pairGenders[0];
8999
- }
9000
- });
9001
- if (sideGenders.filter(Boolean).length === 2 && unique(sideGenders).length === 1) {
9002
- const inferredGender = sideGenders[0];
9003
- matchUpWithContext.inferredGender = inferredGender;
9004
- }
9005
- }
9006
- }
9007
- if (matchUpWithContext.tieMatchUps) {
9008
- const isCollectionBye = matchUpWithContext.matchUpStatus === BYE;
9009
- const lineUps = matchUpWithContext.sides?.map(({ participant, drawPosition, sideNumber, lineUp }) => {
9010
- const teamParticipant = participant?.participantType === TEAM$2 && participant;
9011
- const teamParticipantValues = teamParticipant &&
9012
- definedAttributes({
9013
- participantRoleResponsibilities: teamParticipant.participantRoleResponsibilities,
9014
- participantOtherName: teamParticipant.participanOthertName,
9015
- participantName: teamParticipant.participantName,
9016
- participantId: teamParticipant.participantId,
9017
- teamId: teamParticipant.teamId,
9018
- });
9019
- return {
9020
- teamParticipant: teamParticipantValues,
9021
- drawPosition,
9022
- sideNumber,
9023
- lineUp,
9024
- };
9025
- });
9026
- matchUpWithContext.tieMatchUps = matchUpWithContext.tieMatchUps.map((matchUp) => {
9027
- const matchUpTieId = matchUpWithContext.matchUpId;
9028
- const finishingPositionRange = matchUpWithContext.finishingPositionRange;
9029
- const additionalContext = {
9030
- finishingPositionRange,
9031
- abbreviatedRoundName,
9032
- roundNumber,
9033
- roundName,
9034
- };
9035
- return addMatchUpContext({
9036
- tieDrawPositions: drawPositions,
9037
- scheduleVisibilityFilters,
9038
- sourceDrawPositionRanges,
9039
- sideLineUps: lineUps,
9040
- drawPositionsRanges,
9041
- initialRoundOfPlay,
9042
- roundNamingProfile,
9043
- additionalContext,
9044
- appliedPolicies,
9045
- isCollectionBye,
9046
- usePublishState,
9047
- publishStatus,
9048
- matchUpTieId,
9049
- isRoundRobin,
9050
- roundProfile,
9051
- matchUp,
9052
- event,
9053
- });
9054
- });
9055
- }
9056
- const hasParticipants = matchUpWithContext.sides && matchUpWithContext.sides.filter((side) => side?.participantId).length === 2;
9057
- const hasNoWinner = !matchUpWithContext.winningSide;
9058
- const readyToScore = scoringActive && hasParticipants && hasNoWinner;
9059
- Object.assign(matchUpWithContext, { readyToScore, hasContext: true });
9060
- if (hasParticipants) {
9061
- const { allParticipantsCheckedIn, checkedInParticipantIds } = getCheckedInParticipantIds({
9062
- matchUp: matchUpWithContext,
9063
- });
9064
- Object.assign(matchUpWithContext, {
9065
- allParticipantsCheckedIn,
9066
- checkedInParticipantIds,
9067
- });
9068
- }
9069
- if (Array.isArray(contextProfile?.exclude)) {
9070
- contextProfile?.exclude.forEach((attribute) => delete matchUpWithContext[attribute]);
9071
- }
9072
- return matchUpWithContext;
9073
- }
9074
9103
  }
9075
9104
 
9076
9105
  function checkMatchUpIsComplete({ matchUp }) {
@@ -12331,7 +12360,7 @@ function getParticipantEntries(params) {
12331
12360
  .map((structureId) => {
12332
12361
  const participation = participantAggregator.structureParticipation[structureId];
12333
12362
  if (!participation)
12334
- return;
12363
+ return undefined;
12335
12364
  if (!finishingPositionRange)
12336
12365
  finishingPositionRange = participation?.finishingPositionRange;
12337
12366
  if (diff(finishingPositionRange) > diff(participation?.finishingPositionRange))
@@ -17601,10 +17630,10 @@ function renameStructures({ drawDefinition, structureDetails }) {
17601
17630
  const detailMap = Object.assign({}, ...structureDetails
17602
17631
  .map((detail) => {
17603
17632
  if (!isObject(detail))
17604
- return;
17633
+ return undefined;
17605
17634
  const { structureId, structureName } = detail || {};
17606
17635
  if (!structureId || !structureName)
17607
- return;
17636
+ return undefined;
17608
17637
  return { [structureId]: structureName };
17609
17638
  })
17610
17639
  .filter(Boolean));
@@ -18723,9 +18752,7 @@ function generatePlayoffStructures(params) {
18723
18752
  const rounds = Math.ceil(Math.log(drawSize) / Math.log(2));
18724
18753
  const roundsToPlayOff = roundOffsetLimit
18725
18754
  ? Math.min(roundOffsetLimit - roundOffset, rounds)
18726
- : !finishingPositionLimit || finishingPositionsFrom < finishingPositionLimit
18727
- ? rounds
18728
- : 0;
18755
+ : ((!finishingPositionLimit || finishingPositionsFrom < finishingPositionLimit) && rounds) || 0;
18729
18756
  if (drawSize > 2) {
18730
18757
  generateRange(1, roundsToPlayOff + 1).forEach((roundNumber) => generateChildStructures(roundNumber));
18731
18758
  }
@@ -19171,11 +19198,9 @@ function feedInLinks({ consolationStructure, roundOffset = 0, mainStructure, rou
19171
19198
  const roundFeedProfiles = feedPolicy?.roundFeedProfiles;
19172
19199
  return generateRange(1 + roundOffset, roundsCount + 1 + roundOffset)
19173
19200
  .map((roundNumber) => {
19174
- const feedProfile = roundFeedProfiles && roundFeedProfiles[roundNumber - 1]
19201
+ const feedProfile = roundFeedProfiles?.[roundNumber - 1]
19175
19202
  ? roundFeedProfiles[roundNumber - 1]
19176
- : roundNumber % 2
19177
- ? TOP_DOWN
19178
- : BOTTOM_UP;
19203
+ : (roundNumber % 2 && TOP_DOWN) || BOTTOM_UP;
19179
19204
  const targetRound = roundNumber - roundOffset <= 2 ? roundNumber - roundOffset : (roundNumber - roundOffset - 2) * 2 + 2;
19180
19205
  const link = {
19181
19206
  linkType: LOSER,
@@ -20730,7 +20755,7 @@ function groupSubSort({ participantResults, disableHeadToHead, participantIds, m
20730
20755
  reversed,
20731
20756
  });
20732
20757
  report.push(result.report);
20733
- return result.order ? false : true;
20758
+ return !result.order;
20734
20759
  });
20735
20760
  if (result.order)
20736
20761
  return { order: result.order, report };
@@ -24116,7 +24141,7 @@ function getSourceStructureIdsAndRelevantLinks({ targetRoundNumber, finishingPos
24116
24141
  drawDefinition,
24117
24142
  });
24118
24143
  if (finishingPosition && sourceStructure?.finishingPosition !== finishingPosition)
24119
- return;
24144
+ return undefined;
24120
24145
  return link;
24121
24146
  })
24122
24147
  .filter(Boolean);
@@ -25732,7 +25757,7 @@ function getValidGender(params) {
25732
25757
  ANY === eventGender ||
25733
25758
  ([MALE, FEMALE].includes(eventGender) && pairGender[0] === eventGender) ||
25734
25759
  (MIXED === eventGender &&
25735
- ((pairGender.length == 1 && participant.individualParticipantIds?.length === 1) || pairGender.length === 2));
25760
+ ((pairGender.length === 1 && participant.individualParticipantIds?.length === 1) || pairGender.length === 2));
25736
25761
  const personGender = participant?.person?.sex;
25737
25762
  const validPersonGender = !participant?.person ||
25738
25763
  !eventGender ||
@@ -29409,6 +29434,7 @@ function joinFloatingTiebreak({ score }) {
29409
29434
  return lastSet;
29410
29435
  }
29411
29436
  }
29437
+ return undefined;
29412
29438
  });
29413
29439
  const tiebreakIndices = arrayIndices('tiebreak', profile);
29414
29440
  if (tiebreakIndices.length) {
@@ -30023,8 +30049,8 @@ function handleNumeric(params) {
30023
30049
  score = chunks.join(' ');
30024
30050
  applied.push('chunkSplit');
30025
30051
  }
30026
- else if (numbers.length == 6) {
30027
- if (instances[1] == 2 || instances[2] === 2) {
30052
+ else if (numbers.length === 6) {
30053
+ if (instances[1] === 2 || instances[2] === 2) {
30028
30054
  if (!Object.values(positiveInstances).includes(3)) {
30029
30055
  score = chunks.join(' ');
30030
30056
  applied.push('chunkSplit');
@@ -30276,7 +30302,7 @@ function removeErroneous({ score, applied }) {
30276
30302
  .map((part) => {
30277
30303
  if (/^\d+$/.test(part) && part.length === 1) {
30278
30304
  applied.push('removeErroneous1');
30279
- return;
30305
+ return undefined;
30280
30306
  }
30281
30307
  return part;
30282
30308
  })
@@ -34160,7 +34186,7 @@ function getInContextCourt({ convertExtensions, ignoreDisabled, venue, court })
34160
34186
  .map((availability) => {
34161
34187
  const date = availability.date;
34162
34188
  if (!date || disabledDates.includes(date))
34163
- return;
34189
+ return undefined;
34164
34190
  return availability;
34165
34191
  })
34166
34192
  .filter(Boolean);
@@ -34398,7 +34424,7 @@ function getDrawData(params) {
34398
34424
  .sort((a, b) => structureSort(a, b, sortConfig))
34399
34425
  .map((structure) => {
34400
34426
  if (!structure)
34401
- return;
34427
+ return undefined;
34402
34428
  const structureId = structure?.structureId;
34403
34429
  let seedAssignments = [];
34404
34430
  if (structure.stage && [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
@@ -34516,9 +34542,7 @@ function getDrawData(params) {
34516
34542
  : undefined;
34517
34543
  return {
34518
34544
  structures: !usePublishState || drawInfo.drawPublished
34519
- ? noDeepCopy
34520
- ? structures
34521
- : makeDeepCopy(structures, false, true)
34545
+ ? (noDeepCopy && structures) || makeDeepCopy(structures, false, true)
34522
34546
  : undefined,
34523
34547
  drawInfo: noDeepCopy ? drawInfo : makeDeepCopy(drawInfo, false, true),
34524
34548
  ...SUCCESS,
@@ -34830,7 +34854,7 @@ function getUpdatedSchedulingProfile({ schedulingProfile, venueIds, eventIds, dr
34830
34854
  const date = extractDate(dateSchedulingProfile?.scheduleDate);
34831
34855
  if (!date) {
34832
34856
  issues.push(`Invalid date: ${dateSchedulingProfile?.scheduledDate}`);
34833
- return;
34857
+ return undefined;
34834
34858
  }
34835
34859
  const venues = (dateSchedulingProfile?.venues || [])
34836
34860
  .map((venue) => {
@@ -34838,7 +34862,7 @@ function getUpdatedSchedulingProfile({ schedulingProfile, venueIds, eventIds, dr
34838
34862
  const venueExists = venueIds?.includes(venueId);
34839
34863
  if (!venueExists) {
34840
34864
  issues.push(`Missing venueId: ${venueId}`);
34841
- return;
34865
+ return undefined;
34842
34866
  }
34843
34867
  const filteredRounds = rounds.filter((round) => {
34844
34868
  const validEventIdAndDrawId = eventIds.includes(round.eventId) && drawIds.includes(round.drawId);
@@ -34847,7 +34871,7 @@ function getUpdatedSchedulingProfile({ schedulingProfile, venueIds, eventIds, dr
34847
34871
  return validEventIdAndDrawId;
34848
34872
  });
34849
34873
  if (!filteredRounds.length)
34850
- return;
34874
+ return undefined;
34851
34875
  return { venueId, rounds: filteredRounds };
34852
34876
  })
34853
34877
  .filter(Boolean);
@@ -34903,7 +34927,7 @@ function validateSchedulingProfile({ tournamentRecords, schedulingProfile }) {
34903
34927
  info = 'Invalid segment';
34904
34928
  return validRound && validSegment;
34905
34929
  });
34906
- return !validRounds ? false : true;
34930
+ return !!validRounds;
34907
34931
  });
34908
34932
  });
34909
34933
  if (!isValid && !error) {
@@ -35670,11 +35694,9 @@ function getEventMatchUpFormatTiming({ tournamentRecord, matchUpFormats, categor
35670
35694
  .map((definition) => {
35671
35695
  const definitionObject = typeof definition === 'string' ? { matchUpFormat: definition } : definition;
35672
35696
  if (uniqueMatchUpFormats.includes(definitionObject?.matchUpFormat))
35673
- return;
35674
- if (!isValidMatchUpFormat({
35675
- matchUpFormat: definitionObject?.matchUpFormat,
35676
- }))
35677
- return;
35697
+ return undefined;
35698
+ if (!isValidMatchUpFormat({ matchUpFormat: definitionObject?.matchUpFormat }))
35699
+ return undefined;
35678
35700
  uniqueMatchUpFormats.push(definitionObject.matchUpFormat);
35679
35701
  return definitionObject;
35680
35702
  })
@@ -37104,7 +37126,7 @@ function getEvents({ tournamentRecord, withScaleValues, scaleEventType, inContex
37104
37126
  .map((event) => {
37105
37127
  const eventDrawIds = event.drawDefinitions?.map(getDrawId);
37106
37128
  if (drawIds?.length && !intersection(drawIds, eventDrawIds).length)
37107
- return;
37129
+ return undefined;
37108
37130
  const eventCopy = makeDeepCopy(event);
37109
37131
  if (inContext)
37110
37132
  Object.assign(eventCopy, { tournamentId });
@@ -46289,7 +46311,7 @@ function checkRecoveryTime({ individualParticipantProfiles, matchUpNotBeforeTime
46289
46311
  return { enoughTime };
46290
46312
  }
46291
46313
 
46292
- function checkDailyLimits({ individualParticipantProfiles, matchUpPotentialParticipantIds, matchUpDailyLimits = {}, matchUp, }) {
46314
+ function checkDailyLimits({ matchUpPotentialParticipantIds, individualParticipantProfiles, matchUpDailyLimits = {}, matchUp, }) {
46293
46315
  const { enteredIndividualParticipantIds } = getIndividualParticipantIds(matchUp);
46294
46316
  const { matchUpId, matchUpType } = matchUp;
46295
46317
  const potentialParticipantIds = ((matchUp.roundPosition && matchUpPotentialParticipantIds[matchUpId]) || []).flat();
@@ -46309,6 +46331,7 @@ function checkDailyLimits({ individualParticipantProfiles, matchUpPotentialParti
46309
46331
  return participantsCount && dailyLimit && participantsCount >= dailyLimit;
46310
46332
  });
46311
46333
  }
46334
+ return undefined;
46312
46335
  });
46313
46336
  return { participantIdsAtLimit, relevantParticipantIds };
46314
46337
  }
@@ -47272,7 +47295,7 @@ function scheduleProfileRounds(params) {
47272
47295
  const validScheduleDates = scheduleDates
47273
47296
  .map((scheduleDate) => {
47274
47297
  if (!isValidDateString(scheduleDate))
47275
- return;
47298
+ return undefined;
47276
47299
  return extractDate(scheduleDate);
47277
47300
  })
47278
47301
  .filter(Boolean);
@@ -47714,7 +47737,7 @@ function postalCodeMocks({ count = 1, participantsCount = 32 } = {}) {
47714
47737
  }
47715
47738
 
47716
47739
  function genParticipantId({ idPrefix, participantType, index, uuids }) {
47717
- const type = participantType === INDIVIDUAL ? 'I' : 'P' ;
47740
+ const type = isString(participantType) ? participantType[0] : 'X';
47718
47741
  return idPrefix ? `${idPrefix}-${type}-${index}` : uuids?.pop() || UUID();
47719
47742
  }
47720
47743
 
@@ -48234,7 +48257,7 @@ function generateParticipants(params) {
48234
48257
  : defaultRankingRange;
48235
48258
  rankingRange = rankingRange || [1, rankingUpperBound];
48236
48259
  rankingRange[1] += 1;
48237
- const individualParticipantsCount = participantsCount * (doubles ? 2 : team ? 8 : 1);
48260
+ const individualParticipantsCount = participantsCount * ((doubles && 2) || (team && 8) || 1);
48238
48261
  const result = generatePersons({
48239
48262
  count: individualParticipantsCount,
48240
48263
  personExtensions,
@@ -48311,16 +48334,15 @@ function generateParticipants(params) {
48311
48334
  const isoMin = getMin(nationalityCodesCount);
48312
48335
  const isoList = isoMin
48313
48336
  ? shuffleArray(countryCodes).slice(0, nationalityCodesCount)
48314
- : nationalityCodes
48315
- ? countryCodes.filter((isoCountry) => nationalityCodes.includes(isoCountry.iso))
48316
- : countryCodes;
48337
+ : (nationalityCodes && countryCodes.filter((isoCountry) => nationalityCodes.includes(isoCountry.iso))) ||
48338
+ countryCodes;
48317
48339
  const countriesList = shuffleArray(generateRange(0, Math.ceil(individualParticipantsCount / (isoMin || 1)))
48318
48340
  .map(() => isoList)
48319
48341
  .flat(Infinity));
48320
48342
  const teamNames = nameMocks({ count: participantsCount }).names;
48321
48343
  const participants = generateRange(0, participantsCount)
48322
48344
  .map((i) => {
48323
- const sideParticipantsCount = doubles ? 2 : team ? 8 : 1;
48345
+ const sideParticipantsCount = (doubles && 2) || (team && 8) || 1;
48324
48346
  const individualParticipants = generateRange(0, sideParticipantsCount).map((j) => {
48325
48347
  const participantIndex = i * sideParticipantsCount + j;
48326
48348
  return generateIndividualParticipant(participantIndex);
@@ -50080,7 +50102,7 @@ function validTimePeriod({ startTime = '', endTime = '' } = {}) {
50080
50102
  const [endHour, endMinute] = endTime.split(':').map(getInt);
50081
50103
  if (endHour < startHour)
50082
50104
  return false;
50083
- return startHour === endHour && endMinute < startMinute ? false : true;
50105
+ return !(startHour === endHour && endMinute < startMinute);
50084
50106
  }
50085
50107
  function startTimeSort(a, b) {
50086
50108
  const [startHourA, startMinuteA] = a.startTime.split(':').map(getInt);
@@ -50437,11 +50459,10 @@ function processLeagueProfiles(params) {
50437
50459
  tournamentRecord.events = [];
50438
50460
  tournamentRecord.events.push(event);
50439
50461
  if (entries.length) {
50440
- const roundsCount = isNumeric(leagueProfile.roundsCount)
50441
- ? leagueProfile.roundsCount
50442
- : leagueProfile.roundsCount === DOUBLE_ROUND_ROBIN
50443
- ? (drawSize - 1) * 2
50444
- : drawSize - 1;
50462
+ const roundsCount = (isNumeric(leagueProfile.roundsCount) && leagueProfile.roundsCount) ??
50463
+ leagueProfile.roundsCount === DOUBLE_ROUND_ROBIN
50464
+ ? (drawSize - 1) * 2
50465
+ : drawSize - 1;
50445
50466
  const result = generateDrawDefinition({
50446
50467
  automated: leagueProfile.automated,
50447
50468
  tournamentRecord,
@@ -51225,7 +51246,7 @@ function modifyPersonRequests(params) {
51225
51246
  return request;
51226
51247
  const modification = requests.find((updatedRequest) => updatedRequest.requestId === request.requestId);
51227
51248
  if (!modification.requestType)
51228
- return;
51249
+ return undefined;
51229
51250
  return Object.assign(request, modification);
51230
51251
  })
51231
51252
  .filter(Boolean);