tods-competition-factory 1.8.12 → 1.8.14

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 CHANGED
@@ -87,6 +87,10 @@ function tiebreakFormat(tieobject) {
87
87
  return void 0;
88
88
  }
89
89
 
90
+ function numericSort(a, b) {
91
+ return a - b;
92
+ }
93
+
90
94
  function ensureInt(val) {
91
95
  if (typeof val === "number")
92
96
  return parseInt(val.toString());
@@ -98,6 +102,13 @@ function isPowerOf2(n) {
98
102
  return false;
99
103
  return n && (n & n - 1) === 0;
100
104
  }
105
+ function median(arr) {
106
+ if (!arr.length)
107
+ return void 0;
108
+ const s = [...arr].sort(numericSort);
109
+ const mid = Math.floor(s.length / 2);
110
+ return s.length % 2 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
111
+ }
101
112
  function deriveExponent(n) {
102
113
  if (!isPowerOf2(n))
103
114
  return false;
@@ -2063,10 +2074,6 @@ function generateTimeCode(index = 0) {
2063
2074
  return uidate.getTime().toString(36).slice(-6).toUpperCase();
2064
2075
  }
2065
2076
 
2066
- function numericSort(a, b) {
2067
- return a - b;
2068
- }
2069
-
2070
2077
  function JSON2CSV(arrayOfJSON, config) {
2071
2078
  if (config && typeof config !== "object")
2072
2079
  return INVALID_VALUES;
@@ -2375,7 +2382,7 @@ const matchUpFormatCode = {
2375
2382
  };
2376
2383
 
2377
2384
  function factoryVersion() {
2378
- return "1.8.12";
2385
+ return "1.8.14";
2379
2386
  }
2380
2387
 
2381
2388
  function getObjectTieFormat(obj) {
@@ -5023,36 +5030,6 @@ function getFlightProfile({ event, eventId }) {
5023
5030
  return { flightProfile };
5024
5031
  }
5025
5032
 
5026
- function getEvent({ tournamentRecord, drawDefinition, event, context }) {
5027
- if (!tournamentRecord)
5028
- return { error: MISSING_TOURNAMENT_RECORD };
5029
- if (!event)
5030
- return { error: MISSING_EVENT };
5031
- const eventCopy = makeDeepCopy(event);
5032
- if (context)
5033
- Object.assign(eventCopy, context);
5034
- const drawDefinitionCopy = drawDefinition && eventCopy.drawDefinitions?.find(
5035
- ({ drawId }) => drawDefinition.drawId === drawId
5036
- );
5037
- return definedAttributes({
5038
- event: eventCopy,
5039
- drawDefinition: drawDefinitionCopy
5040
- });
5041
- }
5042
- function getEvents({ tournamentRecord, context, inContext }) {
5043
- if (!tournamentRecord)
5044
- return { error: MISSING_TOURNAMENT_RECORD };
5045
- const { tournamentId } = tournamentRecord;
5046
- const eventCopies = (tournamentRecord.events || []).map((event) => {
5047
- const eventCopy = makeDeepCopy(event);
5048
- if (context)
5049
- Object.assign(eventCopy, context);
5050
- if (inContext)
5051
- Object.assign(eventCopy, { tournamentId });
5052
- return eventCopy;
5053
- });
5054
- return { events: eventCopies };
5055
- }
5056
5033
  function findEvent({
5057
5034
  tournamentRecord,
5058
5035
  eventId,
@@ -5111,26 +5088,6 @@ function findEvent({
5111
5088
  })
5112
5089
  };
5113
5090
  }
5114
- function getDrawDefinition$2({ tournamentRecord, drawId }) {
5115
- if (!tournamentRecord)
5116
- return { error: MISSING_TOURNAMENT_RECORD };
5117
- if (!drawId) {
5118
- return { error: MISSING_DRAW_ID };
5119
- }
5120
- const target = (tournamentRecord.events || []).reduce((target2, event) => {
5121
- const candidate = (event.drawDefinitions || []).reduce(
5122
- (drawDefinition, candidate2) => {
5123
- return candidate2.drawId === drawId ? candidate2 : drawDefinition;
5124
- },
5125
- void 0
5126
- );
5127
- return candidate && candidate.drawId === drawId ? { event, drawDefinition: candidate } : target2;
5128
- }, void 0);
5129
- return target ? { ...target, SUCCESS } : decorateResult({
5130
- result: { error: DRAW_DEFINITION_NOT_FOUND },
5131
- stack: "getDrawDefinition"
5132
- });
5133
- }
5134
5091
 
5135
5092
  function addExtension$1(params) {
5136
5093
  if (typeof params !== "object")
@@ -16664,7 +16621,7 @@ function getMatchUpDependencies(params) {
16664
16621
  const allTournamentRecords = Object.values(tournamentRecords);
16665
16622
  const allLinks = allTournamentRecords.reduce(
16666
16623
  (allLinks2, tournamentRecord2) => {
16667
- return allLinks2.concat(tournamentRecord2.events || []).map(
16624
+ return allLinks2.concat(tournamentRecord2.events ?? []).map(
16668
16625
  (event) => (event.drawDefinitions || []).map(
16669
16626
  (drawDefinition2) => drawDefinition2.links || []
16670
16627
  )
@@ -16696,7 +16653,7 @@ function getMatchUpDependencies(params) {
16696
16653
  for (const sourceStructureId of sourceStructureIds) {
16697
16654
  positionDependencies[sourceStructureId] = [];
16698
16655
  }
16699
- for (const matchUp of matchUps || []) {
16656
+ for (const matchUp of matchUps ?? []) {
16700
16657
  const sourceStructureId = matchUp.containerStructureId || matchUp.structureId;
16701
16658
  if (sourceStructureIds.includes(sourceStructureId)) {
16702
16659
  positionDependencies[sourceStructureId].push(matchUp.matchUpId);
@@ -17287,6 +17244,26 @@ function removeExtraneousAttributes(matchUps, matchUpFormatMap = {}) {
17287
17244
  }
17288
17245
  }
17289
17246
 
17247
+ function getAssignedParticipantIds({
17248
+ drawDefinition,
17249
+ stages
17250
+ }) {
17251
+ if (!drawDefinition)
17252
+ return { error: MISSING_DRAW_DEFINITION };
17253
+ const stageStructures = (drawDefinition?.structures || []).filter(
17254
+ (structure) => !stages?.length || structure.stage && stages.includes(structure.stage)
17255
+ );
17256
+ const assignedParticipantIds = unique(
17257
+ stageStructures.map((structure) => {
17258
+ const { positionAssignments } = getPositionAssignments$1({
17259
+ structure
17260
+ });
17261
+ return positionAssignments ? positionAssignments.map(extractAttributes("participantId")) : [];
17262
+ }).flat().filter(Boolean)
17263
+ );
17264
+ return { ...SUCCESS, assignedParticipantIds };
17265
+ }
17266
+
17290
17267
  function participantScaleItem({
17291
17268
  requireTimeStamp,
17292
17269
  scaleAttributes,
@@ -20471,6 +20448,77 @@ function addMatchUpResumeTime$2({
20471
20448
  }
20472
20449
  }
20473
20450
 
20451
+ function getEventIdsAndDrawIds({
20452
+ tournamentRecords
20453
+ }) {
20454
+ if (!tournamentRecords)
20455
+ return { error: MISSING_TOURNAMENT_RECORDS };
20456
+ const tournamentIds = Object.keys(tournamentRecords);
20457
+ return tournamentIds.reduce(
20458
+ (aggregator, tournamentId) => {
20459
+ aggregator.tournamentIdMap[tournamentId] = [];
20460
+ const tournamentRecord = tournamentRecords[tournamentId];
20461
+ const events = tournamentRecord.events || [];
20462
+ const eventIds = events.map(({ eventId }) => eventId);
20463
+ const drawIds = events.map(
20464
+ (event) => (event.drawDefinitions || []).map(({ drawId }) => drawId)
20465
+ ).flat();
20466
+ aggregator.tournamentIdMap[tournamentId].push(...eventIds, ...drawIds);
20467
+ aggregator.eventIds.push(...eventIds);
20468
+ aggregator.drawIds.push(...drawIds);
20469
+ return aggregator;
20470
+ },
20471
+ { eventIds: [], drawIds: [], tournamentIdMap: {} }
20472
+ );
20473
+ }
20474
+
20475
+ function findTournamentId({
20476
+ tournamentRecords,
20477
+ eventId,
20478
+ drawId
20479
+ }) {
20480
+ const { tournamentIdMap } = getEventIdsAndDrawIds({ tournamentRecords });
20481
+ const tournamentIds = tournamentIdMap ? Object.keys(tournamentIdMap) : [];
20482
+ return tournamentIds.find(
20483
+ (tournamentId) => eventId && tournamentIdMap?.[tournamentId].includes(eventId) || drawId && tournamentIdMap?.[tournamentId].includes(drawId)
20484
+ );
20485
+ }
20486
+
20487
+ function getDrawDefinition$1({
20488
+ tournamentRecords,
20489
+ tournamentRecord,
20490
+ tournamentId,
20491
+ drawId
20492
+ }) {
20493
+ if (!tournamentRecord && !tournamentRecords)
20494
+ return { error: MISSING_TOURNAMENT_RECORD };
20495
+ if (!drawId)
20496
+ return { error: MISSING_DRAW_ID };
20497
+ if (!tournamentRecord && tournamentRecords) {
20498
+ if (typeof tournamentId !== "string") {
20499
+ tournamentId = findTournamentId({ tournamentRecords, drawId });
20500
+ if (!tournamentId)
20501
+ return { error: MISSING_TOURNAMENT_ID };
20502
+ }
20503
+ tournamentRecord = tournamentRecords[tournamentId];
20504
+ if (!tournamentRecord)
20505
+ return { error: MISSING_TOURNAMENT_RECORD };
20506
+ }
20507
+ const result = tournamentRecord && findEvent({ tournamentRecord, drawId });
20508
+ if (!result?.drawDefinition) {
20509
+ return decorateResult({
20510
+ result: { error: DRAW_DEFINITION_NOT_FOUND },
20511
+ stack: "getDrawDefinition"
20512
+ });
20513
+ }
20514
+ return {
20515
+ drawDefinition: result.drawDefinition,
20516
+ event: result.event,
20517
+ tournamentRecord,
20518
+ ...SUCCESS
20519
+ };
20520
+ }
20521
+
20474
20522
  function bulkScheduleMatchUps$1({
20475
20523
  errorOnAnachronism = false,
20476
20524
  checkChronology = true,
@@ -20498,7 +20546,7 @@ function bulkScheduleMatchUps$1({
20498
20546
  if (!inContextMatchUps) {
20499
20547
  inContextMatchUps = allTournamentMatchUps({
20500
20548
  tournamentRecord
20501
- })?.matchUps || [];
20549
+ })?.matchUps ?? [];
20502
20550
  }
20503
20551
  const drawIdMap = inContextMatchUps.reduce((drawIdMap2, matchUp) => {
20504
20552
  const { matchUpId, drawId } = matchUp;
@@ -20511,12 +20559,14 @@ function bulkScheduleMatchUps$1({
20511
20559
  }, {});
20512
20560
  const detailMatchUpIds = matchUpDetails?.map((detail) => detail.matchUpId);
20513
20561
  for (const drawId of Object.keys(drawIdMap)) {
20514
- const { drawDefinition } = getDrawDefinition$2({
20562
+ const { drawDefinition } = getDrawDefinition$1({
20515
20563
  tournamentRecord,
20516
20564
  drawId
20517
20565
  });
20566
+ if (!drawDefinition)
20567
+ continue;
20518
20568
  const drawMatchUpIds = drawIdMap[drawId].filter(
20519
- (matchUpId) => matchUpIds?.includes(matchUpId) || detailMatchUpIds?.includes(matchUpId)
20569
+ (matchUpId) => matchUpIds?.includes(matchUpId) ?? detailMatchUpIds?.includes(matchUpId)
20520
20570
  );
20521
20571
  const drawMatchUps = allDrawMatchUps$1({
20522
20572
  inContext: false,
@@ -20594,42 +20644,6 @@ function bulkScheduleMatchUps({
20594
20644
  return warnings.length ? { ...SUCCESS, scheduled, warnings } : { ...SUCCESS, scheduled };
20595
20645
  }
20596
20646
 
20597
- function getEventIdsAndDrawIds({
20598
- tournamentRecords
20599
- }) {
20600
- if (!tournamentRecords)
20601
- return { error: MISSING_TOURNAMENT_RECORDS };
20602
- const tournamentIds = Object.keys(tournamentRecords);
20603
- return tournamentIds.reduce(
20604
- (aggregator, tournamentId) => {
20605
- aggregator.tournamentIdMap[tournamentId] = [];
20606
- const tournamentRecord = tournamentRecords[tournamentId];
20607
- const events = tournamentRecord.events || [];
20608
- const eventIds = events.map(({ eventId }) => eventId);
20609
- const drawIds = events.map(
20610
- (event) => (event.drawDefinitions || []).map(({ drawId }) => drawId)
20611
- ).flat();
20612
- aggregator.tournamentIdMap[tournamentId].push(...eventIds, ...drawIds);
20613
- aggregator.eventIds.push(...eventIds);
20614
- aggregator.drawIds.push(...drawIds);
20615
- return aggregator;
20616
- },
20617
- { eventIds: [], drawIds: [], tournamentIdMap: {} }
20618
- );
20619
- }
20620
-
20621
- function findTournamentId({
20622
- tournamentRecords,
20623
- eventId,
20624
- drawId
20625
- }) {
20626
- const { tournamentIdMap } = getEventIdsAndDrawIds({ tournamentRecords });
20627
- const tournamentIds = tournamentIdMap ? Object.keys(tournamentIdMap) : [];
20628
- return tournamentIds.find(
20629
- (tournamentId) => eventId && tournamentIdMap?.[tournamentId].includes(eventId) || drawId && tournamentIdMap?.[tournamentId].includes(drawId)
20630
- );
20631
- }
20632
-
20633
20647
  function getProjectedDualWinningSide({
20634
20648
  drawDefinition,
20635
20649
  matchUpStatus,
@@ -32897,7 +32911,7 @@ function jinnScheduler({
32897
32911
  const tournamentRecord = tournamentRecords[tournamentId];
32898
32912
  if (tournamentRecord) {
32899
32913
  Object.keys(matchUpMap[tournamentId]).forEach((drawId) => {
32900
- const { drawDefinition } = getDrawDefinition$2({
32914
+ const { drawDefinition } = getDrawDefinition$1({
32901
32915
  tournamentRecord,
32902
32916
  drawId
32903
32917
  });
@@ -33341,7 +33355,7 @@ function proScheduler({
33341
33355
  const tournamentRecord = tournamentRecords[tournamentId];
33342
33356
  if (tournamentRecord) {
33343
33357
  Object.keys(matchUpMap[tournamentId]).forEach((drawId) => {
33344
- const { drawDefinition } = getDrawDefinition$2({
33358
+ const { drawDefinition } = getDrawDefinition$1({
33345
33359
  tournamentRecord,
33346
33360
  drawId
33347
33361
  });
@@ -33988,7 +34002,7 @@ function toggleParticipantCheckInState(params) {
33988
34002
  if (!tournamentRecords || !tournamentId || !participantId || !matchUpId)
33989
34003
  return { error: MISSING_VALUE, stack: "toggleParticipantCheckInState" };
33990
34004
  const tournamentRecord = tournamentRecords[tournamentId];
33991
- const { drawDefinition, event } = getDrawDefinition$2({
34005
+ const { drawDefinition, event } = getDrawDefinition$1({
33992
34006
  tournamentRecord,
33993
34007
  drawId
33994
34008
  });
@@ -34011,16 +34025,18 @@ function removeMatchUpCourtAssignment$1(params) {
34011
34025
  const tournamentRecord = tournamentRecords[tournamentId];
34012
34026
  if (!tournamentRecord)
34013
34027
  return { error: MISSING_TOURNAMENT_RECORD };
34014
- const { drawDefinition, event } = getDrawDefinition$2({
34028
+ const { drawDefinition, event } = getDrawDefinition$1({
34015
34029
  tournamentRecord,
34016
34030
  drawId
34017
34031
  });
34032
+ if (!drawDefinition)
34033
+ return { error: MISSING_DRAW_DEFINITION };
34018
34034
  const result = findMatchUp$1({ drawDefinition, event, matchUpId });
34019
34035
  if (result.error)
34020
34036
  return result;
34021
34037
  if (result?.matchUp?.matchUpType === TEAM_MATCHUP) {
34022
34038
  const { itemValue: allocatedCourts } = latestVisibleTimeItemValue({
34023
- timeItems: result.matchUp.timeItems || [],
34039
+ timeItems: result.matchUp.timeItems ?? [],
34024
34040
  itemType: ALLOCATE_COURTS
34025
34041
  });
34026
34042
  const itemValue = courtId && allocatedCourts.filter((court) => court.courtId !== courtId);
@@ -34282,7 +34298,7 @@ function scheduleMatchUps({
34282
34298
  ({ matchUpId }) => !overLimitMatchUpIds.includes(matchUpId)
34283
34299
  );
34284
34300
  let iterations = 0;
34285
- const failSafe = scheduleTimes?.length || 0;
34301
+ const failSafe = scheduleTimes?.length ?? 0;
34286
34302
  const { personRequests } = getPersonRequests({
34287
34303
  tournamentRecords,
34288
34304
  requestType: DO_NOT_SCHEDULE
@@ -34367,7 +34383,7 @@ function scheduleMatchUps({
34367
34383
  const tournamentRecord = tournamentRecords[tournamentId];
34368
34384
  if (tournamentRecord) {
34369
34385
  Object.keys(matchUpMap[tournamentId]).forEach((drawId) => {
34370
- const { drawDefinition } = getDrawDefinition$2({
34386
+ const { drawDefinition } = getDrawDefinition$1({
34371
34387
  tournamentRecord,
34372
34388
  drawId
34373
34389
  });
@@ -34404,9 +34420,6 @@ function scheduleMatchUps({
34404
34420
  });
34405
34421
  }
34406
34422
  });
34407
- } else {
34408
- if (getDevContext())
34409
- console.log(MISSING_TOURNAMENT_ID);
34410
34423
  }
34411
34424
  });
34412
34425
  const noTimeMatchUpIds = getMatchUpIds(matchUpsToSchedule);
@@ -34472,10 +34485,12 @@ function reorderUpcomingMatchUps(params) {
34472
34485
  drawId
34473
34486
  }) {
34474
34487
  const tournamentRecord = tournamentRecords[tournamentId];
34475
- const { drawDefinition } = getDrawDefinition$2({
34488
+ const { drawDefinition } = getDrawDefinition$1({
34476
34489
  tournamentRecord,
34477
34490
  drawId
34478
34491
  });
34492
+ if (!drawDefinition)
34493
+ return { error: DRAW_DEFINITION_NOT_FOUND };
34479
34494
  return addMatchUpScheduledTime$2({
34480
34495
  drawDefinition,
34481
34496
  scheduledTime,
@@ -34826,7 +34841,7 @@ function bulkRescheduleMatchUps$1({
34826
34841
  );
34827
34842
  const dayTotalMinutes = 1440;
34828
34843
  for (const drawId of Object.keys(drawIdMap)) {
34829
- const result = getDrawDefinition$2({
34844
+ const result = getDrawDefinition$1({
34830
34845
  tournamentRecord,
34831
34846
  drawId
34832
34847
  });
@@ -34898,7 +34913,7 @@ function bulkRescheduleMatchUps$1({
34898
34913
  const updatedInContext = allTournamentMatchUps({
34899
34914
  matchUpFilters: { matchUpIds },
34900
34915
  tournamentRecord
34901
- }).matchUps || [];
34916
+ }).matchUps ?? [];
34902
34917
  const rescheduled = updatedInContext.filter(
34903
34918
  ({ matchUpId }) => rescheduledMatchUpIds.includes(matchUpId)
34904
34919
  );
@@ -35193,7 +35208,7 @@ function matchUpScheduleChange(params) {
35193
35208
  function assignMatchUp(params2) {
35194
35209
  const { tournamentRecords: tournamentRecords2, tournamentId, matchUp, drawId } = params2;
35195
35210
  const tournamentRecord = tournamentRecords2[tournamentId];
35196
- const { drawDefinition } = getDrawDefinition$2({
35211
+ const { drawDefinition } = getDrawDefinition$1({
35197
35212
  tournamentRecord,
35198
35213
  drawId
35199
35214
  });
@@ -35647,31 +35662,6 @@ function addMatchUpCourtOrder(params) {
35647
35662
  matchUpId
35648
35663
  });
35649
35664
  }
35650
- function getDrawDefinition$1({
35651
- tournamentRecords,
35652
- tournamentId,
35653
- drawId
35654
- }) {
35655
- if (!tournamentRecords)
35656
- return { error: MISSING_TOURNAMENT_RECORDS };
35657
- if (!drawId)
35658
- return { error: MISSING_DRAW_ID };
35659
- if (typeof tournamentId !== "string") {
35660
- tournamentId = findTournamentId({ tournamentRecords, drawId });
35661
- if (!tournamentId)
35662
- return { error: MISSING_TOURNAMENT_ID };
35663
- }
35664
- const tournamentRecord = tournamentRecords[tournamentId];
35665
- if (!tournamentRecord)
35666
- return { error: MISSING_TOURNAMENT_RECORD };
35667
- const result = findEvent({ tournamentRecord, drawId });
35668
- if (result.error)
35669
- return decorateResult({
35670
- stack: "addScheduleItems.getDrawDefinition",
35671
- result
35672
- });
35673
- return { drawDefinition: result.drawDefinition, tournamentRecord };
35674
- }
35675
35665
 
35676
35666
  const scheduleGovernor$1 = {
35677
35667
  scheduleMatchUps,
@@ -36952,7 +36942,7 @@ function removeCourtAssignment({
36952
36942
  } else {
36953
36943
  if (!tournamentRecord)
36954
36944
  return { error: MISSING_TOURNAMENT_RECORD };
36955
- const matchUps = allTournamentMatchUps({ tournamentRecord, inContext: false }).matchUps || [];
36945
+ const matchUps = allTournamentMatchUps({ tournamentRecord, inContext: false }).matchUps ?? [];
36956
36946
  ({ matchUp } = getMatchUp$1({ matchUps, matchUpId }));
36957
36947
  }
36958
36948
  if (!matchUp)
@@ -41088,8 +41078,8 @@ function organizeDrawPositionOptions({
41088
41078
  }
41089
41079
 
41090
41080
  function getUnplacedParticipantIds({
41091
- participantIds,
41092
- positionAssignments
41081
+ positionAssignments,
41082
+ participantIds
41093
41083
  }) {
41094
41084
  const assignedParticipantIds = positionAssignments.map(
41095
41085
  (assignment) => assignment.participantId
@@ -44728,21 +44718,6 @@ function setPositionAssignments$1({
44728
44718
  return { ...SUCCESS };
44729
44719
  }
44730
44720
 
44731
- function getAssignedParticipantIds({
44732
- drawDefinition,
44733
- stages
44734
- }) {
44735
- const stageStructures = (drawDefinition?.structures || []).filter(
44736
- (structure) => !stages?.length || structure.stage && stages.includes(structure.stage)
44737
- );
44738
- return stageStructures.map((structure) => {
44739
- const { positionAssignments } = getPositionAssignments$1({
44740
- structure
44741
- });
44742
- return positionAssignments ? positionAssignments.map(extractAttributes("participantId")) : [];
44743
- }).flat();
44744
- }
44745
-
44746
44721
  function refreshEntryPositions(params) {
44747
44722
  const stagedEntries = (params?.entries ?? []).filter(Boolean).reduce((stages, entry) => {
44748
44723
  const { entryStage, entryStatus } = entry;
@@ -44815,7 +44790,7 @@ function modifyEntriesStatus({
44815
44790
  const participantIds2 = getAssignedParticipantIds({
44816
44791
  stages: stage && [stage],
44817
44792
  drawDefinition: drawDefinition2
44818
- });
44793
+ }).assignedParticipantIds ?? [];
44819
44794
  assignedParticipantIds.push(...participantIds2);
44820
44795
  });
44821
44796
  const tournamentParticipants = tournamentRecord?.participants || [];
@@ -45288,7 +45263,7 @@ function removeEventEntries({
45288
45263
  return decorateResult({ result: { error: INVALID_PARTICIPANT_ID }, stack });
45289
45264
  }
45290
45265
  const assignedParticipantIds = (event.drawDefinitions ?? []).flatMap(
45291
- (drawDefinition) => getAssignedParticipantIds({ drawDefinition })
45266
+ (drawDefinition) => getAssignedParticipantIds({ drawDefinition }).assignedParticipantIds ?? []
45292
45267
  );
45293
45268
  const statusParticipantIds = (entryStatuses?.length && event.entries?.filter(
45294
45269
  (entry) => entry.entryStatus && entryStatuses.includes(entry.entryStatus)
@@ -48108,7 +48083,7 @@ function positionActions$1(params) {
48108
48083
  const stageAssignedParticipantIds = getAssignedParticipantIds({
48109
48084
  drawDefinition,
48110
48085
  stages
48111
- });
48086
+ }).assignedParticipantIds ?? [];
48112
48087
  const unassignedParticipantIds = stageEntries.filter(
48113
48088
  (entry) => !stageAssignedParticipantIds.includes(entry.participantId)
48114
48089
  ).map((entry) => entry.participantId);
@@ -48448,7 +48423,7 @@ function removeEntry({
48448
48423
  const assignedParticipantIds = getAssignedParticipantIds({
48449
48424
  drawDefinition,
48450
48425
  stages
48451
- });
48426
+ }).assignedParticipantIds ?? [];
48452
48427
  const isAssignedParticipant = assignedParticipantIds.includes(participantId);
48453
48428
  if (isAssignedParticipant)
48454
48429
  return { error: EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT };
@@ -48467,6 +48442,7 @@ function removeEntry({
48467
48442
  }
48468
48443
 
48469
48444
  const entryGovernor = {
48445
+ getAssignedParticipantIds,
48470
48446
  setStageAlternatesCount,
48471
48447
  setStageWildcardsCount,
48472
48448
  setStageQualifiersCount,
@@ -51831,8 +51807,8 @@ function setParticipantScaleItem(params) {
51831
51807
  return equivalentValue && {
51832
51808
  ...SUCCESS,
51833
51809
  info: VALUE_UNCHANGED,
51834
- existingValue: scaleItem.scaleValue
51835
- } || participant && { ...SUCCESS, newValue: scaleItem.scaleValue } || {
51810
+ existingValue: scaleItem?.scaleValue
51811
+ } || participant && { ...SUCCESS, newValue: scaleItem?.scaleValue } || {
51836
51812
  error: PARTICIPANT_NOT_FOUND
51837
51813
  };
51838
51814
  }
@@ -55587,7 +55563,7 @@ function deleteDrawDefinitions({
55587
55563
  action: DELETE_DRAW_DEFINITIONS,
55588
55564
  payload: {
55589
55565
  drawDefinitions: [drawDefinition],
55590
- eventId: eventId || event?.eventId,
55566
+ eventId: eventId ?? event?.eventId,
55591
55567
  auditData
55592
55568
  }
55593
55569
  };
@@ -55595,7 +55571,7 @@ function deleteDrawDefinitions({
55595
55571
  deletedDrawsDetail.push(
55596
55572
  definedAttributes({
55597
55573
  tournamentId: tournamentRecord.tournamentId,
55598
- eventId: eventId || event?.eventId,
55574
+ eventId: eventId ?? event?.eventId,
55599
55575
  qualifyingPositionAssignments,
55600
55576
  positionAssignments,
55601
55577
  auditData,
@@ -56708,7 +56684,7 @@ function removeDrawEntries({
56708
56684
  const assignedParticipantIds = getAssignedParticipantIds({
56709
56685
  drawDefinition,
56710
56686
  stages
56711
- });
56687
+ }).assignedParticipantIds ?? [];
56712
56688
  const someAssignedParticipantIds = overlap(
56713
56689
  assignedParticipantIds,
56714
56690
  participantIds
@@ -59290,6 +59266,7 @@ const eventGovernor = {
59290
59266
  getAvailablePlayoffRounds: getAvailablePlayoffProfiles,
59291
59267
  // to be deprecated
59292
59268
  getAvailablePlayoffProfiles,
59269
+ getAssignedParticipantIds,
59293
59270
  deleteDrawDefinitions,
59294
59271
  addPlayoffStructures,
59295
59272
  modifyDrawDefinition,
@@ -59763,6 +59740,182 @@ function getMatchUpsStats({ profileBands, tournamentRecord, matchUps }) {
59763
59740
  };
59764
59741
  }
59765
59742
 
59743
+ function getEvent({
59744
+ tournamentRecord,
59745
+ drawDefinition,
59746
+ context,
59747
+ event
59748
+ }) {
59749
+ if (!tournamentRecord)
59750
+ return { error: MISSING_TOURNAMENT_RECORD };
59751
+ if (!event)
59752
+ return { error: MISSING_EVENT };
59753
+ const eventCopy = makeDeepCopy(event);
59754
+ if (context)
59755
+ Object.assign(eventCopy, context);
59756
+ const drawDefinitionCopy = drawDefinition && eventCopy.drawDefinitions?.find(
59757
+ ({ drawId }) => drawDefinition.drawId === drawId
59758
+ );
59759
+ return definedAttributes({
59760
+ drawDefinition: drawDefinitionCopy,
59761
+ event: eventCopy
59762
+ });
59763
+ }
59764
+ function getEvents({
59765
+ tournamentRecord,
59766
+ withScaleValues,
59767
+ scaleEventType,
59768
+ inContext,
59769
+ eventIds,
59770
+ drawIds,
59771
+ context
59772
+ }) {
59773
+ if (!tournamentRecord)
59774
+ return { error: MISSING_TOURNAMENT_RECORD };
59775
+ const { tournamentId } = tournamentRecord;
59776
+ const eventCopies = (tournamentRecord.events ?? []).filter(
59777
+ ({ eventId }) => !eventIds || Array.isArray(eventIds) && eventIds.includes(eventId)
59778
+ ).map((event) => {
59779
+ const eventCopy = makeDeepCopy(event);
59780
+ if (inContext)
59781
+ Object.assign(eventCopy, { tournamentId });
59782
+ if (context)
59783
+ Object.assign(eventCopy, context);
59784
+ return eventCopy;
59785
+ });
59786
+ const eventsMap = {};
59787
+ if (withScaleValues) {
59788
+ const participantMap = getParticipants$1({
59789
+ withScaleValues: true,
59790
+ tournamentRecord
59791
+ }).participantMap;
59792
+ const sum = (values) => values.reduce((total, value) => total + parseFloat(value), 0);
59793
+ for (const event of eventCopies) {
59794
+ const eventType = scaleEventType ?? event.eventType;
59795
+ const eventId = event.eventId;
59796
+ if (!eventsMap[eventId])
59797
+ eventsMap[eventId] = {
59798
+ ratingsStats: {},
59799
+ ratings: {},
59800
+ ranking: {},
59801
+ draws: {}
59802
+ };
59803
+ const selectedEntries = (event.entries ?? []).filter(
59804
+ ({ entryStatus }) => STRUCTURE_SELECTED_STATUSES.includes(entryStatus)
59805
+ );
59806
+ const participantIds = selectedEntries.map(extractAttributes("participantId"));
59807
+ const processParticipant = (participant) => {
59808
+ if (participant?.ratings?.[eventType]) {
59809
+ for (const rating of participant?.ratings?.[eventType] ?? []) {
59810
+ const scaleName = rating.scaleName;
59811
+ if (!eventsMap[eventId].ratings[scaleName])
59812
+ eventsMap[eventId].ratings[scaleName] = [];
59813
+ const accessor = ratingsParameters[scaleName]?.accessor;
59814
+ if (accessor) {
59815
+ const value = parseFloat(rating.scaleValue?.[accessor]);
59816
+ if (value)
59817
+ eventsMap[eventId].ratings[scaleName].push(value);
59818
+ }
59819
+ }
59820
+ }
59821
+ };
59822
+ for (const participantId of participantIds) {
59823
+ const participant = participantMap?.[participantId]?.participant;
59824
+ if (participant?.participantType !== INDIVIDUAL) {
59825
+ for (const individualParticipantId of participant?.individualParticipantIds ?? []) {
59826
+ const individualParticipant = participantMap?.[individualParticipantId]?.participant;
59827
+ processParticipant(individualParticipant);
59828
+ }
59829
+ } else {
59830
+ processParticipant(participant);
59831
+ }
59832
+ }
59833
+ const ratings = eventsMap[eventId].ratings;
59834
+ for (const scaleName of Object.keys(ratings)) {
59835
+ eventsMap[eventId].ratingsStats[scaleName] = {
59836
+ avg: sum(ratings[scaleName]) / ratings[scaleName].length,
59837
+ median: median(ratings[scaleName]),
59838
+ max: Math.max(...ratings[scaleName]),
59839
+ min: Math.min(...ratings[scaleName])
59840
+ };
59841
+ }
59842
+ const processFlight = (drawId, participantIds2) => {
59843
+ const processParticipant2 = (participant) => {
59844
+ if (participant?.ratings?.[eventType]) {
59845
+ for (const rating of participant?.ratings?.[eventType] ?? []) {
59846
+ const scaleName = rating.scaleName;
59847
+ if (!eventsMap[eventId].draws[drawId].ratings[scaleName])
59848
+ eventsMap[eventId].draws[drawId].ratings[scaleName] = [];
59849
+ const accessor = ratingsParameters[scaleName]?.accessor;
59850
+ if (accessor) {
59851
+ const value = parseFloat(rating.scaleValue?.[accessor]);
59852
+ if (value) {
59853
+ eventsMap[eventId].draws[drawId].ratings[scaleName].push(
59854
+ value
59855
+ );
59856
+ }
59857
+ }
59858
+ }
59859
+ }
59860
+ };
59861
+ for (const participantId of participantIds2.filter(Boolean)) {
59862
+ const participant = participantMap?.[participantId]?.participant;
59863
+ if (participant?.participantType !== INDIVIDUAL) {
59864
+ for (const individualParticipantId of participant?.individualParticipantIds ?? []) {
59865
+ const individualParticipant = participantMap?.[individualParticipantId]?.participant;
59866
+ processParticipant2(individualParticipant);
59867
+ }
59868
+ } else {
59869
+ processParticipant2(participant);
59870
+ }
59871
+ }
59872
+ };
59873
+ const processedDrawIds = [];
59874
+ const ignoreDrawId = (drawId) => drawIds?.length && drawIds.includes(drawId) || processedDrawIds.includes(drawId);
59875
+ for (const drawDefinition of event.drawDefinitions ?? []) {
59876
+ const drawId = drawDefinition.drawId;
59877
+ if (ignoreDrawId(drawId))
59878
+ continue;
59879
+ const participantIds2 = getAssignedParticipantIds({
59880
+ drawDefinition
59881
+ }).assignedParticipantIds ?? [];
59882
+ if (!eventsMap[eventId].draws[drawId])
59883
+ eventsMap[eventId].draws[drawId] = {
59884
+ ratingsStats: {},
59885
+ ratings: {},
59886
+ ranking: {}
59887
+ };
59888
+ processedDrawIds.push(drawId);
59889
+ processFlight(drawId, participantIds2);
59890
+ }
59891
+ const flightProfile = getFlightProfile({ event }).flightProfile;
59892
+ for (const flight of flightProfile?.flights ?? []) {
59893
+ const drawId = flight.drawId;
59894
+ if (ignoreDrawId(drawId))
59895
+ continue;
59896
+ const participantIds2 = flight.drawEntries.map(extractAttributes("participantId"));
59897
+ processFlight(drawId, participantIds2);
59898
+ }
59899
+ for (const drawId of processedDrawIds) {
59900
+ const ratings2 = eventsMap[eventId].draws[drawId].ratings;
59901
+ for (const scaleName of Object.keys(ratings2)) {
59902
+ eventsMap[eventId].draws[drawId].ratingsStats[scaleName] = {
59903
+ avg: sum(ratings2[scaleName]) / ratings2[scaleName].length,
59904
+ max: Math.max(...ratings2[scaleName]),
59905
+ min: Math.min(...ratings2[scaleName]),
59906
+ median: median(ratings2[scaleName])
59907
+ };
59908
+ }
59909
+ }
59910
+ }
59911
+ }
59912
+ return definedAttributes({
59913
+ eventScaleValues: eventsMap,
59914
+ events: eventCopies,
59915
+ ...SUCCESS
59916
+ });
59917
+ }
59918
+
59766
59919
  function bulkUpdatePublishedEventIds({ tournamentRecord, outcomes }) {
59767
59920
  if (!tournamentRecord)
59768
59921
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -59958,6 +60111,8 @@ function positionActions(params) {
59958
60111
  function getDrawDefinition({ tournamentRecord, drawDefinition }) {
59959
60112
  if (!tournamentRecord)
59960
60113
  return { error: MISSING_TOURNAMENT_RECORD };
60114
+ if (!drawDefinition)
60115
+ return { error: MISSING_DRAW_ID };
59961
60116
  return { drawDefinition: makeDeepCopy(drawDefinition) };
59962
60117
  }
59963
60118
  const queryGovernor = {
@@ -64374,6 +64529,7 @@ const utilities = {
64374
64529
  generateRange,
64375
64530
  generateScoreString,
64376
64531
  generateTimeCode,
64532
+ getAssignedParticipantIds,
64377
64533
  getCategoryAgeDetails,
64378
64534
  getScaleValues,
64379
64535
  getTimeItem,