tods-competition-factory 2.0.42 → 2.0.44

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.
@@ -5328,13 +5328,14 @@ type FindMatchUpResult = {
5328
5328
  };
5329
5329
  declare function publicFindMatchUp(params: FindMatchUpType): FindMatchUpResult;
5330
5330
 
5331
- declare function applyLineUps({ tournamentRecord, drawDefinition, matchUpId, lineUps, event }: {
5332
- tournamentRecord: any;
5333
- drawDefinition: any;
5334
- matchUpId: any;
5335
- lineUps: any;
5336
- event: any;
5337
- }): any;
5331
+ type ApplyLineUps = {
5332
+ tournamentRecord: Tournament;
5333
+ drawDefinition: DrawDefinition;
5334
+ lineUps: TeamCompetitor[];
5335
+ matchUpId: string;
5336
+ event: Event$1;
5337
+ };
5338
+ declare function applyLineUps(params: ApplyLineUps): any;
5338
5339
 
5339
5340
  type ResetTieFormatArgs = {
5340
5341
  tournamentRecord: Tournament;
@@ -7782,9 +7783,11 @@ declare function getStructureReports({ firstFlightOnly, extensionProfiles, tourn
7782
7783
  };
7783
7784
  eventStructureReports?: undefined;
7784
7785
  structureReports?: undefined;
7786
+ flightReports?: undefined;
7785
7787
  } | {
7786
7788
  eventStructureReports: unknown[];
7787
7789
  structureReports: any[] | undefined;
7790
+ flightReports: any[];
7788
7791
  error?: undefined;
7789
7792
  };
7790
7793
 
@@ -8241,7 +8244,7 @@ declare function generateBookings({ defaultRecoveryMinutes, averageMatchUpMinute
8241
8244
  bookings: {
8242
8245
  recoveryMinutes: number | undefined;
8243
8246
  averageMinutes: number | undefined;
8244
- periodLength: number | undefined;
8247
+ periodLength: number;
8245
8248
  startTime: any;
8246
8249
  courtId: any;
8247
8250
  endTime: any;
@@ -10446,6 +10449,8 @@ declare const fixtures: {
10446
10449
  participantRole: boolean;
10447
10450
  participantStatus: boolean;
10448
10451
  penalties: boolean;
10452
+ rankings: boolean;
10453
+ ratings: boolean;
10449
10454
  representing: boolean;
10450
10455
  participantRoleResponsibilities: boolean;
10451
10456
  participantType: boolean;
@@ -10481,6 +10486,8 @@ declare const fixtures: {
10481
10486
  participantRole: boolean;
10482
10487
  participantStatus: boolean;
10483
10488
  penalties: boolean;
10489
+ rankings: boolean;
10490
+ ratings: boolean;
10484
10491
  representing: boolean;
10485
10492
  participantRoleResponsibilities: boolean;
10486
10493
  participantType: boolean;
@@ -10623,7 +10630,8 @@ declare const fixtures: {
10623
10630
  drawDefinitions: boolean;
10624
10631
  structures: boolean;
10625
10632
  };
10626
- requireAllPositionsAssigned: boolean;
10633
+ requireParticipantsForScoring: boolean;
10634
+ requireAllPositionsAssigned: undefined;
10627
10635
  allowChangePropagation: boolean;
10628
10636
  stage: {
10629
10637
  MAIN: {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.0.42';
6
+ return '2.0.44';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -19820,7 +19820,7 @@ function calculatePressureRatings({ participantResults, sides, score }) {
19820
19820
  const side2 = sides.find(({ sideNumber }) => sideNumber === 2);
19821
19821
  const side1ratings = side1?.participant?.ratings;
19822
19822
  const side2ratings = side2?.participant?.ratings;
19823
- if (side1ratings[SINGLES] && side2ratings[SINGLES]) {
19823
+ if (side1ratings?.[SINGLES] && side2ratings?.[SINGLES]) {
19824
19824
  const targetRatingType = ELO;
19825
19825
  const { convertedRating: side1ConvertedRating } = getConvertedRating({ ratings: side1ratings, targetRatingType });
19826
19826
  const { convertedRating: side2ConvertedRating } = getConvertedRating({ ratings: side2ratings, targetRatingType });
@@ -21074,16 +21074,16 @@ function modifyMatchUpScore(params) {
21074
21074
  }
21075
21075
 
21076
21076
  function attemptToModifyScore(params) {
21077
- const { matchUpStatusCodes, matchUpStatus, structure, matchUp, dualMatchUp } = params;
21077
+ const { matchUpStatusCodes, matchUpStatus, structure, matchUp, dualMatchUp, inContextMatchUp } = params;
21078
21078
  const matchUpStatusIsValid = isDirectingMatchUpStatus({ matchUpStatus }) ||
21079
21079
  ([CANCELLED$1, ABANDONED$1].includes(matchUpStatus) && dualMatchUp);
21080
21080
  const stack = 'attemptToModifyScore';
21081
- const isCollectionMatchUp = Boolean(matchUp.collectionId);
21082
- const isAdHocMatchUp = isAdHoc({ structure });
21083
- const validToScore = isCollectionMatchUp || isAdHocMatchUp || drawPositionsAssignedParticipantIds({ structure, matchUp });
21084
- if (!validToScore) {
21085
- return { error: MISSING_ASSIGNMENTS };
21086
- }
21081
+ const hasAdHocSides = isAdHoc({ structure }) && matchUp?.sides?.every((side) => side.participantId);
21082
+ const validToScore = hasAdHocSides ||
21083
+ drawPositionsAssignedParticipantIds({ structure, matchUp, inContextMatchUp }) ||
21084
+ params.appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false;
21085
+ if (!validToScore)
21086
+ return decorateResult({ result: { error: MISSING_ASSIGNMENTS }, stack });
21087
21087
  const removeScore = [WALKOVER$2].includes(matchUpStatus);
21088
21088
  const updatedMatchUpStatus = matchUpStatusIsValid ? matchUpStatus : (params.winningSide && COMPLETED$1) || INCOMPLETE;
21089
21089
  const result = modifyMatchUpScore({
@@ -21095,13 +21095,14 @@ function attemptToModifyScore(params) {
21095
21095
  });
21096
21096
  return decorateResult({ result, stack });
21097
21097
  }
21098
- function drawPositionsAssignedParticipantIds({ structure, matchUp }) {
21098
+ function drawPositionsAssignedParticipantIds({ structure, matchUp, inContextMatchUp }) {
21099
21099
  const { drawPositions } = matchUp;
21100
21100
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
21101
21101
  const assignedParticipantIds = positionAssignments?.filter((assignment) => {
21102
21102
  return drawPositions?.includes(assignment.drawPosition) && assignment.participantId;
21103
21103
  });
21104
- return assignedParticipantIds?.length === 2;
21104
+ const bothSidesPresent = inContextMatchUp?.sides?.every((side) => side.participantId);
21105
+ return assignedParticipantIds?.length === 2 || bothSidesPresent;
21105
21106
  }
21106
21107
 
21107
21108
  function getGroupValueGroups({ collectionGroups = [] }) {
@@ -22398,14 +22399,14 @@ function directLoser(params) {
22398
22399
  }
22399
22400
 
22400
22401
  function directParticipants(params) {
22402
+ const stack = 'directParticipants';
22401
22403
  const result = attemptToModifyScore(params);
22402
22404
  if (result.error)
22403
- return result;
22405
+ return decorateResult({ result, stack });
22404
22406
  const matchUpStatusIsValid = isDirectingMatchUpStatus({
22405
22407
  matchUpStatus: params.matchUpStatus,
22406
22408
  });
22407
22409
  const { dualWinningSideChange, projectedWinningSide, inContextDrawMatchUps, tournamentRecord, drawDefinition, matchUpStatus, dualMatchUp, matchUpsMap, winningSide, targetData, matchUpId, structure, matchUp, event, } = params;
22408
- const stack = 'directParticipants';
22409
22410
  const isCollectionMatchUp = Boolean(matchUp.collectionId);
22410
22411
  const isAdHocMatchUp = isAdHoc({ structure });
22411
22412
  let drawPositions = matchUp.drawPositions;
@@ -24169,7 +24170,7 @@ function collectionMatchUpActions({ specifiedPolicyDefinitions, inContextDrawMat
24169
24170
  .filter(Boolean);
24170
24171
  const existingParticipantIds = existingParticipants?.map(getParticipantId);
24171
24172
  const inContextDualMatchUp = inContextDrawMatchUps?.find((drawMatchUp) => drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId);
24172
- const availableIndividualParticipants = inContextDualMatchUp?.sides?.map((side) => side.participant?.individualParticipants.filter(({ participantId, person }) => !existingParticipantIds?.includes(participantId) &&
24173
+ const availableIndividualParticipants = inContextDualMatchUp?.sides?.map((side) => side?.participant?.individualParticipants?.filter(({ participantId, person }) => !existingParticipantIds?.includes(participantId) &&
24173
24174
  (!gender ||
24174
24175
  gender === ANY ||
24175
24176
  person.sex === gender ||
@@ -34201,7 +34202,7 @@ function getDrawData(params) {
34201
34202
  const { drawPosition, participantId } = assignment;
34202
34203
  participantPlacements = true;
34203
34204
  return {
34204
- participantResult: participantId && result.participantResults[participantId],
34205
+ participantResult: participantId && result?.participantResults?.[participantId],
34205
34206
  participantId,
34206
34207
  drawPosition,
34207
34208
  };
@@ -41343,8 +41344,10 @@ function removeTieMatchUpParticipantId(params) {
41343
41344
  side.participant?.individualParticipantIds?.includes(participantId));
41344
41345
  if (!side)
41345
41346
  return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND }, stack });
41347
+ const scoringPolicy = params.policyDefinitions?.[POLICY_TYPE_SCORING] ?? appliedPolicies?.[POLICY_TYPE_SCORING];
41346
41348
  if (!side.substitutions?.length &&
41347
- (checkScoreHasValue({ score: inContextTieMatchUp?.score }) || inContextTieMatchUp?.winningSide))
41349
+ (checkScoreHasValue({ score: inContextTieMatchUp?.score }) || inContextTieMatchUp?.winningSide) &&
41350
+ !(scoringPolicy?.requireParticipantsForScoring === false))
41348
41351
  return decorateResult({ result: { error: EXISTING_OUTCOME }, stack });
41349
41352
  const teamParticipantId = inContextDualMatchUp?.sides?.find(({ sideNumber }) => sideNumber === side.sideNumber)?.participantId;
41350
41353
  if (!teamParticipantId)
@@ -43678,35 +43681,25 @@ function setMatchUpState(params) {
43678
43681
  return result;
43679
43682
  }
43680
43683
  }
43681
- const positionAssignments = !matchUp?.sides
43682
- ? getPositionAssignments$1({
43683
- drawDefinition,
43684
- structureId,
43685
- }).positionAssignments
43686
- : [];
43687
- const participantsCount = inContextMatchUp?.sides?.map((side) => side.participantId).filter(Boolean).length;
43688
- const requiredParticipants = (participantsCount && participantsCount === 2) ||
43689
- (matchUp.collectionId && isAdHoc({ structure }) && participantsCount && participantsCount >= 1) ||
43690
- (assignedDrawPositions?.length === 2 &&
43691
- positionAssignments
43692
- ?.filter((assignment) => assignedDrawPositions.includes(assignment.drawPosition))
43693
- .every((assignment) => assignment.participantId));
43694
- if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !requiredParticipants) {
43695
- return decorateResult({
43696
- info: 'present in participantsRequiredMatchUpStatuses',
43697
- context: { matchUpStatus, requiredParticipants },
43698
- result: { error: INVALID_MATCHUP_STATUS },
43699
- });
43700
- }
43701
43684
  const appliedPolicies = getAppliedPolicies({
43702
43685
  policyTypes: [POLICY_TYPE_PROGRESSION, POLICY_TYPE_SCORING],
43703
43686
  tournamentRecord,
43704
43687
  drawDefinition,
43705
43688
  event,
43706
43689
  })?.appliedPolicies ?? {};
43707
- if (typeof params.policyDefinitions === 'object') {
43690
+ if (isObject(params.policyDefinitions))
43708
43691
  Object.assign(appliedPolicies, params.policyDefinitions);
43709
- }
43692
+ const participantCheck = checkParticipants({
43693
+ assignedDrawPositions,
43694
+ inContextMatchUp,
43695
+ appliedPolicies,
43696
+ drawDefinition,
43697
+ matchUpStatus,
43698
+ structure,
43699
+ matchUp,
43700
+ });
43701
+ if (participantCheck?.error)
43702
+ return participantCheck;
43710
43703
  const qualifyingMatch = inContextMatchUp?.stage === QUALIFYING && inContextMatchUp.finishingRound === 1;
43711
43704
  const qualifierAdvancing = qualifyingMatch && winningSide;
43712
43705
  const removingQualifier = qualifyingMatch &&
@@ -43878,6 +43871,31 @@ function applyMatchUpValues(params) {
43878
43871
  }
43879
43872
  return result;
43880
43873
  }
43874
+ function checkParticipants({ assignedDrawPositions, inContextMatchUp, appliedPolicies, drawDefinition, matchUpStatus, structure, matchUp, }) {
43875
+ if (appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false)
43876
+ return { ...SUCCESS };
43877
+ const participantsCount = inContextMatchUp?.sides?.map((side) => side.participantId).filter(Boolean).length;
43878
+ const positionAssignments = !matchUp?.sides
43879
+ ? getPositionAssignments$1({
43880
+ structureId: structure?.structureId,
43881
+ drawDefinition,
43882
+ }).positionAssignments
43883
+ : [];
43884
+ const requiredParticipants = (participantsCount && participantsCount === 2) ||
43885
+ (matchUp.collectionId && isAdHoc({ structure }) && participantsCount && participantsCount >= 1) ||
43886
+ (assignedDrawPositions?.length === 2 &&
43887
+ positionAssignments
43888
+ ?.filter((assignment) => assignedDrawPositions.includes(assignment.drawPosition))
43889
+ .every((assignment) => assignment.participantId));
43890
+ if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !requiredParticipants) {
43891
+ return decorateResult({
43892
+ info: 'matchUpStatus requires assigned participants',
43893
+ context: { matchUpStatus, requiredParticipants },
43894
+ result: { error: INVALID_MATCHUP_STATUS },
43895
+ });
43896
+ }
43897
+ return { ...SUCCESS };
43898
+ }
43881
43899
 
43882
43900
  function enableTieAutoCalc({ tournamentRecord, drawDefinition, matchUpId, event }) {
43883
43901
  if (!drawDefinition)
@@ -44711,16 +44729,15 @@ function setOrderOfFinish(params) {
44711
44729
  return setOrderOfFinish$1(params);
44712
44730
  }
44713
44731
 
44714
- function applyLineUps({ tournamentRecord, drawDefinition, matchUpId, lineUps, event }) {
44715
- if (!tournamentRecord)
44716
- return { error: MISSING_TOURNAMENT_RECORD };
44717
- if (!drawDefinition)
44718
- return { error: DRAW_DEFINITION_NOT_FOUND };
44719
- if (typeof matchUpId !== 'string')
44720
- return { error: INVALID_MATCHUP };
44721
- if (!Array.isArray(lineUps))
44722
- return { error: INVALID_VALUES, lineUps };
44732
+ function applyLineUps(params) {
44733
+ const { tournamentRecord, drawDefinition, matchUpId, lineUps, event } = params;
44723
44734
  const stack = 'applyLineUps';
44735
+ const paramsCheck = checkRequiredParameters(params, [
44736
+ { [TOURNAMENT_RECORD]: true, [DRAW_DEFINITION]: true, [MATCHUP_ID]: true },
44737
+ { lineUps: true, [OF_TYPE]: ARRAY },
44738
+ ], stack);
44739
+ if (paramsCheck.error)
44740
+ return paramsCheck;
44724
44741
  const tournamentParticipants = tournamentRecord.participants || [];
44725
44742
  let result = findDrawMatchUp({
44726
44743
  tournamentParticipants,
@@ -47048,6 +47065,7 @@ var lastNames = [
47048
47065
  "Bennett",
47049
47066
  "Berry",
47050
47067
  "Bonaparte",
47068
+ "Brewer",
47051
47069
  "Brockovich",
47052
47070
  "Bukowski",
47053
47071
  "Cassidy",
@@ -52155,7 +52173,10 @@ function getAvgWTN({ eventType, matchUps, eventId, drawId }) {
52155
52173
  function getStructureReports({ firstFlightOnly = true, extensionProfiles, tournamentRecord, }) {
52156
52174
  if (!tournamentRecord)
52157
52175
  return { error: MISSING_TOURNAMENT_ID };
52176
+ const mainStructures = [];
52177
+ const structureManipulations = {};
52158
52178
  const eventStructureReports = {};
52179
+ const flightReports = [];
52159
52180
  const extensionValues = Object.assign({}, ...(extensionProfiles ?? []).map(({ name, label, accessor }) => {
52160
52181
  const element = findExtension({
52161
52182
  element: tournamentRecord,
@@ -52178,7 +52199,16 @@ function getStructureReports({ firstFlightOnly = true, extensionProfiles, tourna
52178
52199
  })?.timeItem;
52179
52200
  return timeItem?.itemValue?.scaleBasis;
52180
52201
  };
52181
- const tournamentStructureData = tournamentRecord?.events?.flatMap(({ timeItems: eventTimeItems, drawDefinitions = [], extensions, eventType, eventId, category }) => {
52202
+ const updateStructureManipulations = ({ positionManipulations }) => {
52203
+ positionManipulations?.forEach((action) => {
52204
+ const { structureId, name } = action;
52205
+ const drawPositions = action.drawPositions || [action.drawPosition];
52206
+ if (!structureManipulations[structureId])
52207
+ structureManipulations[structureId] = [];
52208
+ structureManipulations[structureId].push(`${name}: ${drawPositions.join('/')}`);
52209
+ });
52210
+ };
52211
+ const tournamentStructureData = tournamentRecord?.events?.flatMap(({ timeItems: eventTimeItems, drawDefinitions = [], extensions, eventType, eventName, eventId, category }) => {
52182
52212
  const flightProfile = extensions?.find((x) => x.name === FLIGHT_PROFILE);
52183
52213
  const flightNumbers = flightProfile?.value?.flights?.map((flight) => ({
52184
52214
  [flight.drawId]: flight.flightNumber,
@@ -52200,17 +52230,16 @@ function getStructureReports({ firstFlightOnly = true, extensionProfiles, tourna
52200
52230
  return (drawDefinitions
52201
52231
  .filter((d) => !firstFlightOnly || !flightNumbers || flightMap[d.drawId] === minFlightNumber)
52202
52232
  .flatMap((dd) => {
52203
- const { matchUpFormat: drawMatchUpFormat, tieFormat: drawTieFormat, timeItems: drawTimeItems, extensions, structures, drawType, drawId, } = dd;
52233
+ const { matchUpFormat: drawMatchUpFormat, tieFormat: drawTieFormat, timeItems: drawTimeItems, extensions, structures, drawName, drawType, drawId, } = dd;
52204
52234
  const { matchUpFormatCounts, matchUpsCount, avgConfidence, pctNoRating, avgWTN } = getAvgWTN({
52205
52235
  eventType,
52206
52236
  matchUps,
52207
52237
  drawId,
52208
52238
  });
52209
52239
  const seedingBasis = getSeedingBasis(drawTimeItems) || eventSeedingBasis;
52210
- const positionManipulations = getPositionManipulations({
52211
- extensions,
52212
- });
52240
+ const positionManipulations = getPositionManipulations({ extensions });
52213
52241
  const manipulationsCount = positionManipulations?.length || 0;
52242
+ updateStructureManipulations({ positionManipulations });
52214
52243
  eventStructureReports[eventId].totalPositionManipulations += manipulationsCount;
52215
52244
  eventStructureReports[eventId].generatedDrawsCount += 1;
52216
52245
  if (manipulationsCount > eventStructureReports[eventId].maxPositionManipulations)
@@ -52221,6 +52250,8 @@ function getStructureReports({ firstFlightOnly = true, extensionProfiles, tourna
52221
52250
  const finalMatchUp = [MAIN, PLAY_OFF].includes(s.stage)
52222
52251
  ? matchUps.find((matchUp) => matchUp.structureId === s.structureId && matchUp.finishingRound === 1 && matchUp.winningSide)
52223
52252
  : undefined;
52253
+ if (s.stage === MAIN)
52254
+ mainStructures.push({ eventName, drawName, structureId: s.structureId });
52224
52255
  const winningSide = finalMatchUp?.sides?.find((side) => side.sideNumber === finalMatchUp.winningSide);
52225
52256
  const winningParticipant = winningSide?.participant;
52226
52257
  const winningTeamId = winningParticipant?.participantType === TEAM_PARTICIPANT && winningParticipant.participantId;
@@ -52285,9 +52316,14 @@ function getStructureReports({ firstFlightOnly = true, extensionProfiles, tourna
52285
52316
  });
52286
52317
  }));
52287
52318
  });
52319
+ mainStructures.forEach(({ eventName, drawName, structureId }) => {
52320
+ if (structureManipulations[structureId]?.length)
52321
+ flightReports.push({ eventName, drawName, actions: structureManipulations[structureId] });
52322
+ });
52288
52323
  return {
52289
52324
  eventStructureReports: Object.values(eventStructureReports),
52290
52325
  structureReports: tournamentStructureData,
52326
+ flightReports,
52291
52327
  };
52292
52328
  }
52293
52329
  function getPositionManipulations({ extensions }) {
@@ -57670,6 +57706,8 @@ const POLICY_PRIVACY_DEFAULT = {
57670
57706
  participantRole: true,
57671
57707
  participantStatus: true,
57672
57708
  penalties: false,
57709
+ rankings: true,
57710
+ ratings: true,
57673
57711
  representing: true,
57674
57712
  participantRoleResponsibilities: false,
57675
57713
  participantType: true,
@@ -57705,6 +57743,8 @@ const POLICY_PRIVACY_DEFAULT = {
57705
57743
  participantRole: true,
57706
57744
  participantStatus: true,
57707
57745
  penalties: false,
57746
+ rankings: true,
57747
+ ratings: true,
57708
57748
  representing: true,
57709
57749
  participantRoleResponsibilities: false,
57710
57750
  participantType: true,
@@ -57743,7 +57783,8 @@ const POLICY_SCORING_DEFAULT = {
57743
57783
  drawDefinitions: false,
57744
57784
  structures: false,
57745
57785
  },
57746
- requireAllPositionsAssigned: false,
57786
+ requireParticipantsForScoring: false,
57787
+ requireAllPositionsAssigned: undefined,
57747
57788
  allowChangePropagation: false,
57748
57789
  stage: {
57749
57790
  [MAIN]: {