tods-competition-factory 2.1.9 → 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.9';
6
+ return '2.1.11';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -1573,9 +1573,8 @@ function enableNotifications() {
1573
1573
  _globalStateProvider.enableNotifications();
1574
1574
  }
1575
1575
  function setDeepCopy(value, attributes) {
1576
- if (typeof value === 'boolean') {
1576
+ if (typeof value === 'boolean')
1577
1577
  globalState.deepCopy = value;
1578
- }
1579
1578
  if (typeof attributes === 'object') {
1580
1579
  if (Array.isArray(attributes.ignore))
1581
1580
  globalState.deepCopyAttributes.ignore = attributes.ignore;
@@ -6354,393 +6353,1038 @@ function getStructureSeedAssignments({ provisionalPositioning, returnAllProxies,
6354
6353
  };
6355
6354
  }
6356
6355
 
6357
- const add = (a, b) => (a || 0) + (b || 0);
6358
- function getBand(spread, bandProfiles) {
6359
- const spreadValue = Array.isArray(spread) ? spread[0] : spread;
6360
- return ((isNaN(spreadValue) && WALKOVER$1) ||
6361
- (spreadValue <= bandProfiles[DECISIVE] && DECISIVE) ||
6362
- (spreadValue <= bandProfiles[ROUTINE] && ROUTINE) ||
6363
- COMPETITIVE);
6364
- }
6365
- function getScoreComponents({ score }) {
6366
- const sets = score?.sets || [];
6367
- const games = sets.reduce((p, c) => {
6368
- p[0] += c.side1Score || 0;
6369
- p[1] += c.side2Score || 0;
6370
- return p;
6371
- }, [0, 0]);
6372
- const stb = sets.reduce((p, c) => {
6373
- p[0] += c.side1TiebreakScore || 0;
6374
- p[1] += c.side2TiebreakScore || 0;
6375
- return p;
6376
- }, [0, 0]);
6377
- if (stb.reduce(add)) {
6378
- games[stb[0] > stb[1] ? 0 : 1] += 1;
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);
6379
6365
  }
6380
- return { sets, games, score };
6381
- }
6382
- function gamesPercent(scoreComponents) {
6383
- const minGames = Math.min(...scoreComponents.games);
6384
- const maxGames = Math.max(...scoreComponents.games);
6385
- return Math.round((minGames / maxGames) * 100);
6386
- }
6387
- function pctSpread(pcts) {
6388
- return pcts
6389
- .map(gamesPercent)
6390
- .sort()
6391
- .map((p) => parseFloat(p.toFixed(2)));
6392
6366
  }
6393
6367
 
6394
- function getMatchUpCompetitiveProfile({ tournamentRecord, profileBands, matchUp, }) {
6395
- if (!matchUp)
6396
- return { error: MISSING_MATCHUP };
6397
- const { score, winningSide } = matchUp;
6398
- if (!winningSide)
6399
- return { error: INVALID_VALUES };
6400
- const policy = !profileBands &&
6401
- tournamentRecord &&
6402
- findPolicy({
6403
- policyType: POLICY_TYPE_COMPETITIVE_BANDS,
6404
- tournamentRecord,
6405
- }).policy;
6406
- const bandProfiles = profileBands ||
6407
- policy?.profileBands ||
6408
- POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS].profileBands;
6409
- const scoreComponents = getScoreComponents({ score });
6410
- const spread = pctSpread([scoreComponents]);
6411
- const competitiveness = getBand(spread, bandProfiles);
6412
- const pctSpreadValue = Array.isArray(spread) ? spread[0] : spread;
6413
- return { ...SUCCESS, competitiveness, pctSpread: pctSpreadValue };
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
+ }
6414
6390
  }
6415
6391
 
6416
- function getMatchUpParticipantIds({ matchUp }) {
6417
- if (!matchUp)
6418
- return { error: MISSING_MATCHUP };
6419
- if (matchUp && !matchUp.sides)
6420
- return { error: INVALID_MATCHUP };
6421
- if (matchUp && !matchUp.hasContext)
6422
- return { error: MISSING_CONTEXT };
6423
- const sideParticipantIds = (matchUp.sides ?? [])
6424
- ?.map((side) => side?.participantId)
6425
- .filter(Boolean);
6426
- const sideIndividualParticipantIds = matchUp.sides
6427
- ?.filter((side) => side.participant?.participantType === INDIVIDUAL)
6428
- .map((participant) => participant.participantId)
6429
- .filter(Boolean) ?? [];
6430
- const nestedIndividualParticipants = (matchUp.sides ?? [])
6431
- ?.map((side) => side.participant?.individualParticipants)
6432
- .filter(Boolean) ?? [];
6433
- const nestedIndividualParticipantIds = nestedIndividualParticipants.map((participants) => (participants ?? []).map((participant) => participant?.participantId).filter(Boolean));
6434
- const individualParticipantIds = [...sideIndividualParticipantIds, ...nestedIndividualParticipantIds.flat()].filter(Boolean) ?? [];
6435
- const allRelevantParticipantIds = unique(individualParticipantIds.concat(sideParticipantIds)).filter(Boolean) ?? [];
6392
+ function resolveTieFormat({ drawDefinition, structure, matchUp, event }) {
6436
6393
  return {
6437
- nestedIndividualParticipantIds,
6438
- allRelevantParticipantIds,
6439
- individualParticipantIds,
6440
- sideParticipantIds,
6441
- ...SUCCESS,
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),
6442
6408
  };
6443
6409
  }
6444
6410
 
6445
- const CHECK_IN = 'CHECK_IN';
6446
- const CHECK_OUT = 'CHECK_OUT';
6447
- const SCHEDULE$1 = 'SCHEDULE';
6448
- const ASSIGN_VENUE = 'SCHEDULE.ASSIGNMENT.VENUE';
6449
- const ALLOCATE_COURTS = 'SCHEDULE.ALLOCATION.COURTS';
6450
- const ASSIGN_COURT = 'SCHEDULE.ASSIGNMENT.COURT';
6451
- const COURT_ORDER = 'SCHEDULE.COURT.ORDER';
6452
- const SCHEDULED_DATE = 'SCHEDULE.DATE';
6453
- const COMPLETED_DATE = 'COMPLETED.DATE';
6454
- const HOME_PARTICIPANT_ID = 'HOME_PARTICIPANT_ID';
6455
- const ASSIGN_OFFICIAL = 'SCHEDULE.ASSIGN.OFFICIAL';
6456
- const SCHEDULED_TIME = 'SCHEDULE.TIME.SCHEDULED';
6457
- const START_TIME = 'SCHEDULE.TIME.START';
6458
- const STOP_TIME = 'SCHEDULE.TIME.STOP';
6459
- const RESUME_TIME = 'SCHEDULE.TIME.RESUME';
6460
- const END_TIME = 'SCHEDULE.TIME.END';
6461
- const TIME_MODIFIERS = 'SCHEDULE.TIME.MODIFIERS';
6462
- const TO_BE_ANNOUNCED = 'TO_BE_ANNOUNCED';
6463
- const NEXT_AVAILABLE = 'NEXT_AVAILABLE';
6464
- const FOLLOWED_BY = 'FOLLOWED_BY';
6465
- const AFTER_REST = 'AFTER_REST';
6466
- const RAIN_DELAY = 'RAIN_DELAY';
6467
- const NOT_BEFORE = 'NOT_BEFORE';
6468
- const MUTUALLY_EXCLUSIVE_TIME_MODIFIERS = [TO_BE_ANNOUNCED, NEXT_AVAILABLE, FOLLOWED_BY, AFTER_REST, RAIN_DELAY];
6469
- const ELIGIBILITY = 'ELIGIBILITY';
6470
- const REGISTRATION = 'REGISTRATION';
6471
- const SUSPENSION = 'SUSPENSION';
6472
- const MEDICAL$1 = 'MEDICAL';
6473
- const PENALTY$1 = 'PENALTY';
6474
- const SCALE = 'SCALE';
6475
- const RATING = 'RATING';
6476
- const RANKING = 'RANKING';
6477
- const SEEDING = 'SEEDING';
6478
- const PUBLISH = 'PUBLISH';
6479
- const PUBLIC = 'PUBLIC';
6480
- const STATUS$1 = 'STATUS';
6481
- const MODIFICATION = 'MODIFICATION';
6482
- const RETRIEVAL = 'RETRIEVAL';
6483
- const OTHER$3 = 'other';
6484
- const timeItemConstants = {
6485
- MUTUALLY_EXCLUSIVE_TIME_MODIFIERS,
6486
- AFTER_REST,
6487
- ALLOCATE_COURTS,
6488
- ASSIGN_COURT,
6489
- ASSIGN_OFFICIAL,
6490
- ASSIGN_VENUE,
6491
- CHECK_IN,
6492
- CHECK_OUT,
6493
- COMPLETED_DATE,
6494
- COURT_ORDER,
6495
- ELIGIBILITY,
6496
- END_TIME,
6497
- FOLLOWED_BY,
6498
- MEDICAL: MEDICAL$1,
6499
- MODIFICATION,
6500
- NEXT_AVAILABLE,
6501
- NOT_BEFORE,
6502
- OTHER: OTHER$3,
6503
- PENALTY: PENALTY$1,
6504
- PUBLIC,
6505
- PUBLISH,
6506
- RANKING,
6507
- RATING,
6508
- RAIN_DELAY,
6509
- REGISTRATION,
6510
- RESUME_TIME,
6511
- RETRIEVAL,
6512
- SCALE,
6513
- SCHEDULE: SCHEDULE$1,
6514
- SCHEDULED_DATE,
6515
- SCHEDULED_TIME,
6516
- SEEDING,
6517
- START_TIME,
6518
- STATUS: STATUS$1,
6519
- STOP_TIME,
6520
- SUSPENSION,
6521
- TIME_MODIFIERS,
6522
- TO_BE_ANNOUNCED,
6523
- };
6524
-
6525
- function getCheckedInParticipantIds({ matchUp }) {
6526
- if (!matchUp)
6527
- return { error: MISSING_MATCHUP };
6528
- if (!matchUp.hasContext)
6529
- return { error: MISSING_CONTEXT };
6530
- if (!matchUp.sides || matchUp.sides.filter(Boolean).length !== 2) {
6531
- return { error: INVALID_MATCHUP };
6532
- }
6533
- const { nestedIndividualParticipantIds, allRelevantParticipantIds, sideParticipantIds } = getMatchUpParticipantIds({
6534
- matchUp,
6535
- });
6536
- const timeItems = matchUp.timeItems ?? [];
6537
- const checkInItems = timeItems
6538
- .filter((timeItem) => timeItem?.itemType && [CHECK_IN, CHECK_OUT].includes(timeItem.itemType))
6539
- .sort((a, b) => (a.createdAt ? new Date(a.createdAt).getTime() : 0) - (b.createdAt ? new Date(b.createdAt).getTime() : 0));
6540
- const timeItemParticipantIds = checkInItems.map((timeItem) => timeItem.itemValue);
6541
- const checkedInParticipantIds = timeItemParticipantIds.filter((participantId) => {
6542
- return checkInItems.filter((timeItem) => timeItem?.itemValue === participantId).reverse()[0].itemType === CHECK_IN;
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
+ };
6543
6422
  });
6544
- nestedIndividualParticipantIds?.forEach((sideIndividualParticipantIds, sideIndex) => {
6545
- const sideParticipantId = sideParticipantIds?.[sideIndex];
6546
- const allIndividualsCheckedIn = sideIndividualParticipantIds?.length &&
6547
- sideIndividualParticipantIds.every((participantId) => checkedInParticipantIds.includes(participantId));
6548
- if (sideParticipantId && allIndividualsCheckedIn && !checkedInParticipantIds.includes(sideParticipantId)) {
6549
- checkedInParticipantIds.push(sideParticipantId);
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
+ });
6550
6448
  }
6551
- });
6552
- sideParticipantIds?.forEach((sideParticipantId, sideIndex) => {
6553
- if (checkedInParticipantIds.includes(sideParticipantId)) {
6554
- (nestedIndividualParticipantIds?.[sideIndex] ?? []).forEach((participantId) => {
6555
- if (participantId && !checkedInParticipantIds.includes(participantId)) {
6556
- checkedInParticipantIds.push(participantId);
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
+ });
6557
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);
6558
6473
  });
6559
6474
  }
6560
6475
  });
6561
- const allParticipantsCheckedIn = sideParticipantIds?.reduce((checkedIn, participantId) => {
6562
- return checkedInParticipantIds.includes(participantId) && checkedIn;
6563
- }, true);
6564
- return {
6565
- allRelevantParticipantIds,
6566
- allParticipantsCheckedIn,
6567
- checkedInParticipantIds,
6568
- ...SUCCESS,
6569
- };
6570
- }
6571
-
6572
- const matchUpEventTypeMap = {
6573
- [SINGLES]: [SINGLES, 'S'],
6574
- [DOUBLES]: [DOUBLES, 'D'],
6575
- [TEAM$1]: [TEAM$1, 'T'],
6576
- S: [SINGLES, 'S'],
6577
- D: [DOUBLES, 'D'],
6578
- T: [TEAM$1, 'T'],
6579
- };
6580
-
6581
- const isMatchUpEventType = (type) => (params) => {
6582
- const matchUpEventType = (isObject(params) && params?.matchUpType) || (isString(params) && params);
6583
- return matchUpEventType && matchUpEventTypeMap[type].includes(matchUpEventType);
6584
- };
6585
-
6586
- function findMatchupFormatAverageTimes(params) {
6587
- const { matchUpAverageTimes, matchUpFormat } = params || {};
6588
- const codeMatches = matchUpAverageTimes
6589
- ?.map(({ matchUpFormatCodes }) => {
6590
- return matchUpFormatCodes?.filter((code) => code === matchUpFormat);
6591
- })
6592
- .flat()
6593
- .filter(Boolean)
6594
- .sort((a, b) => (a?.length || 0) - (b?.length || 0)) || [];
6595
- const exactCodeMatch = codeMatches.includes(matchUpFormat);
6596
- const targetCode = exactCodeMatch ? matchUpFormat : codeMatches[0];
6597
- const targetDefinition = matchUpAverageTimes?.find(({ matchUpFormatCodes, averageTimes }) => matchUpFormatCodes?.find((code) => targetCode === code) && averageTimes);
6598
- return targetDefinition?.averageTimes;
6476
+ return { mappedMatchUps, drawMatchUps };
6599
6477
  }
6600
- function findMatchupFormatRecoveryTimes(params) {
6601
- const { matchUpRecoveryTimes, averageMinutes, matchUpFormat } = params || {};
6602
- return matchUpRecoveryTimes?.find(({ matchUpFormatCodes, averageTimes, recoveryTimes }) => {
6603
- if (averageTimes && averageMinutes) {
6604
- const { greaterThan = 0, lessThan = 360 } = averageTimes;
6605
- if (averageMinutes > greaterThan && averageMinutes < lessThan)
6606
- return true;
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
+ });
6607
6492
  }
6608
- return matchUpFormatCodes?.find((code) => code === matchUpFormat) && recoveryTimes;
6609
- })?.recoveryTimes;
6493
+ else {
6494
+ return matchUps;
6495
+ }
6496
+ })
6497
+ .flat();
6498
+ return (structureMatchUpsMap?.matchUps || []).concat(...itemStructureMatchUps);
6610
6499
  }
6611
6500
 
6612
- function findCategoryTiming({ timesBlockArray, categoryName, categoryType }) {
6613
- return timesBlockArray
6614
- .filter((f) => Array.isArray(f))
6615
- .map((times) => times
6616
- .sort((a, b) => (b.categoryNames?.length || 0) - (a.categoryNames?.length || 0))
6617
- .find(({ categoryTypes, categoryNames }) => (!categoryNames?.length && !categoryTypes?.length) ||
6618
- categoryNames?.includes(categoryName) ||
6619
- categoryTypes?.includes(categoryType)))
6620
- .find(Boolean);
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);
6621
6509
  }
6622
6510
 
6623
- function getMatchUpFormatRecoveryTimes({ tournamentScheduling, eventScheduling, averageMinutes, defaultTiming, matchUpFormat, categoryName, categoryType, policy, }) {
6624
- const eventRecoveryTimes = eventScheduling?.matchUpRecoveryTimes &&
6625
- findMatchupFormatRecoveryTimes({
6626
- ...eventScheduling,
6627
- averageMinutes,
6628
- matchUpFormat,
6629
- });
6630
- const tournamentRecoveryTimes = tournamentScheduling?.matchUpRecoveryTimes &&
6631
- findMatchupFormatRecoveryTimes({
6632
- ...tournamentScheduling,
6633
- averageMinutes,
6634
- matchUpFormat,
6635
- });
6636
- const policyRecoveryTimes = policy?.matchUpRecoveryTimes &&
6637
- findMatchupFormatRecoveryTimes({
6638
- ...policy,
6639
- averageMinutes,
6640
- matchUpFormat,
6641
- });
6642
- const timesBlockArray = [
6643
- eventRecoveryTimes,
6644
- tournamentRecoveryTimes,
6645
- policyRecoveryTimes,
6646
- policy?.defaultTimes?.recoveryTimes,
6647
- defaultTiming?.recoveryTimes,
6648
- ];
6649
- return findCategoryTiming({
6650
- categoryName,
6651
- categoryType,
6652
- timesBlockArray,
6653
- });
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;
6654
6521
  }
6655
-
6656
- function getMatchUpFormatAverageTimes({ matchUpFormat, categoryName, categoryType, defaultTiming, tournamentScheduling, eventScheduling, policy, }) {
6657
- const eventAverageTimes = eventScheduling?.matchUpAverageTimes &&
6658
- findMatchupFormatAverageTimes({
6659
- ...eventScheduling,
6660
- matchUpFormat,
6661
- });
6662
- const tournamentAverageTimes = tournamentScheduling?.matchUpAverageTimes &&
6663
- findMatchupFormatAverageTimes({
6664
- ...tournamentScheduling,
6665
- matchUpFormat,
6666
- });
6667
- const policyAverageTimes = policy?.matchUpAverageTimes &&
6668
- findMatchupFormatAverageTimes({
6669
- ...policy,
6670
- matchUpFormat,
6671
- });
6672
- const timesBlockArray = [
6673
- eventAverageTimes,
6674
- tournamentAverageTimes,
6675
- policyAverageTimes,
6676
- policy?.defaultTimes?.averageTimes,
6677
- defaultTiming?.averageTimes,
6678
- ];
6679
- return findCategoryTiming({
6680
- categoryName,
6681
- categoryType,
6682
- timesBlockArray,
6683
- });
6522
+ function validMatchUps(matchUps) {
6523
+ if (!Array.isArray(matchUps))
6524
+ return false;
6525
+ return matchUps.every(validMatchUp);
6684
6526
  }
6685
6527
 
6686
- const DOUBLES_SINGLES = 'DOUBLES_SINGLES';
6687
- const SINGLES_DOUBLES = 'SINGLES_DOUBLES';
6688
- const TOTAL = 'total';
6689
- const CONFLICT_PARTICIPANTS = 'participantConflict';
6690
- const CONFLICT_MATCHUP_ORDER = 'matchUpConflict';
6691
- const SCHEDULE_ISSUE_IDS = 'ISSUE_IDS';
6692
- const SCHEDULE_CONFLICT = 'CONFLICT';
6693
- const SCHEDULE_WARNING = 'WARNING';
6694
- const SCHEDULE_ERROR = 'ERROR';
6695
- const SCHEDULE_ISSUE = 'ISSUE';
6696
- const SCHEDULE_STATE = 'STATE';
6697
- const scheduleConstants = {
6698
- SINGLES_DOUBLES,
6699
- DOUBLES_SINGLES,
6700
- TOTAL,
6701
- CONFLICT_MATCHUP_ORDER,
6702
- CONFLICT_PARTICIPANTS,
6703
- SCHEDULE_ISSUE_IDS,
6704
- SCHEDULE_CONFLICT,
6705
- SCHEDULE_WARNING,
6706
- SCHEDULE_ERROR,
6707
- SCHEDULE_ISSUE,
6708
- SCHEDULE_STATE,
6709
- };
6710
-
6711
- function getMatchUpFormatTiming({ defaultAverageMinutes = 90, defaultRecoveryMinutes = 0, tournamentRecord, matchUpFormat, categoryName, categoryType, eventType, event, }) {
6712
- if (!tournamentRecord)
6713
- return { error: MISSING_TOURNAMENT_RECORD };
6714
- eventType = eventType ?? event?.eventType ?? SINGLES_EVENT;
6715
- const defaultTiming = {
6716
- averageTimes: [{ minutes: { default: defaultAverageMinutes } }],
6717
- recoveryTimes: [{ minutes: { default: defaultRecoveryMinutes } }],
6718
- };
6719
- const { scheduleTiming } = getScheduleTiming({
6720
- tournamentRecord,
6721
- categoryName,
6722
- categoryType,
6723
- event,
6724
- });
6725
- const timingDetails = {
6726
- ...scheduleTiming,
6727
- matchUpFormat,
6728
- categoryType,
6729
- defaultTiming,
6730
- };
6731
- return matchUpFormatTimes({ eventType, timingDetails });
6732
- }
6733
- function matchUpFormatTimes({ timingDetails, eventType }) {
6734
- const averageTimes = getMatchUpFormatAverageTimes(timingDetails);
6735
- const averageKeys = Object.keys(averageTimes?.minutes || {});
6736
- const averageMinutes = averageTimes?.minutes &&
6737
- ((averageKeys?.includes(eventType) && averageTimes.minutes[eventType]) || averageTimes.minutes.default);
6738
- const recoveryTimes = getMatchUpFormatRecoveryTimes({
6739
- ...timingDetails,
6740
- averageMinutes,
6741
- });
6742
- const recoveryKeys = Object.keys(recoveryTimes?.minutes || {});
6743
- const recoveryMinutes = recoveryTimes?.minutes &&
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
+
7001
+ const add = (a, b) => (a || 0) + (b || 0);
7002
+ function getBand(spread, bandProfiles) {
7003
+ const spreadValue = Array.isArray(spread) ? spread[0] : spread;
7004
+ return ((isNaN(spreadValue) && WALKOVER$1) ||
7005
+ (spreadValue <= bandProfiles[DECISIVE] && DECISIVE) ||
7006
+ (spreadValue <= bandProfiles[ROUTINE] && ROUTINE) ||
7007
+ COMPETITIVE);
7008
+ }
7009
+ function getScoreComponents({ score }) {
7010
+ const sets = score?.sets || [];
7011
+ const games = sets.reduce((p, c) => {
7012
+ p[0] += c.side1Score || 0;
7013
+ p[1] += c.side2Score || 0;
7014
+ return p;
7015
+ }, [0, 0]);
7016
+ const stb = sets.reduce((p, c) => {
7017
+ p[0] += c.side1TiebreakScore || 0;
7018
+ p[1] += c.side2TiebreakScore || 0;
7019
+ return p;
7020
+ }, [0, 0]);
7021
+ if (stb.reduce(add)) {
7022
+ games[stb[0] > stb[1] ? 0 : 1] += 1;
7023
+ }
7024
+ return { sets, games, score };
7025
+ }
7026
+ function gamesPercent(scoreComponents) {
7027
+ const minGames = Math.min(...scoreComponents.games);
7028
+ const maxGames = Math.max(...scoreComponents.games);
7029
+ return Math.round((minGames / maxGames) * 100);
7030
+ }
7031
+ function pctSpread(pcts) {
7032
+ return pcts
7033
+ .map(gamesPercent)
7034
+ .sort()
7035
+ .map((p) => parseFloat(p.toFixed(2)));
7036
+ }
7037
+
7038
+ function getMatchUpCompetitiveProfile({ tournamentRecord, profileBands, matchUp, }) {
7039
+ if (!matchUp)
7040
+ return { error: MISSING_MATCHUP };
7041
+ const { score, winningSide } = matchUp;
7042
+ if (!winningSide)
7043
+ return { error: INVALID_VALUES };
7044
+ const policy = !profileBands &&
7045
+ tournamentRecord &&
7046
+ findPolicy({
7047
+ policyType: POLICY_TYPE_COMPETITIVE_BANDS,
7048
+ tournamentRecord,
7049
+ }).policy;
7050
+ const bandProfiles = profileBands ||
7051
+ policy?.profileBands ||
7052
+ POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS].profileBands;
7053
+ const scoreComponents = getScoreComponents({ score });
7054
+ const spread = pctSpread([scoreComponents]);
7055
+ const competitiveness = getBand(spread, bandProfiles);
7056
+ const pctSpreadValue = Array.isArray(spread) ? spread[0] : spread;
7057
+ return { ...SUCCESS, competitiveness, pctSpread: pctSpreadValue };
7058
+ }
7059
+
7060
+ function getMatchUpParticipantIds({ matchUp }) {
7061
+ if (!matchUp)
7062
+ return { error: MISSING_MATCHUP };
7063
+ if (matchUp && !matchUp.sides)
7064
+ return { error: INVALID_MATCHUP };
7065
+ if (matchUp && !matchUp.hasContext)
7066
+ return { error: MISSING_CONTEXT };
7067
+ const sideParticipantIds = (matchUp.sides ?? [])
7068
+ ?.map((side) => side?.participantId)
7069
+ .filter(Boolean);
7070
+ const sideIndividualParticipantIds = matchUp.sides
7071
+ ?.filter((side) => side.participant?.participantType === INDIVIDUAL)
7072
+ .map((participant) => participant.participantId)
7073
+ .filter(Boolean) ?? [];
7074
+ const nestedIndividualParticipants = (matchUp.sides ?? [])
7075
+ ?.map((side) => side.participant?.individualParticipants)
7076
+ .filter(Boolean) ?? [];
7077
+ const nestedIndividualParticipantIds = nestedIndividualParticipants.map((participants) => (participants ?? []).map((participant) => participant?.participantId).filter(Boolean));
7078
+ const individualParticipantIds = [...sideIndividualParticipantIds, ...nestedIndividualParticipantIds.flat()].filter(Boolean) ?? [];
7079
+ const allRelevantParticipantIds = unique(individualParticipantIds.concat(sideParticipantIds)).filter(Boolean) ?? [];
7080
+ return {
7081
+ nestedIndividualParticipantIds,
7082
+ allRelevantParticipantIds,
7083
+ individualParticipantIds,
7084
+ sideParticipantIds,
7085
+ ...SUCCESS,
7086
+ };
7087
+ }
7088
+
7089
+ const CHECK_IN = 'CHECK_IN';
7090
+ const CHECK_OUT = 'CHECK_OUT';
7091
+ const SCHEDULE$1 = 'SCHEDULE';
7092
+ const ASSIGN_VENUE = 'SCHEDULE.ASSIGNMENT.VENUE';
7093
+ const ALLOCATE_COURTS = 'SCHEDULE.ALLOCATION.COURTS';
7094
+ const ASSIGN_COURT = 'SCHEDULE.ASSIGNMENT.COURT';
7095
+ const COURT_ORDER = 'SCHEDULE.COURT.ORDER';
7096
+ const SCHEDULED_DATE = 'SCHEDULE.DATE';
7097
+ const COMPLETED_DATE = 'COMPLETED.DATE';
7098
+ const HOME_PARTICIPANT_ID = 'HOME_PARTICIPANT_ID';
7099
+ const ASSIGN_OFFICIAL = 'SCHEDULE.ASSIGN.OFFICIAL';
7100
+ const SCHEDULED_TIME = 'SCHEDULE.TIME.SCHEDULED';
7101
+ const START_TIME = 'SCHEDULE.TIME.START';
7102
+ const STOP_TIME = 'SCHEDULE.TIME.STOP';
7103
+ const RESUME_TIME = 'SCHEDULE.TIME.RESUME';
7104
+ const END_TIME = 'SCHEDULE.TIME.END';
7105
+ const TIME_MODIFIERS = 'SCHEDULE.TIME.MODIFIERS';
7106
+ const TO_BE_ANNOUNCED = 'TO_BE_ANNOUNCED';
7107
+ const NEXT_AVAILABLE = 'NEXT_AVAILABLE';
7108
+ const FOLLOWED_BY = 'FOLLOWED_BY';
7109
+ const AFTER_REST = 'AFTER_REST';
7110
+ const RAIN_DELAY = 'RAIN_DELAY';
7111
+ const NOT_BEFORE = 'NOT_BEFORE';
7112
+ const MUTUALLY_EXCLUSIVE_TIME_MODIFIERS = [TO_BE_ANNOUNCED, NEXT_AVAILABLE, FOLLOWED_BY, AFTER_REST, RAIN_DELAY];
7113
+ const ELIGIBILITY = 'ELIGIBILITY';
7114
+ const REGISTRATION = 'REGISTRATION';
7115
+ const SUSPENSION = 'SUSPENSION';
7116
+ const MEDICAL$1 = 'MEDICAL';
7117
+ const PENALTY$1 = 'PENALTY';
7118
+ const SCALE = 'SCALE';
7119
+ const RATING = 'RATING';
7120
+ const RANKING = 'RANKING';
7121
+ const SEEDING = 'SEEDING';
7122
+ const PUBLISH = 'PUBLISH';
7123
+ const PUBLIC = 'PUBLIC';
7124
+ const STATUS$1 = 'STATUS';
7125
+ const MODIFICATION = 'MODIFICATION';
7126
+ const RETRIEVAL = 'RETRIEVAL';
7127
+ const OTHER$3 = 'other';
7128
+ const timeItemConstants = {
7129
+ MUTUALLY_EXCLUSIVE_TIME_MODIFIERS,
7130
+ AFTER_REST,
7131
+ ALLOCATE_COURTS,
7132
+ ASSIGN_COURT,
7133
+ ASSIGN_OFFICIAL,
7134
+ ASSIGN_VENUE,
7135
+ CHECK_IN,
7136
+ CHECK_OUT,
7137
+ COMPLETED_DATE,
7138
+ COURT_ORDER,
7139
+ ELIGIBILITY,
7140
+ END_TIME,
7141
+ FOLLOWED_BY,
7142
+ MEDICAL: MEDICAL$1,
7143
+ MODIFICATION,
7144
+ NEXT_AVAILABLE,
7145
+ NOT_BEFORE,
7146
+ OTHER: OTHER$3,
7147
+ PENALTY: PENALTY$1,
7148
+ PUBLIC,
7149
+ PUBLISH,
7150
+ RANKING,
7151
+ RATING,
7152
+ RAIN_DELAY,
7153
+ REGISTRATION,
7154
+ RESUME_TIME,
7155
+ RETRIEVAL,
7156
+ SCALE,
7157
+ SCHEDULE: SCHEDULE$1,
7158
+ SCHEDULED_DATE,
7159
+ SCHEDULED_TIME,
7160
+ SEEDING,
7161
+ START_TIME,
7162
+ STATUS: STATUS$1,
7163
+ STOP_TIME,
7164
+ SUSPENSION,
7165
+ TIME_MODIFIERS,
7166
+ TO_BE_ANNOUNCED,
7167
+ };
7168
+
7169
+ function getCheckedInParticipantIds({ matchUp }) {
7170
+ if (!matchUp)
7171
+ return { error: MISSING_MATCHUP };
7172
+ if (!matchUp.hasContext)
7173
+ return { error: MISSING_CONTEXT };
7174
+ if (!matchUp.sides || matchUp.sides.filter(Boolean).length !== 2) {
7175
+ return { error: INVALID_MATCHUP };
7176
+ }
7177
+ const { nestedIndividualParticipantIds, allRelevantParticipantIds, sideParticipantIds } = getMatchUpParticipantIds({
7178
+ matchUp,
7179
+ });
7180
+ const timeItems = matchUp.timeItems ?? [];
7181
+ const checkInItems = timeItems
7182
+ .filter((timeItem) => timeItem?.itemType && [CHECK_IN, CHECK_OUT].includes(timeItem.itemType))
7183
+ .sort((a, b) => (a.createdAt ? new Date(a.createdAt).getTime() : 0) - (b.createdAt ? new Date(b.createdAt).getTime() : 0));
7184
+ const timeItemParticipantIds = checkInItems.map((timeItem) => timeItem.itemValue);
7185
+ const checkedInParticipantIds = timeItemParticipantIds.filter((participantId) => {
7186
+ return checkInItems.filter((timeItem) => timeItem?.itemValue === participantId).reverse()[0].itemType === CHECK_IN;
7187
+ });
7188
+ nestedIndividualParticipantIds?.forEach((sideIndividualParticipantIds, sideIndex) => {
7189
+ const sideParticipantId = sideParticipantIds?.[sideIndex];
7190
+ const allIndividualsCheckedIn = sideIndividualParticipantIds?.length &&
7191
+ sideIndividualParticipantIds.every((participantId) => checkedInParticipantIds.includes(participantId));
7192
+ if (sideParticipantId && allIndividualsCheckedIn && !checkedInParticipantIds.includes(sideParticipantId)) {
7193
+ checkedInParticipantIds.push(sideParticipantId);
7194
+ }
7195
+ });
7196
+ sideParticipantIds?.forEach((sideParticipantId, sideIndex) => {
7197
+ if (checkedInParticipantIds.includes(sideParticipantId)) {
7198
+ (nestedIndividualParticipantIds?.[sideIndex] ?? []).forEach((participantId) => {
7199
+ if (participantId && !checkedInParticipantIds.includes(participantId)) {
7200
+ checkedInParticipantIds.push(participantId);
7201
+ }
7202
+ });
7203
+ }
7204
+ });
7205
+ const allParticipantsCheckedIn = sideParticipantIds?.reduce((checkedIn, participantId) => {
7206
+ return checkedInParticipantIds.includes(participantId) && checkedIn;
7207
+ }, true);
7208
+ return {
7209
+ allRelevantParticipantIds,
7210
+ allParticipantsCheckedIn,
7211
+ checkedInParticipantIds,
7212
+ ...SUCCESS,
7213
+ };
7214
+ }
7215
+
7216
+ const matchUpEventTypeMap = {
7217
+ [SINGLES]: [SINGLES, 'S'],
7218
+ [DOUBLES]: [DOUBLES, 'D'],
7219
+ [TEAM$1]: [TEAM$1, 'T'],
7220
+ S: [SINGLES, 'S'],
7221
+ D: [DOUBLES, 'D'],
7222
+ T: [TEAM$1, 'T'],
7223
+ };
7224
+
7225
+ const isMatchUpEventType = (type) => (params) => {
7226
+ const matchUpEventType = (isObject(params) && params?.matchUpType) || (isString(params) && params);
7227
+ return matchUpEventType && matchUpEventTypeMap[type].includes(matchUpEventType);
7228
+ };
7229
+
7230
+ function findMatchupFormatAverageTimes(params) {
7231
+ const { matchUpAverageTimes, matchUpFormat } = params || {};
7232
+ const codeMatches = matchUpAverageTimes
7233
+ ?.map(({ matchUpFormatCodes }) => {
7234
+ return matchUpFormatCodes?.filter((code) => code === matchUpFormat);
7235
+ })
7236
+ .flat()
7237
+ .filter(Boolean)
7238
+ .sort((a, b) => (a?.length || 0) - (b?.length || 0)) || [];
7239
+ const exactCodeMatch = codeMatches.includes(matchUpFormat);
7240
+ const targetCode = exactCodeMatch ? matchUpFormat : codeMatches[0];
7241
+ const targetDefinition = matchUpAverageTimes?.find(({ matchUpFormatCodes, averageTimes }) => matchUpFormatCodes?.find((code) => targetCode === code) && averageTimes);
7242
+ return targetDefinition?.averageTimes;
7243
+ }
7244
+ function findMatchupFormatRecoveryTimes(params) {
7245
+ const { matchUpRecoveryTimes, averageMinutes, matchUpFormat } = params || {};
7246
+ return matchUpRecoveryTimes?.find(({ matchUpFormatCodes, averageTimes, recoveryTimes }) => {
7247
+ if (averageTimes && averageMinutes) {
7248
+ const { greaterThan = 0, lessThan = 360 } = averageTimes;
7249
+ if (averageMinutes > greaterThan && averageMinutes < lessThan)
7250
+ return true;
7251
+ }
7252
+ return matchUpFormatCodes?.find((code) => code === matchUpFormat) && recoveryTimes;
7253
+ })?.recoveryTimes;
7254
+ }
7255
+
7256
+ function findCategoryTiming({ timesBlockArray, categoryName, categoryType }) {
7257
+ return timesBlockArray
7258
+ .filter((f) => Array.isArray(f))
7259
+ .map((times) => times
7260
+ .sort((a, b) => (b.categoryNames?.length || 0) - (a.categoryNames?.length || 0))
7261
+ .find(({ categoryTypes, categoryNames }) => (!categoryNames?.length && !categoryTypes?.length) ||
7262
+ categoryNames?.includes(categoryName) ||
7263
+ categoryTypes?.includes(categoryType)))
7264
+ .find(Boolean);
7265
+ }
7266
+
7267
+ function getMatchUpFormatRecoveryTimes({ tournamentScheduling, eventScheduling, averageMinutes, defaultTiming, matchUpFormat, categoryName, categoryType, policy, }) {
7268
+ const eventRecoveryTimes = eventScheduling?.matchUpRecoveryTimes &&
7269
+ findMatchupFormatRecoveryTimes({
7270
+ ...eventScheduling,
7271
+ averageMinutes,
7272
+ matchUpFormat,
7273
+ });
7274
+ const tournamentRecoveryTimes = tournamentScheduling?.matchUpRecoveryTimes &&
7275
+ findMatchupFormatRecoveryTimes({
7276
+ ...tournamentScheduling,
7277
+ averageMinutes,
7278
+ matchUpFormat,
7279
+ });
7280
+ const policyRecoveryTimes = policy?.matchUpRecoveryTimes &&
7281
+ findMatchupFormatRecoveryTimes({
7282
+ ...policy,
7283
+ averageMinutes,
7284
+ matchUpFormat,
7285
+ });
7286
+ const timesBlockArray = [
7287
+ eventRecoveryTimes,
7288
+ tournamentRecoveryTimes,
7289
+ policyRecoveryTimes,
7290
+ policy?.defaultTimes?.recoveryTimes,
7291
+ defaultTiming?.recoveryTimes,
7292
+ ];
7293
+ return findCategoryTiming({
7294
+ categoryName,
7295
+ categoryType,
7296
+ timesBlockArray,
7297
+ });
7298
+ }
7299
+
7300
+ function getMatchUpFormatAverageTimes({ matchUpFormat, categoryName, categoryType, defaultTiming, tournamentScheduling, eventScheduling, policy, }) {
7301
+ const eventAverageTimes = eventScheduling?.matchUpAverageTimes &&
7302
+ findMatchupFormatAverageTimes({
7303
+ ...eventScheduling,
7304
+ matchUpFormat,
7305
+ });
7306
+ const tournamentAverageTimes = tournamentScheduling?.matchUpAverageTimes &&
7307
+ findMatchupFormatAverageTimes({
7308
+ ...tournamentScheduling,
7309
+ matchUpFormat,
7310
+ });
7311
+ const policyAverageTimes = policy?.matchUpAverageTimes &&
7312
+ findMatchupFormatAverageTimes({
7313
+ ...policy,
7314
+ matchUpFormat,
7315
+ });
7316
+ const timesBlockArray = [
7317
+ eventAverageTimes,
7318
+ tournamentAverageTimes,
7319
+ policyAverageTimes,
7320
+ policy?.defaultTimes?.averageTimes,
7321
+ defaultTiming?.averageTimes,
7322
+ ];
7323
+ return findCategoryTiming({
7324
+ categoryName,
7325
+ categoryType,
7326
+ timesBlockArray,
7327
+ });
7328
+ }
7329
+
7330
+ const DOUBLES_SINGLES = 'DOUBLES_SINGLES';
7331
+ const SINGLES_DOUBLES = 'SINGLES_DOUBLES';
7332
+ const TOTAL = 'total';
7333
+ const CONFLICT_PARTICIPANTS = 'participantConflict';
7334
+ const CONFLICT_MATCHUP_ORDER = 'matchUpConflict';
7335
+ const SCHEDULE_ISSUE_IDS = 'ISSUE_IDS';
7336
+ const SCHEDULE_CONFLICT = 'CONFLICT';
7337
+ const SCHEDULE_WARNING = 'WARNING';
7338
+ const SCHEDULE_ERROR = 'ERROR';
7339
+ const SCHEDULE_ISSUE = 'ISSUE';
7340
+ const SCHEDULE_STATE = 'STATE';
7341
+ const scheduleConstants = {
7342
+ SINGLES_DOUBLES,
7343
+ DOUBLES_SINGLES,
7344
+ TOTAL,
7345
+ CONFLICT_MATCHUP_ORDER,
7346
+ CONFLICT_PARTICIPANTS,
7347
+ SCHEDULE_ISSUE_IDS,
7348
+ SCHEDULE_CONFLICT,
7349
+ SCHEDULE_WARNING,
7350
+ SCHEDULE_ERROR,
7351
+ SCHEDULE_ISSUE,
7352
+ SCHEDULE_STATE,
7353
+ };
7354
+
7355
+ function getMatchUpFormatTiming({ defaultAverageMinutes = 90, defaultRecoveryMinutes = 0, tournamentRecord, matchUpFormat, categoryName, categoryType, eventType, event, }) {
7356
+ if (!tournamentRecord)
7357
+ return { error: MISSING_TOURNAMENT_RECORD };
7358
+ eventType = eventType ?? event?.eventType ?? SINGLES_EVENT;
7359
+ const defaultTiming = {
7360
+ averageTimes: [{ minutes: { default: defaultAverageMinutes } }],
7361
+ recoveryTimes: [{ minutes: { default: defaultRecoveryMinutes } }],
7362
+ };
7363
+ const { scheduleTiming } = getScheduleTiming({
7364
+ tournamentRecord,
7365
+ categoryName,
7366
+ categoryType,
7367
+ event,
7368
+ });
7369
+ const timingDetails = {
7370
+ ...scheduleTiming,
7371
+ matchUpFormat,
7372
+ categoryType,
7373
+ defaultTiming,
7374
+ };
7375
+ return matchUpFormatTimes({ eventType, timingDetails });
7376
+ }
7377
+ function matchUpFormatTimes({ timingDetails, eventType }) {
7378
+ const averageTimes = getMatchUpFormatAverageTimes(timingDetails);
7379
+ const averageKeys = Object.keys(averageTimes?.minutes || {});
7380
+ const averageMinutes = averageTimes?.minutes &&
7381
+ ((averageKeys?.includes(eventType) && averageTimes.minutes[eventType]) || averageTimes.minutes.default);
7382
+ const recoveryTimes = getMatchUpFormatRecoveryTimes({
7383
+ ...timingDetails,
7384
+ averageMinutes,
7385
+ });
7386
+ const recoveryKeys = Object.keys(recoveryTimes?.minutes || {});
7387
+ const recoveryMinutes = recoveryTimes?.minutes &&
6744
7388
  ((recoveryKeys?.includes(eventType) && recoveryTimes.minutes[eventType]) || recoveryTimes.minutes.default);
6745
7389
  const formatChangeKey = isMatchUpEventType(SINGLES_EVENT)(eventType) ? SINGLES_DOUBLES : DOUBLES_SINGLES;
6746
7390
  const typeChangeRecoveryMinutes = recoveryTimes?.minutes &&
@@ -6908,6 +7552,21 @@ function matchUpCourtOrder({ visibilityThreshold, timeStamp, schedule, matchUp }
6908
7552
  : schedule;
6909
7553
  }
6910
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
+
6911
7570
  function matchUpStartTime({ matchUp }) {
6912
7571
  const timeItems = matchUp?.timeItems || [];
6913
7572
  const getTimeStamp = (item) => (!item.createdAt ? 0 : new Date(item.createdAt).getTime());
@@ -6920,10 +7579,10 @@ function matchUpStartTime({ matchUp }) {
6920
7579
  return { startTime };
6921
7580
  }
6922
7581
 
6923
- function UUIDS(count = 1) {
6924
- return generateRange(0, count).map(UUID);
7582
+ function UUIDS(count = 1, pre) {
7583
+ return generateRange(0, count).map(() => UUID(pre));
6925
7584
  }
6926
- function UUID() {
7585
+ function UUID(pre) {
6927
7586
  const lut = [];
6928
7587
  for (let i = 0; i < 256; i++) {
6929
7588
  lut[i] = (i < 16 ? '0' : '') + i.toString(16);
@@ -6932,7 +7591,7 @@ function UUID() {
6932
7591
  const d1 = (Math.random() * 0xffffffff) | 0;
6933
7592
  const d2 = (Math.random() * 0xffffffff) | 0;
6934
7593
  const d3 = (Math.random() * 0xffffffff) | 0;
6935
- return (lut[d0 & 0xff] +
7594
+ const uuid = lut[d0 & 0xff] +
6936
7595
  lut[(d0 >> 8) & 0xff] +
6937
7596
  lut[(d0 >> 16) & 0xff] +
6938
7597
  lut[(d0 >> 24) & 0xff] +
@@ -6951,7 +7610,8 @@ function UUID() {
6951
7610
  lut[d3 & 0xff] +
6952
7611
  lut[(d3 >> 8) & 0xff] +
6953
7612
  lut[(d3 >> 16) & 0xff] +
6954
- lut[(d3 >> 24) & 0xff]);
7613
+ lut[(d3 >> 24) & 0xff];
7614
+ return typeof pre === 'string' ? `${pre}_${uuid.replace(/-/g, '')}` : uuid;
6955
7615
  }
6956
7616
 
6957
7617
  function addVenue(params) {
@@ -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 ||
@@ -25903,6 +25928,7 @@ function getCoercedDrawType(params) {
25903
25928
  const { drawTypeCoercion, enforceMinimumDrawSize } = params;
25904
25929
  const drawSize = ensureInt(params.drawSize);
25905
25930
  let drawType = (drawTypeCoercion &&
25931
+ params.drawType !== AD_HOC &&
25906
25932
  (typeof drawTypeCoercion === 'boolean' || drawTypeCoercion <= 2) &&
25907
25933
  drawSize === 2 &&
25908
25934
  SINGLE_ELIMINATION) ||
@@ -29408,6 +29434,7 @@ function joinFloatingTiebreak({ score }) {
29408
29434
  return lastSet;
29409
29435
  }
29410
29436
  }
29437
+ return undefined;
29411
29438
  });
29412
29439
  const tiebreakIndices = arrayIndices('tiebreak', profile);
29413
29440
  if (tiebreakIndices.length) {
@@ -30022,8 +30049,8 @@ function handleNumeric(params) {
30022
30049
  score = chunks.join(' ');
30023
30050
  applied.push('chunkSplit');
30024
30051
  }
30025
- else if (numbers.length == 6) {
30026
- if (instances[1] == 2 || instances[2] === 2) {
30052
+ else if (numbers.length === 6) {
30053
+ if (instances[1] === 2 || instances[2] === 2) {
30027
30054
  if (!Object.values(positiveInstances).includes(3)) {
30028
30055
  score = chunks.join(' ');
30029
30056
  applied.push('chunkSplit');
@@ -30275,7 +30302,7 @@ function removeErroneous({ score, applied }) {
30275
30302
  .map((part) => {
30276
30303
  if (/^\d+$/.test(part) && part.length === 1) {
30277
30304
  applied.push('removeErroneous1');
30278
- return;
30305
+ return undefined;
30279
30306
  }
30280
30307
  return part;
30281
30308
  })
@@ -34159,7 +34186,7 @@ function getInContextCourt({ convertExtensions, ignoreDisabled, venue, court })
34159
34186
  .map((availability) => {
34160
34187
  const date = availability.date;
34161
34188
  if (!date || disabledDates.includes(date))
34162
- return;
34189
+ return undefined;
34163
34190
  return availability;
34164
34191
  })
34165
34192
  .filter(Boolean);
@@ -34397,7 +34424,7 @@ function getDrawData(params) {
34397
34424
  .sort((a, b) => structureSort(a, b, sortConfig))
34398
34425
  .map((structure) => {
34399
34426
  if (!structure)
34400
- return;
34427
+ return undefined;
34401
34428
  const structureId = structure?.structureId;
34402
34429
  let seedAssignments = [];
34403
34430
  if (structure.stage && [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
@@ -34515,9 +34542,7 @@ function getDrawData(params) {
34515
34542
  : undefined;
34516
34543
  return {
34517
34544
  structures: !usePublishState || drawInfo.drawPublished
34518
- ? noDeepCopy
34519
- ? structures
34520
- : makeDeepCopy(structures, false, true)
34545
+ ? (noDeepCopy && structures) || makeDeepCopy(structures, false, true)
34521
34546
  : undefined,
34522
34547
  drawInfo: noDeepCopy ? drawInfo : makeDeepCopy(drawInfo, false, true),
34523
34548
  ...SUCCESS,
@@ -34829,7 +34854,7 @@ function getUpdatedSchedulingProfile({ schedulingProfile, venueIds, eventIds, dr
34829
34854
  const date = extractDate(dateSchedulingProfile?.scheduleDate);
34830
34855
  if (!date) {
34831
34856
  issues.push(`Invalid date: ${dateSchedulingProfile?.scheduledDate}`);
34832
- return;
34857
+ return undefined;
34833
34858
  }
34834
34859
  const venues = (dateSchedulingProfile?.venues || [])
34835
34860
  .map((venue) => {
@@ -34837,7 +34862,7 @@ function getUpdatedSchedulingProfile({ schedulingProfile, venueIds, eventIds, dr
34837
34862
  const venueExists = venueIds?.includes(venueId);
34838
34863
  if (!venueExists) {
34839
34864
  issues.push(`Missing venueId: ${venueId}`);
34840
- return;
34865
+ return undefined;
34841
34866
  }
34842
34867
  const filteredRounds = rounds.filter((round) => {
34843
34868
  const validEventIdAndDrawId = eventIds.includes(round.eventId) && drawIds.includes(round.drawId);
@@ -34846,7 +34871,7 @@ function getUpdatedSchedulingProfile({ schedulingProfile, venueIds, eventIds, dr
34846
34871
  return validEventIdAndDrawId;
34847
34872
  });
34848
34873
  if (!filteredRounds.length)
34849
- return;
34874
+ return undefined;
34850
34875
  return { venueId, rounds: filteredRounds };
34851
34876
  })
34852
34877
  .filter(Boolean);
@@ -34902,7 +34927,7 @@ function validateSchedulingProfile({ tournamentRecords, schedulingProfile }) {
34902
34927
  info = 'Invalid segment';
34903
34928
  return validRound && validSegment;
34904
34929
  });
34905
- return !validRounds ? false : true;
34930
+ return !!validRounds;
34906
34931
  });
34907
34932
  });
34908
34933
  if (!isValid && !error) {
@@ -35669,11 +35694,9 @@ function getEventMatchUpFormatTiming({ tournamentRecord, matchUpFormats, categor
35669
35694
  .map((definition) => {
35670
35695
  const definitionObject = typeof definition === 'string' ? { matchUpFormat: definition } : definition;
35671
35696
  if (uniqueMatchUpFormats.includes(definitionObject?.matchUpFormat))
35672
- return;
35673
- if (!isValidMatchUpFormat({
35674
- matchUpFormat: definitionObject?.matchUpFormat,
35675
- }))
35676
- return;
35697
+ return undefined;
35698
+ if (!isValidMatchUpFormat({ matchUpFormat: definitionObject?.matchUpFormat }))
35699
+ return undefined;
35677
35700
  uniqueMatchUpFormats.push(definitionObject.matchUpFormat);
35678
35701
  return definitionObject;
35679
35702
  })
@@ -37103,7 +37126,7 @@ function getEvents({ tournamentRecord, withScaleValues, scaleEventType, inContex
37103
37126
  .map((event) => {
37104
37127
  const eventDrawIds = event.drawDefinitions?.map(getDrawId);
37105
37128
  if (drawIds?.length && !intersection(drawIds, eventDrawIds).length)
37106
- return;
37129
+ return undefined;
37107
37130
  const eventCopy = makeDeepCopy(event);
37108
37131
  if (inContext)
37109
37132
  Object.assign(eventCopy, { tournamentId });
@@ -44322,8 +44345,8 @@ function setMatchUpState(params) {
44322
44345
  AWAITING_RESULT,
44323
44346
  ].includes(matchUpStatus)) {
44324
44347
  return {
44325
- error: INVALID_VALUES,
44326
44348
  info: 'Not supported for matchUpType: TEAM',
44349
+ error: INVALID_VALUES,
44327
44350
  };
44328
44351
  }
44329
44352
  const matchUpTieId = inContextMatchUp?.matchUpTieId;
@@ -44341,9 +44364,8 @@ function setMatchUpState(params) {
44341
44364
  winningSide,
44342
44365
  score,
44343
44366
  });
44344
- if (result.error) {
44367
+ if (result.error)
44345
44368
  return result;
44346
- }
44347
44369
  }
44348
44370
  const appliedPolicies = getAppliedPolicies({
44349
44371
  policyTypes: [POLICY_TYPE_PROGRESSION, POLICY_TYPE_SCORING],
@@ -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);
@@ -49661,7 +49683,7 @@ function generateEventWithDraw(params) {
49661
49683
  return paramsCheck;
49662
49684
  const { allUniqueParticipantIds = [], participantsProfile = {}, matchUpStatusProfile, completeAllMatchUps, autoEntryPositions, hydrateCollections, randomWinningSide, ratingsParameters, tournamentRecord, isMock = true, drawProfile, startDate, drawIndex, uuids, } = params;
49663
49685
  const drawProfileCopy = makeDeepCopy(drawProfile, false, true);
49664
- const { excessParticipantAlternates = true, matchUpFormat = FORMAT_STANDARD, drawType = SINGLE_ELIMINATION, tournamentAlternates = 0, alternatesCount = 0, qualifyingPositions, qualifyingProfiles, generate = true, eventExtensions, drawExtensions, completionGoal, tieFormatName, seedsCount, timeItems, drawName, category, idPrefix, publish, gender, stage, } = drawProfileCopy;
49686
+ const { excessParticipantAlternates = true, matchUpFormat = FORMAT_STANDARD, drawType = SINGLE_ELIMINATION, tournamentAlternates = 0, alternatesCount = 0, qualifyingPositions, qualifyingProfiles, generate = true, eventExtensions, drawExtensions, completionGoal, tieFormatName, buildTeams, seedsCount, timeItems, drawName, category, idPrefix, publish, gender, stage, } = drawProfileCopy;
49665
49687
  const drawSize = drawProfileCopy.drawSize || (drawProfileCopy.ignoreDefaults ? undefined : 32);
49666
49688
  const eventId = drawProfileCopy.eventId || UUID();
49667
49689
  const eventType = drawProfile.eventType || drawProfile.matchUpType || SINGLES$1;
@@ -49776,11 +49798,12 @@ function generateEventWithDraw(params) {
49776
49798
  fIndex += genders[FEMALE];
49777
49799
  mIndex += genders[MALE];
49778
49800
  rIndex += mixedCount;
49801
+ const individualParticipantIds = buildTeams !== false ? [...fPIDs, ...mPIDs, ...rIDs] : [];
49779
49802
  return {
49780
- individualParticipantIds: [...fPIDs, ...mPIDs, ...rIDs],
49781
49803
  participantOtherName: `TM${teamIndex + 1}`,
49782
49804
  participantName: `Team ${teamIndex + 1}`,
49783
49805
  participantRole: COMPETITOR,
49806
+ individualParticipantIds,
49784
49807
  participantType: TEAM,
49785
49808
  participantId: UUID(),
49786
49809
  };
@@ -50079,7 +50102,7 @@ function validTimePeriod({ startTime = '', endTime = '' } = {}) {
50079
50102
  const [endHour, endMinute] = endTime.split(':').map(getInt);
50080
50103
  if (endHour < startHour)
50081
50104
  return false;
50082
- return startHour === endHour && endMinute < startMinute ? false : true;
50105
+ return !(startHour === endHour && endMinute < startMinute);
50083
50106
  }
50084
50107
  function startTimeSort(a, b) {
50085
50108
  const [startHourA, startMinuteA] = a.startTime.split(':').map(getInt);
@@ -50436,11 +50459,10 @@ function processLeagueProfiles(params) {
50436
50459
  tournamentRecord.events = [];
50437
50460
  tournamentRecord.events.push(event);
50438
50461
  if (entries.length) {
50439
- const roundsCount = isNumeric(leagueProfile.roundsCount)
50440
- ? leagueProfile.roundsCount
50441
- : leagueProfile.roundsCount === DOUBLE_ROUND_ROBIN
50442
- ? (drawSize - 1) * 2
50443
- : drawSize - 1;
50462
+ const roundsCount = (isNumeric(leagueProfile.roundsCount) && leagueProfile.roundsCount) ??
50463
+ leagueProfile.roundsCount === DOUBLE_ROUND_ROBIN
50464
+ ? (drawSize - 1) * 2
50465
+ : drawSize - 1;
50444
50466
  const result = generateDrawDefinition({
50445
50467
  automated: leagueProfile.automated,
50446
50468
  tournamentRecord,
@@ -50678,6 +50700,8 @@ function anonymizeTournamentRecord({ keepExtensions = [], anonymizeParticipantNa
50678
50700
  tournamentRecord.isMock = true;
50679
50701
  delete tournamentRecord.parentOrganisation;
50680
50702
  for (const participant of tournamentRecord.participants || []) {
50703
+ participant.extensions = filterExtensions(participant);
50704
+ participant.onlineResources = [];
50681
50705
  const newParticipantId = UUID();
50682
50706
  idMap[participant.participantId] = newParticipantId;
50683
50707
  participant.participantId = newParticipantId;
@@ -50689,17 +50713,28 @@ function anonymizeTournamentRecord({ keepExtensions = [], anonymizeParticipantNa
50689
50713
  }
50690
50714
  let venueIndex = 0;
50691
50715
  for (const venue of tournamentRecord.venues || []) {
50716
+ venue.venueAbbreviation = `V${venueIndex}`;
50692
50717
  venue.extensions = filterExtensions(venue);
50693
50718
  venue.venueName = `Venue #${venueIndex}`;
50694
- venue.venueAbbreviation = `V${venueIndex}`;
50719
+ venue.onlineResources = [];
50720
+ venue.addresses = [];
50695
50721
  const newVenueId = UUID();
50696
50722
  idMap[venue.venueId] = newVenueId;
50697
50723
  venue.isMock = true;
50698
50724
  venueIndex += 1;
50725
+ let courtIndex = 0;
50726
+ for (const court of venue.courts || []) {
50727
+ court.courtName = `V${venueIndex}C${courtIndex}`;
50728
+ court.extensions = filterExtensions(court);
50729
+ court.onlineResources = [];
50730
+ court.isMock = true;
50731
+ courtIndex += 1;
50732
+ }
50699
50733
  }
50700
50734
  let eventCount = 1;
50701
50735
  for (const event of tournamentRecord.events || []) {
50702
50736
  event.extensions = filterExtensions(event);
50737
+ event.onlineResources = [];
50703
50738
  event.isMock = true;
50704
50739
  const newEventId = UUID();
50705
50740
  idMap[event.eventId] = newEventId;
@@ -51211,7 +51246,7 @@ function modifyPersonRequests(params) {
51211
51246
  return request;
51212
51247
  const modification = requests.find((updatedRequest) => updatedRequest.requestId === request.requestId);
51213
51248
  if (!modification.requestType)
51214
- return;
51249
+ return undefined;
51215
51250
  return Object.assign(request, modification);
51216
51251
  })
51217
51252
  .filter(Boolean);