tods-competition-factory 1.8.15 → 1.8.17
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.
- package/dist/forge/generate.d.ts +1 -0
- package/dist/forge/generate.mjs +35 -25
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.d.ts +1 -0
- package/dist/forge/query.mjs +1 -1
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.d.ts +1 -0
- package/dist/forge/transform.mjs +35 -25
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +306 -31
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +463 -43
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +4 -6
package/dist/index.mjs
CHANGED
|
@@ -2382,7 +2382,7 @@ const matchUpFormatCode = {
|
|
|
2382
2382
|
};
|
|
2383
2383
|
|
|
2384
2384
|
function factoryVersion() {
|
|
2385
|
-
return "1.8.
|
|
2385
|
+
return "1.8.17";
|
|
2386
2386
|
}
|
|
2387
2387
|
|
|
2388
2388
|
function getObjectTieFormat(obj) {
|
|
@@ -3189,11 +3189,11 @@ function countSets({
|
|
|
3189
3189
|
score
|
|
3190
3190
|
}) {
|
|
3191
3191
|
const setsTally = [0, 0];
|
|
3192
|
-
const
|
|
3193
|
-
const matchUpWinnerIndex = matchUpWinningSide - 1;
|
|
3192
|
+
const sets = score?.sets;
|
|
3193
|
+
const matchUpWinnerIndex = typeof matchUpWinningSide === "number" && matchUpWinningSide - 1;
|
|
3194
3194
|
const parsedMatchUpFormat = parse(matchUpFormat);
|
|
3195
3195
|
const setsToWin = getSetsToWin(parsedMatchUpFormat?.bestOf ?? 1);
|
|
3196
|
-
if (matchUpStatus === DEFAULTED && tallyPolicy?.setsCreditForDefaults || matchUpStatus === WALKOVER$2 && tallyPolicy?.setsCreditForWalkovers) {
|
|
3196
|
+
if (typeof matchUpWinnerIndex === "number" && (matchUpStatus === DEFAULTED && tallyPolicy?.setsCreditForDefaults || matchUpStatus === WALKOVER$2 && tallyPolicy?.setsCreditForWalkovers)) {
|
|
3197
3197
|
setsTally[matchUpWinnerIndex] = setsToWin;
|
|
3198
3198
|
} else {
|
|
3199
3199
|
for (const set of sets || []) {
|
|
@@ -3202,7 +3202,7 @@ function countSets({
|
|
|
3202
3202
|
setsTally[setWinningSide - 1] += 1;
|
|
3203
3203
|
}
|
|
3204
3204
|
}
|
|
3205
|
-
if (matchUpStatus === RETIRED$1) {
|
|
3205
|
+
if (typeof matchUpWinnerIndex === "number" && matchUpStatus === RETIRED$1) {
|
|
3206
3206
|
if (+setsTally[1 - matchUpWinnerIndex] === setsToWin)
|
|
3207
3207
|
setsTally[1 - matchUpWinnerIndex] -= 1;
|
|
3208
3208
|
if (tallyPolicy?.setsCreditForRetirements)
|
|
@@ -3220,13 +3220,13 @@ function countGames({
|
|
|
3220
3220
|
const { sets } = score || {};
|
|
3221
3221
|
if (!sets)
|
|
3222
3222
|
return [0, 0];
|
|
3223
|
-
const matchUpWinnerIndex = matchUpWinningSide - 1;
|
|
3223
|
+
const matchUpWinnerIndex = typeof matchUpWinningSide === "number" && matchUpWinningSide - 1;
|
|
3224
3224
|
const parsedMatchUpFormat = parse(matchUpFormat);
|
|
3225
3225
|
const bestOf = parsedMatchUpFormat?.bestOf ?? 1;
|
|
3226
3226
|
const setsToWin = getSetsToWin(bestOf);
|
|
3227
3227
|
const tiebreakAt = parsedMatchUpFormat?.setFormat?.tiebreakAt || 0;
|
|
3228
3228
|
const gamesTally = [[], []];
|
|
3229
|
-
if (matchUpStatus === DEFAULTED && tallyPolicy?.gamesCreditForDefaults || matchUpStatus === WALKOVER$2 && tallyPolicy?.gamesCreditForWalkovers) {
|
|
3229
|
+
if (typeof matchUpWinnerIndex === "number" && (matchUpStatus === DEFAULTED && tallyPolicy?.gamesCreditForDefaults || matchUpStatus === WALKOVER$2 && tallyPolicy?.gamesCreditForWalkovers)) {
|
|
3230
3230
|
const gamesForSet = parsedMatchUpFormat?.setFormat?.setTo || 0;
|
|
3231
3231
|
const minimumGameWins = setsToWin * gamesForSet;
|
|
3232
3232
|
gamesTally[matchUpWinnerIndex].push(minimumGameWins);
|
|
@@ -3246,7 +3246,7 @@ function countGames({
|
|
|
3246
3246
|
}
|
|
3247
3247
|
});
|
|
3248
3248
|
}
|
|
3249
|
-
if (matchUpStatus === RETIRED$1) {
|
|
3249
|
+
if (matchUpStatus === RETIRED$1 && typeof matchUpWinnerIndex === "number") {
|
|
3250
3250
|
const whichFormat = sets.length > setsToWin && parsedMatchUpFormat?.finalSetFormat ? "finalSetFormat" : "setFormat";
|
|
3251
3251
|
const format = parsedMatchUpFormat?.[whichFormat];
|
|
3252
3252
|
if (isGamesBased(format.based)) {
|
|
@@ -3286,10 +3286,14 @@ function countGames({
|
|
|
3286
3286
|
gamesTally[1].reduce((a, b) => a + b, 0)
|
|
3287
3287
|
];
|
|
3288
3288
|
}
|
|
3289
|
-
function countPoints({
|
|
3290
|
-
|
|
3289
|
+
function countPoints({
|
|
3290
|
+
matchUpFormat,
|
|
3291
|
+
score
|
|
3292
|
+
}) {
|
|
3293
|
+
const parsedMatchUpFormat = matchUpFormat ? parse(matchUpFormat) : void 0;
|
|
3291
3294
|
const bestOf = parsedMatchUpFormat?.bestOf ?? 1;
|
|
3292
3295
|
const setsToWin = getSetsToWin(bestOf);
|
|
3296
|
+
const tiebreaksTally = [0, 0];
|
|
3293
3297
|
const pointsTally = [0, 0];
|
|
3294
3298
|
score?.sets?.forEach((set, i) => {
|
|
3295
3299
|
const setNumber = set.setNumber || i + 1;
|
|
@@ -3306,9 +3310,11 @@ function countPoints({ matchUpFormat, score }) {
|
|
|
3306
3310
|
pointsTally[0] += ensureInt(set.side1TiebreakScore || 0);
|
|
3307
3311
|
if (set.side2TiebreakScore)
|
|
3308
3312
|
pointsTally[1] += ensureInt(set.side2TiebreakScore || 0);
|
|
3313
|
+
if ((set.side1TiebreakScore || set.side2TiebreakScore) && set.winningSide)
|
|
3314
|
+
tiebreaksTally[set.winningSide - 1] += 1;
|
|
3309
3315
|
}
|
|
3310
3316
|
});
|
|
3311
|
-
return pointsTally;
|
|
3317
|
+
return { pointsTally, tiebreaksTally };
|
|
3312
3318
|
}
|
|
3313
3319
|
function getSetsToWin(bestOfGames) {
|
|
3314
3320
|
return bestOfGames && Math.ceil(bestOfGames / 2) || 1;
|
|
@@ -3423,7 +3429,7 @@ function getParticipantResults({
|
|
|
3423
3429
|
const winningParticipantId = winningSide && getWinningSideId(matchUp);
|
|
3424
3430
|
const losingParticipantId = winningSide && getLosingSideId(matchUp);
|
|
3425
3431
|
if (!winningParticipantId && !losingParticipantId) {
|
|
3426
|
-
if (completedMatchUpStatuses.includes(matchUpStatus)) {
|
|
3432
|
+
if (matchUpStatus && completedMatchUpStatuses.includes(matchUpStatus)) {
|
|
3427
3433
|
const participantIdSide1 = getSideId(matchUp, 0);
|
|
3428
3434
|
const participantIdSide2 = getSideId(matchUp, 1);
|
|
3429
3435
|
if (participantIdSide1) {
|
|
@@ -3438,10 +3444,10 @@ function getParticipantResults({
|
|
|
3438
3444
|
perPlayer = 0;
|
|
3439
3445
|
for (const tieMatchUp of tieMatchUps) {
|
|
3440
3446
|
if (tieMatchUp.winningSide) {
|
|
3441
|
-
const tieWinningParticipantId = sides
|
|
3447
|
+
const tieWinningParticipantId = sides?.find(
|
|
3442
3448
|
({ sideNumber }) => sideNumber === tieMatchUp.winningSide
|
|
3443
3449
|
)?.participantId;
|
|
3444
|
-
const tieLosingParticipantId = sides
|
|
3450
|
+
const tieLosingParticipantId = sides?.find(
|
|
3445
3451
|
({ sideNumber }) => sideNumber === tieMatchUp.winningSide
|
|
3446
3452
|
)?.participantId;
|
|
3447
3453
|
if (tieWinningParticipantId && tieLosingParticipantId) {
|
|
@@ -3560,26 +3566,30 @@ function getParticipantResults({
|
|
|
3560
3566
|
}
|
|
3561
3567
|
}
|
|
3562
3568
|
if (manualGamesOverride) {
|
|
3563
|
-
const side1participantId = sides
|
|
3569
|
+
const side1participantId = sides?.find(
|
|
3564
3570
|
({ sideNumber }) => sideNumber === 1
|
|
3565
3571
|
)?.participantId;
|
|
3566
|
-
const side2participantId = sides
|
|
3572
|
+
const side2participantId = sides?.find(
|
|
3567
3573
|
({ sideNumber }) => sideNumber === 2
|
|
3568
3574
|
)?.participantId;
|
|
3569
3575
|
checkInitializeParticipant(participantResults, side1participantId);
|
|
3570
3576
|
checkInitializeParticipant(participantResults, side2participantId);
|
|
3571
|
-
const gamesWonSide1 = score
|
|
3572
|
-
(total, set) => total + set
|
|
3577
|
+
const gamesWonSide1 = score?.sets?.reduce(
|
|
3578
|
+
(total, set) => total + (set?.side1Score ?? 0),
|
|
3573
3579
|
0
|
|
3574
3580
|
);
|
|
3575
|
-
const gamesWonSide2 = score
|
|
3576
|
-
(total, set) => total + set.side2Score,
|
|
3581
|
+
const gamesWonSide2 = score?.sets?.reduce(
|
|
3582
|
+
(total, set) => total + (set.side2Score ?? 0),
|
|
3577
3583
|
0
|
|
3578
3584
|
);
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3585
|
+
if (side1participantId) {
|
|
3586
|
+
participantResults[side1participantId].gamesWon += gamesWonSide1;
|
|
3587
|
+
participantResults[side1participantId].gamesLost += gamesWonSide2;
|
|
3588
|
+
}
|
|
3589
|
+
if (side2participantId) {
|
|
3590
|
+
participantResults[side2participantId].gamesWon += gamesWonSide2;
|
|
3591
|
+
participantResults[side2participantId].gamesLost += gamesWonSide1;
|
|
3592
|
+
}
|
|
3583
3593
|
}
|
|
3584
3594
|
}
|
|
3585
3595
|
calculatePercentages({
|
|
@@ -3706,7 +3716,7 @@ function processMatchUp$1({
|
|
|
3706
3716
|
winningSide,
|
|
3707
3717
|
score
|
|
3708
3718
|
});
|
|
3709
|
-
const pointsTally = countPoints({ score, matchUpFormat });
|
|
3719
|
+
const { pointsTally } = countPoints({ score, matchUpFormat });
|
|
3710
3720
|
if (winningParticipantId) {
|
|
3711
3721
|
participantResults[winningParticipantId].setsWon += setsTally[winningSideIndex];
|
|
3712
3722
|
participantResults[winningParticipantId].setsLost += setsTally[losingSideIndex];
|
|
@@ -4593,8 +4603,8 @@ function findPolicy({
|
|
|
4593
4603
|
}
|
|
4594
4604
|
|
|
4595
4605
|
function getMatchUpCompetitiveProfile({
|
|
4596
|
-
profileBands,
|
|
4597
4606
|
tournamentRecord,
|
|
4607
|
+
profileBands,
|
|
4598
4608
|
matchUp
|
|
4599
4609
|
}) {
|
|
4600
4610
|
if (!matchUp)
|
|
@@ -37986,7 +37996,7 @@ function setState$4(records, deepCopyOption = true) {
|
|
|
37986
37996
|
function engineLogging({ result, methodName, elapsed, params, engine }) {
|
|
37987
37997
|
const devContext = getDevContext();
|
|
37988
37998
|
const log = { method: methodName };
|
|
37989
|
-
const logError = result
|
|
37999
|
+
const logError = result?.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
|
|
37990
38000
|
const specifiedMethodParams = Array.isArray(devContext.params) && devContext.params?.includes(methodName);
|
|
37991
38001
|
const logParams = devContext.params && !Array.isArray(devContext.params) || specifiedMethodParams;
|
|
37992
38002
|
const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
|
|
@@ -38000,7 +38010,7 @@ function engineLogging({ result, methodName, elapsed, params, engine }) {
|
|
|
38000
38010
|
}
|
|
38001
38011
|
if (Object.keys(log).length > 1)
|
|
38002
38012
|
console.log(engine, log);
|
|
38003
|
-
if (devContext.makeDeepCopy)
|
|
38013
|
+
if (result && devContext.makeDeepCopy)
|
|
38004
38014
|
result.deepCopyIterations = getDeepCopyIterations();
|
|
38005
38015
|
}
|
|
38006
38016
|
|
|
@@ -43536,7 +43546,7 @@ function buildDrawHierarchy({
|
|
|
43536
43546
|
const firstRoundDrawPositions = firstRoundPairedDrawPositions.flat(Infinity);
|
|
43537
43547
|
const secondRoundDrawPositions = secondRoundMatchUps.map((matchUp) => matchUp.drawPositions).flat(Infinity);
|
|
43538
43548
|
const secondRoundEntries = secondRoundDrawPositions.filter((drawPosition) => !firstRoundDrawPositions.includes(drawPosition)).sort(drawPositionSort);
|
|
43539
|
-
const
|
|
43549
|
+
const secondRoundEntrySides = secondRoundMatchUps.filter(
|
|
43540
43550
|
(matchUp) => matchUp.drawPositions?.reduce(
|
|
43541
43551
|
(p, c) => secondRoundEntries.includes(c) || p,
|
|
43542
43552
|
void 0
|
|
@@ -43554,7 +43564,7 @@ function buildDrawHierarchy({
|
|
|
43554
43564
|
const missingPairs = secondRoundEntries.map((drawPosition, index) => {
|
|
43555
43565
|
return [drawPosition, missingDrawPositions[index]].sort(drawPositionSort);
|
|
43556
43566
|
});
|
|
43557
|
-
const entrySides = Object.assign({}, ...
|
|
43567
|
+
const entrySides = Object.assign({}, ...secondRoundEntrySides);
|
|
43558
43568
|
const finishingRound = makeDeepCopy(
|
|
43559
43569
|
firstRoundMatchUps?.[0].finishingRound,
|
|
43560
43570
|
false,
|
|
@@ -54607,6 +54617,267 @@ function getEntryStatusReports({
|
|
|
54607
54617
|
};
|
|
54608
54618
|
}
|
|
54609
54619
|
|
|
54620
|
+
function getParticipantStats({
|
|
54621
|
+
withCompetitiveProfiles,
|
|
54622
|
+
opponentParticipantId,
|
|
54623
|
+
withIndividualStats,
|
|
54624
|
+
teamParticipantId,
|
|
54625
|
+
tournamentRecord,
|
|
54626
|
+
tallyPolicy,
|
|
54627
|
+
matchUps
|
|
54628
|
+
}) {
|
|
54629
|
+
if (!tournamentRecord)
|
|
54630
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
54631
|
+
if (matchUps && !Array.isArray(matchUps))
|
|
54632
|
+
return { error: INVALID_MATCHUP };
|
|
54633
|
+
matchUps = matchUps || allTournamentMatchUps({ tournamentRecord }).matchUps;
|
|
54634
|
+
if (!matchUps?.length)
|
|
54635
|
+
return { error: MISSING_MATCHUPS };
|
|
54636
|
+
const teamParticipantIds = [];
|
|
54637
|
+
if (opponentParticipantId)
|
|
54638
|
+
teamParticipantIds.push(opponentParticipantId);
|
|
54639
|
+
if (teamParticipantId)
|
|
54640
|
+
teamParticipantIds.push(teamParticipantId);
|
|
54641
|
+
const participantFilters = !teamParticipantIds.length ? { participantTypes: [TEAM_PARTICIPANT] } : { participantIds: teamParticipantIds };
|
|
54642
|
+
const teamParticipants = getParticipants$1({ participantFilters, tournamentRecord }).participants ?? [];
|
|
54643
|
+
if (!teamParticipants.every(
|
|
54644
|
+
({ participantType }) => participantType === TEAM_PARTICIPANT
|
|
54645
|
+
)) {
|
|
54646
|
+
return { error: INVALID_PARTICIPANT_IDS };
|
|
54647
|
+
}
|
|
54648
|
+
if (!teamParticipantIds.length)
|
|
54649
|
+
teamParticipantIds.push(...teamParticipants.map(extractAttributes("participantId")));
|
|
54650
|
+
const participantStats = /* @__PURE__ */ new Map();
|
|
54651
|
+
const participantNameMap = /* @__PURE__ */ new Map();
|
|
54652
|
+
const participating = /* @__PURE__ */ new Map();
|
|
54653
|
+
const teamMap = /* @__PURE__ */ new Map();
|
|
54654
|
+
const initStats = (participantId, participantName = "") => participantStats.get(participantId) || participantStats.set(participantId, {
|
|
54655
|
+
participantName,
|
|
54656
|
+
participantId,
|
|
54657
|
+
competitorIds: [],
|
|
54658
|
+
competitiveness: {},
|
|
54659
|
+
matchUpStatuses: {},
|
|
54660
|
+
tiebreaks: [0, 0],
|
|
54661
|
+
matchUps: [0, 0],
|
|
54662
|
+
points: [0, 0],
|
|
54663
|
+
games: [0, 0],
|
|
54664
|
+
sets: [0, 0]
|
|
54665
|
+
}) && participantStats.get(participantId);
|
|
54666
|
+
for (const teamParticipant of teamParticipants) {
|
|
54667
|
+
const { participantId, individualParticipantIds } = teamParticipant;
|
|
54668
|
+
teamMap.set(participantId, individualParticipantIds ?? []);
|
|
54669
|
+
initStats(participantId, teamParticipant.participantName);
|
|
54670
|
+
}
|
|
54671
|
+
if (teamParticipantId && !teamMap.get(teamParticipantId))
|
|
54672
|
+
return decorateResult({
|
|
54673
|
+
result: { error: PARTICIPANT_NOT_FOUND },
|
|
54674
|
+
context: { teamParticipantId }
|
|
54675
|
+
});
|
|
54676
|
+
if (opponentParticipantId && !teamMap.get(opponentParticipantId))
|
|
54677
|
+
return decorateResult({
|
|
54678
|
+
result: { error: PARTICIPANT_NOT_FOUND },
|
|
54679
|
+
context: { opponentParticipantId }
|
|
54680
|
+
});
|
|
54681
|
+
const relevantMatchUps = [];
|
|
54682
|
+
const getSideParticipantIds = (sides) => {
|
|
54683
|
+
const sideParticipantIds = [[], []];
|
|
54684
|
+
for (const side of sides) {
|
|
54685
|
+
if (side.participant?.participantName)
|
|
54686
|
+
participantNameMap.set(
|
|
54687
|
+
side.participant.participantId,
|
|
54688
|
+
side.participant.participantName
|
|
54689
|
+
);
|
|
54690
|
+
}
|
|
54691
|
+
const getCompetitorIds = ({ side, individualParticipantIds }) => {
|
|
54692
|
+
return side.participantId && (!individualParticipantIds?.length || individualParticipantIds.includes(side.participantId)) && [
|
|
54693
|
+
side.participantId
|
|
54694
|
+
] || side.participant?.individualParticipantIds?.length && (!individualParticipantIds?.length || intersection(
|
|
54695
|
+
individualParticipantIds,
|
|
54696
|
+
side.participant?.individualParticipantIds
|
|
54697
|
+
).length === side.participant?.individualParticipantIds?.length) && side.participant.individualParticipantIds;
|
|
54698
|
+
};
|
|
54699
|
+
if (teamMap.size) {
|
|
54700
|
+
const processSides = (thisTeamId, individualParticipantIds) => {
|
|
54701
|
+
for (const side of sides) {
|
|
54702
|
+
if (!side.participant)
|
|
54703
|
+
continue;
|
|
54704
|
+
const competitorIds = getCompetitorIds({
|
|
54705
|
+
individualParticipantIds,
|
|
54706
|
+
side
|
|
54707
|
+
});
|
|
54708
|
+
if (competitorIds?.length) {
|
|
54709
|
+
const sideNumber = side.sideNumber;
|
|
54710
|
+
if (!sideNumber)
|
|
54711
|
+
continue;
|
|
54712
|
+
const ids = [thisTeamId];
|
|
54713
|
+
if (withIndividualStats)
|
|
54714
|
+
ids.push(...competitorIds);
|
|
54715
|
+
sideParticipantIds[sideNumber - 1] = ids;
|
|
54716
|
+
const stats = participantStats.get(thisTeamId);
|
|
54717
|
+
for (const id of competitorIds.filter(Boolean)) {
|
|
54718
|
+
if (stats && !stats.competitorIds.includes(id))
|
|
54719
|
+
stats.competitorIds.push(id);
|
|
54720
|
+
}
|
|
54721
|
+
}
|
|
54722
|
+
}
|
|
54723
|
+
};
|
|
54724
|
+
if (teamParticipantId) {
|
|
54725
|
+
const processForTeam = !opponentParticipantId || sides.every((side) => {
|
|
54726
|
+
side.participant && (getCompetitorIds({
|
|
54727
|
+
side,
|
|
54728
|
+
individualParticipantIds: teamMap.get(teamParticipantId)
|
|
54729
|
+
}) || getCompetitorIds({
|
|
54730
|
+
side,
|
|
54731
|
+
individualParticipantIds: teamMap.get(opponentParticipantId)
|
|
54732
|
+
}));
|
|
54733
|
+
});
|
|
54734
|
+
if (processForTeam)
|
|
54735
|
+
processSides(teamParticipantId, teamMap.get(teamParticipantId));
|
|
54736
|
+
} else {
|
|
54737
|
+
for (const [thisTeamId, individualParticipantIds] of teamMap) {
|
|
54738
|
+
processSides(thisTeamId, individualParticipantIds);
|
|
54739
|
+
}
|
|
54740
|
+
}
|
|
54741
|
+
} else if (withIndividualStats) {
|
|
54742
|
+
for (const side of sides) {
|
|
54743
|
+
if (!side.participant)
|
|
54744
|
+
continue;
|
|
54745
|
+
const competitorIds = getCompetitorIds({
|
|
54746
|
+
individualParticipantIds: [],
|
|
54747
|
+
side
|
|
54748
|
+
});
|
|
54749
|
+
const sideNumber = side.sideNumber;
|
|
54750
|
+
if (!sideNumber)
|
|
54751
|
+
continue;
|
|
54752
|
+
sideParticipantIds[sideNumber - 1] = competitorIds;
|
|
54753
|
+
}
|
|
54754
|
+
}
|
|
54755
|
+
return sideParticipantIds;
|
|
54756
|
+
};
|
|
54757
|
+
for (const matchUp of matchUps) {
|
|
54758
|
+
if (!isObject(matchUp))
|
|
54759
|
+
return { error: INVALID_MATCHUP };
|
|
54760
|
+
const {
|
|
54761
|
+
matchUpStatus,
|
|
54762
|
+
matchUpFormat,
|
|
54763
|
+
matchUpType,
|
|
54764
|
+
winningSide,
|
|
54765
|
+
score,
|
|
54766
|
+
sides
|
|
54767
|
+
} = matchUp;
|
|
54768
|
+
if (!sides || !score || matchUpType === TEAM_MATCHUP || matchUpStatus === BYE)
|
|
54769
|
+
continue;
|
|
54770
|
+
const sideParticipantIds = getSideParticipantIds(sides);
|
|
54771
|
+
if (!sideParticipantIds.filter(Boolean).length)
|
|
54772
|
+
continue;
|
|
54773
|
+
const competitiveness = withCompetitiveProfiles && winningSide && getMatchUpCompetitiveProfile({ matchUp })?.competitiveness;
|
|
54774
|
+
relevantMatchUps.push(matchUp);
|
|
54775
|
+
const setsTally = countSets({
|
|
54776
|
+
matchUpStatus,
|
|
54777
|
+
matchUpFormat,
|
|
54778
|
+
tallyPolicy,
|
|
54779
|
+
winningSide,
|
|
54780
|
+
score
|
|
54781
|
+
});
|
|
54782
|
+
const gamesTally = countGames({
|
|
54783
|
+
matchUpStatus,
|
|
54784
|
+
matchUpFormat,
|
|
54785
|
+
tallyPolicy,
|
|
54786
|
+
winningSide,
|
|
54787
|
+
score
|
|
54788
|
+
});
|
|
54789
|
+
const { pointsTally, tiebreaksTally } = countPoints({
|
|
54790
|
+
matchUpFormat,
|
|
54791
|
+
score
|
|
54792
|
+
});
|
|
54793
|
+
sideParticipantIds.forEach((ids, index) => {
|
|
54794
|
+
for (const id of ids) {
|
|
54795
|
+
const stats = initStats(id, participantNameMap.get(id));
|
|
54796
|
+
if (stats) {
|
|
54797
|
+
const teamSumTally = (stat, tally) => tally.forEach((t, i) => stats[stat][i] += t);
|
|
54798
|
+
const tiebreaks = index ? [...tiebreaksTally].reverse() : tiebreaksTally;
|
|
54799
|
+
const points = index ? [...pointsTally].reverse() : pointsTally;
|
|
54800
|
+
const games = index ? [...gamesTally].reverse() : gamesTally;
|
|
54801
|
+
const sets = index ? [...setsTally].reverse() : setsTally;
|
|
54802
|
+
teamSumTally("tiebreaks", tiebreaks);
|
|
54803
|
+
teamSumTally("points", points);
|
|
54804
|
+
teamSumTally("games", games);
|
|
54805
|
+
teamSumTally("sets", sets);
|
|
54806
|
+
if (winningSide) {
|
|
54807
|
+
const tallyIndex = winningSide - 1 === index ? 0 : 1;
|
|
54808
|
+
stats.matchUps[tallyIndex] += 1;
|
|
54809
|
+
}
|
|
54810
|
+
if (competitiveness) {
|
|
54811
|
+
const attr = competitiveness.toLowerCase();
|
|
54812
|
+
if (!stats.competitiveness[attr])
|
|
54813
|
+
stats.competitiveness[attr] = [0, 0];
|
|
54814
|
+
stats.competitiveness[attr][index] += 1;
|
|
54815
|
+
}
|
|
54816
|
+
if (matchUpStatus) {
|
|
54817
|
+
const attr = matchUpStatus.toLowerCase();
|
|
54818
|
+
if (!stats.matchUpStatuses[attr])
|
|
54819
|
+
stats.matchUpStatuses[attr] = 0;
|
|
54820
|
+
stats.matchUpStatuses[attr] += 1;
|
|
54821
|
+
}
|
|
54822
|
+
}
|
|
54823
|
+
}
|
|
54824
|
+
});
|
|
54825
|
+
}
|
|
54826
|
+
const statsattributes = ["tiebreaks", "matchUps", "points", "games", "sets"];
|
|
54827
|
+
const competitivenessAttributes = ["competitive", "routine", "decisive"];
|
|
54828
|
+
const ratio = /* @__PURE__ */ new Map();
|
|
54829
|
+
const add = (a, b) => (a ?? 0) + (b ?? 0);
|
|
54830
|
+
for (const [participantId, stats] of participantStats.entries()) {
|
|
54831
|
+
for (const attr of statsattributes) {
|
|
54832
|
+
const total = stats[attr].reduce(add);
|
|
54833
|
+
if (total) {
|
|
54834
|
+
const value = stats[attr][0] / total;
|
|
54835
|
+
const accessor = `${attr}Ratio`;
|
|
54836
|
+
const fixedValue = parseFloat(value.toFixed(2));
|
|
54837
|
+
stats[accessor] = fixedValue;
|
|
54838
|
+
participating.set(participantId, true);
|
|
54839
|
+
if (!ratio.has(accessor))
|
|
54840
|
+
ratio.set(accessor, []);
|
|
54841
|
+
ratio.get(accessor)?.push(fixedValue);
|
|
54842
|
+
}
|
|
54843
|
+
}
|
|
54844
|
+
for (const attr of competitivenessAttributes) {
|
|
54845
|
+
const total = stats.competitiveness?.[attr]?.reduce(add);
|
|
54846
|
+
if (total) {
|
|
54847
|
+
const value = stats.competitiveness[attr][0] / total;
|
|
54848
|
+
const accessor = `${attr}Ratio`;
|
|
54849
|
+
const fixedValue = parseFloat(value.toFixed(2));
|
|
54850
|
+
stats[accessor] = fixedValue;
|
|
54851
|
+
}
|
|
54852
|
+
}
|
|
54853
|
+
}
|
|
54854
|
+
if (!teamParticipantId) {
|
|
54855
|
+
const highLowSort = (a, b) => b - a;
|
|
54856
|
+
for (const stats of participantStats.values()) {
|
|
54857
|
+
for (const attr of statsattributes) {
|
|
54858
|
+
const accessor = `${attr}Ratio`;
|
|
54859
|
+
if (typeof stats[accessor] === "number") {
|
|
54860
|
+
const index = ratio.get(accessor)?.sort(highLowSort).indexOf(stats[accessor]);
|
|
54861
|
+
if (typeof index === "number" && index >= 0) {
|
|
54862
|
+
const rankAccessor = `${attr}Rank`;
|
|
54863
|
+
stats[rankAccessor] = index + 1;
|
|
54864
|
+
}
|
|
54865
|
+
}
|
|
54866
|
+
}
|
|
54867
|
+
}
|
|
54868
|
+
}
|
|
54869
|
+
const result = { relevantMatchUps, ...SUCCESS };
|
|
54870
|
+
if (teamParticipantId) {
|
|
54871
|
+
result.teamStats = participantStats.get(teamParticipantId);
|
|
54872
|
+
if (opponentParticipantId)
|
|
54873
|
+
result.opponentStats = participantStats.get(opponentParticipantId);
|
|
54874
|
+
} else {
|
|
54875
|
+
result.participatingTeamsCount = participating.size;
|
|
54876
|
+
}
|
|
54877
|
+
result.allParticipantStats = [...participantStats.values()];
|
|
54878
|
+
return result;
|
|
54879
|
+
}
|
|
54880
|
+
|
|
54610
54881
|
function getAvgWTN({
|
|
54611
54882
|
eventType,
|
|
54612
54883
|
matchUps,
|
|
@@ -54857,7 +55128,11 @@ function getPositionManipulations({ extensions }) {
|
|
|
54857
55128
|
return extensions?.find(({ name }) => name === AUDIT_POSITION_ACTIONS)?.value?.slice(1);
|
|
54858
55129
|
}
|
|
54859
55130
|
|
|
54860
|
-
const reportGovernor = {
|
|
55131
|
+
const reportGovernor = {
|
|
55132
|
+
getStructureReports,
|
|
55133
|
+
getEntryStatusReports,
|
|
55134
|
+
getParticipantStats
|
|
55135
|
+
};
|
|
54861
55136
|
|
|
54862
55137
|
function setDrawParticipantRepresentativeIds({
|
|
54863
55138
|
representativeParticipantIds,
|