tods-competition-factory 1.8.15 → 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;
@@ -14910,11 +14910,11 @@ function countSets({
14910
14910
  score
14911
14911
  }) {
14912
14912
  const setsTally = [0, 0];
14913
- const { sets } = score || {};
14914
- const matchUpWinnerIndex = matchUpWinningSide - 1;
14913
+ const sets = score?.sets;
14914
+ const matchUpWinnerIndex = typeof matchUpWinningSide === "number" && matchUpWinningSide - 1;
14915
14915
  const parsedMatchUpFormat = parse(matchUpFormat);
14916
14916
  const setsToWin = getSetsToWin(parsedMatchUpFormat?.bestOf ?? 1);
14917
- if (matchUpStatus === DEFAULTED && tallyPolicy?.setsCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.setsCreditForWalkovers) {
14917
+ if (typeof matchUpWinnerIndex === "number" && (matchUpStatus === DEFAULTED && tallyPolicy?.setsCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.setsCreditForWalkovers)) {
14918
14918
  setsTally[matchUpWinnerIndex] = setsToWin;
14919
14919
  } else {
14920
14920
  for (const set of sets || []) {
@@ -14923,7 +14923,7 @@ function countSets({
14923
14923
  setsTally[setWinningSide - 1] += 1;
14924
14924
  }
14925
14925
  }
14926
- if (matchUpStatus === RETIRED) {
14926
+ if (typeof matchUpWinnerIndex === "number" && matchUpStatus === RETIRED) {
14927
14927
  if (+setsTally[1 - matchUpWinnerIndex] === setsToWin)
14928
14928
  setsTally[1 - matchUpWinnerIndex] -= 1;
14929
14929
  if (tallyPolicy?.setsCreditForRetirements)
@@ -14941,13 +14941,13 @@ function countGames({
14941
14941
  const { sets } = score || {};
14942
14942
  if (!sets)
14943
14943
  return [0, 0];
14944
- const matchUpWinnerIndex = matchUpWinningSide - 1;
14944
+ const matchUpWinnerIndex = typeof matchUpWinningSide === "number" && matchUpWinningSide - 1;
14945
14945
  const parsedMatchUpFormat = parse(matchUpFormat);
14946
14946
  const bestOf = parsedMatchUpFormat?.bestOf ?? 1;
14947
14947
  const setsToWin = getSetsToWin(bestOf);
14948
14948
  const tiebreakAt = parsedMatchUpFormat?.setFormat?.tiebreakAt || 0;
14949
14949
  const gamesTally = [[], []];
14950
- if (matchUpStatus === DEFAULTED && tallyPolicy?.gamesCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.gamesCreditForWalkovers) {
14950
+ if (typeof matchUpWinnerIndex === "number" && (matchUpStatus === DEFAULTED && tallyPolicy?.gamesCreditForDefaults || matchUpStatus === WALKOVER$1 && tallyPolicy?.gamesCreditForWalkovers)) {
14951
14951
  const gamesForSet = parsedMatchUpFormat?.setFormat?.setTo || 0;
14952
14952
  const minimumGameWins = setsToWin * gamesForSet;
14953
14953
  gamesTally[matchUpWinnerIndex].push(minimumGameWins);
@@ -14967,7 +14967,7 @@ function countGames({
14967
14967
  }
14968
14968
  });
14969
14969
  }
14970
- if (matchUpStatus === RETIRED) {
14970
+ if (matchUpStatus === RETIRED && typeof matchUpWinnerIndex === "number") {
14971
14971
  const whichFormat = sets.length > setsToWin && parsedMatchUpFormat?.finalSetFormat ? "finalSetFormat" : "setFormat";
14972
14972
  const format = parsedMatchUpFormat?.[whichFormat];
14973
14973
  if (isGamesBased(format.based)) {
@@ -15007,10 +15007,14 @@ function countGames({
15007
15007
  gamesTally[1].reduce((a, b) => a + b, 0)
15008
15008
  ];
15009
15009
  }
15010
- function countPoints({ matchUpFormat, score }) {
15011
- const parsedMatchUpFormat = parse(matchUpFormat);
15010
+ function countPoints({
15011
+ matchUpFormat,
15012
+ score
15013
+ }) {
15014
+ const parsedMatchUpFormat = matchUpFormat ? parse(matchUpFormat) : void 0;
15012
15015
  const bestOf = parsedMatchUpFormat?.bestOf ?? 1;
15013
15016
  const setsToWin = getSetsToWin(bestOf);
15017
+ const tiebreaksTally = [0, 0];
15014
15018
  const pointsTally = [0, 0];
15015
15019
  score?.sets?.forEach((set, i) => {
15016
15020
  const setNumber = set.setNumber || i + 1;
@@ -15027,9 +15031,11 @@ function countPoints({ matchUpFormat, score }) {
15027
15031
  pointsTally[0] += ensureInt(set.side1TiebreakScore || 0);
15028
15032
  if (set.side2TiebreakScore)
15029
15033
  pointsTally[1] += ensureInt(set.side2TiebreakScore || 0);
15034
+ if ((set.side1TiebreakScore || set.side2TiebreakScore) && set.winningSide)
15035
+ tiebreaksTally[set.winningSide - 1] += 1;
15030
15036
  }
15031
15037
  });
15032
- return pointsTally;
15038
+ return { pointsTally, tiebreaksTally };
15033
15039
  }
15034
15040
  function getSetsToWin(bestOfGames) {
15035
15041
  return bestOfGames && Math.ceil(bestOfGames / 2) || 1;
@@ -15129,7 +15135,7 @@ function getParticipantResults({
15129
15135
  const winningParticipantId = winningSide && getWinningSideId(matchUp);
15130
15136
  const losingParticipantId = winningSide && getLosingSideId(matchUp);
15131
15137
  if (!winningParticipantId && !losingParticipantId) {
15132
- if (completedMatchUpStatuses.includes(matchUpStatus)) {
15138
+ if (matchUpStatus && completedMatchUpStatuses.includes(matchUpStatus)) {
15133
15139
  const participantIdSide1 = getSideId(matchUp, 0);
15134
15140
  const participantIdSide2 = getSideId(matchUp, 1);
15135
15141
  if (participantIdSide1) {
@@ -15144,10 +15150,10 @@ function getParticipantResults({
15144
15150
  perPlayer = 0;
15145
15151
  for (const tieMatchUp of tieMatchUps) {
15146
15152
  if (tieMatchUp.winningSide) {
15147
- const tieWinningParticipantId = sides.find(
15153
+ const tieWinningParticipantId = sides?.find(
15148
15154
  ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
15149
15155
  )?.participantId;
15150
- const tieLosingParticipantId = sides.find(
15156
+ const tieLosingParticipantId = sides?.find(
15151
15157
  ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
15152
15158
  )?.participantId;
15153
15159
  if (tieWinningParticipantId && tieLosingParticipantId) {
@@ -15266,26 +15272,30 @@ function getParticipantResults({
15266
15272
  }
15267
15273
  }
15268
15274
  if (manualGamesOverride) {
15269
- const side1participantId = sides.find(
15275
+ const side1participantId = sides?.find(
15270
15276
  ({ sideNumber }) => sideNumber === 1
15271
15277
  )?.participantId;
15272
- const side2participantId = sides.find(
15278
+ const side2participantId = sides?.find(
15273
15279
  ({ sideNumber }) => sideNumber === 2
15274
15280
  )?.participantId;
15275
15281
  checkInitializeParticipant(participantResults, side1participantId);
15276
15282
  checkInitializeParticipant(participantResults, side2participantId);
15277
- const gamesWonSide1 = score.sets.reduce(
15278
- (total, set) => total + set.side1Score,
15283
+ const gamesWonSide1 = score?.sets?.reduce(
15284
+ (total, set) => total + (set?.side1Score ?? 0),
15279
15285
  0
15280
15286
  );
15281
- const gamesWonSide2 = score.sets.reduce(
15282
- (total, set) => total + set.side2Score,
15287
+ const gamesWonSide2 = score?.sets?.reduce(
15288
+ (total, set) => total + (set.side2Score ?? 0),
15283
15289
  0
15284
15290
  );
15285
- participantResults[side1participantId].gamesWon += gamesWonSide1;
15286
- participantResults[side2participantId].gamesWon += gamesWonSide2;
15287
- participantResults[side1participantId].gamesLost += gamesWonSide2;
15288
- 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
+ }
15289
15299
  }
15290
15300
  }
15291
15301
  calculatePercentages({
@@ -15412,7 +15422,7 @@ function processMatchUp({
15412
15422
  winningSide,
15413
15423
  score
15414
15424
  });
15415
- const pointsTally = countPoints({ score, matchUpFormat });
15425
+ const { pointsTally } = countPoints({ score, matchUpFormat });
15416
15426
  if (winningParticipantId) {
15417
15427
  participantResults[winningParticipantId].setsWon += setsTally[winningSideIndex];
15418
15428
  participantResults[winningParticipantId].setsLost += setsTally[losingSideIndex];