tods-competition-factory 0.64.2 → 0.66.0

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.
@@ -248,6 +248,10 @@ const matchUpFormatCode = {
248
248
  parse
249
249
  };
250
250
 
251
+ function factoryVersion() {
252
+ return '0.66.0';
253
+ }
254
+
251
255
  const FORMAT_STANDARD = 'SET3-S:6/TB7'; // Best of 3 Tiebreak Sets to 6
252
256
 
253
257
  const FORMAT_STANDARD_NOAD = 'SET3-S:6NOAD'; // Best of 3 NOAD Sets to 6 with deciding game at 5-5
@@ -9451,7 +9455,9 @@ function getRoundMatchUps$1({
9451
9455
  const currentRoundMatchUps = roundMatchUps[roundNumber].sort((a, b) => a.roundPosition - b.roundPosition);
9452
9456
  const currentRoundDrawPositions = currentRoundMatchUps.map(matchUp => (matchUp === null || matchUp === void 0 ? void 0 : matchUp.drawPositions) || []).flat();
9453
9457
  roundProfile[roundNumber].roundNumber = roundNumber; // convenience
9458
+ // convenience for display calculations
9454
9459
 
9460
+ roundProfile[roundNumber].roundFactor = roundProfile[roundNumber].matchUpsCount ? maxMatchUpsCount / roundProfile[roundNumber].matchUpsCount : 1;
9455
9461
  roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber].finishingRound;
9456
9462
  roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber].roundName;
9457
9463
  roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber].abbreviatedRoundName;
@@ -11375,7 +11381,7 @@ function getAllStructureMatchUps({
11375
11381
  matchUp,
11376
11382
  event
11377
11383
  }) {
11378
- var _roundNamingProfile$r, _roundNamingProfile$r2;
11384
+ var _roundNamingProfile$r, _roundNamingProfile$r2, _roundProfile$roundNu, _roundProfile$roundNu2, _roundProfile$roundNu3;
11379
11385
 
11380
11386
  const tieFormat = matchUp.tieFormat || structure.tieFormat || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat);
11381
11387
  const collectionDefinitions = tieFormat === null || tieFormat === void 0 ? void 0 : tieFormat.collectionDefinitions;
@@ -11415,7 +11421,9 @@ function getAllStructureMatchUps({
11415
11421
  });
11416
11422
  const roundName = roundNamingProfile && ((_roundNamingProfile$r = roundNamingProfile[roundNumber]) === null || _roundNamingProfile$r === void 0 ? void 0 : _roundNamingProfile$r.roundName) || additionalContext.roundName;
11417
11423
  const abbreviatedRoundName = roundNamingProfile && ((_roundNamingProfile$r2 = roundNamingProfile[roundNumber]) === null || _roundNamingProfile$r2 === void 0 ? void 0 : _roundNamingProfile$r2.abbreviatedRoundName) || additionalContext.abbreviatedRoundName;
11418
- const feedRound = roundProfile && roundProfile[roundNumber] && roundProfile[roundNumber].feedRound;
11424
+ const feedRound = roundProfile === null || roundProfile === void 0 ? void 0 : (_roundProfile$roundNu = roundProfile[roundNumber]) === null || _roundProfile$roundNu === void 0 ? void 0 : _roundProfile$roundNu.feedRound;
11425
+ const preFeedRound = roundProfile === null || roundProfile === void 0 ? void 0 : (_roundProfile$roundNu2 = roundProfile[roundNumber]) === null || _roundProfile$roundNu2 === void 0 ? void 0 : _roundProfile$roundNu2.preFeedRound;
11426
+ const roundFactor = roundProfile === null || roundProfile === void 0 ? void 0 : (_roundProfile$roundNu3 = roundProfile[roundNumber]) === null || _roundProfile$roundNu3 === void 0 ? void 0 : _roundProfile$roundNu3.roundFactor;
11419
11427
  const drawPositionsRoundRanges = drawPositionsRanges && drawPositionsRanges[roundNumber];
11420
11428
  const drawPositionsRange = drawPositionsRoundRanges && drawPositionsRoundRanges[roundPosition];
11421
11429
  const sourceDrawPositionRoundRanges = sourceDrawPositionRanges && sourceDrawPositionRanges[roundNumber]; // order is important here as Round Robin matchUps already have inContext structureId
@@ -11433,6 +11441,8 @@ function getAllStructureMatchUps({
11433
11441
  drawPositions,
11434
11442
  matchUpStatus,
11435
11443
  matchUpTieId,
11444
+ preFeedRound,
11445
+ roundFactor,
11436
11446
  matchUpType,
11437
11447
  exitProfile,
11438
11448
  structureId,
@@ -13032,7 +13042,7 @@ function addUpcomingMatchUps({
13032
13042
  }
13033
13043
 
13034
13044
  if ((_loserTo = loserTo) !== null && _loserTo !== void 0 && (_loserTo$schedule = _loserTo.schedule) !== null && _loserTo$schedule !== void 0 && _loserTo$schedule.scheduledTime) {
13035
- const scheduleConflict = timeStringMinutes(winnerTo.schedule.scheduledTime) < timeStringMinutes(timeAfterRecovery);
13045
+ const scheduleConflict = timeStringMinutes(loserTo.schedule.scheduledTime) < timeStringMinutes(timeAfterRecovery);
13036
13046
 
13037
13047
  if (scheduleConflict) {
13038
13048
  scheduleConflictMatchUpIds[loserTo.matchUpId] = inContextMatchUp.matchUpId;
@@ -18057,9 +18067,9 @@ function getAvailableAdHocParticipantIds({
18057
18067
  drawPosition,
18058
18068
  participantId
18059
18069
  }) => roundDrawPositions.includes(drawPosition) && participantId).map(getParticipantId);
18060
- const enteredParticipantIds = drawDefinition.entries.filter(({
18070
+ const enteredParticipantIds = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries.filter(({
18061
18071
  entryStatus
18062
- }) => [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId); // AdHoc available participants are those entered in the draw who are not assigned to the target round
18072
+ }) => [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId)) || []; // AdHoc available participants are those entered in the draw who are not assigned to the target round
18063
18073
 
18064
18074
  const availableParticipantIds = enteredParticipantIds.filter(participantId => !roundAssignedParticipantIds.includes(participantId));
18065
18075
  return availableParticipantIds;
@@ -28039,10 +28049,6 @@ const scheduleGovernor$1 = {
28039
28049
  removePersonRequests
28040
28050
  };
28041
28051
 
28042
- function factoryVersion() {
28043
- return '0.64.2';
28044
- }
28045
-
28046
28052
  function attachPolicies$2({
28047
28053
  tournamentRecord,
28048
28054
  policyDefinitions,
@@ -34633,7 +34639,7 @@ function getAssignedParticipantIds({
34633
34639
  function refreshEntryPositions({
34634
34640
  entries = []
34635
34641
  } = {}) {
34636
- const stagedEntries = entries.reduce((stages, entry) => {
34642
+ const stagedEntries = entries.filter(Boolean).reduce((stages, entry) => {
34637
34643
  const {
34638
34644
  entryStage,
34639
34645
  entryStatus
@@ -34845,6 +34851,8 @@ function modifyEntriesStatus({
34845
34851
  return true;
34846
34852
  });
34847
34853
  (_event$drawDefinition4 = event.drawDefinitions) === null || _event$drawDefinition4 === void 0 ? void 0 : _event$drawDefinition4.every(drawDefinition => {
34854
+ var _drawDefinition$entri2;
34855
+
34848
34856
  const result = updateEntryStatus(drawDefinition.entries);
34849
34857
 
34850
34858
  if (result.error) {
@@ -34852,7 +34860,7 @@ function modifyEntriesStatus({
34852
34860
  return false;
34853
34861
  }
34854
34862
 
34855
- drawDefinition.entries = drawDefinition.entries.filter(({
34863
+ drawDefinition.entries = (_drawDefinition$entri2 = drawDefinition.entries) === null || _drawDefinition$entri2 === void 0 ? void 0 : _drawDefinition$entri2.filter(({
34856
34864
  participantId
34857
34865
  }) => !participantIds.includes(participantId));
34858
34866
  return true;
@@ -35189,8 +35197,8 @@ function participantInEntries({
35189
35197
  function addDrawEntry({
35190
35198
  entryStatus = DIRECT_ACCEPTANCE,
35191
35199
  entryStage = MAIN,
35192
- entryPosition,
35193
35200
  drawDefinition,
35201
+ entryPosition,
35194
35202
  participantId,
35195
35203
  participant
35196
35204
  }) {
@@ -35222,7 +35230,7 @@ function addDrawEntry({
35222
35230
  };
35223
35231
  }
35224
35232
 
35225
- participantId = participantId || participant && participant.participantId;
35233
+ participantId = participantId || (participant === null || participant === void 0 ? void 0 : participant.participantId);
35226
35234
  if (!participantId) return {
35227
35235
  error: MISSING_PARTICIPANT_ID
35228
35236
  };
@@ -35344,7 +35352,7 @@ function addDrawEntries$1({
35344
35352
  };
35345
35353
  }
35346
35354
 
35347
- participantIds.forEach(participantId => {
35355
+ participantIds.filter(Boolean).forEach(participantId => {
35348
35356
  const entry = Object.assign({
35349
35357
  participantId
35350
35358
  }, {
@@ -36439,6 +36447,7 @@ function generateDrawMaticRound({
36439
36447
  const {
36440
36448
  participantIdPairings
36441
36449
  } = eventType === DOUBLES ? getDoublesPairings(params) : getSinglesPairings(params);
36450
+ console.log(participantIdPairings);
36442
36451
 
36443
36452
  for (const [index, matchUp] of roundMatchUps.entries()) {
36444
36453
  const drawPositions = matchUp.drawPositions;
@@ -36599,13 +36608,16 @@ function drawMatic$1({
36599
36608
  matchUpIds,
36600
36609
  scaleName,
36601
36610
  // custom rating name to seed dynamic ratings
36602
- eventType
36611
+ event
36603
36612
  }) {
36604
36613
  var _drawDefinition$struc2;
36605
36614
 
36606
36615
  if (typeof drawDefinition !== 'object') return {
36607
36616
  error: INVALID_DRAW_DEFINITION
36608
36617
  };
36618
+ const {
36619
+ eventType
36620
+ } = event || {};
36609
36621
  const enteredParticipantIds = drawDefinition.entries.filter(({
36610
36622
  entryStatus
36611
36623
  }) => !restrictEntryStatus || [DIRECT_ACCEPTANCE, ORGANISER_ACCEPTANCE, WILDCARD].includes(entryStatus)).map(getParticipantId);
@@ -50143,6 +50155,7 @@ function generateParticipants({
50143
50155
  participantsCount = 32,
50144
50156
  participantType,
50145
50157
  personIds,
50158
+ idPrefix,
50146
50159
  uuids,
50147
50160
  personExtensions,
50148
50161
  addressProps,
@@ -50272,12 +50285,18 @@ function generateParticipants({
50272
50285
  });
50273
50286
  const individualParticipantIds = individualParticipants.map(participant => participant.participantId);
50274
50287
  const pairName = individualParticipants.map(i => i.person.standardFamilyName).join('/');
50288
+ const participantType = doubles ? PAIR$1 : TEAM$1;
50275
50289
  const groupParticipant = {
50276
- participantId: (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID(),
50277
- participantType: doubles ? PAIR$1 : TEAM$1,
50290
+ participantId: genParticipantId({
50291
+ participantType,
50292
+ idPrefix,
50293
+ index: i,
50294
+ uuids
50295
+ }),
50278
50296
  participantRole: COMPETITOR,
50279
50297
  participantName: doubles ? pairName : teamNames[i],
50280
- individualParticipantIds
50298
+ individualParticipantIds,
50299
+ participantType
50281
50300
  };
50282
50301
  if (inContext) groupParticipant.individualParticipants = individualParticipants;
50283
50302
  return doubles || team ? [groupParticipant, ...individualParticipants] : individualParticipants;
@@ -50317,7 +50336,12 @@ function generateParticipants({
50317
50336
  nationalityCode
50318
50337
  });
50319
50338
  const participant = definedAttributes({
50320
- participantId: (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID(),
50339
+ participantId: genParticipantId({
50340
+ participantType: INDIVIDUAL$1,
50341
+ index: participantIndex,
50342
+ idPrefix,
50343
+ uuids
50344
+ }),
50321
50345
  extensions: participantExtensions,
50322
50346
  timeItems: participantTimeItems,
50323
50347
  participantRole: COMPETITOR,
@@ -50402,6 +50426,16 @@ function addScaleItem({
50402
50426
  }
50403
50427
  }
50404
50428
 
50429
+ function genParticipantId({
50430
+ idPrefix,
50431
+ participantType,
50432
+ index,
50433
+ uuids
50434
+ }) {
50435
+ const type = participantType === INDIVIDUAL$1 ? 'I' : 'P' ;
50436
+ return idPrefix ? `${idPrefix}-${type}-${index}` : (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID();
50437
+ }
50438
+
50405
50439
  function processTieFormat({
50406
50440
  tieFormat,
50407
50441
  tieFormatName,
@@ -50572,7 +50606,7 @@ function getParticipantsCount({
50572
50606
  }
50573
50607
 
50574
50608
  function addTournamentParticipants({
50575
- participantsProfile,
50609
+ participantsProfile = {},
50576
50610
  tournamentRecord,
50577
50611
  eventProfiles,
50578
50612
  drawProfiles,
@@ -50590,35 +50624,16 @@ function addTournamentParticipants({
50590
50624
  drawProfiles
50591
50625
  });
50592
50626
  const {
50593
- nationalityCodesCount,
50594
- nationalityCodeType,
50595
- valuesInstanceLimit,
50596
- nationalityCodes,
50597
- personExtensions,
50598
- addressProps,
50599
- personData,
50600
- personIds,
50601
- inContext,
50602
- teamKey,
50603
- sex
50627
+ teamKey
50604
50628
  } = participantsProfile || {};
50605
50629
  const {
50606
50630
  participants
50607
50631
  } = generateParticipants({
50632
+ uuids,
50633
+ ...participantsProfile,
50608
50634
  consideredDate: startDate,
50609
- valuesInstanceLimit,
50610
- nationalityCodesCount,
50611
- nationalityCodeType,
50612
- nationalityCodes,
50613
- personExtensions,
50614
- addressProps,
50615
- personData,
50616
- sex,
50617
50635
  participantsCount,
50618
- participantType,
50619
- personIds,
50620
- uuids,
50621
- inContext
50636
+ participantType
50622
50637
  });
50623
50638
  let result = addParticipants({
50624
50639
  tournamentRecord,
@@ -50655,11 +50670,12 @@ function addTournamentParticipants({
50655
50670
  }
50656
50671
 
50657
50672
  function generateEventParticipants({
50673
+ participantsProfile = {},
50658
50674
  uniqueParticipantsCount,
50659
- participantsProfile,
50660
50675
  ratingsParameters,
50661
50676
  tournamentRecord,
50662
50677
  eventProfile,
50678
+ eventIndex,
50663
50679
  event,
50664
50680
  uuids
50665
50681
  }) {
@@ -50668,38 +50684,25 @@ function generateEventParticipants({
50668
50684
  gender,
50669
50685
  eventType
50670
50686
  } = event;
50671
- const {
50672
- valuesInstanceLimit,
50673
- nationalityCodesCount,
50674
- nationalityCodeType,
50675
- nationalityCodes,
50676
- addressProps,
50677
- personIds,
50678
- inContext
50679
- } = participantsProfile || {};
50680
50687
  const eventParticipantType = eventType === SINGLES ? INDIVIDUAL$1 : eventType === DOUBLES ? PAIR$1 : eventType;
50681
50688
  const mainParticipantsCount = uniqueParticipantsCount[MAIN] || 0;
50682
50689
  const qualifyingParticipantsCount = uniqueParticipantsCount[QUALIFYING] || 0;
50683
50690
  const participantsCount = mainParticipantsCount + qualifyingParticipantsCount;
50684
50691
  const sex = [MALE, FEMALE].includes(gender) ? gender : undefined;
50692
+ const idPrefix = participantsProfile !== null && participantsProfile !== void 0 && participantsProfile.idPrefix ? `E-${eventIndex}-${participantsProfile === null || participantsProfile === void 0 ? void 0 : participantsProfile.idPrefix}` : undefined;
50685
50693
  const {
50686
50694
  participants: uniqueFlightParticipants
50687
50695
  } = generateParticipants({
50696
+ uuids: eventProfile.uuids || uuids,
50697
+ ...participantsProfile,
50688
50698
  scaledParticipantsCount: eventProfile.scaledParticipantsCount,
50689
50699
  consideredDate: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.startDate,
50690
50700
  rankingRange: eventProfile.rankingRange,
50691
50701
  participantType: eventParticipantType,
50692
- nationalityCodesCount,
50693
- nationalityCodeType,
50694
- valuesInstanceLimit,
50695
50702
  participantsCount,
50696
50703
  ratingsParameters,
50697
- nationalityCodes,
50698
- addressProps,
50699
- personIds,
50700
- inContext,
50704
+ idPrefix,
50701
50705
  category,
50702
- uuids,
50703
50706
  sex
50704
50707
  });
50705
50708
  let result = addParticipants({
@@ -50868,222 +50871,6 @@ function generateFlights({
50868
50871
  };
50869
50872
  }
50870
50873
 
50871
- function modifyTournamentRecord({
50872
- matchUpStatusProfile,
50873
- completeAllMatchUps,
50874
- participantsProfile,
50875
- autoEntryPositions,
50876
- randomWinningSide,
50877
- tournamentRecord,
50878
- eventProfiles,
50879
- uuids
50880
- }) {
50881
- if (!tournamentRecord) return {
50882
- error: MISSING_TOURNAMENT_RECORD
50883
- };
50884
- const allUniqueParticipantIds = [];
50885
- const drawIds = [];
50886
- eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
50887
- const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
50888
-
50889
- if (event !== null && event !== void 0 && event.gender) {
50890
- eventProfile.gender = event.gender;
50891
- }
50892
- });
50893
- const result = addTournamentParticipants({
50894
- startDate: tournamentRecord.startDate,
50895
- participantsProfile,
50896
- tournamentRecord,
50897
- eventProfiles,
50898
- // drawProfiles,
50899
- uuids
50900
- });
50901
- if (!result.success) return result;
50902
-
50903
- if (eventProfiles) {
50904
- for (const eventProfile of eventProfiles) {
50905
- let {
50906
- ratingsParameters
50907
- } = eventProfile;
50908
- const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
50909
- if (!event) return {
50910
- error: EVENT_NOT_FOUND
50911
- };
50912
- const {
50913
- gender,
50914
- category,
50915
- eventType
50916
- } = event;
50917
- const {
50918
- drawProfiles
50919
- } = eventProfile;
50920
- const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
50921
-
50922
- if (drawProfiles) {
50923
- const {
50924
- stageParticipantsCount,
50925
- uniqueParticipantsCount,
50926
- uniqueParticipantStages
50927
- } = getStageParticipantsCount({
50928
- drawProfiles,
50929
- category,
50930
- gender
50931
- });
50932
- const {
50933
- uniqueDrawParticipants = [],
50934
- uniqueParticipantIds = []
50935
- } = uniqueParticipantStages ? generateEventParticipants({
50936
- event: {
50937
- eventType,
50938
- category,
50939
- gender
50940
- },
50941
- uniqueParticipantsCount,
50942
- participantsProfile,
50943
- ratingsParameters,
50944
- tournamentRecord,
50945
- eventProfile,
50946
- uuids
50947
- }) : {};
50948
- allUniqueParticipantIds.push(...uniqueParticipantIds);
50949
- const {
50950
- stageParticipants
50951
- } = getStageParticipants({
50952
- targetParticipants: tournamentRecord.participants || [],
50953
- allUniqueParticipantIds,
50954
- stageParticipantsCount,
50955
- eventParticipantType
50956
- });
50957
- let result = generateFlights({
50958
- uniqueDrawParticipants,
50959
- autoEntryPositions,
50960
- stageParticipants,
50961
- tournamentRecord,
50962
- drawProfiles,
50963
- category,
50964
- gender,
50965
- event
50966
- });
50967
- if (result.error) return result;
50968
- result = generateFlightDrawDefinitions({
50969
- matchUpStatusProfile,
50970
- completeAllMatchUps,
50971
- randomWinningSide,
50972
- tournamentRecord,
50973
- drawProfiles,
50974
- event
50975
- });
50976
- if (result.error) return result;
50977
- drawIds.push(...result.drawIds);
50978
- }
50979
- }
50980
- }
50981
-
50982
- return { ...SUCCESS,
50983
- drawIds
50984
- };
50985
- }
50986
-
50987
- const amendsGovernor = {
50988
- anonymizeTournamentRecord,
50989
- modifyTournamentRecord
50990
- };
50991
-
50992
- function generateSchedulingProfile({
50993
- schedulingProfile,
50994
- tournamentRecord
50995
- }) {
50996
- if (typeof schedulingProfile !== 'object') return {
50997
- error: INVALID_VALUES
50998
- };
50999
- const containedStructures = getContainedStructures({
51000
- tournamentRecord
51001
- }).containedStructures;
51002
- const {
51003
- matchUps
51004
- } = allTournamentMatchUps({
51005
- tournamentRecord
51006
- });
51007
- const {
51008
- tournamentId
51009
- } = tournamentRecord;
51010
- const scheduledRounds = [];
51011
-
51012
- for (const dateProfile of schedulingProfile) {
51013
- const {
51014
- scheduleDate,
51015
- venues = []
51016
- } = dateProfile;
51017
-
51018
- for (const venue of venues) {
51019
- const {
51020
- rounds,
51021
- venueId
51022
- } = venue;
51023
-
51024
- for (const round of rounds) {
51025
- const {
51026
- drawId,
51027
- winnerFinishingPositionRange,
51028
- roundSegment
51029
- } = round;
51030
- const targetMatchUps = matchUps.filter(matchUp => {
51031
- var _matchUp$finishingPos;
51032
-
51033
- const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
51034
- const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
51035
- const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
51036
- return target;
51037
- });
51038
- const targetMatchUp = targetMatchUps[0];
51039
-
51040
- if (targetMatchUp) {
51041
- const {
51042
- eventId,
51043
- roundNumber,
51044
- drawName,
51045
- structureName,
51046
- roundName
51047
- } = targetMatchUp;
51048
- let structureId = targetMatchUp.structureId;
51049
-
51050
- if (roundNumber && !winnerFinishingPositionRange) {
51051
- structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
51052
- }
51053
-
51054
- const roundToSchedule = {
51055
- tournamentId,
51056
- eventId,
51057
- drawId,
51058
- structureId,
51059
- roundNumber,
51060
- roundSegment
51061
- };
51062
- let result = addSchedulingProfileRound({
51063
- tournamentRecords: {
51064
- [tournamentId]: tournamentRecord
51065
- },
51066
- scheduleDate,
51067
- venueId,
51068
- round: roundToSchedule
51069
- });
51070
- if (result.error) return result;
51071
- scheduledRounds.push({
51072
- drawName,
51073
- structureName,
51074
- roundName,
51075
- ...roundToSchedule
51076
- });
51077
- }
51078
- }
51079
- }
51080
- }
51081
-
51082
- return {
51083
- scheduledRounds
51084
- };
51085
- }
51086
-
51087
50874
  function generateEventWithFlights({
51088
50875
  allUniqueParticipantIds,
51089
50876
  matchUpStatusProfile,
@@ -51094,6 +50881,7 @@ function generateEventWithFlights({
51094
50881
  ratingsParameters,
51095
50882
  tournamentRecord,
51096
50883
  eventProfile,
50884
+ eventIndex,
51097
50885
  uuids
51098
50886
  }) {
51099
50887
  let gender = eventProfile.gender;
@@ -51143,6 +50931,7 @@ function generateEventWithFlights({
51143
50931
  ratingsParameters,
51144
50932
  tournamentRecord,
51145
50933
  eventProfile,
50934
+ eventIndex,
51146
50935
  uuids
51147
50936
  }) : {}; // Create event object -------------------------------------------------------
51148
50937
 
@@ -51231,8 +51020,8 @@ function generateEventWithFlights({
51231
51020
 
51232
51021
  function generateEventWithDraw({
51233
51022
  allUniqueParticipantIds = [],
51023
+ participantsProfile = {},
51234
51024
  matchUpStatusProfile,
51235
- participantsProfile,
51236
51025
  completeAllMatchUps,
51237
51026
  autoEntryPositions,
51238
51027
  randomWinningSide,
@@ -51240,6 +51029,7 @@ function generateEventWithDraw({
51240
51029
  tournamentRecord,
51241
51030
  drawProfile,
51242
51031
  startDate,
51032
+ drawIndex,
51243
51033
  goesTo,
51244
51034
  uuids
51245
51035
  }) {
@@ -51308,34 +51098,20 @@ function generateEventWithDraw({
51308
51098
  individualParticipantsCount = teamSize * drawSize;
51309
51099
  }
51310
51100
 
51101
+ const idPrefix = participantsProfile !== null && participantsProfile !== void 0 && participantsProfile.idPrefix ? `D-${drawIndex}-${participantsProfile === null || participantsProfile === void 0 ? void 0 : participantsProfile.idPrefix}` : undefined;
51311
51102
  const participantType = eventType === DOUBLES ? PAIR$1 : INDIVIDUAL$1;
51312
- const {
51313
- valuesInstanceLimit,
51314
- nationalityCodesCount,
51315
- nationalityCodeType,
51316
- nationalityCodes,
51317
- addressProps,
51318
- personIds,
51319
- inContext
51320
- } = participantsProfile || {};
51321
51103
  const {
51322
51104
  participants: unique
51323
- } = generateParticipants({
51105
+ } = generateParticipants({ ...participantsProfile,
51324
51106
  scaledParticipantsCount: drawProfile.scaledParticipantsCount,
51325
51107
  participantsCount: individualParticipantsCount,
51326
51108
  consideredDate: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.startDate,
51327
51109
  sex: gender || (participantsProfile === null || participantsProfile === void 0 ? void 0 : participantsProfile.sex),
51328
51110
  rankingRange: drawProfile.rankingRange,
51329
51111
  uuids: drawProfile.uuids || uuids,
51330
- nationalityCodesCount,
51331
- nationalityCodeType,
51332
- valuesInstanceLimit,
51333
51112
  ratingsParameters,
51334
- nationalityCodes,
51335
51113
  participantType,
51336
- addressProps,
51337
- personIds,
51338
- inContext,
51114
+ idPrefix,
51339
51115
  category
51340
51116
  });
51341
51117
 
@@ -51648,6 +51424,340 @@ function generateVenues({
51648
51424
  return venueIds;
51649
51425
  }
51650
51426
 
51427
+ function modifyTournamentRecord({
51428
+ ratingsParameters: ratingsParameters$1 = ratingsParameters,
51429
+ participantsProfile = {},
51430
+ matchUpStatusProfile,
51431
+ completeAllMatchUps,
51432
+ autoEntryPositions,
51433
+ randomWinningSide,
51434
+ schedulingProfile,
51435
+ tournamentRecord,
51436
+ eventProfiles,
51437
+ venueProfiles,
51438
+ autoSchedule,
51439
+ drawProfiles,
51440
+ goesTo,
51441
+ uuids
51442
+ }) {
51443
+ var _tournamentRecord$par;
51444
+
51445
+ if (!tournamentRecord) return {
51446
+ error: MISSING_TOURNAMENT_RECORD
51447
+ };
51448
+ const allUniqueParticipantIds = [];
51449
+ const eventIds = [];
51450
+ const drawIds = [];
51451
+ eventProfiles === null || eventProfiles === void 0 ? void 0 : eventProfiles.forEach(eventProfile => {
51452
+ const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
51453
+
51454
+ if (event !== null && event !== void 0 && event.gender) {
51455
+ eventProfile.gender = event.gender;
51456
+ }
51457
+ });
51458
+ const participantsCount = ((_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.length) || undefined;
51459
+ if (participantsCount && participantsProfile !== null && participantsProfile !== void 0 && participantsProfile.idPrefix) participantsProfile.idPrefix = `${participantsProfile.idPrefix}-${participantsCount}`;
51460
+ const result = addTournamentParticipants({
51461
+ startDate: tournamentRecord.startDate,
51462
+ participantsProfile,
51463
+ tournamentRecord,
51464
+ eventProfiles,
51465
+ drawProfiles,
51466
+ uuids
51467
+ });
51468
+ if (!result.success) return result;
51469
+
51470
+ if (eventProfiles) {
51471
+ var _tournamentRecord$eve;
51472
+
51473
+ let eventIndex = ((_tournamentRecord$eve = tournamentRecord.events) === null || _tournamentRecord$eve === void 0 ? void 0 : _tournamentRecord$eve.length) || 0;
51474
+
51475
+ for (const eventProfile of eventProfiles) {
51476
+ let {
51477
+ ratingsParameters
51478
+ } = eventProfile;
51479
+ const event = tournamentRecord.events.find((event, index) => eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex || eventProfile.eventName && event.eventName === eventProfile.eventName || eventProfile.eventId && event.eventId === eventProfile.eventId);
51480
+
51481
+ if (!event) {
51482
+ const {
51483
+ error,
51484
+ eventId,
51485
+ drawIds: generatedDrawIds,
51486
+ uniqueParticipantIds
51487
+ } = generateEventWithFlights({
51488
+ startDate: tournamentRecord.startDate,
51489
+ allUniqueParticipantIds,
51490
+ matchUpStatusProfile,
51491
+ participantsProfile,
51492
+ completeAllMatchUps,
51493
+ autoEntryPositions,
51494
+ randomWinningSide,
51495
+ ratingsParameters,
51496
+ tournamentRecord,
51497
+ eventProfile,
51498
+ eventIndex,
51499
+ uuids
51500
+ });
51501
+ if (error) return {
51502
+ error
51503
+ };
51504
+ if (generatedDrawIds) drawIds.push(...generatedDrawIds);
51505
+ eventIds.push(eventId);
51506
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51507
+ eventIndex += 1;
51508
+ } else {
51509
+ const {
51510
+ gender,
51511
+ category,
51512
+ eventType
51513
+ } = event;
51514
+ const {
51515
+ drawProfiles
51516
+ } = eventProfile;
51517
+ const eventParticipantType = eventType === SINGLES ? INDIVIDUAL : eventType === DOUBLES ? PAIR : eventType;
51518
+
51519
+ if (drawProfiles) {
51520
+ const {
51521
+ stageParticipantsCount,
51522
+ uniqueParticipantsCount,
51523
+ uniqueParticipantStages
51524
+ } = getStageParticipantsCount({
51525
+ drawProfiles,
51526
+ category,
51527
+ gender
51528
+ });
51529
+ const {
51530
+ uniqueDrawParticipants = [],
51531
+ uniqueParticipantIds = []
51532
+ } = uniqueParticipantStages ? generateEventParticipants({
51533
+ event: {
51534
+ eventType,
51535
+ category,
51536
+ gender
51537
+ },
51538
+ uniqueParticipantsCount,
51539
+ participantsProfile,
51540
+ ratingsParameters,
51541
+ tournamentRecord,
51542
+ eventProfile,
51543
+ uuids
51544
+ }) : {};
51545
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
51546
+ const {
51547
+ stageParticipants
51548
+ } = getStageParticipants({
51549
+ targetParticipants: tournamentRecord.participants || [],
51550
+ allUniqueParticipantIds,
51551
+ stageParticipantsCount,
51552
+ eventParticipantType
51553
+ });
51554
+ let result = generateFlights({
51555
+ uniqueDrawParticipants,
51556
+ autoEntryPositions,
51557
+ stageParticipants,
51558
+ tournamentRecord,
51559
+ drawProfiles,
51560
+ category,
51561
+ gender,
51562
+ event
51563
+ });
51564
+ if (result.error) return result;
51565
+ result = generateFlightDrawDefinitions({
51566
+ matchUpStatusProfile,
51567
+ completeAllMatchUps,
51568
+ randomWinningSide,
51569
+ tournamentRecord,
51570
+ drawProfiles,
51571
+ event
51572
+ });
51573
+ if (result.error) return result;
51574
+ drawIds.push(...result.drawIds);
51575
+ }
51576
+ }
51577
+ }
51578
+ }
51579
+
51580
+ if (drawProfiles) {
51581
+ let drawIndex = (tournamentRecord.events || []).map(event => {
51582
+ var _event$drawDefinition;
51583
+
51584
+ return ((_event$drawDefinition = event.drawDefinitions) === null || _event$drawDefinition === void 0 ? void 0 : _event$drawDefinition.map(() => 1)) || [];
51585
+ }).flat().reduce((a, b) => a + b, 0);
51586
+
51587
+ for (const drawProfile of drawProfiles) {
51588
+ const {
51589
+ drawId,
51590
+ eventId,
51591
+ event,
51592
+ error,
51593
+ uniqueParticipantIds
51594
+ } = generateEventWithDraw({
51595
+ startDate: tournamentRecord.startDate,
51596
+ allUniqueParticipantIds,
51597
+ matchUpStatusProfile,
51598
+ participantsProfile,
51599
+ completeAllMatchUps,
51600
+ autoEntryPositions,
51601
+ randomWinningSide,
51602
+ ratingsParameters: ratingsParameters$1,
51603
+ tournamentRecord,
51604
+ drawProfile,
51605
+ drawIndex,
51606
+ goesTo,
51607
+ uuids
51608
+ });
51609
+ if (error) return {
51610
+ error
51611
+ };
51612
+ const result = addEvent({
51613
+ tournamentRecord,
51614
+ event
51615
+ });
51616
+ if (result.error) return result;
51617
+ if (drawId) drawIds.push(drawId);
51618
+ eventIds.push(eventId);
51619
+ if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51620
+ drawIndex += 1;
51621
+ }
51622
+ }
51623
+
51624
+ const venueIds = venueProfiles !== null && venueProfiles !== void 0 && venueProfiles.length ? generateVenues({
51625
+ tournamentRecord,
51626
+ venueProfiles
51627
+ }) : [];
51628
+ let scheduledRounds;
51629
+ let schedulerResult = {};
51630
+
51631
+ if (schedulingProfile) {
51632
+ const result = generateScheduleTimes({
51633
+ schedulingProfile,
51634
+ tournamentRecord
51635
+ });
51636
+ if (result.error) return result;
51637
+ scheduledRounds = result.scheduledRounds;
51638
+
51639
+ if (autoSchedule) {
51640
+ const {
51641
+ tournamentId
51642
+ } = tournamentRecord;
51643
+ const tournamentRecords = {
51644
+ [tournamentId]: tournamentRecord
51645
+ };
51646
+ schedulerResult = scheduleProfileRounds({
51647
+ tournamentRecords
51648
+ });
51649
+ }
51650
+ }
51651
+
51652
+ return { ...SUCCESS,
51653
+ drawIds,
51654
+ eventIds,
51655
+ venueIds,
51656
+ scheduledRounds,
51657
+ schedulerResult
51658
+ };
51659
+ }
51660
+
51661
+ const amendsGovernor = {
51662
+ anonymizeTournamentRecord,
51663
+ modifyTournamentRecord
51664
+ };
51665
+
51666
+ function generateSchedulingProfile({
51667
+ schedulingProfile,
51668
+ tournamentRecord
51669
+ }) {
51670
+ if (typeof schedulingProfile !== 'object') return {
51671
+ error: INVALID_VALUES
51672
+ };
51673
+ const containedStructures = getContainedStructures({
51674
+ tournamentRecord
51675
+ }).containedStructures;
51676
+ const {
51677
+ matchUps
51678
+ } = allTournamentMatchUps({
51679
+ tournamentRecord
51680
+ });
51681
+ const {
51682
+ tournamentId
51683
+ } = tournamentRecord;
51684
+ const scheduledRounds = [];
51685
+
51686
+ for (const dateProfile of schedulingProfile) {
51687
+ const {
51688
+ scheduleDate,
51689
+ venues = []
51690
+ } = dateProfile;
51691
+
51692
+ for (const venue of venues) {
51693
+ const {
51694
+ rounds,
51695
+ venueId
51696
+ } = venue;
51697
+
51698
+ for (const round of rounds) {
51699
+ const {
51700
+ drawId,
51701
+ winnerFinishingPositionRange,
51702
+ roundSegment
51703
+ } = round;
51704
+ const targetMatchUps = matchUps.filter(matchUp => {
51705
+ var _matchUp$finishingPos;
51706
+
51707
+ const targetRange = (winnerFinishingPositionRange === null || winnerFinishingPositionRange === void 0 ? void 0 : winnerFinishingPositionRange.indexOf('-')) > 0 && winnerFinishingPositionRange.split('-').map(x => +x);
51708
+ const range = (_matchUp$finishingPos = matchUp.finishingPositionRange) === null || _matchUp$finishingPos === void 0 ? void 0 : _matchUp$finishingPos.winner;
51709
+ const target = matchUp.drawId === drawId && (!round.roundNumber || matchUp.roundNumber === round.roundNumber) && (!range || !targetRange || intersection(range, targetRange).length === 2);
51710
+ return target;
51711
+ });
51712
+ const targetMatchUp = targetMatchUps[0];
51713
+
51714
+ if (targetMatchUp) {
51715
+ const {
51716
+ eventId,
51717
+ roundNumber,
51718
+ drawName,
51719
+ structureName,
51720
+ roundName
51721
+ } = targetMatchUp;
51722
+ let structureId = targetMatchUp.structureId;
51723
+
51724
+ if (roundNumber && !winnerFinishingPositionRange) {
51725
+ structureId = Object.keys(containedStructures).find(containingStructureId => containedStructures[containingStructureId].includes(structureId));
51726
+ }
51727
+
51728
+ const roundToSchedule = {
51729
+ tournamentId,
51730
+ eventId,
51731
+ drawId,
51732
+ structureId,
51733
+ roundNumber,
51734
+ roundSegment
51735
+ };
51736
+ let result = addSchedulingProfileRound({
51737
+ tournamentRecords: {
51738
+ [tournamentId]: tournamentRecord
51739
+ },
51740
+ scheduleDate,
51741
+ venueId,
51742
+ round: roundToSchedule
51743
+ });
51744
+ if (result.error) return result;
51745
+ scheduledRounds.push({
51746
+ drawName,
51747
+ structureName,
51748
+ roundName,
51749
+ ...roundToSchedule
51750
+ });
51751
+ }
51752
+ }
51753
+ }
51754
+ }
51755
+
51756
+ return {
51757
+ scheduledRounds
51758
+ };
51759
+ }
51760
+
51651
51761
  /**
51652
51762
  *
51653
51763
  * Generate a complete tournamentRecord from the following attributes
@@ -51748,6 +51858,8 @@ function generateTournamentRecord({
51748
51858
  allUniqueParticipantIds = [];
51749
51859
 
51750
51860
  if (drawProfiles) {
51861
+ let drawIndex = 0;
51862
+
51751
51863
  for (const drawProfile of drawProfiles) {
51752
51864
  const {
51753
51865
  drawId,
@@ -51766,6 +51878,7 @@ function generateTournamentRecord({
51766
51878
  tournamentRecord,
51767
51879
  drawProfile,
51768
51880
  startDate,
51881
+ drawIndex,
51769
51882
  goesTo,
51770
51883
  uuids
51771
51884
  });
@@ -51780,10 +51893,13 @@ function generateTournamentRecord({
51780
51893
  if (drawId) drawIds.push(drawId);
51781
51894
  eventIds.push(eventId);
51782
51895
  if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51896
+ drawIndex += 1;
51783
51897
  }
51784
51898
  }
51785
51899
 
51786
51900
  if (eventProfiles) {
51901
+ let eventIndex = 0;
51902
+
51787
51903
  for (const eventProfile of eventProfiles) {
51788
51904
  const {
51789
51905
  error,
@@ -51800,6 +51916,7 @@ function generateTournamentRecord({
51800
51916
  ratingsParameters: ratingsParameters$1,
51801
51917
  tournamentRecord,
51802
51918
  eventProfile,
51919
+ eventIndex,
51803
51920
  startDate,
51804
51921
  uuids
51805
51922
  });
@@ -51809,6 +51926,7 @@ function generateTournamentRecord({
51809
51926
  if (generatedDrawIds) drawIds.push(...generatedDrawIds);
51810
51927
  eventIds.push(eventId);
51811
51928
  if (uniqueParticipantIds !== null && uniqueParticipantIds !== void 0 && uniqueParticipantIds.length) allUniqueParticipantIds.push(...uniqueParticipantIds);
51929
+ eventIndex += 1;
51812
51930
  }
51813
51931
  }
51814
51932
 
@@ -52064,4 +52182,5 @@ exports.tournamentEngine = tournamentEngine;
52064
52182
  exports.tournamentEngineAsync = tournamentEngineAsync;
52065
52183
  exports.utilities = utilities;
52066
52184
  exports.venueConstants = venueConstants;
52185
+ exports.version = factoryVersion;
52067
52186
  //# sourceMappingURL=tods-competition-factory.development.cjs.js.map