tods-competition-factory 2.1.13 → 2.1.15

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.13';
6
+ return '2.1.15';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -9414,46 +9414,6 @@ function scheduledMatchUpDate({ timeStamp, schedule, matchUp }) {
9414
9414
  : schedule;
9415
9415
  }
9416
9416
 
9417
- function matchUpAllocatedCourts({ timeStamp, schedule, matchUp }) {
9418
- const { itemValue: allocatedCourts, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
9419
- timeItems: matchUp?.timeItems || [],
9420
- itemType: ALLOCATE_COURTS,
9421
- });
9422
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
9423
- ? { allocatedCourts: makeDeepCopy(allocatedCourts, false, true) }
9424
- : schedule;
9425
- }
9426
-
9427
- function matchUpAssignedCourtId({ timeStamp, schedule, matchUp }) {
9428
- const { itemValue: courtId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
9429
- timeItems: matchUp?.timeItems || [],
9430
- itemType: ASSIGN_COURT,
9431
- });
9432
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
9433
- ? { courtId }
9434
- : schedule;
9435
- }
9436
-
9437
- function matchUpAssignedVenueId({ timeStamp, schedule, matchUp }) {
9438
- const { itemValue: venueId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
9439
- timeItems: matchUp?.timeItems || [],
9440
- itemType: ASSIGN_VENUE,
9441
- });
9442
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
9443
- ? { venueId }
9444
- : schedule;
9445
- }
9446
-
9447
- function matchUpTimeModifiers({ timeStamp, schedule, matchUp }) {
9448
- const { itemValue: timeModifiers, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
9449
- timeItems: matchUp?.timeItems || [],
9450
- itemType: TIME_MODIFIERS,
9451
- });
9452
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
9453
- ? { timeModifiers }
9454
- : schedule;
9455
- }
9456
-
9457
9417
  function timeDate$1(value) {
9458
9418
  if (validTimeString.test(value)) {
9459
9419
  const dateString = getUTCdateString();
@@ -9523,30 +9483,6 @@ function msToTime(s) {
9523
9483
  return pad((s / 3.6e6) | 0) + ':' + pad(((s % 3.6e6) / 6e4) | 0) + ':' + pad(((s % 6e4) / 1000) | 0);
9524
9484
  }
9525
9485
 
9526
- function matchUpCourtOrder({ timeStamp, schedule, matchUp }) {
9527
- const { itemValue: courtOrder, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
9528
- timeItems: matchUp?.timeItems || [],
9529
- itemType: COURT_ORDER,
9530
- });
9531
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
9532
- ? { courtOrder }
9533
- : schedule;
9534
- }
9535
-
9536
- function getHomeParticipantId(params) {
9537
- const { timeStamp, schedule, matchUp } = params;
9538
- const paramsCheck = checkRequiredParameters(params, [{ [MATCHUP]: true }]);
9539
- if (paramsCheck.error)
9540
- return paramsCheck;
9541
- const { itemValue: homeParticipantId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
9542
- timeItems: matchUp?.timeItems || [],
9543
- itemType: HOME_PARTICIPANT_ID,
9544
- });
9545
- return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
9546
- ? { homeParticipantId }
9547
- : schedule;
9548
- }
9549
-
9550
9486
  function matchUpStartTime({ matchUp }) {
9551
9487
  const timeItems = matchUp?.timeItems || [];
9552
9488
  const getTimeStamp = (item) => (!item.createdAt ? 0 : new Date(item.createdAt).getTime());
@@ -9716,11 +9652,14 @@ function getCourtInfo({ tournamentRecord, internalUse, courtId }) {
9716
9652
  return { ...SUCCESS, courtInfo: makeDeepCopy(courtInfo, false, internalUse) };
9717
9653
  }
9718
9654
 
9719
- function getVenueData({ tournamentRecord, venueId }) {
9720
- if (!tournamentRecord)
9721
- return { error: MISSING_TOURNAMENT_RECORD };
9722
- if (!venueId)
9723
- return { error: MISSING_VENUE_ID };
9655
+ function getVenueData(params) {
9656
+ const paramsCheck = checkRequiredParameters(params, [
9657
+ { [TOURNAMENT_RECORD]: true },
9658
+ { venueId: true, [ERROR]: MISSING_VENUE_ID },
9659
+ ]);
9660
+ if (paramsCheck.error)
9661
+ return paramsCheck;
9662
+ const { tournamentRecord, venueId } = params;
9724
9663
  const result = findVenue({ tournamentRecord, venueId });
9725
9664
  if (result.error)
9726
9665
  return result;
@@ -9879,15 +9818,21 @@ function getMatchUpScheduleDetails(params) {
9879
9818
  let schedule;
9880
9819
  const { eventIds, drawIds } = scheduleVisibilityFilters ?? {};
9881
9820
  if ((!eventIds || eventIds.includes(matchUp.eventId)) && (!drawIds || drawIds.includes(matchUp.drawId))) {
9882
- const scheduleSource = { matchUp };
9883
- const { allocatedCourts } = matchUpAllocatedCourts(scheduleSource);
9884
- const { homeParticipantId } = getHomeParticipantId(scheduleSource);
9885
- const { scheduledTime } = scheduledMatchUpTime(scheduleSource);
9886
- const { timeModifiers } = matchUpTimeModifiers(scheduleSource);
9887
- let { scheduledDate } = scheduledMatchUpDate(scheduleSource);
9888
- const { venueId } = matchUpAssignedVenueId(scheduleSource);
9889
- const { courtId } = matchUpAssignedCourtId(scheduleSource);
9890
- const { courtOrder } = matchUpCourtOrder(scheduleSource);
9821
+ const getTimeStamp = (item) => (!item.createdAt ? 0 : new Date(item.createdAt).getTime());
9822
+ const timeItemMap = new Map();
9823
+ const sortedTimeItems = matchUp.timeItems?.toSorted((a, b) => getTimeStamp(a) - getTimeStamp(b)) ?? [];
9824
+ for (const timeItem of sortedTimeItems) {
9825
+ timeItemMap.set(timeItem.itemType, timeItem.itemValue);
9826
+ }
9827
+ const homeParticipantId = timeItemMap.get(HOME_PARTICIPANT_ID);
9828
+ const allocatedCourts = timeItemMap.get(ALLOCATE_COURTS);
9829
+ const scheduledTime = timeItemMap.get(SCHEDULED_TIME);
9830
+ const timeModifiers = timeItemMap.get(TIME_MODIFIERS);
9831
+ let scheduledDate = timeItemMap.get(SCHEDULED_DATE);
9832
+ const official = timeItemMap.get(ASSIGN_OFFICIAL);
9833
+ const courtOrder = timeItemMap.get(COURT_ORDER);
9834
+ const venueId = timeItemMap.get(ASSIGN_VENUE);
9835
+ const courtId = timeItemMap.get(ASSIGN_COURT);
9891
9836
  let timeAfterRecovery, averageMinutes, recoveryMinutes, typeChangeRecoveryMinutes, typeChangeTimeAfterRecovery;
9892
9837
  const eventType = matchUp.matchUpType ?? matchUpType;
9893
9838
  if (scheduleTiming && scheduledTime && afterRecoveryTimes && eventType) {
@@ -9944,15 +9889,16 @@ function getMatchUpScheduleDetails(params) {
9944
9889
  scheduledDate,
9945
9890
  scheduledTime,
9946
9891
  isoDateString,
9947
- allocatedCourts,
9948
9892
  homeParticipantId,
9949
- timeModifiers,
9950
9893
  venueAbbreviation,
9894
+ allocatedCourts,
9895
+ timeModifiers,
9951
9896
  venueName,
9952
9897
  venueId,
9953
9898
  courtOrder,
9954
9899
  courtName,
9955
9900
  courtId,
9901
+ official,
9956
9902
  typeChangeRecoveryMinutes,
9957
9903
  recoveryMinutes,
9958
9904
  averageMinutes,
@@ -10549,6 +10495,36 @@ function addMatchUpContext({ scheduleVisibilityFilters, sourceDrawPositionRanges
10549
10495
  return matchUpWithContext;
10550
10496
  }
10551
10497
 
10498
+ function matchUpAllocatedCourts({ timeStamp, schedule, matchUp }) {
10499
+ const { itemValue: allocatedCourts, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
10500
+ timeItems: matchUp?.timeItems || [],
10501
+ itemType: ALLOCATE_COURTS,
10502
+ });
10503
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
10504
+ ? { allocatedCourts: makeDeepCopy(allocatedCourts, false, true) }
10505
+ : schedule;
10506
+ }
10507
+
10508
+ function matchUpAssignedCourtId({ timeStamp, schedule, matchUp }) {
10509
+ const { itemValue: courtId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
10510
+ timeItems: matchUp?.timeItems || [],
10511
+ itemType: ASSIGN_COURT,
10512
+ });
10513
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
10514
+ ? { courtId }
10515
+ : schedule;
10516
+ }
10517
+
10518
+ function matchUpAssignedVenueId({ timeStamp, schedule, matchUp }) {
10519
+ const { itemValue: venueId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
10520
+ timeItems: matchUp?.timeItems || [],
10521
+ itemType: ASSIGN_VENUE,
10522
+ });
10523
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
10524
+ ? { venueId }
10525
+ : schedule;
10526
+ }
10527
+
10552
10528
  function filterMatchUps(params) {
10553
10529
  if (!Array.isArray(params.matchUps))
10554
10530
  return [];
@@ -12251,10 +12227,13 @@ function pushGlobalLog(value, devContextOverride) {
12251
12227
  }
12252
12228
  function getGlobalLog(purge) {
12253
12229
  const globalLogCopy = globalLog.slice();
12230
+ if (purge) {
12231
+ globalLog.length = 0;
12232
+ }
12254
12233
  return globalLogCopy;
12255
12234
  }
12256
12235
  function printGlobalLog(purge) {
12257
- const globalLogCopy = getGlobalLog();
12236
+ const globalLogCopy = getGlobalLog(purge);
12258
12237
  const modifiedText = globalLogCopy.map((line) => {
12259
12238
  const { color, keyColors, method, newline } = line;
12260
12239
  const methodColor = Object.keys(logColors).includes(color) ? logColors[color] : logColors.cyan;
@@ -13774,7 +13753,7 @@ function processSides(params) {
13774
13753
  }
13775
13754
 
13776
13755
  function getParticipantEntries(params) {
13777
- const { participantFilters, convertExtensions, policyDefinitions, tournamentRecord, usePublishState, contextProfile, participantMap, withPotentialMatchUps, withRankingProfile, withScheduleItems, scheduleAnalysis, withTeamMatchUps, withStatistics, withOpponents, withMatchUps, withSeeding, withEvents, withDraws, } = params;
13756
+ const { participantFilters, convertExtensions, policyDefinitions, tournamentRecord, usePublishState, participantMap, contextProfile, withPotentialMatchUps, withRankingProfile, withScheduleItems, scheduleAnalysis, withTeamMatchUps, withStatistics, withOpponents, withMatchUps, withSeeding, withEvents, withDraws, } = params;
13778
13757
  const targetParticipantIds = participantFilters?.participantIds;
13779
13758
  const getRelevantParticipantIds = (participantId) => {
13780
13759
  const relevantParticipantIds = [participantId];
@@ -13888,10 +13867,8 @@ function getParticipantEntries(params) {
13888
13867
  const assignedParticipantIds = structures
13889
13868
  .filter(({ stage, stageSequence }) => (stage === MAIN && stageSequence === 1) || stage === QUALIFYING)
13890
13869
  .flatMap((structure) => {
13870
+ const { positionAssignments } = getPositionAssignments$1({ structure });
13891
13871
  const { seedAssignments, stageSequence, stage } = structure;
13892
- const { positionAssignments } = getPositionAssignments$1({
13893
- structure,
13894
- });
13895
13872
  if (stage === MAIN) {
13896
13873
  drawSize = positionAssignments?.length ?? 0;
13897
13874
  mainPositionAssignments = positionAssignments;
@@ -19134,9 +19111,7 @@ function automatedPositioning(params) {
19134
19111
  }
19135
19112
 
19136
19113
  function automatedPlayoffPositioning(params) {
19137
- const { applyPositioning = true, provisionalPositioning, tournamentRecord, drawDefinition, seedingProfile, structureId, placeByes, seedsOnly, event, } = params;
19138
- if (!event)
19139
- return { error: EVENT_NOT_FOUND };
19114
+ const { applyPositioning = true, provisionalPositioning, tournamentRecord, drawDefinition, seedingProfile, structureId, placeByes, seedsOnly, } = params;
19140
19115
  if (!drawDefinition)
19141
19116
  return { error: DRAW_DEFINITION_NOT_FOUND };
19142
19117
  const structureIsComplete = isCompletedStructure({
@@ -20880,7 +20855,7 @@ function availablePlayoffProfiles({ playoffPositions, drawDefinition, structure,
20880
20855
  function getPositionRangeMap({ playoffGroups, drawDefinition, structureId }) {
20881
20856
  if (!drawDefinition)
20882
20857
  return { error: MISSING_DRAW_DEFINITION };
20883
- if (typeof structureId !== 'string' || !Array.isArray(playoffGroups)) {
20858
+ if (!isString(structureId) || !Array.isArray(playoffGroups)) {
20884
20859
  return { error: INVALID_VALUES };
20885
20860
  }
20886
20861
  const playoffGroupFinishingPostions = playoffGroups.map(({ finishingPositions }) => finishingPositions).flat();
@@ -21491,7 +21466,7 @@ function generateAndPopulateRRplayoffStructures(params) {
21491
21466
  });
21492
21467
  }
21493
21468
  const { sourceStructureId, requireSequential, tournamentRecord, drawDefinition, playoffGroups, groupCount, groupSize, event, } = params;
21494
- const { structures: playoffStructures = [], links: playoffLinks = [], finishingPositionTargets, positionRangeMap, error, } = processPlayoffGroups({
21469
+ const processResult = processPlayoffGroups({
21495
21470
  requireSequential,
21496
21471
  sourceStructureId,
21497
21472
  playoffGroups,
@@ -21499,8 +21474,9 @@ function generateAndPopulateRRplayoffStructures(params) {
21499
21474
  groupSize,
21500
21475
  ...params,
21501
21476
  });
21502
- if (error)
21503
- return { error };
21477
+ if (processResult.error)
21478
+ return decorateResult({ result: processResult, stack });
21479
+ const { structures: playoffStructures = [], links: playoffLinks = [], finishingPositionTargets, positionRangeMap, } = processResult;
21504
21480
  const positionsPlayedOff = finishingPositionTargets
21505
21481
  ?.map(({ finishingPositions }) => finishingPositions)
21506
21482
  .flat()
@@ -28715,10 +28691,14 @@ function generateScoreString(params) {
28715
28691
  return `[${tiebreakScore.join('-')}]`;
28716
28692
  }
28717
28693
  const lowTiebreakScore = Math.min(t1, t2);
28694
+ const lowTiebreakSide = lowTiebreakScore === t1 ? 1 : 2;
28718
28695
  const tiebreak = lowTiebreakScore ? `(${lowTiebreakScore})` : '';
28719
28696
  const s1 = side1Score || (isNumeric(side1Score) || autoComplete ? 0 : '');
28720
28697
  const s2 = side2Score || (isNumeric(side2Score) || autoComplete ? 0 : '');
28721
- let scoreString = reverseScores ? `${[s2, s1].join('-')}${tiebreak}` : `${[s1, s2].join('-')}${tiebreak}`;
28698
+ const includeTiebreak = (sideNumber) => (lowTiebreakSide === sideNumber ? tiebreak : '');
28699
+ const ss1 = `${s1}${includeTiebreak(1)}`;
28700
+ const ss2 = `${s2}${includeTiebreak(2)}`;
28701
+ let scoreString = reverseScores ? `${[ss2, ss1].join('-')}` : `${[ss1, ss2].join('-')}`;
28722
28702
  if (['-', ' '].includes(scoreString))
28723
28703
  scoreString = '';
28724
28704
  return scoreString;
@@ -29361,13 +29341,14 @@ function getMatchUpWinner({ matchUpFormat, matchUpStatus, winningSide, sets }) {
29361
29341
  return { matchUpWinningSide };
29362
29342
  }
29363
29343
 
29364
- function checkSetIsComplete({ ignoreTiebreak = false, matchUpScoringFormat, matchUpFormat, isTiebreakSet, isDecidingSet, set, }) {
29344
+ function checkSetIsComplete({ ignoreTiebreak = false, matchUpScoringFormat, matchUpFormat, isTiebreakSet, isDecidingSet, isTimedSet, set, }) {
29365
29345
  if (!set)
29366
29346
  return { error: MISSING_VALUE, info: 'missing set' };
29367
29347
  matchUpScoringFormat = matchUpScoringFormat || (matchUpFormat && parse(matchUpFormat));
29368
29348
  const setFormat = (isDecidingSet && matchUpScoringFormat.finalSetFormat) || matchUpScoringFormat?.setFormat || {};
29369
29349
  const { side1Score, side2Score } = set;
29370
29350
  const { setTo, tiebreakAt } = setFormat;
29351
+ const hasScore = side1Score || side2Score;
29371
29352
  const leadingSide = getLeadingSide({ set });
29372
29353
  const scoreDiff = Math.abs(side1Score - side2Score);
29373
29354
  const containsSetTo = side1Score >= setTo || side2Score >= setTo;
@@ -29383,7 +29364,8 @@ function checkSetIsComplete({ ignoreTiebreak = false, matchUpScoringFormat, matc
29383
29364
  : 2;
29384
29365
  const hasWinMargin = scoreDiff >= winMargin;
29385
29366
  const validNormalSetScore = containsSetTo && (hasWinMargin || requiresTiebreak);
29386
- return !!((validNormalSetScore || isTiebreakSet) && (!requiresTiebreak || tiebreakIsValid));
29367
+ return !!(((isTimedSet && hasScore) || validNormalSetScore || isTiebreakSet) &&
29368
+ (!requiresTiebreak || tiebreakIsValid));
29387
29369
  }
29388
29370
  function getLeadingSide({ set }) {
29389
29371
  if (set.side1Score || set.side2Score) {
@@ -31919,18 +31901,17 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '' }) {
31919
31901
  .filter(Boolean)
31920
31902
  .map((set, index) => parseSet({ set, setNumber: index + 1 }));
31921
31903
  function parseSet({ set, setNumber }) {
31922
- const matchTiebreak = set?.startsWith('[') &&
31923
- set
31924
- .split('[')[1]
31925
- .split(']')[0]
31926
- .split('-')
31927
- .map((sideScore) => parseInt(sideScore));
31928
- const setString = (set.includes('(') && set.split('(')[0]) || (set.includes('[') && set.split('[')[0]) || set;
31904
+ const inParentheses = /\(([^)]+)\)/;
31905
+ const inBrackets = /\[([^)]+)\]/;
31906
+ const tiebreak = inParentheses.exec(set);
31907
+ const supertiebreak = inBrackets.exec(set);
31908
+ const matchTiebreak = set?.startsWith('[') && supertiebreak && supertiebreak[1].split('-').map((sideScore) => parseInt(sideScore));
31909
+ const setString = (tiebreak && set.replace(tiebreak[0], '')) || (supertiebreak && set.replace(supertiebreak[0], '')) || set;
31929
31910
  const setScores = !matchTiebreak && setString.split('-').map((sideScore) => parseInt(sideScore));
31930
31911
  const winningSide = matchTiebreak
31931
31912
  ? (matchTiebreak[0] > matchTiebreak[1] && 1) || (matchTiebreak[0] < matchTiebreak[1] && 2) || undefined
31932
31913
  : (setScores[0] > setScores[1] && 1) || (setScores[0] < setScores[1] && 2) || undefined;
31933
- const setTiebreakLowScore = set.includes('(') ? set.split('(')[1].split(')')[0] : undefined;
31914
+ const setTiebreakLowScore = tiebreak ? tiebreak[1] : undefined;
31934
31915
  const side1TiebreakPerspective = setTiebreakLowScore &&
31935
31916
  getTiebreakComplement({
31936
31917
  lowValue: setTiebreakLowScore,
@@ -31951,7 +31932,7 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '' }) {
31951
31932
  }
31952
31933
  }
31953
31934
 
31954
- function getSetWinningSide({ matchUpScoringFormat, isDecidingSet, isTiebreakSet, setObject, }) {
31935
+ function getSetWinningSide({ matchUpScoringFormat, isDecidingSet, isTiebreakSet, isTimedSet, setObject, }) {
31955
31936
  if (!setObject)
31956
31937
  return undefined;
31957
31938
  const leadingSide = getLeadingSide({ set: setObject });
@@ -31960,6 +31941,7 @@ function getSetWinningSide({ matchUpScoringFormat, isDecidingSet, isTiebreakSet,
31960
31941
  set: setObject,
31961
31942
  isDecidingSet,
31962
31943
  isTiebreakSet,
31944
+ isTimedSet,
31963
31945
  });
31964
31946
  return (setIsComplete && leadingSide) || undefined;
31965
31947
  }
@@ -31969,13 +31951,14 @@ function analyzeSet(params) {
31969
31951
  if (!setObject)
31970
31952
  return { error: MISSING_SET_OBJECT };
31971
31953
  const { setNumber } = setObject || {};
31972
- const { bestOf } = matchUpScoringFormat || {};
31973
- const isDecidingSet = !!(setNumber && bestOf && setNumber === bestOf);
31954
+ const { bestOf, exactly } = matchUpScoringFormat || {};
31955
+ const maxSetNumber = bestOf || exactly;
31956
+ const isDecidingSet = !!(setNumber && maxSetNumber && setNumber === maxSetNumber);
31974
31957
  const setFormat = (isDecidingSet && matchUpScoringFormat?.finalSetFormat) || matchUpScoringFormat?.setFormat;
31975
31958
  const expectTiebreakSet = !!setFormat?.tiebreakSet;
31976
31959
  const expectTimedSet = !!setFormat?.timed;
31977
31960
  const expectStandardSet = !expectTiebreakSet && !expectTimedSet;
31978
- const isValidSetNumber = !!(setNumber && bestOf && setNumber <= bestOf);
31961
+ const isValidSetNumber = !!(setNumber && maxSetNumber && setNumber <= maxSetNumber);
31979
31962
  const sideGameScores = [setObject?.side1Score, setObject?.side2Score];
31980
31963
  const sidePointScores = [setObject?.side1PointScore, setObject?.side2PointScore];
31981
31964
  const sideTiebreakScores = [setObject?.side1TiebreakScore, setObject?.side2TiebreakScore];
@@ -31991,26 +31974,28 @@ function analyzeSet(params) {
31991
31974
  const isTiebreakSet = !!(tiebreakScoresCount && !gameScoresCount);
31992
31975
  const isCompletedSet = !!setObject?.winningSide;
31993
31976
  const { error: standardSetError, result: isValidStandardSetOutcome } = checkValidStandardSetOutcome({
31994
- setObject,
31995
- setFormat,
31996
- sideGameScores,
31997
31977
  sideTiebreakScores,
31978
+ sideGameScores,
31979
+ setFormat,
31980
+ setObject,
31998
31981
  });
31999
31982
  const { error: tiebreakSetError, result: isValidTiebreakSetOutcome } = checkValidTiebreakSetOutcome({
31983
+ sideTiebreakScores,
32000
31984
  setObject,
32001
31985
  setFormat,
32002
- sideTiebreakScores,
32003
31986
  });
32004
31987
  const isValidSetOutcome = (expectStandardSet && !isTiebreakSet && isValidStandardSetOutcome) ||
32005
- (expectTiebreakSet && isTiebreakSet && isValidTiebreakSetOutcome);
31988
+ (expectTiebreakSet && isTiebreakSet && isValidTiebreakSetOutcome) ||
31989
+ expectTimedSet;
32006
31990
  const isValidSet = isValidSetNumber &&
32007
31991
  !(expectTiebreakSet && !isTiebreakSet) &&
32008
31992
  !(expectStandardSet && isTiebreakSet) &&
32009
31993
  (!isCompletedSet || isValidSetOutcome);
32010
31994
  const winningSide = getSetWinningSide({
31995
+ isTimedSet: expectTimedSet,
31996
+ matchUpScoringFormat,
32011
31997
  isDecidingSet,
32012
31998
  isTiebreakSet,
32013
- matchUpScoringFormat,
32014
31999
  setObject,
32015
32000
  });
32016
32001
  const analysis = {
@@ -33807,35 +33792,115 @@ function getAggregateTeamResults(params) {
33807
33792
  const paramsCheck = checkRequiredParameters(params, [{ [TOURNAMENT_RECORD]: true }]);
33808
33793
  if (paramsCheck.error)
33809
33794
  return paramsCheck;
33795
+ const bonusPoints = params.finishingPositionRangeBounsPoints || {};
33796
+ const teamBonusPointHashes = {};
33797
+ const getTeamParticipant = (participant) => {
33798
+ const individualTeams = participant?.individualParticipants?.map((i) => i.teams?.length === 1 && i.teams[0]);
33799
+ return ((participant?.teams?.length === 1 && participant?.teams?.[0]) ||
33800
+ (individualTeams?.[0].participantId === individualTeams?.[1].participantId && individualTeams?.[0]));
33801
+ };
33802
+ const { matchUps, participants } = getParticipants({
33803
+ participantFilters: { participantTypes: [INDIVIDUAL] },
33804
+ withRankingProfile: true,
33805
+ withStatistics: true,
33806
+ ...params,
33807
+ });
33808
+ for (const participant of participants ?? []) {
33809
+ if (participant.participantType === TEAM_PARTICIPANT)
33810
+ continue;
33811
+ if (participant.draws?.[0]?.drawId === 'draw-0-3') {
33812
+ console.log(participant.participantType, participant.draws[0].finishingPositionRange);
33813
+ }
33814
+ const teamParticipant = getTeamParticipant(participant);
33815
+ if (!teamParticipant)
33816
+ continue;
33817
+ for (const draw of participant?.draws ?? []) {
33818
+ const finishingPositionRange = draw?.finishingPositionRange?.join('-');
33819
+ if (finishingPositionRange && bonusPoints?.[finishingPositionRange]) {
33820
+ const teamParticipantId = teamParticipant?.participantId;
33821
+ const drawId = draw?.drawId;
33822
+ const hash = `${teamParticipantId}|${drawId}|${finishingPositionRange}`;
33823
+ teamBonusPointHashes[hash] = bonusPoints[finishingPositionRange];
33824
+ }
33825
+ }
33826
+ }
33827
+ const initializeResults = (teamName) => ({
33828
+ teamName,
33829
+ standingPoints: 0,
33830
+ pointsPlayed: 0,
33831
+ pointsPct: 0,
33832
+ points: 0,
33833
+ bonus: 0,
33834
+ diff: 0,
33835
+ loss: 0,
33836
+ win: 0,
33837
+ });
33838
+ const increment = (results, key, value) => {
33839
+ if (results[key] === undefined)
33840
+ results[key] = 0;
33841
+ results[key] += value;
33842
+ };
33843
+ const individualResults = {};
33810
33844
  const teamResults = {};
33811
- for (const matchUp of allTournamentMatchUps(params)?.matchUps ?? []) {
33845
+ for (const matchUp of matchUps ?? []) {
33812
33846
  const { sides, matchUpFormat } = matchUp;
33813
33847
  const parsedMatchUpFormat = matchUpFormat && parse(matchUpFormat);
33814
33848
  if (sides?.length === 2 &&
33815
33849
  parsedMatchUpFormat.setFormat?.timed &&
33816
33850
  (!parsedMatchUpFormat.finalSetFormat || parsedMatchUpFormat.finalSetFormat?.timed)) {
33817
33851
  for (const side of sides) {
33818
- const individualTeams = side?.participant?.individualParticipants?.map((i) => i.teams?.length === 1 && i.teams[0]);
33819
- const teamParticipant = (side?.participant?.teams?.length === 1 && side?.participant?.teams?.[0]) ||
33820
- (individualTeams?.[0].participantId === individualTeams?.[1].participantId && individualTeams?.[0]);
33852
+ const teamParticipant = getTeamParticipant(side.participant);
33821
33853
  const teamParticipantId = teamParticipant?.participantId;
33854
+ const participantId = side.participant?.participantId;
33855
+ const teamName = teamParticipant?.participantName;
33822
33856
  const sideNumber = side.sideNumber;
33857
+ const individualParticipantIds = side.participant?.individualParticipantIds || (participantId && [participantId]) || [];
33858
+ individualParticipantIds.forEach((individualParticipantId) => {
33859
+ if (individualParticipantId && !individualResults[individualParticipantId]) {
33860
+ individualResults[individualParticipantId] = initializeResults(teamName);
33861
+ }
33862
+ });
33823
33863
  if (teamParticipantId && sideNumber) {
33824
- if (!teamResults[teamParticipantId]) {
33825
- teamResults[teamParticipantId] = { score: 0, diff: 0, teamName: teamParticipant.participantName };
33864
+ if (!teamResults[teamParticipantId])
33865
+ teamResults[teamParticipantId] = initializeResults(teamName);
33866
+ const resultObjects = [
33867
+ ...individualParticipantIds.map((id) => individualResults[id]),
33868
+ teamResults[teamParticipantId],
33869
+ ];
33870
+ if (matchUp.winningSide) {
33871
+ if (sideNumber === matchUp.winningSide) {
33872
+ resultObjects.forEach((resultObject) => increment(resultObject, 'win', 1));
33873
+ }
33874
+ else {
33875
+ resultObjects.forEach((resultObject) => increment(resultObject, 'loss', 1));
33876
+ }
33826
33877
  }
33827
- for (const set of matchUp.score?.sets ?? []) {
33878
+ const sets = matchUp.score?.sets || [];
33879
+ for (const set of sets) {
33828
33880
  const opponentPoints = set?.[`side${3 - sideNumber}Score`] || 0;
33829
33881
  const points = set?.[`side${sideNumber}Score`] || 0;
33830
33882
  const diff = points - opponentPoints;
33831
- teamResults[teamParticipantId].score += points;
33832
- teamResults[teamParticipantId].diff += diff;
33883
+ resultObjects.forEach((resultObject) => increment(resultObject, 'pointsPlayed', points + opponentPoints));
33884
+ resultObjects.forEach((resultObject) => increment(resultObject, 'points', points));
33885
+ resultObjects.forEach((resultObject) => increment(resultObject, 'diff', diff));
33833
33886
  }
33834
33887
  }
33835
33888
  }
33836
33889
  }
33837
33890
  }
33838
- return { ...SUCCESS, teamResults };
33891
+ for (const hash of Object.keys(teamBonusPointHashes)) {
33892
+ const [teamParticipantId] = hash.split('|');
33893
+ if (teamResults[teamParticipantId]) {
33894
+ teamResults[teamParticipantId].bonus += teamBonusPointHashes[hash];
33895
+ teamResults[teamParticipantId].pointsPct = parseFloat((teamResults[teamParticipantId].points / teamResults[teamParticipantId].pointsPlayed).toFixed(2));
33896
+ teamResults[teamParticipantId].standingPoints =
33897
+ teamResults[teamParticipantId].win + teamResults[teamParticipantId].bonus;
33898
+ }
33899
+ }
33900
+ for (const individualParticipantId of Object.keys(individualResults)) {
33901
+ individualResults[individualParticipantId].pointsPct = parseFloat((individualResults[individualParticipantId].points / individualResults[individualParticipantId].pointsPlayed).toFixed(2));
33902
+ }
33903
+ return { ...SUCCESS, individualResults, teamResults };
33839
33904
  }
33840
33905
 
33841
33906
  function checkIsDual(tournamentRecord) {
@@ -34961,13 +35026,12 @@ function getEventData(params) {
34961
35026
  })
34962
35027
  .filter((drawData) => drawData.structures?.length)
34963
35028
  : undefined;
34964
- const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
34965
- const venues = tournamentRecord.venues || [];
35029
+ const venues = Array.isArray(tournamentRecord.venues) ? tournamentRecord.venues : [];
34966
35030
  const venuesData = venues.map((venue) => (({ venueData }) => ({
34967
35031
  ...venueData,
34968
35032
  }))(getVenueData({
34969
- tournamentRecord,
34970
35033
  venueId: venue.venueId,
35034
+ tournamentRecord,
34971
35035
  })));
34972
35036
  const eventInfo = (({ eventId, eventName, eventType, eventLevel, surfaceCategory, matchUpFormat, category, gender, startDate, endDate, ballType, discipline, }) => ({
34973
35037
  eventId,
@@ -34987,6 +35051,7 @@ function getEventData(params) {
34987
35051
  element: event,
34988
35052
  name: DISPLAY,
34989
35053
  }).extension?.value;
35054
+ const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
34990
35055
  const eventData = {
34991
35056
  tournamentInfo,
34992
35057
  venuesData,
@@ -35011,6 +35076,87 @@ var query$5 = {
35011
35076
  getVenueData: getVenueData
35012
35077
  };
35013
35078
 
35079
+ function processNextMatchUps({ matchUpPotentialParticipantIds, matchUpNotBeforeTimes, timeAfterRecovery, matchUp, }) {
35080
+ const { individualParticipantIds } = getIndividualParticipantIds(matchUp);
35081
+ timeAfterRecovery = timeAfterRecovery ?? matchUp.schedule?.timeAfterRecovery;
35082
+ const addPotentialParticipantIds = (targetMatchUpId) => {
35083
+ if (!matchUpPotentialParticipantIds[targetMatchUpId])
35084
+ matchUpPotentialParticipantIds[targetMatchUpId] = [];
35085
+ matchUpPotentialParticipantIds[targetMatchUpId] = unique(matchUpPotentialParticipantIds[targetMatchUpId].concat(...individualParticipantIds));
35086
+ };
35087
+ const updateNotBeforeTime = (matchUpId) => {
35088
+ if (timeAfterRecovery &&
35089
+ (!matchUpNotBeforeTimes[matchUpId] || timeAfterRecovery > matchUpNotBeforeTimes[matchUpId])) {
35090
+ matchUpNotBeforeTimes[matchUpId] = timeAfterRecovery;
35091
+ }
35092
+ };
35093
+ const winnerMatchUpId = matchUp.winnerTo?.matchUpId || matchUp.winnerMatchUpId;
35094
+ if (winnerMatchUpId) {
35095
+ timeAfterRecovery && updateNotBeforeTime(winnerMatchUpId);
35096
+ addPotentialParticipantIds(winnerMatchUpId);
35097
+ }
35098
+ const loserMatchUpId = matchUp.loserTo?.matchUpId || matchUp.loserMatchUpId;
35099
+ if (loserMatchUpId) {
35100
+ timeAfterRecovery && updateNotBeforeTime(loserMatchUpId);
35101
+ addPotentialParticipantIds(loserMatchUpId);
35102
+ }
35103
+ if (matchUp.sidesTo?.length) {
35104
+ matchUp.sidesTo.forEach(({ matchUpId }) => {
35105
+ if (matchUpId) {
35106
+ timeAfterRecovery && updateNotBeforeTime(matchUpId);
35107
+ addPotentialParticipantIds(matchUpId);
35108
+ }
35109
+ });
35110
+ }
35111
+ }
35112
+
35113
+ function getMatchUpsToSchedule(params) {
35114
+ const paramsCheck = checkRequiredParameters(params, [{ [MATCHUPS]: true }]);
35115
+ if (paramsCheck.error)
35116
+ return paramsCheck;
35117
+ const { matchUpPotentialParticipantIds, scheduleCompletedMatchUps, dateScheduledMatchUpIds, matchUpNotBeforeTimes, matchUpScheduleTimes, orderedMatchUpIds, clearDate, matchUps, } = params;
35118
+ const alreadyScheduledMatchUpIds = Object.keys(matchUpScheduleTimes);
35119
+ const matchUpsToSchedule = (orderedMatchUpIds ?? [])
35120
+ .map((matchUpId) => matchUps.find((matchUp) => matchUp.matchUpId === matchUpId))
35121
+ .filter(Boolean)
35122
+ .filter((matchUp) => {
35123
+ const alreadyScheduled = !clearDate &&
35124
+ (dateScheduledMatchUpIds.includes(matchUp.matchUpId) || alreadyScheduledMatchUpIds.includes(matchUp.matchUpId));
35125
+ const doNotSchedule = [
35126
+ BYE,
35127
+ DEFAULTED,
35128
+ COMPLETED$1,
35129
+ ABANDONED$1,
35130
+ RETIRED$1,
35131
+ WALKOVER$2,
35132
+ DOUBLE_WALKOVER,
35133
+ DOUBLE_DEFAULT,
35134
+ ].includes(matchUp?.matchUpStatus);
35135
+ return (scheduleCompletedMatchUps ||
35136
+ (!alreadyScheduled && !matchUp.winningSide && !doNotSchedule));
35137
+ });
35138
+ const matchUpMap = matchUpPotentialParticipantIds && matchUpNotBeforeTimes
35139
+ ? matchUpsToSchedule.reduce((aggregator, matchUp) => {
35140
+ const { drawId, tournamentId } = matchUp;
35141
+ if (!aggregator.matchUpMap[tournamentId])
35142
+ aggregator.matchUpMap[tournamentId] = {};
35143
+ if (!aggregator.matchUpMap[tournamentId][drawId]) {
35144
+ aggregator.matchUpMap[tournamentId][drawId] = [matchUp];
35145
+ }
35146
+ else {
35147
+ aggregator.matchUpMap[tournamentId][drawId].push(matchUp);
35148
+ }
35149
+ processNextMatchUps({
35150
+ matchUpPotentialParticipantIds,
35151
+ matchUpNotBeforeTimes,
35152
+ matchUp,
35153
+ });
35154
+ return aggregator;
35155
+ }, { matchUpMap: {} }).matchUpMap
35156
+ : {};
35157
+ return { matchUpsToSchedule, matchUpMap };
35158
+ }
35159
+
35014
35160
  function findMatchUpFormatTiming({ defaultRecoveryMinutes = 0, defaultAverageMinutes, tournamentRecords, matchUpFormat, categoryName, categoryType, tournamentId, eventType, eventId, }) {
35015
35161
  if (!isValidMatchUpFormat({ matchUpFormat }))
35016
35162
  return { error: UNRECOGNIZED_MATCHUP_FORMAT };
@@ -35038,23 +35184,27 @@ function findMatchUpFormatTiming({ defaultRecoveryMinutes = 0, defaultAverageMin
35038
35184
  };
35039
35185
  }
35040
35186
 
35041
- function getScheduledRoundsDetails({ scheduleCompletedMatchUps, containedStructureIds, tournamentRecords, periodLength = 30, matchUps, rounds, }) {
35187
+ function getScheduledRoundsDetails(params) {
35188
+ const paramsCheck = checkRequiredParameters(params, [
35189
+ { [ANY_OF]: { tournamentRecords: false, tournamentRecord: false } },
35190
+ { rounds: true, [OF_TYPE]: ARRAY },
35191
+ ]);
35192
+ if (paramsCheck.error)
35193
+ return paramsCheck;
35194
+ const { scheduleCompletedMatchUps, periodLength = 30 } = params;
35195
+ const tournamentRecords = params.tournamentRecords ||
35196
+ (params.tournamentRecord && {
35197
+ [params.tournamentRecord.tournamentId]: params.tournamentRecord,
35198
+ }) ||
35199
+ {};
35042
35200
  if (typeof tournamentRecords !== 'object')
35043
35201
  return { error: MISSING_TOURNAMENT_RECORDS };
35044
- if (!Array.isArray(rounds))
35045
- return { error: MISSING_VALUE, info: mustBeAnArray('rounds') };
35046
35202
  const matchUpFormatCohorts = {};
35047
35203
  const orderedMatchUpIds = [];
35048
- rounds.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0));
35049
- containedStructureIds =
35050
- containedStructureIds ??
35051
- Object.assign({}, ...Object.values(tournamentRecords).map((tournamentRecord) => getContainedStructures({ tournamentRecord }).containedStructures));
35052
- if (!matchUps) {
35053
- ({ matchUps } = allCompetitionMatchUps({
35054
- nextMatchUps: true,
35055
- tournamentRecords,
35056
- }));
35057
- }
35204
+ const rounds = params.rounds.toSorted((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0));
35205
+ const containedStructureIds = params.containedStructureIds ??
35206
+ Object.assign({}, ...Object.values(tournamentRecords).map((tournamentRecord) => getContainedStructures({ tournamentRecord }).containedStructures));
35207
+ const matchUps = params.matchUps ?? allCompetitionMatchUps({ nextMatchUps: true, tournamentRecords }).matchUps;
35058
35208
  let greatestAverageMinutes = 0;
35059
35209
  const recoveryMinutesMap = {};
35060
35210
  const averageMinutesMap = {};
@@ -35699,6 +35849,7 @@ var query$4 = {
35699
35849
  __proto__: null,
35700
35850
  courtGridRows: courtGridRows,
35701
35851
  findVenue: findVenue,
35852
+ getMatchUpsToSchedule: getMatchUpsToSchedule,
35702
35853
  getPersonRequests: getPersonRequests,
35703
35854
  getProfileRounds: getProfileRounds,
35704
35855
  getScheduledRoundsDetails: getScheduledRoundsDetails,
@@ -36890,6 +37041,20 @@ function calculateWinCriteria({ collectionDefinitions = [], collectionGroups = [
36890
37041
  return { valueGoal, ...SUCCESS };
36891
37042
  }
36892
37043
 
37044
+ function getHomeParticipantId(params) {
37045
+ const { timeStamp, schedule, matchUp } = params;
37046
+ const paramsCheck = checkRequiredParameters(params, [{ [MATCHUP]: true }]);
37047
+ if (paramsCheck.error)
37048
+ return paramsCheck;
37049
+ const { itemValue: homeParticipantId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
37050
+ timeItems: matchUp?.timeItems || [],
37051
+ itemType: HOME_PARTICIPANT_ID,
37052
+ });
37053
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
37054
+ ? { homeParticipantId }
37055
+ : schedule;
37056
+ }
37057
+
36893
37058
  function getMatchUpContextIds({ matchUps, matchUpId }) {
36894
37059
  if (!validMatchUps(matchUps))
36895
37060
  return { error: INVALID_VALUES };
@@ -37232,8 +37397,8 @@ function analyzeMatchUp(params) {
37232
37397
  const losingSideSetsCount = setsWinCounts[matchUpLosingSideIndex];
37233
37398
  const maxSetsCount = Math.max(...setsWinCounts);
37234
37399
  const maxSetsInstances = instanceCount(setsWinCounts)[maxSetsCount];
37235
- const { bestOf } = matchUpScoringFormat ?? {};
37236
- const setsToWin = (bestOf && Math.ceil(bestOf / 2)) || 1;
37400
+ const { bestOf, exactly } = matchUpScoringFormat ?? {};
37401
+ const setsToWin = (bestOf && Math.ceil(bestOf / 2)) || exactly || 1;
37237
37402
  const calculatedWinningSide = (maxSetsCount === setsToWin && maxSetsInstances === 1 && setsWinCounts.indexOf(maxSetsCount) + 1) || undefined;
37238
37403
  const validMatchUpWinningSide = winningSideSetsCount > losingSideSetsCount && matchUpWinningSide === calculatedWinningSide;
37239
37404
  const validMatchUpOutcome = calculatedWinningSide && completedSetsHaveValidOutcomes && validMatchUpWinningSide;
@@ -37711,6 +37876,7 @@ var index$f = {
37711
37876
  getMatchUpType: getMatchUpType,
37712
37877
  getMatchUpsMap: getMatchUpsMap,
37713
37878
  getMatchUpsStats: getMatchUpsStats,
37879
+ getMatchUpsToSchedule: getMatchUpsToSchedule,
37714
37880
  getMaxEntryPosition: getMaxEntryPosition,
37715
37881
  getModifiedMatchUpFormatTiming: getModifiedMatchUpFormatTiming,
37716
37882
  getPairedParticipant: getPairedParticipant,
@@ -43904,6 +44070,16 @@ function setMatchUpHomeParticipantId(params) {
43904
44070
  });
43905
44071
  }
43906
44072
 
44073
+ function matchUpTimeModifiers({ timeStamp, schedule, matchUp }) {
44074
+ const { itemValue: timeModifiers, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
44075
+ timeItems: matchUp?.timeItems || [],
44076
+ itemType: TIME_MODIFIERS,
44077
+ });
44078
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
44079
+ ? { timeModifiers }
44080
+ : schedule;
44081
+ }
44082
+
43907
44083
  function addMatchUpScheduledTime(params) {
43908
44084
  const stack = 'addMatchUpScheduledTime';
43909
44085
  let matchUp = params.matchUp;
@@ -46101,40 +46277,6 @@ function checkDependenciesScheduled({ matchUpScheduleTimes, matchUpDependencies,
46101
46277
  return { dependenciesScheduled, remainingDependencies };
46102
46278
  }
46103
46279
 
46104
- function processNextMatchUps({ matchUpPotentialParticipantIds, matchUpNotBeforeTimes, timeAfterRecovery, matchUp, }) {
46105
- const { individualParticipantIds } = getIndividualParticipantIds(matchUp);
46106
- timeAfterRecovery = timeAfterRecovery ?? matchUp.schedule?.timeAfterRecovery;
46107
- const addPotentialParticipantIds = (targetMatchUpId) => {
46108
- if (!matchUpPotentialParticipantIds[targetMatchUpId])
46109
- matchUpPotentialParticipantIds[targetMatchUpId] = [];
46110
- matchUpPotentialParticipantIds[targetMatchUpId] = unique(matchUpPotentialParticipantIds[targetMatchUpId].concat(...individualParticipantIds));
46111
- };
46112
- const updateNotBeforeTime = (matchUpId) => {
46113
- if (timeAfterRecovery &&
46114
- (!matchUpNotBeforeTimes[matchUpId] || timeAfterRecovery > matchUpNotBeforeTimes[matchUpId])) {
46115
- matchUpNotBeforeTimes[matchUpId] = timeAfterRecovery;
46116
- }
46117
- };
46118
- const winnerMatchUpId = matchUp.winnerTo?.matchUpId || matchUp.winnerMatchUpId;
46119
- if (winnerMatchUpId) {
46120
- timeAfterRecovery && updateNotBeforeTime(winnerMatchUpId);
46121
- addPotentialParticipantIds(winnerMatchUpId);
46122
- }
46123
- const loserMatchUpId = matchUp.loserTo?.matchUpId || matchUp.loserMatchUpId;
46124
- if (loserMatchUpId) {
46125
- timeAfterRecovery && updateNotBeforeTime(loserMatchUpId);
46126
- addPotentialParticipantIds(loserMatchUpId);
46127
- }
46128
- if (matchUp.sidesTo?.length) {
46129
- matchUp.sidesTo.forEach(({ matchUpId }) => {
46130
- if (matchUpId) {
46131
- timeAfterRecovery && updateNotBeforeTime(matchUpId);
46132
- addPotentialParticipantIds(matchUpId);
46133
- }
46134
- });
46135
- }
46136
- }
46137
-
46138
46280
  function checkParticipantProfileInitialization({ individualParticipantProfiles, participantId }) {
46139
46281
  if (!individualParticipantProfiles[participantId]) {
46140
46282
  individualParticipantProfiles[participantId] = {
@@ -46372,47 +46514,6 @@ function processAlreadyScheduledMatchUps({ matchUpPotentialParticipantIds, indiv
46372
46514
  };
46373
46515
  }
46374
46516
 
46375
- function getMatchUpsToSchedule({ matchUpPotentialParticipantIds, scheduleCompletedMatchUps, dateScheduledMatchUpIds, matchUpNotBeforeTimes, matchUpScheduleTimes, orderedMatchUpIds, clearDate, matchUps, }) {
46376
- const alreadyScheduledMatchUpIds = Object.keys(matchUpScheduleTimes);
46377
- const matchUpsToSchedule = orderedMatchUpIds
46378
- .map((matchUpId) => matchUps.find((matchUp) => matchUp.matchUpId === matchUpId))
46379
- .filter(Boolean)
46380
- .filter((matchUp) => {
46381
- const alreadyScheduled = !clearDate &&
46382
- (dateScheduledMatchUpIds.includes(matchUp.matchUpId) || alreadyScheduledMatchUpIds.includes(matchUp.matchUpId));
46383
- const doNotSchedule = [
46384
- BYE,
46385
- DEFAULTED,
46386
- COMPLETED$1,
46387
- ABANDONED$1,
46388
- RETIRED$1,
46389
- WALKOVER$2,
46390
- DOUBLE_WALKOVER,
46391
- DOUBLE_DEFAULT,
46392
- ].includes(matchUp?.matchUpStatus);
46393
- return (scheduleCompletedMatchUps ||
46394
- (!alreadyScheduled && !matchUp.winningSide && !doNotSchedule));
46395
- });
46396
- const { matchUpMap } = matchUpsToSchedule.reduce((aggregator, matchUp) => {
46397
- const { drawId, tournamentId } = matchUp;
46398
- if (!aggregator.matchUpMap[tournamentId])
46399
- aggregator.matchUpMap[tournamentId] = {};
46400
- if (!aggregator.matchUpMap[tournamentId][drawId]) {
46401
- aggregator.matchUpMap[tournamentId][drawId] = [matchUp];
46402
- }
46403
- else {
46404
- aggregator.matchUpMap[tournamentId][drawId].push(matchUp);
46405
- }
46406
- processNextMatchUps({
46407
- matchUpPotentialParticipantIds,
46408
- matchUpNotBeforeTimes,
46409
- matchUp,
46410
- });
46411
- return aggregator;
46412
- }, { matchUpMap: {} });
46413
- return { matchUpsToSchedule, matchUpMap };
46414
- }
46415
-
46416
46517
  function generateBookings({ defaultRecoveryMinutes = 0, averageMatchUpMinutes = 90, dateScheduledMatchUps, tournamentRecords, venueIds = [], periodLength, scheduleDate, matchUps, }) {
46417
46518
  if (typeof tournamentRecords !== 'object')
46418
46519
  return { error: MISSING_TOURNAMENT_RECORDS };
@@ -46707,6 +46808,41 @@ function checkRecoveryTime({ individualParticipantProfiles, matchUpNotBeforeTime
46707
46808
  return { enoughTime };
46708
46809
  }
46709
46810
 
46811
+ function auditAutoScheduling({ autoSchedulingAudit, tournamentRecords }) {
46812
+ addNotice({ topic: AUDIT, payload: autoSchedulingAudit });
46813
+ const getCount = (obj) => {
46814
+ if (!obj)
46815
+ return 0;
46816
+ const values = Object.values(obj);
46817
+ return values.reduce((count, value) => count + value.length || 0, 0);
46818
+ };
46819
+ const profileRoundsCount = (autoSchedulingAudit?.schedulingProfile || []).reduce((count, dateProfile) => count + dateProfile.venues.reduce((vc, venue) => vc + venue.rounds.length, 0), 0);
46820
+ const itemValue = {
46821
+ scheduledDatesCount: autoSchedulingAudit.scheduledDates?.length,
46822
+ noTimeMatchUpIdsCount: getCount(autoSchedulingAudit?.noTimeMatchUpIds),
46823
+ scheduledMatchUpIdsCount: getCount(autoSchedulingAudit?.scheduledMatchUpIds),
46824
+ overLimitMatchUpIdsCount: getCount(autoSchedulingAudit?.overLimitMatchUpIds),
46825
+ requestConflictsCount: getCount(autoSchedulingAudit?.requestConflicts),
46826
+ profileRoundsCount,
46827
+ };
46828
+ const timeItem = {
46829
+ itemType: AUTO_SCHEDULING_AUDIT,
46830
+ itemValue,
46831
+ };
46832
+ for (const tournamentRecord of Object.values(tournamentRecords)) {
46833
+ const tournamentId = tournamentRecord.tournamentId;
46834
+ if (hasTopic(AUDIT)) {
46835
+ addNotice({
46836
+ payload: { type: AUTO_SCHEDULING_AUDIT, tournamentId, detail: itemValue },
46837
+ topic: AUDIT,
46838
+ });
46839
+ }
46840
+ else {
46841
+ addTournamentTimeItem({ tournamentRecord, timeItem });
46842
+ }
46843
+ }
46844
+ }
46845
+
46710
46846
  function checkDailyLimits({ matchUpPotentialParticipantIds, individualParticipantProfiles, matchUpDailyLimits = {}, matchUp, }) {
46711
46847
  const { enteredIndividualParticipantIds } = getIndividualParticipantIds(matchUp);
46712
46848
  const { matchUpId, matchUpType } = matchUp;
@@ -46860,41 +46996,6 @@ function bulkScheduleMatchUps(params) {
46860
46996
  return warnings.length ? { ...SUCCESS, scheduled, warnings } : { ...SUCCESS, scheduled };
46861
46997
  }
46862
46998
 
46863
- function auditAutoScheduling({ autoSchedulingAudit, tournamentRecords }) {
46864
- addNotice({ topic: AUDIT, payload: autoSchedulingAudit });
46865
- const getCount = (obj) => {
46866
- if (!obj)
46867
- return 0;
46868
- const values = Object.values(obj);
46869
- return values.reduce((count, value) => count + value.length || 0, 0);
46870
- };
46871
- const profileRoundsCount = (autoSchedulingAudit?.schedulingProfile || []).reduce((count, dateProfile) => count + dateProfile.venues.reduce((vc, venue) => vc + venue.rounds.length, 0), 0);
46872
- const itemValue = {
46873
- scheduledDatesCount: autoSchedulingAudit.scheduledDates?.length,
46874
- noTimeMatchUpIdsCount: getCount(autoSchedulingAudit?.noTimeMatchUpIds),
46875
- scheduledMatchUpIdsCount: getCount(autoSchedulingAudit?.scheduledMatchUpIds),
46876
- overLimitMatchUpIdsCount: getCount(autoSchedulingAudit?.overLimitMatchUpIds),
46877
- requestConflictsCount: getCount(autoSchedulingAudit?.requestConflicts),
46878
- profileRoundsCount,
46879
- };
46880
- const timeItem = {
46881
- itemType: AUTO_SCHEDULING_AUDIT,
46882
- itemValue,
46883
- };
46884
- for (const tournamentRecord of Object.values(tournamentRecords)) {
46885
- const tournamentId = tournamentRecord.tournamentId;
46886
- if (hasTopic(AUDIT)) {
46887
- addNotice({
46888
- payload: { type: AUTO_SCHEDULING_AUDIT, tournamentId, detail: itemValue },
46889
- topic: AUDIT,
46890
- });
46891
- }
46892
- else {
46893
- addTournamentTimeItem({ tournamentRecord, timeItem });
46894
- }
46895
- }
46896
- }
46897
-
46898
46999
  function jinnScheduler({ schedulingProfileModifications, checkPotentialRequestConflicts, scheduleCompletedMatchUps, schedulingProfileIssues, dateSchedulingProfiles, containedStructureIds, matchUpDependencies, matchUpDailyLimits, clearScheduleDates, tournamentRecords, schedulingProfile, personRequests, periodLength, matchUps, courts, dryRun, }) {
46899
47000
  const scheduleTimesRemaining = {};
46900
47001
  const skippedScheduleTimes = {};
@@ -49225,8 +49326,8 @@ function generateOutcome(params) {
49225
49326
  winningSide = winningSide || randomInt(1, 2);
49226
49327
  const outcome = {
49227
49328
  score: noScore,
49228
- winningSide,
49229
49329
  matchUpStatus,
49330
+ winningSide,
49230
49331
  };
49231
49332
  const scoreDefaulted = matchUpStatus === DEFAULTED && randomInt(1, 100) > 100 - defaultWithScorePercent;
49232
49333
  if (!scoreDefaulted)
@@ -49236,49 +49337,46 @@ function generateOutcome(params) {
49236
49337
  return { outcome: { score: noScore, matchUpStatus } };
49237
49338
  }
49238
49339
  const parsedFormat = parse(matchUpFormat);
49239
- const { bestOf, setFormat, finalSetFormat } = parsedFormat ?? {};
49340
+ const { bestOf = 1, exactly, setFormat, finalSetFormat } = parsedFormat ?? {};
49240
49341
  const sets = [];
49241
49342
  const weightedSide = randomInt(0, 1);
49242
49343
  const weightedRange = winningSide
49243
49344
  ? [winningSide - 1]
49244
49345
  : [...generateRange(0, sideWeight).map(() => weightedSide), 1 - weightedSide];
49245
49346
  const incompleteSet = [RETIRED$1, DEFAULTED, INCOMPLETE, SUSPENDED].includes(matchUpStatus);
49246
- const incompleteAt = incompleteSet && (randomPop(generateRange(1, bestOf)) || 1);
49347
+ const incompleteAt = incompleteSet && (randomPop(generateRange(1, exactly || bestOf)) || 1);
49247
49348
  let weightedWinningSide;
49248
- for (const setNumber of generateRange(1, (bestOf ?? 0) + 1)) {
49249
- const isFinalSet = setNumber === bestOf;
49349
+ const setsToGenerate = generateRange(1, (exactly ?? bestOf) + 1);
49350
+ for (const setNumber of setsToGenerate) {
49351
+ const isFinalSet = setNumber === (exactly ?? bestOf);
49250
49352
  const { set, incomplete, winningSideNumber } = generateSet({
49353
+ setFormat: (isFinalSet && finalSetFormat) || setFormat,
49251
49354
  incomplete: incompleteAt === setNumber,
49252
- matchUpStatus,
49253
49355
  pointsPerMinute,
49254
- setFormat: (isFinalSet && finalSetFormat) || setFormat,
49255
- setNumber,
49356
+ matchUpStatus,
49256
49357
  weightedRange,
49358
+ setNumber,
49257
49359
  });
49258
49360
  sets.push(set);
49259
49361
  if (incomplete) {
49260
49362
  weightedWinningSide = winningSideNumber;
49261
49363
  break;
49262
49364
  }
49263
- const analysis = analyzeMatchUp({
49264
- matchUp: { score: { sets }, matchUpFormat },
49265
- });
49365
+ const analysis = analyzeMatchUp({ matchUp: { score: { sets }, matchUpFormat } });
49266
49366
  if (analysis.calculatedWinningSide)
49267
49367
  break;
49268
49368
  }
49269
- const analysis = analyzeMatchUp({
49270
- matchUp: { score: { sets }, matchUpFormat },
49271
- });
49369
+ const analysis = analyzeMatchUp({ matchUp: { score: { sets }, matchUpFormat, winningSide } });
49272
49370
  const matchUpWinningSide = weightedWinningSide ? winningSide || weightedWinningSide : analysis.calculatedWinningSide;
49273
49371
  const { score } = matchUpScore({
49274
- score: { sets },
49275
49372
  winningSide: matchUpWinningSide,
49373
+ score: { sets },
49276
49374
  matchUpStatus,
49277
49375
  });
49278
49376
  const outcome = {
49279
- score,
49280
49377
  winningSide: matchUpWinningSide,
49281
49378
  matchUpStatus,
49379
+ score,
49282
49380
  };
49283
49381
  return { outcome };
49284
49382
  }
@@ -49404,13 +49502,8 @@ function completeDrawMatchUps(params) {
49404
49502
  const sortedStructures = drawDefinition.structures.slice().sort(structureSort);
49405
49503
  let completedCount = 0;
49406
49504
  const { matchUps: firstRoundDualMatchUps, matchUpsMap } = getAllDrawMatchUps({
49407
- contextFilters: {
49408
- stages: [MAIN, QUALIFYING],
49409
- },
49410
- matchUpFilters: {
49411
- matchUpTypes: [TEAM$2],
49412
- roundNumbers: [1],
49413
- },
49505
+ matchUpFilters: { matchUpTypes: [TEAM$2], roundNumbers: [1] },
49506
+ contextFilters: { stages: [MAIN, QUALIFYING] },
49414
49507
  inContext: true,
49415
49508
  drawDefinition,
49416
49509
  });
@@ -49504,11 +49597,16 @@ function completeDrawMatchUps(params) {
49504
49597
  }
49505
49598
  const scoreString = typeof completeAllMatchUps === 'string' && completeAllMatchUps;
49506
49599
  const matchUpStatus = scoreString && COMPLETED$1;
49507
- for (const structure of sortedStructures) {
49600
+ const isRoundRobinWithPlayoff = sortedStructures.length === 2 &&
49601
+ sortedStructures[0].finishingPosition === WIN_RATIO$1 &&
49602
+ intersection(sortedStructures.map(({ stage }) => stage), [MAIN, PLAY_OFF]).length === 2;
49603
+ const structureIds = sortedStructures.map(({ structureId }) => structureId);
49604
+ for (const structureId of structureIds) {
49508
49605
  if (completedCount >= completionGoal)
49509
49606
  break;
49510
- const { matchUps } = getAllStructureMatchUps({
49511
- matchUpFilters: { matchUpTypes: [DOUBLES$1, SINGLES$1] },
49607
+ const structure = drawDefinition.structures.find((structure) => structure.structureId === structureId);
49608
+ const matchUps = getAllStructureMatchUps({
49609
+ contextFilters: { matchUpTypes: [DOUBLES$1, SINGLES$1] },
49512
49610
  afterRecoveryTimes: false,
49513
49611
  tournamentRecord,
49514
49612
  inContext: true,
@@ -49516,7 +49614,10 @@ function completeDrawMatchUps(params) {
49516
49614
  matchUpsMap,
49517
49615
  structure,
49518
49616
  event,
49519
- });
49617
+ }).matchUps;
49618
+ if (!matchUps.length) {
49619
+ console.log('##', drawDefinition);
49620
+ }
49520
49621
  const sortedMatchUpIds = matchUps
49521
49622
  .filter(({ winningSide }) => !winningSide)
49522
49623
  .sort(matchUpSort)
@@ -49537,8 +49638,8 @@ function completeDrawMatchUps(params) {
49537
49638
  const targetMatchUp = matchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
49538
49639
  const isDoubleExit = [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(targetMatchUp.matchUpStatus);
49539
49640
  if (targetMatchUp?.readyToScore && !isDoubleExit) {
49641
+ const winningSide = !randomWinningSide && 1;
49540
49642
  const result = smartComplete({
49541
- winningSide: !randomWinningSide && 1,
49542
49643
  matchUpStatusProfile,
49543
49644
  tournamentRecord,
49544
49645
  drawDefinition,
@@ -49546,6 +49647,7 @@ function completeDrawMatchUps(params) {
49546
49647
  matchUpFormat,
49547
49648
  matchUpStatus,
49548
49649
  scoreString,
49650
+ winningSide,
49549
49651
  event,
49550
49652
  });
49551
49653
  if (result?.error)
@@ -49553,6 +49655,13 @@ function completeDrawMatchUps(params) {
49553
49655
  completedCount += 1;
49554
49656
  }
49555
49657
  }
49658
+ if (isRoundRobinWithPlayoff && structure.finishingPosition === WIN_RATIO$1 && params.completeRoundRobinPlayoffs) {
49659
+ automatedPlayoffPositioning({
49660
+ structureId: structure.structureId,
49661
+ applyPositioning: true,
49662
+ drawDefinition,
49663
+ });
49664
+ }
49556
49665
  }
49557
49666
  return { ...SUCCESS, completedCount };
49558
49667
  }
@@ -54823,6 +54932,7 @@ var index$5 = {
54823
54932
  findVenue: findVenue,
54824
54933
  generateBookings: generateBookings,
54825
54934
  generateVirtualCourts: generateVirtualCourts,
54935
+ getMatchUpsToSchedule: getMatchUpsToSchedule,
54826
54936
  getPersonRequests: getPersonRequests,
54827
54937
  getProfileRounds: getProfileRounds,
54828
54938
  getScheduledRoundsDetails: getScheduledRoundsDetails,
@@ -56514,20 +56624,30 @@ function copyTournamentRecord(params) {
56514
56624
  const tournamentDayMilliseconds = startDate && endDate ? new Date(extractDate(endDate)).getTime() - new Date(extractDate(startDate)).getTime() : 0;
56515
56625
  const tournamentDays = tournamentDayMilliseconds / dayMilliseconds;
56516
56626
  const newEndDate = params.endDate || addDays(params.startDate, tournamentDays);
56627
+ const filteredTimeItems = (timeItems) => timeItems?.filter(({ itemType }) => params.itemTypeList?.includes(itemType));
56628
+ const filteredExtensions = (extensions) => extensions?.filter(({ name }) => params.extensionList?.includes(name));
56517
56629
  const copyParticipant = (participant) => {
56518
- const { timeItems, ...rest } = participant;
56519
- return { ...rest };
56630
+ const { timeItems, extensions, ...rest } = participant;
56631
+ return makeDeepCopy({ ...rest, timeItems: filteredTimeItems(timeItems), extensions: filteredExtensions(extensions) }, false, true);
56520
56632
  };
56521
56633
  const copyEvent = (event) => {
56522
- const { drawDefinitions, ...rest } = event;
56523
- return { ...rest };
56634
+ const { drawDefinitions, timeItems, extensions, startDate, endDate, ...rest } = event;
56635
+ return makeDeepCopy({
56636
+ extensions: filteredExtensions(extensions),
56637
+ timeItems: filteredTimeItems(timeItems),
56638
+ startDate: params.startDate,
56639
+ endDate: newEndDate,
56640
+ ...rest,
56641
+ }, false, true);
56524
56642
  };
56525
56643
  const tournamentRecord = {
56526
56644
  participants: params.copyParticipants ? params.tournamentRecord.participants?.map(copyParticipant) ?? [] : [],
56527
- parentOrganisation: { ...params.tournamentRecord.parentOrganisation },
56645
+ parentOrganisation: makeDeepCopy({ ...params.tournamentRecord.parentOrganisation }, false, true),
56646
+ venues: makeDeepCopy(params.tournamentRecord.venues ?? [], false, true),
56647
+ extensions: filteredExtensions(params.tournamentRecord.extensions),
56648
+ timeItems: filteredTimeItems(params.tournamentRecord.timeItems),
56528
56649
  events: params.tournamentRecord.events?.map(copyEvent) ?? [],
56529
- weekdays: { ...params.tournamentRecord.weekdays },
56530
- venues: { ...params.tournamentRecord.venues },
56650
+ weekdays: [...(params.tournamentRecord.weekdays ?? [])],
56531
56651
  tournamentName: params.tournamentName,
56532
56652
  startDate: params.startDate,
56533
56653
  tournamentId: UUID(),