tods-competition-factory 1.8.14 → 1.8.16

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.
@@ -523,6 +523,7 @@ interface Side {
523
523
  lineUp?: TeamCompetitor[];
524
524
  notes?: string;
525
525
  participantId?: string;
526
+ participant?: Participant;
526
527
  sideNumber?: number;
527
528
  timeItems?: TimeItem[];
528
529
  updatedAt?: Date | string;
@@ -7554,6 +7554,21 @@ function addNationalityCode({
7554
7554
  persons.forEach(annotatePerson);
7555
7555
  }
7556
7556
 
7557
+ function addIndividualParticipants({ participantMap }) {
7558
+ const participantObjects = Object.values(participantMap);
7559
+ for (const participantObject of participantObjects) {
7560
+ const participant = participantObject.participant;
7561
+ if (participant.individualParticipantIds?.length) {
7562
+ participant.individualParticipants = [];
7563
+ for (const participantId of participant.individualParticipantIds) {
7564
+ participant.individualParticipants.push(
7565
+ participantMap[participantId].participant
7566
+ );
7567
+ }
7568
+ }
7569
+ }
7570
+ }
7571
+
7557
7572
  function getTimeItem({
7558
7573
  returnPreviousValues,
7559
7574
  itemSubTypes,
@@ -7656,20 +7671,6 @@ function signedIn(participant) {
7656
7671
  });
7657
7672
  return timeItem?.itemValue === SIGNED_IN;
7658
7673
  }
7659
- function addIndividualParticipants({ participantMap }) {
7660
- const participantObjects = Object.values(participantMap);
7661
- for (const participantObject of participantObjects) {
7662
- const participant = participantObject.participant;
7663
- if (participant.individualParticipantIds?.length) {
7664
- participant.individualParticipants = [];
7665
- for (const participantId of participant.individualParticipantIds) {
7666
- participant.individualParticipants.push(
7667
- participantMap[participantId].participant
7668
- );
7669
- }
7670
- }
7671
- }
7672
- }
7673
7674
  function processIndividualParticipantIds({
7674
7675
  individualParticipantIds,
7675
7676
  participantCopy,
@@ -8739,7 +8740,6 @@ function allEventMatchUps(params) {
8739
8740
  if (!event)
8740
8741
  return { error: MISSING_EVENT };
8741
8742
  const { eventId, eventName, endDate, category, gender, matchUpFormat } = event;
8742
- const eventMatchUps2 = [];
8743
8743
  const additionalContext = {
8744
8744
  ...context,
8745
8745
  ...definedAttributes({
@@ -8783,7 +8783,7 @@ function allEventMatchUps(params) {
8783
8783
  }).scheduleTiming;
8784
8784
  const matchUps = drawDefinitions.flatMap(
8785
8785
  (drawDefinition) => {
8786
- const { matchUps: matchUps2, matchUpsMap } = getAllDrawMatchUps({
8786
+ const { matchUps: matchUps2 } = getAllDrawMatchUps({
8787
8787
  tournamentParticipants: participants,
8788
8788
  tournamentAppliedPolicies,
8789
8789
  scheduleVisibilityFilters,
@@ -8803,12 +8803,10 @@ function allEventMatchUps(params) {
8803
8803
  inContext,
8804
8804
  event
8805
8805
  });
8806
- if (matchUpsMap?.drawMatchUps)
8807
- eventMatchUps2.push(...matchUpsMap.drawMatchUps);
8808
8806
  return matchUps2 ?? [];
8809
8807
  }
8810
8808
  );
8811
- return { matchUps, eventMatchUps: eventMatchUps2 };
8809
+ return { matchUps };
8812
8810
  }
8813
8811
 
8814
8812
  function addFinishingRounds({
@@ -14912,11 +14910,11 @@ function countSets({
14912
14910
  score
14913
14911
  }) {
14914
14912
  const setsTally = [0, 0];
14915
- const { sets } = score || {};
14916
- const matchUpWinnerIndex = matchUpWinningSide - 1;
14913
+ const sets = score?.sets;
14914
+ const matchUpWinnerIndex = typeof matchUpWinningSide === "number" && matchUpWinningSide - 1;
14917
14915
  const parsedMatchUpFormat = parse(matchUpFormat);
14918
14916
  const setsToWin = getSetsToWin(parsedMatchUpFormat?.bestOf ?? 1);
14919
- if (matchUpStatus === DEFAULTED && tallyPolicy?.setsCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.setsCreditForWalkovers) {
14917
+ if (typeof matchUpWinnerIndex === "number" && (matchUpStatus === DEFAULTED && tallyPolicy?.setsCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.setsCreditForWalkovers)) {
14920
14918
  setsTally[matchUpWinnerIndex] = setsToWin;
14921
14919
  } else {
14922
14920
  for (const set of sets || []) {
@@ -14925,7 +14923,7 @@ function countSets({
14925
14923
  setsTally[setWinningSide - 1] += 1;
14926
14924
  }
14927
14925
  }
14928
- if (matchUpStatus === RETIRED) {
14926
+ if (typeof matchUpWinnerIndex === "number" && matchUpStatus === RETIRED) {
14929
14927
  if (+setsTally[1 - matchUpWinnerIndex] === setsToWin)
14930
14928
  setsTally[1 - matchUpWinnerIndex] -= 1;
14931
14929
  if (tallyPolicy?.setsCreditForRetirements)
@@ -14943,13 +14941,13 @@ function countGames({
14943
14941
  const { sets } = score || {};
14944
14942
  if (!sets)
14945
14943
  return [0, 0];
14946
- const matchUpWinnerIndex = matchUpWinningSide - 1;
14944
+ const matchUpWinnerIndex = typeof matchUpWinningSide === "number" && matchUpWinningSide - 1;
14947
14945
  const parsedMatchUpFormat = parse(matchUpFormat);
14948
14946
  const bestOf = parsedMatchUpFormat?.bestOf ?? 1;
14949
14947
  const setsToWin = getSetsToWin(bestOf);
14950
14948
  const tiebreakAt = parsedMatchUpFormat?.setFormat?.tiebreakAt || 0;
14951
14949
  const gamesTally = [[], []];
14952
- if (matchUpStatus === DEFAULTED && tallyPolicy?.gamesCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.gamesCreditForWalkovers) {
14950
+ if (typeof matchUpWinnerIndex === "number" && (matchUpStatus === DEFAULTED && tallyPolicy?.gamesCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.gamesCreditForWalkovers)) {
14953
14951
  const gamesForSet = parsedMatchUpFormat?.setFormat?.setTo || 0;
14954
14952
  const minimumGameWins = setsToWin * gamesForSet;
14955
14953
  gamesTally[matchUpWinnerIndex].push(minimumGameWins);
@@ -14969,7 +14967,7 @@ function countGames({
14969
14967
  }
14970
14968
  });
14971
14969
  }
14972
- if (matchUpStatus === RETIRED) {
14970
+ if (matchUpStatus === RETIRED && typeof matchUpWinnerIndex === "number") {
14973
14971
  const whichFormat = sets.length > setsToWin && parsedMatchUpFormat?.finalSetFormat ? "finalSetFormat" : "setFormat";
14974
14972
  const format = parsedMatchUpFormat?.[whichFormat];
14975
14973
  if (isGamesBased(format.based)) {
@@ -15009,10 +15007,14 @@ function countGames({
15009
15007
  gamesTally[1].reduce((a, b) => a + b, 0)
15010
15008
  ];
15011
15009
  }
15012
- function countPoints({ matchUpFormat, score }) {
15013
- const parsedMatchUpFormat = parse(matchUpFormat);
15010
+ function countPoints({
15011
+ matchUpFormat,
15012
+ score
15013
+ }) {
15014
+ const parsedMatchUpFormat = matchUpFormat ? parse(matchUpFormat) : void 0;
15014
15015
  const bestOf = parsedMatchUpFormat?.bestOf ?? 1;
15015
15016
  const setsToWin = getSetsToWin(bestOf);
15017
+ const tiebreaksTally = [0, 0];
15016
15018
  const pointsTally = [0, 0];
15017
15019
  score?.sets?.forEach((set, i) => {
15018
15020
  const setNumber = set.setNumber || i + 1;
@@ -15029,9 +15031,11 @@ function countPoints({ matchUpFormat, score }) {
15029
15031
  pointsTally[0] += ensureInt(set.side1TiebreakScore || 0);
15030
15032
  if (set.side2TiebreakScore)
15031
15033
  pointsTally[1] += ensureInt(set.side2TiebreakScore || 0);
15034
+ if ((set.side1TiebreakScore || set.side2TiebreakScore) && set.winningSide)
15035
+ tiebreaksTally[set.winningSide - 1] += 1;
15032
15036
  }
15033
15037
  });
15034
- return pointsTally;
15038
+ return { pointsTally, tiebreaksTally };
15035
15039
  }
15036
15040
  function getSetsToWin(bestOfGames) {
15037
15041
  return bestOfGames && Math.ceil(bestOfGames / 2) || 1;
@@ -15131,7 +15135,7 @@ function getParticipantResults({
15131
15135
  const winningParticipantId = winningSide && getWinningSideId(matchUp);
15132
15136
  const losingParticipantId = winningSide && getLosingSideId(matchUp);
15133
15137
  if (!winningParticipantId && !losingParticipantId) {
15134
- if (completedMatchUpStatuses.includes(matchUpStatus)) {
15138
+ if (matchUpStatus && completedMatchUpStatuses.includes(matchUpStatus)) {
15135
15139
  const participantIdSide1 = getSideId(matchUp, 0);
15136
15140
  const participantIdSide2 = getSideId(matchUp, 1);
15137
15141
  if (participantIdSide1) {
@@ -15146,10 +15150,10 @@ function getParticipantResults({
15146
15150
  perPlayer = 0;
15147
15151
  for (const tieMatchUp of tieMatchUps) {
15148
15152
  if (tieMatchUp.winningSide) {
15149
- const tieWinningParticipantId = sides.find(
15153
+ const tieWinningParticipantId = sides?.find(
15150
15154
  ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
15151
15155
  )?.participantId;
15152
- const tieLosingParticipantId = sides.find(
15156
+ const tieLosingParticipantId = sides?.find(
15153
15157
  ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
15154
15158
  )?.participantId;
15155
15159
  if (tieWinningParticipantId && tieLosingParticipantId) {
@@ -15268,26 +15272,30 @@ function getParticipantResults({
15268
15272
  }
15269
15273
  }
15270
15274
  if (manualGamesOverride) {
15271
- const side1participantId = sides.find(
15275
+ const side1participantId = sides?.find(
15272
15276
  ({ sideNumber }) => sideNumber === 1
15273
15277
  )?.participantId;
15274
- const side2participantId = sides.find(
15278
+ const side2participantId = sides?.find(
15275
15279
  ({ sideNumber }) => sideNumber === 2
15276
15280
  )?.participantId;
15277
15281
  checkInitializeParticipant(participantResults, side1participantId);
15278
15282
  checkInitializeParticipant(participantResults, side2participantId);
15279
- const gamesWonSide1 = score.sets.reduce(
15280
- (total, set) => total + set.side1Score,
15283
+ const gamesWonSide1 = score?.sets?.reduce(
15284
+ (total, set) => total + (set?.side1Score ?? 0),
15281
15285
  0
15282
15286
  );
15283
- const gamesWonSide2 = score.sets.reduce(
15284
- (total, set) => total + set.side2Score,
15287
+ const gamesWonSide2 = score?.sets?.reduce(
15288
+ (total, set) => total + (set.side2Score ?? 0),
15285
15289
  0
15286
15290
  );
15287
- participantResults[side1participantId].gamesWon += gamesWonSide1;
15288
- participantResults[side2participantId].gamesWon += gamesWonSide2;
15289
- participantResults[side1participantId].gamesLost += gamesWonSide2;
15290
- participantResults[side2participantId].gamesLost += gamesWonSide1;
15291
+ if (side1participantId) {
15292
+ participantResults[side1participantId].gamesWon += gamesWonSide1;
15293
+ participantResults[side1participantId].gamesLost += gamesWonSide2;
15294
+ }
15295
+ if (side2participantId) {
15296
+ participantResults[side2participantId].gamesWon += gamesWonSide2;
15297
+ participantResults[side2participantId].gamesLost += gamesWonSide1;
15298
+ }
15291
15299
  }
15292
15300
  }
15293
15301
  calculatePercentages({
@@ -15414,7 +15422,7 @@ function processMatchUp({
15414
15422
  winningSide,
15415
15423
  score
15416
15424
  });
15417
- const pointsTally = countPoints({ score, matchUpFormat });
15425
+ const { pointsTally } = countPoints({ score, matchUpFormat });
15418
15426
  if (winningParticipantId) {
15419
15427
  participantResults[winningParticipantId].setsWon += setsTally[winningSideIndex];
15420
15428
  participantResults[winningParticipantId].setsLost += setsTally[losingSideIndex];
@@ -19073,7 +19081,6 @@ function getParticipants(params) {
19073
19081
  getMatchUpDependencies({ tournamentRecord });
19074
19082
  }
19075
19083
  let { participantMap } = getParticipantMap({
19076
- withIndividualParticipants,
19077
19084
  convertExtensions,
19078
19085
  tournamentRecord,
19079
19086
  withSignInStatus,
@@ -19112,45 +19119,48 @@ function getParticipants(params) {
19112
19119
  const matchUps = entriesResult.matchUps;
19113
19120
  participantMap = entriesResult.participantMap;
19114
19121
  const nextMatchUps = scheduleAnalysis ?? withPotentialMatchUps;
19115
- const processedParticipants = Object.values(participantMap).map(
19116
- ({
19117
- potentialMatchUps,
19118
- scheduleConflicts,
19119
- scheduleItems,
19120
- participant,
19121
- statistics,
19122
- opponents,
19123
- matchUps: matchUps2,
19124
- events,
19125
- draws
19126
- }) => {
19127
- const participantDraws = Object.values(draws);
19128
- const participantOpponents = Object.values(opponents);
19129
- if (withOpponents) {
19130
- participantDraws?.forEach((draw) => {
19131
- draw.opponents = participantOpponents.filter(
19132
- (opponent) => opponent.drawId === draw.drawId
19133
- );
19134
- });
19135
- }
19136
- return definedAttributes(
19137
- {
19138
- ...participant,
19139
- scheduleConflicts: scheduleAnalysis ? scheduleConflicts : void 0,
19140
- draws: withDraws || withRankingProfile ? participantDraws : void 0,
19141
- events: withEvents || withRankingProfile ? Object.values(events) : void 0,
19142
- matchUps: withMatchUps || withRankingProfile ? Object.values(matchUps2) : void 0,
19143
- opponents: withOpponents ? participantOpponents : void 0,
19144
- potentialMatchUps: nextMatchUps ? Object.values(potentialMatchUps) : void 0,
19145
- statistics: withStatistics ? Object.values(statistics) : void 0,
19146
- scheduleItems: withScheduleItems ? scheduleItems : void 0
19147
- },
19148
- false,
19149
- false,
19150
- true
19151
- );
19122
+ const processParticipant = ({
19123
+ potentialMatchUps,
19124
+ scheduleConflicts,
19125
+ scheduleItems,
19126
+ participant,
19127
+ statistics,
19128
+ opponents,
19129
+ matchUps: matchUps2,
19130
+ events,
19131
+ draws
19132
+ }) => {
19133
+ const participantDraws = Object.values(draws);
19134
+ const participantOpponents = Object.values(opponents);
19135
+ if (withOpponents) {
19136
+ participantDraws?.forEach((draw) => {
19137
+ draw.opponents = participantOpponents.filter(
19138
+ (opponent) => opponent.drawId === draw.drawId
19139
+ );
19140
+ });
19152
19141
  }
19153
- );
19142
+ return definedAttributes(
19143
+ {
19144
+ ...participant,
19145
+ scheduleConflicts: scheduleAnalysis ? scheduleConflicts : void 0,
19146
+ draws: withDraws || withRankingProfile ? participantDraws : void 0,
19147
+ events: withEvents || withRankingProfile ? Object.values(events) : void 0,
19148
+ matchUps: withMatchUps || withRankingProfile ? Object.values(matchUps2) : void 0,
19149
+ opponents: withOpponents ? participantOpponents : void 0,
19150
+ potentialMatchUps: nextMatchUps ? Object.values(potentialMatchUps) : void 0,
19151
+ statistics: withStatistics ? Object.values(statistics) : void 0,
19152
+ scheduleItems: withScheduleItems ? scheduleItems : void 0
19153
+ },
19154
+ false,
19155
+ false,
19156
+ true
19157
+ );
19158
+ };
19159
+ const ppMap = /* @__PURE__ */ new Map();
19160
+ for (const participantId of Object.keys(participantMap)) {
19161
+ ppMap.set(participantId, processParticipant(participantMap[participantId]));
19162
+ }
19163
+ const processedParticipants = [...ppMap.values()];
19154
19164
  const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
19155
19165
  const template = participantAttributes?.participant;
19156
19166
  const filteredParticipants = filterParticipants({
@@ -19158,6 +19168,17 @@ function getParticipants(params) {
19158
19168
  participantFilters,
19159
19169
  tournamentRecord
19160
19170
  });
19171
+ if (withIndividualParticipants) {
19172
+ for (const participant of filteredParticipants) {
19173
+ for (const individualParticipantId of participant.individualParticipantIds ?? []) {
19174
+ if (!participant.individualParticipants)
19175
+ participant.individualParticipants = [];
19176
+ participant.individualParticipants.push(
19177
+ ppMap.get(individualParticipantId)
19178
+ );
19179
+ }
19180
+ }
19181
+ }
19161
19182
  const participants = template ? filteredParticipants.map(
19162
19183
  (source) => attributeFilter({ source, template })
19163
19184
  ) : filteredParticipants;