tods-competition-factory 2.1.5 → 2.1.7
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/index.mjs +6 -6
- package/dist/tods-competition-factory.development.cjs.js +128 -31
- 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 +8 -8
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function factoryVersion() {
|
|
6
|
-
return '2.1.
|
|
6
|
+
return '2.1.7';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function isFunction(obj) {
|
|
@@ -1682,10 +1682,11 @@ function getProvider() {
|
|
|
1682
1682
|
function handleCaughtError({ engineName, methodName, params, err }) {
|
|
1683
1683
|
const caughtErrorHandler = (isFunction(_globalStateProvider.handleCaughtError) && _globalStateProvider.handleCaughtError) ||
|
|
1684
1684
|
syncGlobalState$1.handleCaughtError;
|
|
1685
|
+
const { tournamentRecord, ...rest } = params;
|
|
1685
1686
|
return caughtErrorHandler({
|
|
1687
|
+
params: rest,
|
|
1686
1688
|
engineName,
|
|
1687
1689
|
methodName,
|
|
1688
|
-
params,
|
|
1689
1690
|
err,
|
|
1690
1691
|
});
|
|
1691
1692
|
}
|
|
@@ -10439,7 +10440,7 @@ const logColors = {
|
|
|
10439
10440
|
|
|
10440
10441
|
const globalLog = [];
|
|
10441
10442
|
function pushGlobalLog(value, devContextOverride) {
|
|
10442
|
-
if (
|
|
10443
|
+
if (isString(value))
|
|
10443
10444
|
value = { method: value };
|
|
10444
10445
|
if (devContextOverride || getDevContext())
|
|
10445
10446
|
globalLog.push(value);
|
|
@@ -40222,19 +40223,76 @@ function generateStatCrew(params) {
|
|
|
40222
40223
|
if (paramsCheck.error)
|
|
40223
40224
|
return paramsCheck;
|
|
40224
40225
|
const { tournamentRecord } = params;
|
|
40225
|
-
const { startDate, tournamentId } = tournamentRecord;
|
|
40226
|
+
const { startDate, tournamentId, tournamentName } = tournamentRecord;
|
|
40227
|
+
const { participantMap, matchUps, mappedMatchUps } = getParticipants({
|
|
40228
|
+
withMatchUps: true,
|
|
40229
|
+
withEvents: true,
|
|
40230
|
+
tournamentRecord,
|
|
40231
|
+
});
|
|
40226
40232
|
const teamParticipants = tournamentRecord.participants.filter((participant) => participant.participantType === TEAM);
|
|
40227
40233
|
const homeTeam = teamParticipants?.find((team) => team.participantRoleResponsibilities?.includes('Home'));
|
|
40228
40234
|
const awayTeams = teamParticipants?.filter((team) => team.participantId !== homeTeam?.participantId);
|
|
40229
40235
|
const date = formatDate(startDate, '/', 'MDY');
|
|
40230
|
-
const neutralGame = !homeTeam ? 'Y' : 'N';
|
|
40231
40236
|
const homename = homeTeam?.participantName || awayTeams?.[1]?.participantName;
|
|
40232
40237
|
const homeid = homeTeam?.participantId || awayTeams?.[1]?.participantId;
|
|
40233
40238
|
const visname = awayTeams?.[0]?.participantName;
|
|
40234
40239
|
const visid = awayTeams?.[0]?.participantId;
|
|
40235
|
-
const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps;
|
|
40236
40240
|
const singles = matchUps?.filter((matchUp) => matchUp.matchUpType === SINGLES);
|
|
40237
40241
|
const doubles = matchUps?.filter((matchUp) => matchUp.matchUpType === DOUBLES);
|
|
40242
|
+
const uniValues = {};
|
|
40243
|
+
const getTeam = (teamParticipant) => {
|
|
40244
|
+
const { participantId: id, participantName: name } = teamParticipant;
|
|
40245
|
+
const vh = (homeid && (id === homeid ? 'H' : 'V')) || '';
|
|
40246
|
+
const teamMatchUps = participantMap?.[id]?.matchUps;
|
|
40247
|
+
const matchUpIds = teamMatchUps && Object.keys(teamMatchUps);
|
|
40248
|
+
uniValues[id] = {};
|
|
40249
|
+
const winLoss = { SINGLES: { w: 0, l: 0 }, DOUBLES: { w: 0, l: 0 } };
|
|
40250
|
+
const doubles = [];
|
|
40251
|
+
const singles = [];
|
|
40252
|
+
let score = 0;
|
|
40253
|
+
for (const matchUpId of matchUpIds ?? []) {
|
|
40254
|
+
const matchUp = mappedMatchUps?.[matchUpId];
|
|
40255
|
+
const sideNumber = matchUp.sides.find(({ participant }) => participant.participantId === id)?.sideNumber;
|
|
40256
|
+
const matchScore = matchUp.score?.sets?.[0]?.[`side${sideNumber}Score`] ?? 0;
|
|
40257
|
+
score += matchScore;
|
|
40258
|
+
for (const tieMatchUp of matchUp.tieMatchUps ?? []) {
|
|
40259
|
+
const { matchUpType, winningSide } = tieMatchUp;
|
|
40260
|
+
const wl = (winningSide && (winningSide === sideNumber ? 'w' : 'l')) || '';
|
|
40261
|
+
if (wl)
|
|
40262
|
+
winLoss[matchUpType][wl] += 1;
|
|
40263
|
+
const won = wl === 'w' ? '1' : '0';
|
|
40264
|
+
const lost = wl === 'l' ? '1' : '0';
|
|
40265
|
+
if (matchUpType === SINGLES) {
|
|
40266
|
+
const pair = singles.length + 1;
|
|
40267
|
+
singles.push({ singles_pair: { pair, won, lost } });
|
|
40268
|
+
}
|
|
40269
|
+
else if (matchUpType === DOUBLES) {
|
|
40270
|
+
const pair = doubles.length + 1;
|
|
40271
|
+
doubles.push({ doubles_pair: { pair, won, lost } });
|
|
40272
|
+
}
|
|
40273
|
+
}
|
|
40274
|
+
}
|
|
40275
|
+
const totals = [
|
|
40276
|
+
{ singles: { childArray: singles, won: winLoss.SINGLES.w, lost: winLoss.SINGLES.l } },
|
|
40277
|
+
{ doubles: { childArray: doubles, won: winLoss.DOUBLES.w, lost: winLoss.DOUBLES.l } },
|
|
40278
|
+
];
|
|
40279
|
+
const players = [];
|
|
40280
|
+
let playerIndex = 1;
|
|
40281
|
+
for (const individualParticipantId of teamParticipant.individualParticipantIds) {
|
|
40282
|
+
const mappedParticipant = participantMap?.[individualParticipantId];
|
|
40283
|
+
if (mappedParticipant) {
|
|
40284
|
+
const { participant, counters } = mappedParticipant;
|
|
40285
|
+
const doublesStats = { won: counters?.DOUBLES?.wins || 0, lost: counters?.DOUBLES?.losses || 0 };
|
|
40286
|
+
const singlesStats = { won: counters?.SINGLES?.wins || 0, lost: counters?.SINGLES?.losses || 0 };
|
|
40287
|
+
const { participantName: name, participantId } = participant;
|
|
40288
|
+
uniValues[id][participantId] = playerIndex;
|
|
40289
|
+
players.push({ player: { name, uni: playerIndex, singles: singlesStats, doubles: doublesStats } });
|
|
40290
|
+
}
|
|
40291
|
+
playerIndex += 1;
|
|
40292
|
+
}
|
|
40293
|
+
return { vh, id, name, score, totals, childArray: players };
|
|
40294
|
+
};
|
|
40295
|
+
const teams = teamParticipants.map((p) => ({ team: { ...getTeam(p) } }));
|
|
40238
40296
|
const getScoreAttributes = ({ sets, sideNumber }) => Object.assign({}, ...(sets?.map((set) => {
|
|
40239
40297
|
const { setNumber, side1Score, side2Score, side1TiebreakScore, side2TiebreakScore } = set;
|
|
40240
40298
|
const setKey = `set_${setNumber}`;
|
|
@@ -40243,26 +40301,53 @@ function generateStatCrew(params) {
|
|
|
40243
40301
|
const tieValue = sideNumber === 1 ? side1TiebreakScore : side2TiebreakScore;
|
|
40244
40302
|
return { [setKey]: setValue, [tbKey]: tieValue };
|
|
40245
40303
|
}) ?? []));
|
|
40246
|
-
const getParticipantAttibutes = ({
|
|
40247
|
-
|
|
40304
|
+
const getParticipantAttibutes = ({ participant }) => {
|
|
40305
|
+
if (!participant)
|
|
40306
|
+
return {};
|
|
40307
|
+
const pair = participant.individualParticipants?.length === 2;
|
|
40308
|
+
const pairTeamParticipantIds = pair
|
|
40309
|
+
? unique(participant.individualParticipants?.map((p) => p.teams?.[0]?.participantId))
|
|
40310
|
+
: [];
|
|
40311
|
+
const pairTeamIds = pair ? unique(participant.individualParticipants?.map((p) => p.teams?.[0]?.teamId)) : [];
|
|
40312
|
+
const teamParticipantId = (!pair && participant.teams?.[0]?.participantId) ||
|
|
40313
|
+
(pairTeamParticipantIds?.length === 1 && pairTeamParticipantIds[0]) ||
|
|
40314
|
+
undefined;
|
|
40315
|
+
const team = (!pair && participant.teams?.[0]?.teamId) || (pairTeamIds?.length === 1 && pairTeamIds[0]) || teamParticipantId;
|
|
40316
|
+
const name = !pair ? participant.participantName : undefined;
|
|
40248
40317
|
const name_1 = participant.individualParticipants?.[0]?.participantName;
|
|
40249
40318
|
const name_2 = participant.individualParticipants?.[1]?.participantName;
|
|
40250
|
-
const vh =
|
|
40251
|
-
|
|
40319
|
+
const vh = (homeid && (teamParticipantId === homeid ? 'H' : 'V')) || '';
|
|
40320
|
+
const uni = !pair ? uniValues[teamParticipantId][participant.participantId] : undefined;
|
|
40321
|
+
const uni_1 = uniValues[teamParticipantId][participant.individualParticipants?.[0]?.participantId];
|
|
40322
|
+
const uni_2 = uniValues[teamParticipantId][participant.individualParticipants?.[1]?.participantId];
|
|
40323
|
+
return definedAttributes({ vh, uni, uni_1, uni_2, team, name, name_1, name_2 });
|
|
40252
40324
|
};
|
|
40253
40325
|
const mapMatchUp = (matchUp) => {
|
|
40254
|
-
const { collectionPosition: match, orderOfFinish: order,
|
|
40326
|
+
const { collectionPosition: match, orderOfFinish: order, matchUpType, sides } = matchUp ?? {};
|
|
40255
40327
|
const childArray = sides?.map((side) => {
|
|
40256
40328
|
const { sideNumber, participant } = side;
|
|
40257
40329
|
const scoreAttributes = getScoreAttributes({ sets: matchUp.score?.sets, sideNumber });
|
|
40258
40330
|
const scoreType = matchUpType === SINGLES ? 'singles_score' : 'doubles_score';
|
|
40259
|
-
return { [scoreType]: { ...getParticipantAttibutes({
|
|
40331
|
+
return { [scoreType]: { ...getParticipantAttibutes({ participant }), ...scoreAttributes } };
|
|
40260
40332
|
});
|
|
40261
40333
|
const matchType = matchUpType === SINGLES ? 'singles_match' : 'doubles_match';
|
|
40262
40334
|
return { [matchType]: { match, order, childArray } };
|
|
40263
40335
|
};
|
|
40264
40336
|
const json = {
|
|
40265
|
-
venue: {
|
|
40337
|
+
venue: {
|
|
40338
|
+
tournament: teamParticipants?.length > 2 ? 'Y' : 'N',
|
|
40339
|
+
neutralgame: !homeTeam ? 'Y' : 'N',
|
|
40340
|
+
tournamentname: tournamentName,
|
|
40341
|
+
gameid: tournamentId,
|
|
40342
|
+
officials: {},
|
|
40343
|
+
rules: {},
|
|
40344
|
+
homename,
|
|
40345
|
+
visname,
|
|
40346
|
+
homeid,
|
|
40347
|
+
visid,
|
|
40348
|
+
date,
|
|
40349
|
+
},
|
|
40350
|
+
childArray: teams,
|
|
40266
40351
|
singles_matches: singles?.map(mapMatchUp),
|
|
40267
40352
|
doubles_matches: doubles?.map(mapMatchUp),
|
|
40268
40353
|
};
|
|
@@ -42326,7 +42411,13 @@ function removeDirectedLoser({ sourceMatchUpStatus, loserParticipantId, tourname
|
|
|
42326
42411
|
}
|
|
42327
42412
|
function removeDirectedBye({ inContextDrawMatchUps, tournamentRecord, drawDefinition, drawPosition, matchUpsMap, targetLink, event, }) {
|
|
42328
42413
|
const structureId = targetLink.target.structureId;
|
|
42329
|
-
|
|
42414
|
+
const stack = 'removeDirectedBye';
|
|
42415
|
+
pushGlobalLog({
|
|
42416
|
+
color: 'brightyellow',
|
|
42417
|
+
method: stack,
|
|
42418
|
+
drawPosition,
|
|
42419
|
+
});
|
|
42420
|
+
const result = clearDrawPosition({
|
|
42330
42421
|
inContextDrawMatchUps,
|
|
42331
42422
|
tournamentRecord,
|
|
42332
42423
|
drawDefinition,
|
|
@@ -42335,7 +42426,7 @@ function removeDirectedBye({ inContextDrawMatchUps, tournamentRecord, drawDefini
|
|
|
42335
42426
|
structureId,
|
|
42336
42427
|
event,
|
|
42337
42428
|
});
|
|
42338
|
-
return {
|
|
42429
|
+
return decorateResult({ result, stack });
|
|
42339
42430
|
}
|
|
42340
42431
|
|
|
42341
42432
|
function lastSetFormatIsTimed(inContextMatchUp) {
|
|
@@ -42979,24 +43070,27 @@ const keyColors = {
|
|
|
42979
43070
|
};
|
|
42980
43071
|
function removeDoubleExit(params) {
|
|
42981
43072
|
const { inContextDrawMatchUps, appliedPolicies, drawDefinition, matchUpsMap, targetData, matchUp } = params;
|
|
43073
|
+
const { matchUpId } = matchUp;
|
|
42982
43074
|
let { iteration = 0 } = params;
|
|
42983
43075
|
iteration += 1;
|
|
42984
43076
|
const stack = 'removeDoubleExit';
|
|
42985
43077
|
pushGlobalLog({
|
|
42986
|
-
method: stack,
|
|
42987
43078
|
color: 'brightyellow',
|
|
43079
|
+
method: stack,
|
|
43080
|
+
matchUpId,
|
|
42988
43081
|
iteration,
|
|
42989
43082
|
keyColors,
|
|
42990
43083
|
});
|
|
42991
|
-
const {
|
|
43084
|
+
const { targetMatchUps: { loserMatchUp, winnerMatchUp, loserTargetDrawPosition }, targetLinks: { loserTargetLink }, } = targetData;
|
|
42992
43085
|
if (winnerMatchUp && winnerMatchUp.matchUpStatus !== BYE) {
|
|
42993
|
-
const { stage, roundNumber, roundPosition } = winnerMatchUp;
|
|
43086
|
+
const { stage, roundNumber, roundPosition, structureName } = winnerMatchUp;
|
|
42994
43087
|
pushGlobalLog({
|
|
42995
43088
|
winner: 'winner',
|
|
42996
|
-
stage,
|
|
42997
|
-
roundNumber,
|
|
42998
43089
|
roundPosition,
|
|
43090
|
+
structureName,
|
|
43091
|
+
roundNumber,
|
|
42999
43092
|
keyColors,
|
|
43093
|
+
stage,
|
|
43000
43094
|
});
|
|
43001
43095
|
conditionallyRemoveDrawPosition({
|
|
43002
43096
|
...params,
|
|
@@ -43005,22 +43099,24 @@ function removeDoubleExit(params) {
|
|
|
43005
43099
|
iteration,
|
|
43006
43100
|
});
|
|
43007
43101
|
}
|
|
43008
|
-
|
|
43102
|
+
const byePropagatedToLoserMatchUp = loserMatchUp?.matchUpStatus === BYE && (loserMatchUp?.feedRound || loserMatchUp?.roundNumber === 1);
|
|
43103
|
+
if (loserMatchUp && (loserMatchUp.matchUpStatus !== BYE || byePropagatedToLoserMatchUp)) {
|
|
43009
43104
|
const inContextLoserMatchUp = inContextDrawMatchUps.find(({ matchUpId }) => matchUpId === loserMatchUp.matchUpId);
|
|
43010
43105
|
const { structure: loserStructure } = findStructure({
|
|
43011
43106
|
drawDefinition,
|
|
43012
43107
|
structureId: inContextLoserMatchUp.structureId,
|
|
43013
43108
|
});
|
|
43014
|
-
const { stage, roundNumber, roundPosition, feedRound } = loserMatchUp;
|
|
43109
|
+
const { stage, roundNumber, roundPosition, feedRound, structureName } = loserMatchUp;
|
|
43015
43110
|
pushGlobalLog({
|
|
43016
43111
|
loser: 'loser',
|
|
43017
|
-
stage,
|
|
43018
|
-
roundNumber,
|
|
43019
43112
|
roundPosition,
|
|
43113
|
+
structureName,
|
|
43114
|
+
roundNumber,
|
|
43020
43115
|
keyColors,
|
|
43021
43116
|
feedRound,
|
|
43117
|
+
stage,
|
|
43022
43118
|
});
|
|
43023
|
-
if (appliedPolicies?.progression?.doubleExitPropagateBye) {
|
|
43119
|
+
if (appliedPolicies?.progression?.doubleExitPropagateBye || byePropagatedToLoserMatchUp) {
|
|
43024
43120
|
removeDirectedBye({
|
|
43025
43121
|
drawPosition: loserTargetDrawPosition,
|
|
43026
43122
|
targetLink: loserTargetLink,
|
|
@@ -43032,8 +43128,8 @@ function removeDoubleExit(params) {
|
|
|
43032
43128
|
else {
|
|
43033
43129
|
const result = conditionallyRemoveDrawPosition({
|
|
43034
43130
|
...params,
|
|
43035
|
-
structure: loserStructure,
|
|
43036
43131
|
targetMatchUp: loserMatchUp,
|
|
43132
|
+
structure: loserStructure,
|
|
43037
43133
|
iteration,
|
|
43038
43134
|
});
|
|
43039
43135
|
if (result.error)
|
|
@@ -43045,7 +43141,7 @@ function removeDoubleExit(params) {
|
|
|
43045
43141
|
function conditionallyRemoveDrawPosition(params) {
|
|
43046
43142
|
const { inContextDrawMatchUps, appliedPolicies, drawDefinition, sourceMatchUp, targetMatchUp, matchUpsMap, structure, iteration, } = params;
|
|
43047
43143
|
const stack = 'conditionallyRemoveDrawPosition';
|
|
43048
|
-
pushGlobalLog({ method: stack });
|
|
43144
|
+
pushGlobalLog({ method: stack, structureName: structure?.structureName, iteration });
|
|
43049
43145
|
const nextTargetData = positionTargets({
|
|
43050
43146
|
matchUpId: targetMatchUp.matchUpId,
|
|
43051
43147
|
inContextDrawMatchUps,
|
|
@@ -43085,15 +43181,16 @@ function conditionallyRemoveDrawPosition(params) {
|
|
|
43085
43181
|
}
|
|
43086
43182
|
}
|
|
43087
43183
|
if (nextWinnerMatchUp && drawPositionToRemove) {
|
|
43088
|
-
const { stage, roundNumber, roundPosition } = nextWinnerMatchUp;
|
|
43184
|
+
const { stage, roundNumber, roundPosition, structureName } = nextWinnerMatchUp;
|
|
43089
43185
|
pushGlobalLog({
|
|
43090
43186
|
method: 'removeDirectedWinner',
|
|
43091
43187
|
drawPositionToRemove,
|
|
43092
|
-
keyColors,
|
|
43093
43188
|
color: 'brightgreen',
|
|
43094
|
-
stage,
|
|
43095
|
-
roundNumber,
|
|
43096
43189
|
roundPosition,
|
|
43190
|
+
structureName,
|
|
43191
|
+
roundNumber,
|
|
43192
|
+
keyColors,
|
|
43193
|
+
stage,
|
|
43097
43194
|
});
|
|
43098
43195
|
removeDirectedWinner({
|
|
43099
43196
|
winningDrawPosition: drawPositionToRemove,
|