tods-competition-factory 0.67.3 → 0.67.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -249,7 +249,7 @@ const matchUpFormatCode = {
249
249
  };
250
250
 
251
251
  function factoryVersion() {
252
- return '0.67.3';
252
+ return '0.67.4';
253
253
  }
254
254
 
255
255
  const FORMAT_STANDARD = 'SET3-S:6/TB7'; // Best of 3 Tiebreak Sets to 6
@@ -9403,7 +9403,10 @@ function getAppliedPolicies({
9403
9403
  function getRoundMatchUps$1({
9404
9404
  matchUps = []
9405
9405
  }) {
9406
- // create an array of arrays of matchUps grouped by roundNumber
9406
+ if (!Array.isArray(matchUps)) return {
9407
+ error: INVALID_VALUES
9408
+ }; // create an array of arrays of matchUps grouped by roundNumber
9409
+
9407
9410
  const roundMatchUpsArray = matchUps.reduce((roundNumbers, matchUp) => {
9408
9411
  return !matchUp.roundNumber || roundNumbers.includes(matchUp.roundNumber) ? roundNumbers : roundNumbers.concat(parseInt(matchUp.roundNumber));
9409
9412
  }, []).sort(numericSort).map(roundNumber => {
@@ -9439,13 +9442,21 @@ function getRoundMatchUps$1({
9439
9442
  // - finishingRound: reverse count of rounds. Final is finishingRound #1
9440
9443
 
9441
9444
  const roundProfile = Object.assign({}, ...Object.keys(roundMatchUps).map(roundNumber => {
9442
- var _roundMatchUps$roundN;
9445
+ var _roundMatchUps$roundN, _roundMatchUps$roundN2, _roundMatchUps$roundN3;
9443
9446
 
9444
9447
  const matchUpsCount = (_roundMatchUps$roundN = roundMatchUps[roundNumber]) === null || _roundMatchUps$roundN === void 0 ? void 0 : _roundMatchUps$roundN.length;
9448
+ const inactiveCount = (_roundMatchUps$roundN2 = roundMatchUps[roundNumber]) === null || _roundMatchUps$roundN2 === void 0 ? void 0 : (_roundMatchUps$roundN3 = _roundMatchUps$roundN2.filter(matchUp => {
9449
+ var _matchUp$score;
9450
+
9451
+ return !completedMatchUpStatuses.includes(matchUp.matchUpStatus) && !((_matchUp$score = matchUp.score) !== null && _matchUp$score !== void 0 && _matchUp$score.scoreStringSide1);
9452
+ })) === null || _roundMatchUps$roundN3 === void 0 ? void 0 : _roundMatchUps$roundN3.length;
9453
+ const inactiveRound = matchUpsCount && matchUpsCount === inactiveCount;
9445
9454
  maxMatchUpsCount = Math.max(maxMatchUpsCount, matchUpsCount);
9446
9455
  return {
9447
9456
  [roundNumber]: {
9448
- matchUpsCount
9457
+ matchUpsCount,
9458
+ inactiveCount,
9459
+ inactiveRound
9449
9460
  }
9450
9461
  };
9451
9462
  }));
@@ -15396,23 +15407,24 @@ function isActiveMatchUp({
15396
15407
 
15397
15408
  function structureActiveDrawPositions({
15398
15409
  drawDefinition,
15399
- structureId
15410
+ structureId,
15411
+ structure
15400
15412
  }) {
15401
15413
  const matchUpFilters = {
15402
15414
  isCollectionMatchUp: false
15403
15415
  };
15416
+
15417
+ if (!structure) {
15418
+ const result = findStructure({
15419
+ drawDefinition,
15420
+ structureId
15421
+ });
15422
+ if (result.error) return result;
15423
+ structure = result.structure;
15424
+ }
15425
+
15404
15426
  const {
15405
- structure,
15406
- error
15407
- } = findStructure({
15408
- drawDefinition,
15409
- structureId
15410
- });
15411
- if (error) return {
15412
- error
15413
- };
15414
- const {
15415
- matchUps
15427
+ matchUps: inContextStructureMatchUps
15416
15428
  } = getAllStructureMatchUps({
15417
15429
  inContext: true,
15418
15430
  drawDefinition,
@@ -15420,24 +15432,24 @@ function structureActiveDrawPositions({
15420
15432
  structure
15421
15433
  }); // first collect all drawPositions for the structure
15422
15434
 
15423
- const drawPositions = unique([].concat(...matchUps.map(matchUp => matchUp.drawPositions || [])).filter(Boolean)).sort(numericSort); // get a mapping of all matchUpIds to dependent matchUpIds
15435
+ const drawPositions = unique([].concat(...inContextStructureMatchUps.map(matchUp => matchUp.drawPositions || [])).filter(Boolean)).sort(numericSort); // get a mapping of all matchUpIds to dependent matchUpIds
15424
15436
 
15425
15437
  const {
15426
15438
  matchUpDependencies
15427
15439
  } = getMatchUpDependencies({
15440
+ matchUps: inContextStructureMatchUps,
15428
15441
  drawIds: [drawDefinition.drawId],
15429
- drawDefinition,
15430
- matchUps
15442
+ drawDefinition
15431
15443
  }); // determine which matchUps are active
15432
15444
 
15433
- const activeMatchUps = matchUps.filter(isActiveMatchUp); // create an array of all matchUpIds active because they are dependent
15445
+ const activeMatchUps = inContextStructureMatchUps.filter(isActiveMatchUp); // create an array of all matchUpIds active because they are dependent
15434
15446
 
15435
15447
  const activeDependentMatchUpIds = unique(activeMatchUps.map(matchUp => {
15436
15448
  var _matchUpDependencies$;
15437
15449
 
15438
15450
  return [].concat(...(((_matchUpDependencies$ = matchUpDependencies[matchUp.matchUpId]) === null || _matchUpDependencies$ === void 0 ? void 0 : _matchUpDependencies$.matchUpIds) || []), matchUp.matchUpId);
15439
15451
  }).flat());
15440
- const activeDrawPositions = unique(matchUps.map(({
15452
+ const activeDrawPositions = unique(inContextStructureMatchUps.map(({
15441
15453
  matchUpId,
15442
15454
  drawPositions
15443
15455
  }) => activeDependentMatchUpIds.includes(matchUpId) ? drawPositions : []).flat().filter(Boolean)).sort(numericSort);
@@ -15452,6 +15464,8 @@ function structureActiveDrawPositions({
15452
15464
  const inactiveDrawPositions = (drawPositions === null || drawPositions === void 0 ? void 0 : drawPositions.filter(drawPosition => !activeDrawPositions.includes(drawPosition))) || [];
15453
15465
  return {
15454
15466
  allDrawPositions: drawPositions,
15467
+ inContextStructureMatchUps,
15468
+ activeDependentMatchUpIds,
15455
15469
  inactiveDrawPositions,
15456
15470
  positionAssignments,
15457
15471
  activeDrawPositions,
@@ -41469,6 +41483,118 @@ const publishingGovernor = {
41469
41483
  unPublishEvent
41470
41484
  };
41471
41485
 
41486
+ function analyzeDraws(tournamentRecord) {
41487
+ var _tournamentRecord$eve;
41488
+
41489
+ const drawsAnalysis = {
41490
+ noPositionsAssigned: 0,
41491
+ // no positions assigned
41492
+ positionsNoOutcomes: 0,
41493
+ // all positions assigned and no outcomes
41494
+ matchPlayDraws: 0,
41495
+ // only first round has active matchUps; some unassigned positions
41496
+ canBeTrimmed: 0,
41497
+ // partially assigned positions with outcomes => can be reconfigured
41498
+ draws: []
41499
+ };
41500
+ const drawDefinitions = (_tournamentRecord$eve = tournamentRecord.events) === null || _tournamentRecord$eve === void 0 ? void 0 : _tournamentRecord$eve.map(event => event === null || event === void 0 ? void 0 : event.drawDefinitions).flat().filter(Boolean);
41501
+ drawDefinitions.forEach(drawDefinition => {
41502
+ const structures = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) || [];
41503
+ const structureData = structures.map(structure => {
41504
+ const {
41505
+ stage,
41506
+ stageSequence,
41507
+ structureId
41508
+ } = structure;
41509
+ const orderNumber = stageOrder[stage];
41510
+ const {
41511
+ inContextStructureMatchUps
41512
+ } = structureActiveDrawPositions({
41513
+ drawDefinition,
41514
+ structure
41515
+ });
41516
+ const {
41517
+ positionAssignments
41518
+ } = getPositionAssignments$1({
41519
+ structure
41520
+ });
41521
+ const positionsAssigned = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.filter(({
41522
+ participantId
41523
+ }) => participantId);
41524
+ const unassignedPositionsCount = ((positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.length) || 0) - ((positionsAssigned === null || positionsAssigned === void 0 ? void 0 : positionsAssigned.length) || 0);
41525
+ const {
41526
+ roundMatchUps,
41527
+ roundProfile,
41528
+ roundNumbers,
41529
+ maxMatchUpsCount
41530
+ } = getRoundMatchUps$1({
41531
+ matchUps: inContextStructureMatchUps
41532
+ });
41533
+ const activeRounds = Object.keys(roundProfile).filter(roundNumber => !roundProfile[roundNumber].inactiveRound);
41534
+ const inactiveStructure = Object.values(roundProfile).every(profile => profile.inactiveRound);
41535
+ return {
41536
+ positionsAssignedCount: (positionsAssigned === null || positionsAssigned === void 0 ? void 0 : positionsAssigned.length) || 0,
41537
+ unassignedPositionsCount,
41538
+ inactiveStructure,
41539
+ maxMatchUpsCount,
41540
+ roundMatchUps,
41541
+ activeRounds,
41542
+ roundNumbers,
41543
+ roundProfile,
41544
+ structureId,
41545
+ stageSequence,
41546
+ orderNumber,
41547
+ stage
41548
+ };
41549
+ });
41550
+ const mainStructure = structureData.find(data => data.orderNumber === 2 && data.stageSequence === 1);
41551
+ const isMatchPlay = mainStructure.activeRounds.length === 1 && parseInt(mainStructure.activeRounds[0]) === 1;
41552
+ const canBeTrimmed = mainStructure.activeRounds.length && mainStructure.roundProfile[1].inActiveCount;
41553
+ if (isMatchPlay) drawsAnalysis.matchPlayDraws += 1;
41554
+ if (canBeTrimmed) drawsAnalysis.canBeTrimmed += 1;
41555
+ drawsAnalysis.draws.push({
41556
+ drawId: drawDefinition.drawId,
41557
+ structureData,
41558
+ isMatchPlay
41559
+ });
41560
+ });
41561
+ return { ...SUCCESS,
41562
+ drawsAnalysis
41563
+ };
41564
+ }
41565
+
41566
+ function checkIsDual(tournamentRecord) {
41567
+ var _tournamentRecord$par, _tournamentRecord$eve, _event$drawDefinition, _drawDefinition$struc, _structure$positionAs;
41568
+
41569
+ const teamParticipants = (_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.filter(({
41570
+ participantType
41571
+ }) => participantType === TEAM$1);
41572
+ const twoTeams = (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.length) === 2;
41573
+ const event = ((_tournamentRecord$eve = tournamentRecord.events) === null || _tournamentRecord$eve === void 0 ? void 0 : _tournamentRecord$eve.length) === 1 && tournamentRecord.events[0];
41574
+ const drawDefinition = (event === null || event === void 0 ? void 0 : (_event$drawDefinition = event.drawDefinitions) === null || _event$drawDefinition === void 0 ? void 0 : _event$drawDefinition.length) === 1 && event.drawDefinitions[0];
41575
+ const structure = (drawDefinition === null || drawDefinition === void 0 ? void 0 : (_drawDefinition$struc = drawDefinition.structures) === null || _drawDefinition$struc === void 0 ? void 0 : _drawDefinition$struc.length) === 1 && drawDefinition.structures[0];
41576
+ const twoDrawPositions = (structure === null || structure === void 0 ? void 0 : (_structure$positionAs = structure.positionAssignments) === null || _structure$positionAs === void 0 ? void 0 : _structure$positionAs.length) === 2;
41577
+ return event.tieFormat && twoTeams && twoDrawPositions;
41578
+ }
41579
+
41580
+ function analyzeTournament({
41581
+ tournamentRecord
41582
+ }) {
41583
+ if (!tournamentRecord) return {
41584
+ error: MISSING_TOURNAMENT_RECORD
41585
+ };
41586
+ const {
41587
+ drawsAnalysis
41588
+ } = analyzeDraws(tournamentRecord);
41589
+ const analysis = {
41590
+ isDual: checkIsDual(tournamentRecord),
41591
+ drawsAnalysis
41592
+ };
41593
+ return { ...SUCCESS,
41594
+ analysis
41595
+ };
41596
+ }
41597
+
41472
41598
  function setTournamentName({
41473
41599
  tournamentRecord,
41474
41600
  tournamentName,
@@ -41565,6 +41691,7 @@ function setTournamentCategories({
41565
41691
  const tournamentGovernor = {
41566
41692
  addNotes,
41567
41693
  removeNotes,
41694
+ analyzeTournament,
41568
41695
  setTournamentName,
41569
41696
  setTournamentNotes,
41570
41697
  setTournamentEndDate,