tods-competition-factory 1.8.5 → 1.8.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/forge/query.d.ts +55 -52
- package/dist/forge/query.mjs +802 -779
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +17 -20
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +371 -349
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +361 -318
- 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 +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2375,7 +2375,7 @@ const matchUpFormatCode = {
|
|
|
2375
2375
|
};
|
|
2376
2376
|
|
|
2377
2377
|
function factoryVersion() {
|
|
2378
|
-
return "1.8.
|
|
2378
|
+
return "1.8.7";
|
|
2379
2379
|
}
|
|
2380
2380
|
|
|
2381
2381
|
function getObjectTieFormat(obj) {
|
|
@@ -19795,6 +19795,7 @@ function getMatchUpContextIds({ matchUps, matchUpId }) {
|
|
|
19795
19795
|
}
|
|
19796
19796
|
|
|
19797
19797
|
function addMatchUpScheduledTime$2(params) {
|
|
19798
|
+
const stack = "addMatchUpScheduledTime";
|
|
19798
19799
|
let matchUp = params.matchUp;
|
|
19799
19800
|
const {
|
|
19800
19801
|
removePriorValues,
|
|
@@ -19805,27 +19806,18 @@ function addMatchUpScheduledTime$2(params) {
|
|
|
19805
19806
|
matchUpId
|
|
19806
19807
|
} = params;
|
|
19807
19808
|
if (!matchUpId)
|
|
19808
|
-
return { error: MISSING_MATCHUP_ID };
|
|
19809
|
+
return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack });
|
|
19809
19810
|
if (!validTimeValue(scheduledTime))
|
|
19810
|
-
return { error: INVALID_TIME };
|
|
19811
|
+
return decorateResult({ result: { error: INVALID_TIME }, stack });
|
|
19811
19812
|
if (!matchUp) {
|
|
19812
19813
|
const result = findMatchUp$1({ drawDefinition, matchUpId });
|
|
19813
19814
|
if (result.error)
|
|
19814
|
-
return result;
|
|
19815
|
+
return decorateResult({ result, stack });
|
|
19815
19816
|
matchUp = result.matchUp;
|
|
19816
19817
|
}
|
|
19817
19818
|
const timeDate = extractDate(scheduledTime);
|
|
19818
|
-
const
|
|
19819
|
-
|
|
19820
|
-
const scheduledDate = scheduledMatchUpDate({ matchUp }).scheduledDate;
|
|
19821
|
-
if (scheduledDate && scheduledDate !== timeDate) {
|
|
19822
|
-
return decorateResult({
|
|
19823
|
-
info: `date in time: ${timeDate} does not corresponde to scheduledDate: ${scheduledDate}`,
|
|
19824
|
-
result: { error: INVALID_TIME },
|
|
19825
|
-
stack
|
|
19826
|
-
});
|
|
19827
|
-
}
|
|
19828
|
-
}
|
|
19819
|
+
const scheduledDate = scheduledMatchUpDate({ matchUp }).scheduledDate;
|
|
19820
|
+
const keepDate = timeDate && !scheduledDate;
|
|
19829
19821
|
const existingTimeModifiers = matchUpTimeModifiers({ matchUp }).timeModifiers || [];
|
|
19830
19822
|
if (existingTimeModifiers?.length) {
|
|
19831
19823
|
const result = addMatchUpTimeModifiers({
|
|
@@ -19838,9 +19830,9 @@ function addMatchUpScheduledTime$2(params) {
|
|
|
19838
19830
|
matchUp
|
|
19839
19831
|
});
|
|
19840
19832
|
if (result?.error)
|
|
19841
|
-
return result;
|
|
19833
|
+
return decorateResult({ result, stack });
|
|
19842
19834
|
}
|
|
19843
|
-
const militaryTime = convertTime(scheduledTime, true,
|
|
19835
|
+
const militaryTime = convertTime(scheduledTime, true, keepDate);
|
|
19844
19836
|
const itemValue = militaryTime;
|
|
19845
19837
|
const timeItem = {
|
|
19846
19838
|
itemType: SCHEDULED_TIME,
|
|
@@ -19865,14 +19857,19 @@ function addMatchUpTimeModifiers({
|
|
|
19865
19857
|
matchUpId,
|
|
19866
19858
|
matchUp
|
|
19867
19859
|
}) {
|
|
19860
|
+
const stack = "addMatchUpTimeModifiers";
|
|
19868
19861
|
if (!matchUpId)
|
|
19869
|
-
return { error: MISSING_MATCHUP_ID };
|
|
19862
|
+
return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack });
|
|
19870
19863
|
if (timeModifiers !== void 0 && !Array.isArray(timeModifiers))
|
|
19871
|
-
return {
|
|
19864
|
+
return decorateResult({
|
|
19865
|
+
info: mustBeAnArray("timeModifiers"),
|
|
19866
|
+
result: { error: INVALID_VALUES },
|
|
19867
|
+
stack
|
|
19868
|
+
});
|
|
19872
19869
|
if (!matchUp) {
|
|
19873
19870
|
const result = findMatchUp$1({ drawDefinition, matchUpId });
|
|
19874
19871
|
if (result.error)
|
|
19875
|
-
return result;
|
|
19872
|
+
return decorateResult({ result, stack });
|
|
19876
19873
|
matchUp = result.matchUp;
|
|
19877
19874
|
}
|
|
19878
19875
|
let existingTimeModifiers = matchUpTimeModifiers({ matchUp }).timeModifiers || [];
|
|
@@ -19897,7 +19894,7 @@ function addMatchUpTimeModifiers({
|
|
|
19897
19894
|
matchUpId
|
|
19898
19895
|
});
|
|
19899
19896
|
if (result.error)
|
|
19900
|
-
return result;
|
|
19897
|
+
return decorateResult({ result, stack });
|
|
19901
19898
|
}
|
|
19902
19899
|
const itemValue = !timeModifiers?.length ? void 0 : [...toBeAdded, ...existingTimeModifiers];
|
|
19903
19900
|
const timeItem = {
|
|
@@ -35138,326 +35135,6 @@ function getMatchUpDailyLimitsUpdate$1({ tournamentRecords }) {
|
|
|
35138
35135
|
});
|
|
35139
35136
|
}
|
|
35140
35137
|
|
|
35141
|
-
const { stageOrder } = drawDefinitionConstants;
|
|
35142
|
-
function getProfileRounds({
|
|
35143
|
-
tournamentRecords,
|
|
35144
|
-
schedulingProfile,
|
|
35145
|
-
tournamentRecord,
|
|
35146
|
-
withRoundId
|
|
35147
|
-
}) {
|
|
35148
|
-
if (tournamentRecord && !tournamentRecords) {
|
|
35149
|
-
if (typeof tournamentRecord !== "object") {
|
|
35150
|
-
return { error: INVALID_TOURNAMENT_RECORD };
|
|
35151
|
-
} else {
|
|
35152
|
-
tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
|
|
35153
|
-
}
|
|
35154
|
-
}
|
|
35155
|
-
if (schedulingProfile) {
|
|
35156
|
-
const profileValidity = validateSchedulingProfile({
|
|
35157
|
-
tournamentRecords,
|
|
35158
|
-
schedulingProfile
|
|
35159
|
-
});
|
|
35160
|
-
if (profileValidity.error)
|
|
35161
|
-
return profileValidity;
|
|
35162
|
-
}
|
|
35163
|
-
if (!schedulingProfile && tournamentRecords) {
|
|
35164
|
-
const result = getSchedulingProfile$1({ tournamentRecords });
|
|
35165
|
-
if (result.error)
|
|
35166
|
-
return result;
|
|
35167
|
-
schedulingProfile = result.schedulingProfile;
|
|
35168
|
-
}
|
|
35169
|
-
if (!schedulingProfile)
|
|
35170
|
-
return { error: NOT_FOUND };
|
|
35171
|
-
const segmentedRounds = {};
|
|
35172
|
-
const profileRounds = schedulingProfile.map(
|
|
35173
|
-
({ venues, scheduleDate }) => venues.map(
|
|
35174
|
-
({ rounds }) => rounds.map((round) => {
|
|
35175
|
-
const roundRef = getRoundId(round);
|
|
35176
|
-
if (roundRef.roundSegment?.segmentsCount) {
|
|
35177
|
-
segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
|
|
35178
|
-
}
|
|
35179
|
-
return definedAttributes({
|
|
35180
|
-
id: withRoundId ? roundRef.id : void 0,
|
|
35181
|
-
scheduleDate,
|
|
35182
|
-
...roundRef
|
|
35183
|
-
});
|
|
35184
|
-
})
|
|
35185
|
-
)
|
|
35186
|
-
).flat(Infinity);
|
|
35187
|
-
return { profileRounds, segmentedRounds };
|
|
35188
|
-
}
|
|
35189
|
-
function getRoundId(obj) {
|
|
35190
|
-
const {
|
|
35191
|
-
containerStructureId,
|
|
35192
|
-
roundSegment,
|
|
35193
|
-
isRoundRobin,
|
|
35194
|
-
tournamentId,
|
|
35195
|
-
roundNumber,
|
|
35196
|
-
structureId,
|
|
35197
|
-
eventId,
|
|
35198
|
-
drawId
|
|
35199
|
-
} = obj;
|
|
35200
|
-
const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
|
|
35201
|
-
const id = [
|
|
35202
|
-
tournamentId,
|
|
35203
|
-
// 1
|
|
35204
|
-
eventId,
|
|
35205
|
-
// 2
|
|
35206
|
-
drawId,
|
|
35207
|
-
// 3
|
|
35208
|
-
relevantStructureId,
|
|
35209
|
-
// 4
|
|
35210
|
-
roundNumber
|
|
35211
|
-
// 5
|
|
35212
|
-
].join("|");
|
|
35213
|
-
return definedAttributes({
|
|
35214
|
-
id,
|
|
35215
|
-
roundSegment,
|
|
35216
|
-
tournamentId,
|
|
35217
|
-
eventId,
|
|
35218
|
-
drawId,
|
|
35219
|
-
structureId: relevantStructureId,
|
|
35220
|
-
roundNumber
|
|
35221
|
-
});
|
|
35222
|
-
}
|
|
35223
|
-
function getRoundProfile(matchUps) {
|
|
35224
|
-
const matchUpsCount = matchUps.length;
|
|
35225
|
-
const byeCount = matchUps.filter(({ sides }) => sides?.some(({ bye }) => bye)).length || 0;
|
|
35226
|
-
const completedCount = matchUps.filter(
|
|
35227
|
-
({ winningSide, matchUpStatus }) => winningSide || completedMatchUpStatuses.includes(matchUpStatus)
|
|
35228
|
-
).length || 0;
|
|
35229
|
-
const scheduledCount = matchUps.filter(
|
|
35230
|
-
({ schedule }) => schedule?.scheduledDate && schedule?.scheduledTime
|
|
35231
|
-
).length || 0;
|
|
35232
|
-
const consideredCount = matchUpsCount - byeCount;
|
|
35233
|
-
const isComplete = consideredCount === completedCount;
|
|
35234
|
-
const unscheduledCount = consideredCount - scheduledCount;
|
|
35235
|
-
const incompleteCount = consideredCount - scheduledCount;
|
|
35236
|
-
const isScheduled = consideredCount === scheduledCount;
|
|
35237
|
-
return {
|
|
35238
|
-
unscheduledCount,
|
|
35239
|
-
incompleteCount,
|
|
35240
|
-
scheduledCount,
|
|
35241
|
-
completedCount,
|
|
35242
|
-
matchUpsCount,
|
|
35243
|
-
isScheduled,
|
|
35244
|
-
isComplete,
|
|
35245
|
-
byeCount
|
|
35246
|
-
};
|
|
35247
|
-
}
|
|
35248
|
-
function getRounds({
|
|
35249
|
-
excludeScheduleDateProfileRounds,
|
|
35250
|
-
excludeScheduledRounds,
|
|
35251
|
-
excludeCompletedRounds,
|
|
35252
|
-
inContextMatchUps,
|
|
35253
|
-
tournamentRecords,
|
|
35254
|
-
schedulingProfile,
|
|
35255
|
-
tournamentRecord,
|
|
35256
|
-
withSplitRounds,
|
|
35257
|
-
matchUpFilters,
|
|
35258
|
-
withRoundId,
|
|
35259
|
-
context
|
|
35260
|
-
}) {
|
|
35261
|
-
if (inContextMatchUps && !Array.isArray(
|
|
35262
|
-
inContextMatchUps || typeof inContextMatchUps[0] !== "object"
|
|
35263
|
-
)) {
|
|
35264
|
-
return { error: INVALID_VALUES, inContextMatchUps };
|
|
35265
|
-
}
|
|
35266
|
-
if (tournamentRecord && !tournamentRecords) {
|
|
35267
|
-
if (typeof tournamentRecord !== "object") {
|
|
35268
|
-
return { error: INVALID_TOURNAMENT_RECORD };
|
|
35269
|
-
} else {
|
|
35270
|
-
tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
|
|
35271
|
-
}
|
|
35272
|
-
}
|
|
35273
|
-
const noTournamentRecords = typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length;
|
|
35274
|
-
const needsTournamentRecords = !inContextMatchUps || !schedulingProfile && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds);
|
|
35275
|
-
if (needsTournamentRecords && noTournamentRecords)
|
|
35276
|
-
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
35277
|
-
const events = Object.values(tournamentRecords ?? {}).map(({ events: events2 }) => events2).flat();
|
|
35278
|
-
const { segmentedRounds, profileRounds } = tournamentRecords && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds) && getProfileRounds({ tournamentRecords, schedulingProfile }) || {};
|
|
35279
|
-
const profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign(
|
|
35280
|
-
{},
|
|
35281
|
-
...profileRounds.map((profile) => ({ [profile.id]: profile }))
|
|
35282
|
-
);
|
|
35283
|
-
const consideredMatchUps = inContextMatchUps || tournamentRecords && allCompetitionMatchUps({ tournamentRecords, matchUpFilters })?.matchUps || [];
|
|
35284
|
-
const excludedRounds = [];
|
|
35285
|
-
const rounds = consideredMatchUps && Object.values(
|
|
35286
|
-
consideredMatchUps.reduce((rounds2, matchUp) => {
|
|
35287
|
-
const id = getRoundId(matchUp).id;
|
|
35288
|
-
const segmentsCount = segmentedRounds?.[id];
|
|
35289
|
-
const matchUps = [...rounds2[id]?.matchUps ?? [], matchUp];
|
|
35290
|
-
const {
|
|
35291
|
-
containerStructureId,
|
|
35292
|
-
stageSequence,
|
|
35293
|
-
structureName,
|
|
35294
|
-
tournamentId,
|
|
35295
|
-
isRoundRobin,
|
|
35296
|
-
matchUpType,
|
|
35297
|
-
roundNumber,
|
|
35298
|
-
roundOffset,
|
|
35299
|
-
structureId,
|
|
35300
|
-
eventName,
|
|
35301
|
-
roundName,
|
|
35302
|
-
drawName,
|
|
35303
|
-
eventId,
|
|
35304
|
-
drawId
|
|
35305
|
-
} = matchUp;
|
|
35306
|
-
const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
|
|
35307
|
-
return {
|
|
35308
|
-
...rounds2,
|
|
35309
|
-
[id]: {
|
|
35310
|
-
id: withRoundId ? id : void 0,
|
|
35311
|
-
structureId: relevantStructureId,
|
|
35312
|
-
stageSequence,
|
|
35313
|
-
segmentsCount,
|
|
35314
|
-
structureName,
|
|
35315
|
-
tournamentId,
|
|
35316
|
-
matchUpType,
|
|
35317
|
-
roundNumber,
|
|
35318
|
-
roundOffset,
|
|
35319
|
-
eventName,
|
|
35320
|
-
roundName,
|
|
35321
|
-
drawName,
|
|
35322
|
-
matchUps,
|
|
35323
|
-
eventId,
|
|
35324
|
-
drawId
|
|
35325
|
-
}
|
|
35326
|
-
};
|
|
35327
|
-
}, {})
|
|
35328
|
-
).map((round) => {
|
|
35329
|
-
const { minFinishingSum, winnerFinishingPositionRange } = getFinishingPositionDetails(round.matchUps);
|
|
35330
|
-
const segmentsCount = round.segmentsCount;
|
|
35331
|
-
if (segmentsCount) {
|
|
35332
|
-
const chunkSize = round.matchUps.length / segmentsCount;
|
|
35333
|
-
const sortedMatchUps = chunkArray(
|
|
35334
|
-
round.matchUps.sort((a, b) => a.roundPosition - b.roundPosition),
|
|
35335
|
-
chunkSize
|
|
35336
|
-
);
|
|
35337
|
-
return sortedMatchUps.map((matchUps, i) => {
|
|
35338
|
-
const {
|
|
35339
|
-
unscheduledCount: unscheduledCount2,
|
|
35340
|
-
incompleteCount: incompleteCount2,
|
|
35341
|
-
matchUpsCount: matchUpsCount2,
|
|
35342
|
-
isScheduled: isScheduled2,
|
|
35343
|
-
isComplete: isComplete2,
|
|
35344
|
-
byeCount: byeCount2
|
|
35345
|
-
} = getRoundProfile(matchUps);
|
|
35346
|
-
const roundTiming2 = getRoundTiming({
|
|
35347
|
-
matchUps: round.matchUps,
|
|
35348
|
-
tournamentRecords,
|
|
35349
|
-
events,
|
|
35350
|
-
round
|
|
35351
|
-
});
|
|
35352
|
-
return definedAttributes({
|
|
35353
|
-
...round,
|
|
35354
|
-
...context,
|
|
35355
|
-
roundSegment: { segmentsCount, segmentNumber: i + 1 },
|
|
35356
|
-
winnerFinishingPositionRange,
|
|
35357
|
-
unscheduledCount: unscheduledCount2,
|
|
35358
|
-
incompleteCount: incompleteCount2,
|
|
35359
|
-
minFinishingSum,
|
|
35360
|
-
matchUpsCount: matchUpsCount2,
|
|
35361
|
-
isScheduled: isScheduled2,
|
|
35362
|
-
roundTiming: roundTiming2,
|
|
35363
|
-
isComplete: isComplete2,
|
|
35364
|
-
byeCount: byeCount2,
|
|
35365
|
-
matchUps
|
|
35366
|
-
});
|
|
35367
|
-
});
|
|
35368
|
-
}
|
|
35369
|
-
const {
|
|
35370
|
-
unscheduledCount,
|
|
35371
|
-
incompleteCount,
|
|
35372
|
-
matchUpsCount,
|
|
35373
|
-
isScheduled,
|
|
35374
|
-
isComplete,
|
|
35375
|
-
byeCount
|
|
35376
|
-
} = getRoundProfile(round.matchUps);
|
|
35377
|
-
const roundTiming = getRoundTiming({
|
|
35378
|
-
matchUps: round.matchUps,
|
|
35379
|
-
tournamentRecords,
|
|
35380
|
-
events,
|
|
35381
|
-
round
|
|
35382
|
-
});
|
|
35383
|
-
return definedAttributes({
|
|
35384
|
-
...round,
|
|
35385
|
-
...context,
|
|
35386
|
-
winnerFinishingPositionRange,
|
|
35387
|
-
unscheduledCount,
|
|
35388
|
-
incompleteCount,
|
|
35389
|
-
minFinishingSum,
|
|
35390
|
-
matchUpsCount,
|
|
35391
|
-
isScheduled,
|
|
35392
|
-
roundTiming,
|
|
35393
|
-
isComplete,
|
|
35394
|
-
byeCount
|
|
35395
|
-
});
|
|
35396
|
-
}).flat().filter((round) => {
|
|
35397
|
-
if (excludeScheduleDateProfileRounds) {
|
|
35398
|
-
const scheduleDate = extractDate(excludeScheduleDateProfileRounds);
|
|
35399
|
-
const roundId = withRoundId ? round.id : getRoundId(round).id;
|
|
35400
|
-
if (scheduleDate && profileRoundsMap[roundId] && extractDate(profileRoundsMap[roundId].scheduleDate) === scheduleDate) {
|
|
35401
|
-
return false;
|
|
35402
|
-
}
|
|
35403
|
-
}
|
|
35404
|
-
const { isComplete, isScheduled } = round;
|
|
35405
|
-
const keepComplete = !excludeCompletedRounds || !isComplete;
|
|
35406
|
-
const keepScheduled = !excludeScheduledRounds || !isScheduled;
|
|
35407
|
-
const keepRound = keepComplete && keepScheduled;
|
|
35408
|
-
if (!keepRound)
|
|
35409
|
-
excludedRounds.push(round);
|
|
35410
|
-
return keepRound;
|
|
35411
|
-
}).sort(roundSort) || [];
|
|
35412
|
-
return { ...SUCCESS, rounds, excludedRounds };
|
|
35413
|
-
}
|
|
35414
|
-
function getRoundTiming({ round, matchUps, events, tournamentRecords }) {
|
|
35415
|
-
const event = events.find((event2) => event2.eventId === round.eventId);
|
|
35416
|
-
const { eventType, category, categoryType } = event || {};
|
|
35417
|
-
const { categoryName, ageCategoryCode } = category || {};
|
|
35418
|
-
const formatCounts = instanceCount(
|
|
35419
|
-
matchUps.map(({ matchUpFormat }) => matchUpFormat)
|
|
35420
|
-
);
|
|
35421
|
-
let roundMinutes = 0;
|
|
35422
|
-
Object.keys(formatCounts).forEach((matchUpFormat) => {
|
|
35423
|
-
const formatCount = formatCounts[matchUpFormat];
|
|
35424
|
-
const result = findMatchUpFormatTiming({
|
|
35425
|
-
categoryName: categoryName || ageCategoryCode,
|
|
35426
|
-
tournamentId: round.tournamentId,
|
|
35427
|
-
eventId: round.eventId,
|
|
35428
|
-
tournamentRecords,
|
|
35429
|
-
matchUpFormat,
|
|
35430
|
-
categoryType,
|
|
35431
|
-
eventType
|
|
35432
|
-
});
|
|
35433
|
-
if (result.error)
|
|
35434
|
-
return result;
|
|
35435
|
-
const formatMinutes = result.averageMinutes * formatCount;
|
|
35436
|
-
if (!isNaN(roundMinutes))
|
|
35437
|
-
roundMinutes += formatMinutes;
|
|
35438
|
-
return void 0;
|
|
35439
|
-
});
|
|
35440
|
-
return { roundMinutes };
|
|
35441
|
-
}
|
|
35442
|
-
function roundSort(a, b) {
|
|
35443
|
-
return a.eventName.localeCompare(b.eventName) || a.eventId.localeCompare(b.eventId) || (stageOrder[a?.stage] || 0) - (stageOrder[b?.stage] || 0) || b.matchUpsCount - a.matchUpsCount || `${a.stageSequence}-${a.roundNumber}-${a.minFinishingSum}`.localeCompare(
|
|
35444
|
-
`${b.stageSequence}-${b.roundNumber}-${b.minFinishingSum}`
|
|
35445
|
-
);
|
|
35446
|
-
}
|
|
35447
|
-
function getFinishingPositionDetails(matchUps) {
|
|
35448
|
-
return (matchUps || []).reduce(
|
|
35449
|
-
(foo, matchUp) => {
|
|
35450
|
-
const sum = (matchUp.finishingPositionRange?.winner || []).reduce(
|
|
35451
|
-
(a, b) => a + b,
|
|
35452
|
-
0
|
|
35453
|
-
);
|
|
35454
|
-
const winnerFinishingPositionRange = (matchUp.finishingPositionRange?.winner || []).join("-") || "";
|
|
35455
|
-
return !foo.minFinishingSum || sum < foo.minFinishingSum ? { minFinishingSum: sum, winnerFinishingPositionRange } : foo;
|
|
35456
|
-
},
|
|
35457
|
-
{ minFinishingSum: 0, winnerFinishingPositionRange: "" }
|
|
35458
|
-
);
|
|
35459
|
-
}
|
|
35460
|
-
|
|
35461
35138
|
function bulkUpdateCourtAssignments({
|
|
35462
35139
|
tournamentRecords,
|
|
35463
35140
|
courtAssignments,
|
|
@@ -35888,6 +35565,155 @@ function reorderUpcomingMatchUps(params) {
|
|
|
35888
35565
|
}
|
|
35889
35566
|
}
|
|
35890
35567
|
|
|
35568
|
+
function getRoundId(obj) {
|
|
35569
|
+
const {
|
|
35570
|
+
containerStructureId,
|
|
35571
|
+
roundSegment,
|
|
35572
|
+
isRoundRobin,
|
|
35573
|
+
tournamentId,
|
|
35574
|
+
roundNumber,
|
|
35575
|
+
structureId,
|
|
35576
|
+
eventId,
|
|
35577
|
+
drawId
|
|
35578
|
+
} = obj;
|
|
35579
|
+
const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
|
|
35580
|
+
const id = [
|
|
35581
|
+
tournamentId,
|
|
35582
|
+
// 1
|
|
35583
|
+
eventId,
|
|
35584
|
+
// 2
|
|
35585
|
+
drawId,
|
|
35586
|
+
// 3
|
|
35587
|
+
relevantStructureId,
|
|
35588
|
+
// 4
|
|
35589
|
+
roundNumber
|
|
35590
|
+
// 5
|
|
35591
|
+
].join("|");
|
|
35592
|
+
return definedAttributes({
|
|
35593
|
+
structureId: relevantStructureId,
|
|
35594
|
+
roundSegment,
|
|
35595
|
+
tournamentId,
|
|
35596
|
+
roundNumber,
|
|
35597
|
+
eventId,
|
|
35598
|
+
drawId,
|
|
35599
|
+
id
|
|
35600
|
+
});
|
|
35601
|
+
}
|
|
35602
|
+
function getRoundTiming({ round, matchUps, events, tournamentRecords }) {
|
|
35603
|
+
const event = events.find((event2) => event2.eventId === round.eventId);
|
|
35604
|
+
const { eventType, category, categoryType } = event || {};
|
|
35605
|
+
const { categoryName, ageCategoryCode } = category || {};
|
|
35606
|
+
const formatCounts = instanceCount(
|
|
35607
|
+
matchUps.map(({ matchUpFormat }) => matchUpFormat)
|
|
35608
|
+
);
|
|
35609
|
+
let roundMinutes = 0;
|
|
35610
|
+
Object.keys(formatCounts).forEach((matchUpFormat) => {
|
|
35611
|
+
const formatCount = formatCounts[matchUpFormat];
|
|
35612
|
+
const result = findMatchUpFormatTiming({
|
|
35613
|
+
categoryName: categoryName || ageCategoryCode,
|
|
35614
|
+
tournamentId: round.tournamentId,
|
|
35615
|
+
eventId: round.eventId,
|
|
35616
|
+
tournamentRecords,
|
|
35617
|
+
matchUpFormat,
|
|
35618
|
+
categoryType,
|
|
35619
|
+
eventType
|
|
35620
|
+
});
|
|
35621
|
+
if (result.error)
|
|
35622
|
+
return result;
|
|
35623
|
+
const formatMinutes = result.averageMinutes * formatCount;
|
|
35624
|
+
if (!isNaN(roundMinutes))
|
|
35625
|
+
roundMinutes += formatMinutes;
|
|
35626
|
+
return void 0;
|
|
35627
|
+
});
|
|
35628
|
+
return { roundMinutes };
|
|
35629
|
+
}
|
|
35630
|
+
function getFinishingPositionDetails(matchUps) {
|
|
35631
|
+
return (matchUps || []).reduce(
|
|
35632
|
+
(foo, matchUp) => {
|
|
35633
|
+
const sum = (matchUp.finishingPositionRange?.winner || []).reduce(
|
|
35634
|
+
(a, b) => a + b,
|
|
35635
|
+
0
|
|
35636
|
+
);
|
|
35637
|
+
const winnerFinishingPositionRange = (matchUp.finishingPositionRange?.winner || []).join("-") || "";
|
|
35638
|
+
return !foo.minFinishingSum || sum < foo.minFinishingSum ? { minFinishingSum: sum, winnerFinishingPositionRange } : foo;
|
|
35639
|
+
},
|
|
35640
|
+
{ minFinishingSum: 0, winnerFinishingPositionRange: "" }
|
|
35641
|
+
);
|
|
35642
|
+
}
|
|
35643
|
+
function getRoundProfile(matchUps) {
|
|
35644
|
+
const matchUpsCount = matchUps.length;
|
|
35645
|
+
const byeCount = matchUps.filter(({ sides }) => sides?.some(({ bye }) => bye)).length || 0;
|
|
35646
|
+
const completedCount = matchUps.filter(
|
|
35647
|
+
({ winningSide, matchUpStatus }) => winningSide || completedMatchUpStatuses.includes(matchUpStatus)
|
|
35648
|
+
).length || 0;
|
|
35649
|
+
const scheduledCount = matchUps.filter(
|
|
35650
|
+
({ schedule }) => schedule?.scheduledDate && schedule?.scheduledTime
|
|
35651
|
+
).length || 0;
|
|
35652
|
+
const consideredCount = matchUpsCount - byeCount;
|
|
35653
|
+
const isComplete = consideredCount === completedCount;
|
|
35654
|
+
const unscheduledCount = consideredCount - scheduledCount;
|
|
35655
|
+
const incompleteCount = consideredCount - scheduledCount;
|
|
35656
|
+
const isScheduled = consideredCount === scheduledCount;
|
|
35657
|
+
return {
|
|
35658
|
+
unscheduledCount,
|
|
35659
|
+
incompleteCount,
|
|
35660
|
+
scheduledCount,
|
|
35661
|
+
completedCount,
|
|
35662
|
+
matchUpsCount,
|
|
35663
|
+
isScheduled,
|
|
35664
|
+
isComplete,
|
|
35665
|
+
byeCount
|
|
35666
|
+
};
|
|
35667
|
+
}
|
|
35668
|
+
|
|
35669
|
+
function getProfileRounds({
|
|
35670
|
+
tournamentRecords,
|
|
35671
|
+
schedulingProfile,
|
|
35672
|
+
tournamentRecord,
|
|
35673
|
+
withRoundId
|
|
35674
|
+
}) {
|
|
35675
|
+
if (tournamentRecord && !tournamentRecords) {
|
|
35676
|
+
if (typeof tournamentRecord !== "object") {
|
|
35677
|
+
return { error: INVALID_TOURNAMENT_RECORD };
|
|
35678
|
+
} else {
|
|
35679
|
+
tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
|
|
35680
|
+
}
|
|
35681
|
+
}
|
|
35682
|
+
if (schedulingProfile) {
|
|
35683
|
+
const profileValidity = validateSchedulingProfile({
|
|
35684
|
+
tournamentRecords,
|
|
35685
|
+
schedulingProfile
|
|
35686
|
+
});
|
|
35687
|
+
if (profileValidity.error)
|
|
35688
|
+
return profileValidity;
|
|
35689
|
+
}
|
|
35690
|
+
if (!schedulingProfile && tournamentRecords) {
|
|
35691
|
+
const result = getSchedulingProfile$1({ tournamentRecords });
|
|
35692
|
+
if (result.error)
|
|
35693
|
+
return result;
|
|
35694
|
+
schedulingProfile = result.schedulingProfile;
|
|
35695
|
+
}
|
|
35696
|
+
if (!schedulingProfile)
|
|
35697
|
+
return { error: NOT_FOUND };
|
|
35698
|
+
const segmentedRounds = {};
|
|
35699
|
+
const profileRounds = schedulingProfile.map(
|
|
35700
|
+
({ venues, scheduleDate }) => venues.map(
|
|
35701
|
+
({ rounds }) => rounds.map((round) => {
|
|
35702
|
+
const roundRef = getRoundId(round);
|
|
35703
|
+
if (roundRef.roundSegment?.segmentsCount) {
|
|
35704
|
+
segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
|
|
35705
|
+
}
|
|
35706
|
+
return definedAttributes({
|
|
35707
|
+
id: withRoundId ? roundRef.id : void 0,
|
|
35708
|
+
scheduleDate,
|
|
35709
|
+
...roundRef
|
|
35710
|
+
});
|
|
35711
|
+
})
|
|
35712
|
+
)
|
|
35713
|
+
).flat(Infinity);
|
|
35714
|
+
return { profileRounds, segmentedRounds };
|
|
35715
|
+
}
|
|
35716
|
+
|
|
35891
35717
|
function addMatchUpScheduleItems$1(params) {
|
|
35892
35718
|
return addMatchUpScheduleItems$2(params);
|
|
35893
35719
|
}
|
|
@@ -36505,6 +36331,200 @@ function matchUpScheduleChange(params) {
|
|
|
36505
36331
|
}
|
|
36506
36332
|
}
|
|
36507
36333
|
|
|
36334
|
+
const { stageOrder } = drawDefinitionConstants;
|
|
36335
|
+
function roundSort(a, b) {
|
|
36336
|
+
return a.eventName.localeCompare(b.eventName) || a.eventId.localeCompare(b.eventId) || (stageOrder[a?.stage] || 0) - (stageOrder[b?.stage] || 0) || b.matchUpsCount - a.matchUpsCount || `${a.stageSequence}-${a.roundNumber}-${a.minFinishingSum}`.localeCompare(
|
|
36337
|
+
`${b.stageSequence}-${b.roundNumber}-${b.minFinishingSum}`
|
|
36338
|
+
);
|
|
36339
|
+
}
|
|
36340
|
+
|
|
36341
|
+
function getRounds({
|
|
36342
|
+
excludeScheduleDateProfileRounds,
|
|
36343
|
+
excludeScheduledRounds,
|
|
36344
|
+
excludeCompletedRounds,
|
|
36345
|
+
inContextMatchUps,
|
|
36346
|
+
tournamentRecords,
|
|
36347
|
+
schedulingProfile,
|
|
36348
|
+
tournamentRecord,
|
|
36349
|
+
withSplitRounds,
|
|
36350
|
+
matchUpFilters,
|
|
36351
|
+
scheduleDate,
|
|
36352
|
+
withRoundId,
|
|
36353
|
+
venueId,
|
|
36354
|
+
context
|
|
36355
|
+
}) {
|
|
36356
|
+
if (inContextMatchUps && !Array.isArray(
|
|
36357
|
+
inContextMatchUps || typeof inContextMatchUps[0] !== "object"
|
|
36358
|
+
)) {
|
|
36359
|
+
return { error: INVALID_VALUES, inContextMatchUps };
|
|
36360
|
+
}
|
|
36361
|
+
if (tournamentRecord && !tournamentRecords) {
|
|
36362
|
+
if (typeof tournamentRecord !== "object") {
|
|
36363
|
+
return { error: INVALID_TOURNAMENT_RECORD };
|
|
36364
|
+
} else {
|
|
36365
|
+
tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
|
|
36366
|
+
}
|
|
36367
|
+
}
|
|
36368
|
+
const noTournamentRecords = typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length;
|
|
36369
|
+
const needsTournamentRecords = venueId || scheduleDate || !inContextMatchUps || !schedulingProfile && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds);
|
|
36370
|
+
if (needsTournamentRecords && noTournamentRecords)
|
|
36371
|
+
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
36372
|
+
const tournamentVenueIds = Object.assign(
|
|
36373
|
+
{},
|
|
36374
|
+
...Object.values(tournamentRecords ?? {}).map(
|
|
36375
|
+
({ venues = [], tournamentId }) => ({
|
|
36376
|
+
[tournamentId]: venues?.map(({ venueId: venueId2 }) => venueId2)
|
|
36377
|
+
})
|
|
36378
|
+
)
|
|
36379
|
+
);
|
|
36380
|
+
const events = Object.values(tournamentRecords ?? {}).map(
|
|
36381
|
+
({ events: events2 = [], tournamentId, startDate, endDate }) => events2.map((event) => ({
|
|
36382
|
+
...event,
|
|
36383
|
+
validVenueIds: tournamentVenueIds[tournamentId],
|
|
36384
|
+
startDate: event.startDate ?? startDate,
|
|
36385
|
+
endDate: event.endDate ?? endDate
|
|
36386
|
+
}))
|
|
36387
|
+
).flat();
|
|
36388
|
+
const { segmentedRounds, profileRounds } = tournamentRecords && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds) && getProfileRounds({ tournamentRecords, schedulingProfile }) || {};
|
|
36389
|
+
const profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign(
|
|
36390
|
+
{},
|
|
36391
|
+
...profileRounds.map((profile) => ({ [profile.id]: profile }))
|
|
36392
|
+
);
|
|
36393
|
+
const consideredMatchUps = inContextMatchUps || tournamentRecords && allCompetitionMatchUps({ tournamentRecords, matchUpFilters })?.matchUps || [];
|
|
36394
|
+
const excludedRounds = [];
|
|
36395
|
+
const rounds = consideredMatchUps && Object.values(
|
|
36396
|
+
consideredMatchUps.reduce((rounds2, matchUp) => {
|
|
36397
|
+
const id = getRoundId(matchUp).id;
|
|
36398
|
+
const segmentsCount = segmentedRounds?.[id];
|
|
36399
|
+
const matchUps = [...rounds2[id]?.matchUps ?? [], matchUp];
|
|
36400
|
+
const {
|
|
36401
|
+
containerStructureId,
|
|
36402
|
+
stageSequence,
|
|
36403
|
+
structureName,
|
|
36404
|
+
tournamentId,
|
|
36405
|
+
isRoundRobin,
|
|
36406
|
+
matchUpType,
|
|
36407
|
+
roundNumber,
|
|
36408
|
+
roundOffset,
|
|
36409
|
+
structureId,
|
|
36410
|
+
eventName,
|
|
36411
|
+
roundName,
|
|
36412
|
+
drawName,
|
|
36413
|
+
eventId,
|
|
36414
|
+
drawId
|
|
36415
|
+
} = matchUp;
|
|
36416
|
+
const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
|
|
36417
|
+
return {
|
|
36418
|
+
...rounds2,
|
|
36419
|
+
[id]: {
|
|
36420
|
+
id: withRoundId ? id : void 0,
|
|
36421
|
+
structureId: relevantStructureId,
|
|
36422
|
+
stageSequence,
|
|
36423
|
+
segmentsCount,
|
|
36424
|
+
structureName,
|
|
36425
|
+
tournamentId,
|
|
36426
|
+
matchUpType,
|
|
36427
|
+
roundNumber,
|
|
36428
|
+
roundOffset,
|
|
36429
|
+
eventName,
|
|
36430
|
+
roundName,
|
|
36431
|
+
drawName,
|
|
36432
|
+
matchUps,
|
|
36433
|
+
eventId,
|
|
36434
|
+
drawId
|
|
36435
|
+
}
|
|
36436
|
+
};
|
|
36437
|
+
}, {})
|
|
36438
|
+
).map((round) => {
|
|
36439
|
+
const { minFinishingSum, winnerFinishingPositionRange } = getFinishingPositionDetails(round.matchUps);
|
|
36440
|
+
const segmentsCount = round.segmentsCount;
|
|
36441
|
+
if (segmentsCount) {
|
|
36442
|
+
const chunkSize = round.matchUps.length / segmentsCount;
|
|
36443
|
+
const sortedMatchUps = chunkArray(
|
|
36444
|
+
round.matchUps.sort((a, b) => a.roundPosition - b.roundPosition),
|
|
36445
|
+
chunkSize
|
|
36446
|
+
);
|
|
36447
|
+
return sortedMatchUps.map((matchUps, i) => {
|
|
36448
|
+
const {
|
|
36449
|
+
unscheduledCount: unscheduledCount2,
|
|
36450
|
+
incompleteCount: incompleteCount2,
|
|
36451
|
+
matchUpsCount: matchUpsCount2,
|
|
36452
|
+
isScheduled: isScheduled2,
|
|
36453
|
+
isComplete: isComplete2,
|
|
36454
|
+
byeCount: byeCount2
|
|
36455
|
+
} = getRoundProfile(matchUps);
|
|
36456
|
+
const roundTiming2 = getRoundTiming({
|
|
36457
|
+
matchUps: round.matchUps,
|
|
36458
|
+
tournamentRecords,
|
|
36459
|
+
events,
|
|
36460
|
+
round
|
|
36461
|
+
});
|
|
36462
|
+
return definedAttributes({
|
|
36463
|
+
...round,
|
|
36464
|
+
...context,
|
|
36465
|
+
roundSegment: { segmentsCount, segmentNumber: i + 1 },
|
|
36466
|
+
winnerFinishingPositionRange,
|
|
36467
|
+
unscheduledCount: unscheduledCount2,
|
|
36468
|
+
incompleteCount: incompleteCount2,
|
|
36469
|
+
minFinishingSum,
|
|
36470
|
+
matchUpsCount: matchUpsCount2,
|
|
36471
|
+
isScheduled: isScheduled2,
|
|
36472
|
+
roundTiming: roundTiming2,
|
|
36473
|
+
isComplete: isComplete2,
|
|
36474
|
+
byeCount: byeCount2,
|
|
36475
|
+
matchUps
|
|
36476
|
+
});
|
|
36477
|
+
});
|
|
36478
|
+
}
|
|
36479
|
+
const {
|
|
36480
|
+
unscheduledCount,
|
|
36481
|
+
incompleteCount,
|
|
36482
|
+
matchUpsCount,
|
|
36483
|
+
isScheduled,
|
|
36484
|
+
isComplete,
|
|
36485
|
+
byeCount
|
|
36486
|
+
} = getRoundProfile(round.matchUps);
|
|
36487
|
+
const roundTiming = getRoundTiming({
|
|
36488
|
+
matchUps: round.matchUps,
|
|
36489
|
+
tournamentRecords,
|
|
36490
|
+
events,
|
|
36491
|
+
round
|
|
36492
|
+
});
|
|
36493
|
+
return definedAttributes({
|
|
36494
|
+
...round,
|
|
36495
|
+
...context,
|
|
36496
|
+
winnerFinishingPositionRange,
|
|
36497
|
+
unscheduledCount,
|
|
36498
|
+
incompleteCount,
|
|
36499
|
+
minFinishingSum,
|
|
36500
|
+
matchUpsCount,
|
|
36501
|
+
isScheduled,
|
|
36502
|
+
roundTiming,
|
|
36503
|
+
isComplete,
|
|
36504
|
+
byeCount
|
|
36505
|
+
});
|
|
36506
|
+
}).flat().filter((round) => {
|
|
36507
|
+
if (excludeScheduleDateProfileRounds) {
|
|
36508
|
+
const scheduleDate2 = extractDate(excludeScheduleDateProfileRounds);
|
|
36509
|
+
const roundId = withRoundId ? round.id : getRoundId(round).id;
|
|
36510
|
+
if (scheduleDate2 && profileRoundsMap[roundId] && extractDate(profileRoundsMap[roundId].scheduleDate) === scheduleDate2) {
|
|
36511
|
+
return false;
|
|
36512
|
+
}
|
|
36513
|
+
}
|
|
36514
|
+
const { isComplete, isScheduled } = round;
|
|
36515
|
+
const keepComplete = !excludeCompletedRounds || !isComplete;
|
|
36516
|
+
const keepScheduled = !excludeScheduledRounds || !isScheduled;
|
|
36517
|
+
const event = venueId || scheduleDate ? events?.find(({ eventId }) => eventId === round.eventId) : void 0;
|
|
36518
|
+
const validDate = !scheduleDate || event?.startDate && event?.endDate && new Date(scheduleDate) >= new Date(event?.startDate) && new Date(scheduleDate) <= new Date(event?.endDate);
|
|
36519
|
+
const validVenue = !venueId || event?.validVenueIds.includes(venueId);
|
|
36520
|
+
const keepRound = keepComplete && keepScheduled && validVenue && validDate;
|
|
36521
|
+
if (!keepRound)
|
|
36522
|
+
excludedRounds.push(round);
|
|
36523
|
+
return keepRound;
|
|
36524
|
+
}).sort(roundSort) || [];
|
|
36525
|
+
return { ...SUCCESS, rounds, excludedRounds };
|
|
36526
|
+
}
|
|
36527
|
+
|
|
36508
36528
|
function addMatchUpScheduleItems(params) {
|
|
36509
36529
|
const result = getDrawDefinition$1(params);
|
|
36510
36530
|
if (result.error)
|
|
@@ -39110,13 +39130,14 @@ const competitionEngine = function() {
|
|
|
39110
39130
|
const elapsed = Date.now() - start;
|
|
39111
39131
|
const devContext = getDevContext();
|
|
39112
39132
|
const log = { method: methodName };
|
|
39113
|
-
const
|
|
39114
|
-
|
|
39133
|
+
const logError = result.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
|
|
39134
|
+
const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
|
|
39135
|
+
if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
|
|
39115
39136
|
log.elapsed = elapsed;
|
|
39116
|
-
if (
|
|
39137
|
+
if (!exclude && (logError || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName))) {
|
|
39117
39138
|
log.params = params;
|
|
39118
39139
|
}
|
|
39119
|
-
if (
|
|
39140
|
+
if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
|
|
39120
39141
|
log.result = result;
|
|
39121
39142
|
}
|
|
39122
39143
|
if (Object.keys(log).length > 1)
|
|
@@ -59984,13 +60005,14 @@ const tournamentEngine = (() => {
|
|
|
59984
60005
|
const elapsed = Date.now() - start;
|
|
59985
60006
|
const devContext = getDevContext();
|
|
59986
60007
|
const log = { method: methodName };
|
|
59987
|
-
const
|
|
59988
|
-
|
|
60008
|
+
const logError = result.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
|
|
60009
|
+
const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
|
|
60010
|
+
if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
|
|
59989
60011
|
log.elapsed = elapsed;
|
|
59990
|
-
if (
|
|
60012
|
+
if (!exclude && (logError || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName))) {
|
|
59991
60013
|
log.params = params;
|
|
59992
60014
|
}
|
|
59993
|
-
if (
|
|
60015
|
+
if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
|
|
59994
60016
|
log.result = result;
|
|
59995
60017
|
}
|
|
59996
60018
|
if (Object.keys(log).length > 1)
|