tods-competition-factory 1.7.19 → 1.8.1

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.
@@ -1279,68 +1279,16 @@ function UUID() {
1279
1279
  const APPLIED_POLICIES = "appliedPolicies";
1280
1280
  const AUDIT_POSITION_ACTIONS = "positionActions";
1281
1281
  const CONTEXT = "context";
1282
- const DELEGATED_OUTCOME = "delegatedOutcome";
1283
- const DISABLED = "disabled";
1284
1282
  const DISABLE_LINKS = "disableLinks";
1285
1283
  const DISABLE_AUTO_CALC = "disableAutoCalc";
1286
- const DRAW_DELETIONS = "drawDeletions";
1287
- const DRAW_PROFILE = "drawProfile";
1288
1284
  const ENTRY_PROFILE = "entryProfile";
1289
- const EVENT_PROFILE = "eventProfile";
1290
- const FACTORY = "factory";
1291
1285
  const FLIGHT_PROFILE = "flightProfile";
1292
- const GROUPING_ATTRIBUTE = "groupingAttribute";
1293
1286
  const LINEUPS = "lineUps";
1294
1287
  const LINKED_TOURNAMENTS = "linkedTournamentsIds";
1295
- const MATCHUP_HISTORY = "matchUpHistory";
1296
- const PARTICIPANT_REPRESENTATIVES = "participantRepresentatives";
1297
- const PERSON_REQUESTS = "personRequests";
1298
- const RANKING_POINTS = "rankingPoints";
1299
1288
  const ROUND_TARGET = "roundTarget";
1300
- const SCHEDULE_LIMITS = "scheduleLimits";
1301
1289
  const SCHEDULE_TIMING = "scheduleTiming";
1302
- const SCHEDULING_PROFILE = "schedulingProfile";
1303
- const STATUS_DETAIL = "statusDetail";
1304
1290
  const SUB_ORDER = "subOrder";
1305
1291
  const TALLY = "tally";
1306
- const TIE_FORMAT_MODIFICATIONS = "tieFormatModification";
1307
- const extensionConstants = {
1308
- APPLIED_POLICIES,
1309
- AUDIT_POSITION_ACTIONS,
1310
- CONTEXT,
1311
- // used to capture, e.g. context in which a venue was added
1312
- DELEGATED_OUTCOME,
1313
- DISABLED,
1314
- DISABLE_LINKS,
1315
- DISABLE_AUTO_CALC,
1316
- DRAW_DELETIONS,
1317
- DRAW_PROFILE,
1318
- ENTRY_PROFILE,
1319
- // used for drawGeneration; not relevant for anonymized tournaments
1320
- EVENT_PROFILE,
1321
- FLIGHT_PROFILE,
1322
- GROUPING_ATTRIBUTE,
1323
- // for generating teams; not relevant for anonymized tournaments
1324
- LINEUPS,
1325
- LINKED_TOURNAMENTS,
1326
- MATCHUP_HISTORY,
1327
- PARTICIPANT_REPRESENTATIVES,
1328
- PERSON_REQUESTS,
1329
- RANKING_POINTS,
1330
- // for attaching points awarded to tournamentRecord
1331
- ROUND_TARGET,
1332
- SCHEDULE_LIMITS,
1333
- SCHEDULE_TIMING,
1334
- SCHEDULING_PROFILE,
1335
- STATUS_DETAIL,
1336
- // attached to event.entries
1337
- SUB_ORDER,
1338
- TALLY,
1339
- TIE_FORMAT_MODIFICATIONS,
1340
- // for auditing, not important when anonymized
1341
- FACTORY
1342
- // used for capturing versioning of factory and other TODS document processors
1343
- };
1344
1292
 
1345
1293
  function getAppliedPolicies({
1346
1294
  onlySpecifiedPolicyTypes = false,
@@ -1794,9 +1742,7 @@ function getScheduleTiming({
1794
1742
  return { scheduleTiming };
1795
1743
  }
1796
1744
 
1797
- const SINGLES_MATCHUP = "SINGLES";
1798
1745
  const SINGLES$1 = "SINGLES";
1799
- const DOUBLES_MATCHUP = "DOUBLES";
1800
1746
  const DOUBLES$1 = "DOUBLES";
1801
1747
  const TEAM_MATCHUP = "TEAM";
1802
1748
  const TEAM$2 = "TEAM";
@@ -7596,24 +7542,6 @@ function getTimeItem({
7596
7542
  return { info: NOT_FOUND };
7597
7543
  }
7598
7544
  }
7599
- function getEventTimeItem({
7600
- returnPreviousValues,
7601
- itemSubTypes,
7602
- itemType,
7603
- event
7604
- }) {
7605
- if (!event)
7606
- return { error: MISSING_EVENT };
7607
- if (!event.timeItems)
7608
- return { info: NOT_FOUND };
7609
- const { timeItem, previousItems, info } = getTimeItem({
7610
- returnPreviousValues,
7611
- element: event,
7612
- itemSubTypes,
7613
- itemType
7614
- });
7615
- return timeItem && { timeItem, previousItems } || { info };
7616
- }
7617
7545
 
7618
7546
  const typeMap = {
7619
7547
  [GROUP]: "groupParticipantIds",
@@ -7627,7 +7555,6 @@ const membershipMap = {
7627
7555
  function getParticipantMap({
7628
7556
  withIndividualParticipants,
7629
7557
  convertExtensions,
7630
- policyDefinitions,
7631
7558
  tournamentRecord,
7632
7559
  withSignInStatus,
7633
7560
  withScaleValues,
@@ -7635,32 +7562,23 @@ function getParticipantMap({
7635
7562
  withISO2,
7636
7563
  withIOC
7637
7564
  }) {
7638
- const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
7639
- const filterAttributes = participantAttributes?.participant;
7640
7565
  const participantMap = {};
7641
- for (const participant of tournamentRecord.participants || []) {
7566
+ for (const participant of tournamentRecord.participants ?? []) {
7642
7567
  const participantId = participant?.participantId;
7643
7568
  participantId && initializeParticipantId({ participantMap, participantId });
7644
7569
  }
7645
- for (const participant of tournamentRecord.participants || []) {
7570
+ for (const participant of tournamentRecord.participants ?? []) {
7646
7571
  const participantCopy = makeDeepCopy(
7647
7572
  participant,
7648
7573
  convertExtensions,
7649
7574
  internalUse
7650
7575
  );
7651
- const filteredParticipant = filterAttributes ? attributeFilter({
7652
- template: participantAttributes.participant,
7653
- source: participantCopy
7654
- }) : participantCopy;
7655
- const { participantId, individualParticipantIds, participantType } = filteredParticipant;
7656
- Object.assign(
7657
- participantMap[participantId].participant,
7658
- filteredParticipant
7659
- );
7576
+ const { participantId, individualParticipantIds, participantType } = participantCopy;
7577
+ Object.assign(participantMap[participantId].participant, participantCopy);
7660
7578
  if (individualParticipantIds) {
7661
7579
  processIndividualParticipantIds({
7662
7580
  individualParticipantIds,
7663
- filteredParticipant,
7581
+ participantCopy,
7664
7582
  participantMap,
7665
7583
  participantType,
7666
7584
  participantId
@@ -7711,7 +7629,7 @@ function addIndividualParticipants({ participantMap }) {
7711
7629
  }
7712
7630
  function processIndividualParticipantIds({
7713
7631
  individualParticipantIds,
7714
- filteredParticipant,
7632
+ participantCopy,
7715
7633
  participantMap,
7716
7634
  participantType,
7717
7635
  participantId
@@ -7726,7 +7644,7 @@ function processIndividualParticipantIds({
7726
7644
  participantName,
7727
7645
  participantId: participantId2,
7728
7646
  teamId
7729
- } = filteredParticipant;
7647
+ } = participantCopy;
7730
7648
  const membership = membershipMap[participantType];
7731
7649
  individualParticipant[membership].push({
7732
7650
  participantRoleResponsibilities,
@@ -7789,7 +7707,6 @@ function initializeParticipantId({ participantMap, participantId }) {
7789
7707
  function hydrateParticipants({
7790
7708
  participantsProfile,
7791
7709
  useParticipantMap,
7792
- policyDefinitions,
7793
7710
  tournamentRecord,
7794
7711
  contextProfile,
7795
7712
  inContext
@@ -7798,7 +7715,6 @@ function hydrateParticipants({
7798
7715
  const participantMap = getParticipantMap({
7799
7716
  ...participantsProfile,
7800
7717
  ...contextProfile,
7801
- policyDefinitions,
7802
7718
  tournamentRecord
7803
7719
  })?.participantMap;
7804
7720
  return { participantMap };
@@ -15262,7 +15178,7 @@ function getParticipantResults({
15262
15178
  }
15263
15179
  }
15264
15180
  }
15265
- processMatchUp$1({
15181
+ processMatchUp({
15266
15182
  matchUpFormat: tieMatchUp.matchUpFormat,
15267
15183
  matchUpStatus: tieMatchUp.matchUpStatus,
15268
15184
  score: tieMatchUp.score,
@@ -15282,7 +15198,7 @@ function getParticipantResults({
15282
15198
  matchUpStatus
15283
15199
  });
15284
15200
  } else {
15285
- processMatchUp$1({
15201
+ processMatchUp({
15286
15202
  matchUpFormat: matchUp.matchUpFormat || matchUpFormat,
15287
15203
  isTieMatchUp: void 0,
15288
15204
  winningParticipantId,
@@ -15407,7 +15323,7 @@ function processScore({
15407
15323
  }
15408
15324
  });
15409
15325
  }
15410
- function processMatchUp$1({
15326
+ function processMatchUp({
15411
15327
  winningParticipantId,
15412
15328
  losingParticipantId,
15413
15329
  participantResults,
@@ -17695,125 +17611,30 @@ function generateAndPopulatePlayoffStructures(params) {
17695
17611
  };
17696
17612
  }
17697
17613
 
17698
- function getDerivedPositionAssignments({
17699
- derivedDrawInfo,
17700
- participantId,
17701
- drawId
17702
- }) {
17703
- const mainPositionAssignment = derivedDrawInfo[drawId]?.mainPositionAssignments?.find(
17704
- (assignment) => assignment.participantId === participantId
17705
- );
17706
- const qualifyingPositionAssignment = derivedDrawInfo[drawId]?.qualifyingPositionAssignments?.find(
17707
- (assignment) => assignment.participantId === participantId
17708
- );
17709
- const positionAssignments = {};
17710
- if (mainPositionAssignment) {
17711
- const { participantId: participantId2, ...props } = mainPositionAssignment;
17712
- if (participantId2)
17713
- positionAssignments[MAIN] = { ...props };
17714
- }
17715
- if (qualifyingPositionAssignment) {
17716
- const { participantId: participantId2, ...props } = qualifyingPositionAssignment;
17717
- if (participantId2)
17718
- positionAssignments[QUALIFYING] = { ...props };
17719
- }
17720
- return Object.keys(positionAssignments).length ? positionAssignments : void 0;
17721
- }
17722
-
17723
- function getRelevantParticipantIdsMap({
17724
- processParticipantId,
17725
- // optional method which is passed each participantId
17726
- tournamentRecords,
17727
- tournamentRecord
17728
- }) {
17729
- if (typeof tournamentRecord !== "object" && typeof tournamentRecords !== "object")
17730
- return { error: MISSING_TOURNAMENT_RECORD };
17731
- const allParticipants = tournamentRecords ? Object.values(tournamentRecords).map((tournamentRecord2) => tournamentRecord2?.participants || []).flat() : tournamentRecord?.participants || [];
17732
- const relevantParticipantIdsMap = Object.assign(
17733
- {},
17734
- ...allParticipants.map(
17735
- ({ participantId, participantType, individualParticipantIds }) => {
17736
- typeof processParticipantId === "function" && processParticipantId(participantId);
17737
- const individualParticipantIdObjects = (individualParticipantIds || []).map((relevantParticipantId) => ({
17738
- participantType: INDIVIDUAL,
17739
- relevantParticipantId
17740
- }));
17741
- return {
17742
- [participantId]: individualParticipantIdObjects.concat({
17743
- relevantParticipantId: participantId,
17744
- participantType
17745
- })
17746
- };
17747
- }
17748
- )
17749
- );
17750
- return { relevantParticipantIdsMap };
17751
- }
17752
-
17753
- function getDerivedSeedAssignments({
17754
- derivedDrawInfo,
17755
- participantId,
17756
- drawId
17757
- }) {
17758
- const mainSeedAssignment = derivedDrawInfo[drawId]?.mainSeedAssignments?.find(
17759
- (assignment) => assignment.participantId === participantId
17760
- );
17761
- const qualifyingSeedAssignment = derivedDrawInfo[drawId]?.qualifyingSeedAssignments?.find(
17762
- (assignment) => assignment.participantId === participantId
17763
- );
17764
- const seedAssignments = {};
17765
- if (mainSeedAssignment) {
17766
- const { participantId: participantId2, ...props } = mainSeedAssignment;
17767
- if (participantId2)
17768
- seedAssignments[MAIN] = { ...props };
17769
- }
17770
- if (qualifyingSeedAssignment) {
17771
- const { participantId: participantId2, ...props } = qualifyingSeedAssignment;
17772
- if (participantId2)
17773
- seedAssignments[QUALIFYING] = { ...props };
17774
- }
17775
- return Object.keys(seedAssignments).length ? seedAssignments : void 0;
17776
- }
17777
-
17778
- const hasSchedule = ({
17779
- scheduleAttributes = ["scheduledDate", "scheduledTime"],
17780
- schedule = {}
17781
- }) => {
17782
- const matchUpScheduleKeys = Object.keys(schedule).filter((key) => scheduleAttributes.includes(key)).filter((key) => schedule[key]);
17783
- return !!matchUpScheduleKeys.length;
17784
- };
17785
-
17786
- function participantScheduledMatchUps({
17787
- scheduleAttributes = ["scheduledDate", "scheduledTime"],
17788
- matchUps = []
17789
- }) {
17790
- if (!validMatchUps(matchUps))
17791
- return { error: MISSING_MATCHUPS };
17792
- if (!Array.isArray(scheduleAttributes))
17793
- return { error: INVALID_VALUES };
17794
- const scheduledMatchUps = matchUps.filter(Boolean).filter(({ schedule }) => hasSchedule({ schedule, scheduleAttributes })).reduce((dateMatchUps, matchUp) => {
17795
- const { schedule } = matchUp;
17796
- const date = extractDate(schedule?.scheduledDate);
17797
- const time = extractTime(schedule?.scheduledTime);
17798
- if (date && time) {
17799
- if (dateMatchUps[date]) {
17800
- dateMatchUps[date].push(matchUp);
17801
- } else {
17802
- dateMatchUps[date] = [matchUp];
17803
- }
17804
- }
17805
- return dateMatchUps;
17806
- }, {});
17807
- const dates = Object.keys(scheduledMatchUps);
17808
- dates.forEach((date) => {
17809
- scheduledMatchUps[date].sort(
17810
- (a, b) => timeSort(
17811
- extractTime(a.schedule?.scheduledTime),
17812
- extractTime(b.schedule?.scheduledTime)
17813
- )
17814
- );
17614
+ function getEventPublishStatuses({ event }) {
17615
+ const itemType = `${PUBLISH}.${STATUS}`;
17616
+ const { timeItem } = getTimeItem({
17617
+ element: event,
17618
+ itemType
17815
17619
  });
17816
- return { scheduledMatchUps };
17620
+ if (timeItem?.itemValue?.PUBLIC) {
17621
+ const { drawIds: publishedDrawIds = [], seeding } = timeItem.itemValue.PUBLIC || {};
17622
+ const publishedSeeding = {
17623
+ published: void 0,
17624
+ // seeding can be present for all entries in an event when no flights have been defined
17625
+ seedingScaleNames: [],
17626
+ drawIds: []
17627
+ // seeding can be specific to drawIds
17628
+ };
17629
+ if (seeding) {
17630
+ Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
17631
+ }
17632
+ return {
17633
+ publishedDrawIds,
17634
+ publishedSeeding
17635
+ };
17636
+ }
17637
+ return void 0;
17817
17638
  }
17818
17639
 
17819
17640
  function participantScaleItem({
@@ -17855,871 +17676,968 @@ function participantScaleItem({
17855
17676
  return { error: MISSING_PARTICIPANT };
17856
17677
  }
17857
17678
 
17858
- function annotateParticipant(params) {
17859
- const {
17860
- withScaleValues = true,
17861
- eventsPublishStatuses,
17862
- withEvents = true,
17863
- withDraws = true,
17864
- participantIdMap,
17865
- scheduleAnalysis,
17866
- derivedDrawInfo,
17867
- usePublishState,
17868
- withStatistics,
17869
- withOpponents,
17870
- withMatchUps,
17871
- withSeeding,
17872
- participant,
17873
- withISO2,
17874
- withIOC
17875
- } = params;
17876
- const scheduleConflicts = [];
17877
- const scheduleItems = [];
17878
- if (withIOC || withISO2)
17879
- addNationalityCode({ participant, withIOC, withISO2 });
17880
- if (withScaleValues) {
17881
- const { ratings, rankings } = getScaleValues({ participant });
17882
- participant.rankings = rankings;
17883
- participant.ratings = ratings;
17884
- }
17885
- const participantId = participant?.participantId;
17886
- if (!participantId || !participantIdMap[participantId])
17887
- return {};
17888
- const {
17889
- potentialMatchUps,
17890
- opponents,
17891
- matchUps,
17892
- events,
17893
- losses,
17894
- draws,
17895
- wins
17896
- } = participantIdMap[participantId];
17897
- const denominator = wins + losses;
17898
- const numerator = wins;
17899
- const statValue = denominator && numerator / denominator;
17900
- const winRatioStat = {
17901
- statCode: WIN_RATIO$1,
17902
- denominator,
17903
- numerator,
17904
- statValue
17905
- };
17906
- const participantDraws = Object.values(draws);
17907
- const participantEvents = Object.values(events);
17908
- if (withDraws && participantDraws) {
17909
- participant.draws = participantDraws;
17910
- for (const participantDraw of participantDraws) {
17911
- const publishedSeeding = eventsPublishStatuses[participantDraw.eventId]?.publishedSeeding;
17912
- const seedingPublished = !usePublishState || publishedSeeding?.published && (publishedSeeding?.drawIds?.length === 0 || publishedSeeding?.drawIds?.includes(participantDraw.drawId));
17913
- if (seedingPublished) {
17914
- const seedAssignments = getDerivedSeedAssignments({
17915
- drawId: participantDraw.drawId,
17916
- derivedDrawInfo,
17917
- participantId
17918
- });
17919
- if (seedAssignments) {
17920
- participantDraw.seedAssignments = seedAssignments;
17921
- }
17679
+ function getEventSeedAssignments({
17680
+ publishedSeeding,
17681
+ usePublishState,
17682
+ withSeeding,
17683
+ participant,
17684
+ event
17685
+ }) {
17686
+ const eventSeedAssignments = {};
17687
+ const getScaleAccessor = (scaleName) => [SCALE, SEEDING, event.eventType, scaleName].join(".");
17688
+ const seedingScales = Object.assign(
17689
+ {},
17690
+ ...(participant.timeItems || []).filter(({ itemType }) => itemType.split(".")[1] === SEEDING).map(({ itemType: seedingScaleName, itemValue: seedValue }) => ({
17691
+ [seedingScaleName]: seedValue
17692
+ }))
17693
+ );
17694
+ const eventSeedingScaleNames = (publishedSeeding?.stageSeedingScaleNames && Object.values(publishedSeeding?.stageSeedingScaleNames) || Array.isArray(publishedSeeding?.seedingScaleNames) && publishedSeeding.seedingScaleNames || []).map(getScaleAccessor);
17695
+ const publishedEventSeedingScaleNames = intersection(
17696
+ Object.keys(seedingScales),
17697
+ eventSeedingScaleNames
17698
+ );
17699
+ const eventSeedingPublished = !!(!usePublishState || !Object.keys(seedingScales).length && !publishedSeeding?.drawIds?.length || publishedEventSeedingScaleNames.length);
17700
+ if (eventSeedingPublished && publishedEventSeedingScaleNames.length) {
17701
+ if (publishedSeeding?.stageSeedingScaleNames) {
17702
+ const scaleValues = Object.keys(publishedSeeding.stageSeedingScaleNames).map((key) => {
17703
+ const accessor = getScaleAccessor(
17704
+ publishedSeeding.stageSeedingScaleNames[key]
17705
+ );
17706
+ const scaleValue = seedingScales[accessor];
17707
+ return [key, scaleValue];
17708
+ }).filter((pair) => pair[1]).map((pair) => ({ [pair[0]]: { seedValue: pair[1] } }));
17709
+ const seedAssignments = Object.assign({}, ...scaleValues);
17710
+ eventSeedAssignments.seedAssignments = seedAssignments;
17711
+ } else if (publishedEventSeedingScaleNames) {
17712
+ const seedValues = publishedEventSeedingScaleNames.map(
17713
+ (scaleName) => seedingScales[scaleName]
17714
+ );
17715
+ eventSeedAssignments.seedValue = seedValues.pop();
17716
+ }
17717
+ } else if (!usePublishState && typeof withSeeding === "object") {
17718
+ const scaleValues = Object.keys(withSeeding).map((key) => {
17719
+ const accessor = getScaleAccessor(withSeeding[key]);
17720
+ const scaleValue = seedingScales[accessor];
17721
+ return [key, scaleValue];
17722
+ }).filter((pair) => pair[1]).map((pair) => ({ [pair[0]]: { seedValue: pair[1] } }));
17723
+ const seedAssignments = Object.assign({}, ...scaleValues);
17724
+ eventSeedAssignments.seedAssignments = seedAssignments;
17725
+ } else {
17726
+ const { categoryName, ageCategoryCode } = event.category || {};
17727
+ let scaleItem;
17728
+ for (const scaleName of [ageCategoryCode, event.eventId, categoryName]) {
17729
+ const scaleAttributes = {
17730
+ eventType: event.eventType,
17731
+ scaleType: SEEDING,
17732
+ scaleName
17733
+ };
17734
+ const result = participantScaleItem({
17735
+ scaleAttributes,
17736
+ participant
17737
+ });
17738
+ if (result.scaleItem) {
17739
+ scaleItem = result.scaleItem;
17740
+ break;
17922
17741
  }
17923
17742
  }
17924
- }
17925
- if (withEvents && participantEvents) {
17926
- participant.events = participantEvents;
17927
- if (withSeeding) {
17928
- const seedingScales = Object.assign(
17929
- {},
17930
- ...(participant.timeItems || []).filter(({ itemType }) => itemType.split(".")[1] === SEEDING).map(({ itemType: seedingScaleName, itemValue: seedValue }) => ({
17931
- [seedingScaleName]: seedValue
17932
- }))
17933
- );
17934
- for (const participantEvent of participantEvents) {
17935
- const getScaleAccessor = (scaleName) => [SCALE, SEEDING, participantEvent.eventType, scaleName].join(".");
17936
- const publishedSeeding = eventsPublishStatuses[participantEvent.eventId]?.publishedSeeding;
17937
- const eventSeedingScaleNames = (publishedSeeding?.stageSeedingScaleNames && Object.values(publishedSeeding?.stageSeedingScaleNames) || Array.isArray(publishedSeeding?.seedingScaleNames) && publishedSeeding.seedingScaleNames || []).map(getScaleAccessor);
17938
- const publishedEventSeedingScaleNames = intersection(
17939
- Object.keys(seedingScales),
17940
- eventSeedingScaleNames
17941
- );
17942
- const eventSeedingPublished = !!(!usePublishState || !Object.keys(seedingScales).length && !publishedSeeding?.drawIds?.length || publishedEventSeedingScaleNames.length);
17943
- if (eventSeedingPublished && publishedEventSeedingScaleNames.length) {
17944
- if (publishedSeeding?.stageSeedingScaleNames) {
17945
- const scaleValues = Object.keys(
17946
- publishedSeeding.stageSeedingScaleNames
17947
- ).map((key) => {
17948
- const accessor = getScaleAccessor(
17949
- publishedSeeding.stageSeedingScaleNames[key]
17950
- );
17951
- const scaleValue = seedingScales[accessor];
17952
- return [key, scaleValue];
17953
- }).filter((pair) => pair[1]).map((pair) => ({ [pair[0]]: { seedValue: pair[1] } }));
17954
- const seedAssignments = Object.assign({}, ...scaleValues);
17955
- participantEvent.seedAssignments = seedAssignments;
17956
- } else if (publishedEventSeedingScaleNames) {
17957
- const seedValues = publishedEventSeedingScaleNames.map(
17958
- (scaleName) => seedingScales[scaleName]
17959
- );
17960
- participantEvent.seedValue = seedValues.pop();
17961
- }
17962
- } else if (!usePublishState && typeof withSeeding === "object") {
17963
- const scaleValues = Object.keys(withSeeding).map((key) => {
17964
- const accessor = getScaleAccessor(withSeeding[key]);
17965
- const scaleValue = seedingScales[accessor];
17966
- return [key, scaleValue];
17967
- }).filter((pair) => pair[1]).map((pair) => ({ [pair[0]]: { seedValue: pair[1] } }));
17968
- const seedAssignments = Object.assign({}, ...scaleValues);
17969
- participantEvent.seedAssignments = seedAssignments;
17970
- } else {
17971
- const { categoryName, ageCategoryCode } = participantEvent.category || {};
17972
- let scaleItem;
17973
- for (const scaleName of [
17974
- participantEvent.eventId,
17975
- ageCategoryCode,
17976
- categoryName
17977
- ]) {
17978
- const scaleAttributes = {
17979
- eventType: participantEvent.eventType,
17980
- scaleType: SEEDING,
17981
- scaleName
17982
- };
17983
- const result = participantScaleItem({
17984
- scaleAttributes,
17985
- participant
17986
- });
17987
- if (result.scaleItem) {
17988
- scaleItem = result.scaleItem;
17989
- break;
17990
- }
17991
- }
17992
- if (scaleItem) {
17993
- const seedValue = scaleItem.scaleValue;
17994
- const seedingPublished = !usePublishState || publishedSeeding?.published && (publishedSeeding?.drawIds?.length === 0 || publishedSeeding?.drawIds?.includes(
17995
- participantEvent.drawId
17996
- ));
17997
- if (seedingPublished) {
17998
- participantEvent.seedValue = seedValue;
17999
- }
18000
- }
18001
- }
18002
- if (participantEvent.drawIds?.length) {
18003
- for (const flightDrawId of participantEvent.drawIds || []) {
18004
- const drawSeedPublishingDisabled = publishedSeeding?.drawIds?.length && !publishedSeeding?.drawIds?.includes(flightDrawId);
18005
- if (eventSeedingPublished && !drawSeedPublishingDisabled) {
18006
- const seedAssignments = getDerivedSeedAssignments({
18007
- drawId: flightDrawId,
18008
- derivedDrawInfo,
18009
- participantId
18010
- });
18011
- if (seedAssignments && participantEvent.seedAssignments) {
18012
- for (const key of Object.keys(
18013
- participantEvent.seedAssignments
18014
- )) {
18015
- participantEvent.seedAssignments[key] = seedAssignments[key];
18016
- }
18017
- } else {
18018
- participantEvent.seedAssignments = seedAssignments;
18019
- }
18020
- }
18021
- }
18022
- }
17743
+ if (scaleItem) {
17744
+ const seedingPublished = !usePublishState || publishedSeeding?.published && // if drawIds have been specified then don't attach event seeding here
17745
+ // defer to seedValue that is in seedAssignments for draw in which participant appears
17746
+ !publishedSeeding?.published?.drawIds?.length;
17747
+ if (seedingPublished) {
17748
+ const seedValue = scaleItem.scaleValue;
17749
+ eventSeedAssignments.seedValue = seedValue;
18023
17750
  }
18024
17751
  }
18025
17752
  }
18026
- const participantOpponents = Object.values(opponents).flat();
18027
- if (withOpponents && participantOpponents?.length) {
18028
- participant.opponents = participantOpponents;
18029
- participantDraws?.forEach((draw) => {
18030
- draw.opponents = participantOpponents.filter(
18031
- (opponent) => opponent.drawId === draw.drawId
18032
- );
18033
- });
18034
- }
18035
- const participantPotentialMatchUps = Object.values(potentialMatchUps);
18036
- const participantMatchUps = Object.values(matchUps);
18037
- if (withMatchUps) {
18038
- participant.potentialMatchUps = participantPotentialMatchUps;
18039
- participant.matchUps = participantMatchUps;
18040
- }
18041
- const allParticipantMatchUps = participantMatchUps.concat(
18042
- participantPotentialMatchUps
18043
- );
18044
- const scheduledMatchUps = participantScheduledMatchUps({
18045
- matchUps: allParticipantMatchUps
18046
- })?.scheduledMatchUps || [];
18047
- const { scheduledMinutesDifference } = scheduleAnalysis || {};
18048
- const dates = Object.keys(scheduledMatchUps);
18049
- dates.forEach((date) => {
18050
- scheduledMatchUps[date].filter(Boolean).forEach((matchUp, i) => {
18051
- const {
18052
- schedule: {
18053
- scheduledTime,
18054
- timeAfterRecovery,
18055
- typeChangeTimeAfterRecovery
18056
- },
18057
- matchUpStatus,
18058
- roundPosition,
18059
- structureName,
18060
- matchUpType,
18061
- roundNumber,
18062
- matchUpId,
18063
- drawId,
18064
- score
18065
- } = matchUp;
18066
- scheduleItems.push({
18067
- ...matchUp.schedule,
18068
- scheduledTime: extractTime(matchUp.schedule?.scheduledTime),
18069
- roundPosition,
18070
- structureName,
18071
- matchUpType,
18072
- roundNumber,
18073
- matchUpId,
18074
- drawId
18075
- });
18076
- const ignoreMatchUp = matchUpStatus === BYE || [WALKOVER$1, DEFAULTED].includes(matchUpStatus) && !scoreHasValue({ score });
18077
- if (scheduledTime && !ignoreMatchUp) {
18078
- const scheduledMinutes = timeStringMinutes(scheduledTime);
18079
- const matchUpsToConsider = scheduledMatchUps[date].slice(i + 1);
18080
- for (const consideredMatchUp of matchUpsToConsider) {
18081
- const ignoreMatchUp2 = consideredMatchUp.matchUpStatus === BYE || [WALKOVER$1, DEFAULTED].includes(consideredMatchUp.matchUpStatus) && !scoreHasValue(consideredMatchUp);
18082
- if (!ignoreMatchUp2 && consideredMatchUp.schedule?.scheduledTime) {
18083
- const typeChange = matchUp.matchUpType !== consideredMatchUp.matchUpType;
18084
- const notBeforeTime = typeChange ? typeChangeTimeAfterRecovery || timeAfterRecovery : timeAfterRecovery;
18085
- const sameDraw = matchUp.drawId === consideredMatchUp.drawId;
18086
- const bothPotential = matchUp.potential && consideredMatchUp.potential;
18087
- const nextMinutes = timeStringMinutes(
18088
- consideredMatchUp.schedule?.scheduledTime
18089
- );
18090
- const minutesDifference = nextMinutes - scheduledMinutes;
18091
- const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : timeStringMinutes(notBeforeTime) > timeStringMinutes(consideredMatchUp.schedule?.scheduledTime);
18092
- if (timeOverlap && !(bothPotential && sameDraw)) {
18093
- scheduleConflicts.push({
18094
- priorScheduledMatchUpId: consideredMatchUp.matchUpId,
18095
- matchUpIdWithConflict: matchUpId
18096
- });
18097
- }
18098
- }
18099
- }
18100
- }
18101
- });
18102
- });
18103
- if (withStatistics)
18104
- participant.statistics = [winRatioStat];
18105
- return { scheduleConflicts, scheduleItems };
17753
+ return eventSeedAssignments;
18106
17754
  }
18107
17755
 
18108
- function getDrawDetails({
18109
- eventEntries,
18110
- sortConfig,
18111
- event
17756
+ function processEventEntry({
17757
+ extensionConversions,
17758
+ seedAssignments,
17759
+ participant,
17760
+ withSeeding,
17761
+ seedValue,
17762
+ eventId,
17763
+ ranking,
17764
+ entry
18112
17765
  }) {
18113
- const derivedInfo = {};
18114
- const drawDetails = Object.assign(
18115
- {},
18116
- ...(event.drawDefinitions ?? []).map((drawDefinition) => {
18117
- const entriesMap = Object.assign(
18118
- {},
18119
- ...(eventEntries ?? []).filter((entry) => entry.participantId).map((entry) => ({ [entry.participantId]: entry })),
18120
- ...drawDefinition.entries.filter((entry) => entry.participantId).map((entry) => ({ [entry.participantId]: entry }))
18121
- );
18122
- const drawEntries = Object.values(entriesMap);
18123
- const mainStructure = getDrawStructures({
18124
- stageSequence: 1,
18125
- drawDefinition,
18126
- stage: MAIN
18127
- })?.structures?.[0];
18128
- const mainPositionAssignments = mainStructure && getPositionAssignments({
18129
- structure: mainStructure
18130
- })?.positionAssignments;
18131
- const drawSize = mainPositionAssignments?.length;
18132
- const qualifyingStructure = getDrawStructures({
18133
- stageSequence: 1,
18134
- stage: QUALIFYING,
18135
- drawDefinition
18136
- })?.structures?.[0];
18137
- const qualifyingPositionAssignments = mainStructure && getPositionAssignments({
18138
- structure: qualifyingStructure
18139
- })?.positionAssignments;
18140
- const qualifyingDrawSize = qualifyingPositionAssignments?.length;
18141
- const mainSeedAssignments = mainStructure?.seedAssignments;
18142
- const qualifyingSeedAssignments = qualifyingStructure?.seedAssignments;
18143
- const orderedStructureIds = (drawDefinition.structures || []).sort((a, b) => structureSort(a, b, sortConfig)).map(({ structureId, structures }) => {
18144
- return [
18145
- structureId,
18146
- ...(structures || []).map(({ structureId: structureId2 }) => structureId2)
18147
- ];
18148
- }).flat(Infinity);
18149
- const flightNumber = event?._flightProfile?.flights?.find(
18150
- (flight) => flight.drawId === drawDefinition.drawId
18151
- )?.flightNumber;
18152
- derivedInfo[drawDefinition.drawId] = {
18153
- qualifyingPositionAssignments,
18154
- qualifyingSeedAssignments,
18155
- mainPositionAssignments,
18156
- mainSeedAssignments,
18157
- orderedStructureIds,
18158
- qualifyingDrawSize,
18159
- flightNumber,
18160
- drawSize
18161
- };
18162
- return {
18163
- [drawDefinition.drawId]: {
18164
- drawType: drawDefinition.drawType,
18165
- drawEntries
18166
- }
18167
- };
18168
- })
17766
+ const { entryStatus, entryStage, entryPosition, extensions } = entry;
17767
+ const entryExtensions = extensions?.length ? Object.assign({}, ...extensionsToAttributes(extensions)) : {};
17768
+ const attributes = Object.assign(entryExtensions, {
17769
+ ...extensionConversions,
17770
+ // this should be deprecated and clients should use derivedEventInfo
17771
+ entryPosition,
17772
+ entryStatus,
17773
+ entryStage,
17774
+ ranking,
17775
+ eventId
17776
+ });
17777
+ participant.events[eventId] = definedAttributes(
17778
+ attributes,
17779
+ false,
17780
+ false,
17781
+ true
18169
17782
  );
18170
- return { derivedInfo, drawDetails };
17783
+ if (withSeeding) {
17784
+ if (seedAssignments)
17785
+ participant.events[eventId].seedAssignments = seedAssignments;
17786
+ if (seedValue)
17787
+ participant.events[eventId].seedValue = seedValue;
17788
+ }
18171
17789
  }
18172
17790
 
18173
- function processMatchUp({
18174
- relevantParticipantIdsMap,
18175
- participantFilters,
18176
- participantIdMap,
18177
- derivedDrawInfo,
18178
- eventDrawsCount,
18179
- drawDetails,
18180
- eventType,
18181
- matchUp
18182
- }) {
17791
+ function addScheduleItem(params) {
18183
17792
  const {
18184
- collectionId,
18185
- collectionPosition,
18186
- drawId,
18187
- drawName,
18188
- eventId,
18189
- eventName,
18190
- finishingRound,
18191
- finishingPositionRange,
18192
- processCodes,
18193
- loserTo,
18194
- matchUpId,
18195
- matchUpType,
18196
- matchUpFormat,
17793
+ participantMap,
17794
+ participantId,
18197
17795
  matchUpStatus,
18198
- matchUpStatusCodes,
18199
- matchUpTieId,
18200
- roundName,
18201
- roundNumber,
18202
17796
  roundPosition,
18203
- score,
18204
- sides,
18205
- stage,
18206
- stageSequence,
18207
- schedule,
18208
- structureName,
18209
17797
  structureId,
18210
- tieFormat,
18211
- tieMatchUps,
18212
- tournamentId,
18213
- winnerTo,
18214
- winningSide
18215
- } = matchUp;
18216
- const targetParticipantIds = participantFilters?.participantIds;
18217
- const getRelevantParticipantIds = (participantId) => {
18218
- const relevantParticipantIds = participantId && relevantParticipantIdsMap[participantId] || [];
18219
- relevantParticipantIds.push(participantId);
18220
- return relevantParticipantIds.some(
18221
- (obj) => !targetParticipantIds || targetParticipantIds.includes(obj.relevantParticipantId)
18222
- ) ? relevantParticipantIds : [];
18223
- };
18224
- const { winner, loser } = finishingPositionRange || {};
18225
- const doublesTieParticipants = tieMatchUps?.length && tieMatchUps.filter(({ matchUpType: matchUpType2 }) => matchUpType2 === DOUBLES_MATCHUP).map(
18226
- ({ sides: sides2 }) => sides2.map(
18227
- ({ sideNumber, participantId, participant }) => sideNumber && participantId && {
18228
- sideNumber,
18229
- participantId,
18230
- participant
18231
- }
18232
- )
18233
- ).flat().filter(Boolean) || [];
18234
- if (eventType === TEAM_EVENT && matchUpType === DOUBLES_MATCHUP) {
18235
- const participants = (matchUp.sides?.filter(Boolean) || []).map(
18236
- ({ sideNumber, participantId, participant }) => sideNumber && participantId && {
18237
- sideNumber,
18238
- participantId,
18239
- participant
18240
- }
18241
- ).filter(Boolean);
18242
- doublesTieParticipants.push(...participants);
18243
- }
18244
- sides?.forEach((params) => {
18245
- const { participantId, sideNumber } = params;
18246
- if (!participantId)
18247
- return;
18248
- const { drawType, drawEntries } = drawDetails[drawId];
18249
- const participantScore = sideNumber === 1 ? score?.scoreStringSide1 : score?.scoreStringSide2;
18250
- const participantWon = winningSide && sideNumber === winningSide;
18251
- const opponent = matchUp.sides.find(
18252
- (side) => side.sideNumber === 3 - sideNumber
18253
- );
18254
- const opponentParticipantId = opponent?.participantId;
18255
- const relevantOpponents = opponentParticipantId && relevantParticipantIdsMap[opponentParticipantId] || [];
18256
- const finishingPositionRange2 = participantWon ? winner : loser;
18257
- const drawEntry = drawEntries.find(
18258
- (entry) => entry.participantId === participantId
18259
- );
18260
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
18261
- const addedPairParticipantIds = [];
18262
- doublesTieParticipants?.filter((participant) => participant.sideNumber === sideNumber).forEach((p) => {
18263
- const participantId2 = p.participantId;
18264
- if (participantId2 && !addedPairParticipantIds.includes(participantId2)) {
18265
- relevantParticipantIds.push({
18266
- relevantParticipantId: participantId2,
18267
- participantType: PAIR
18268
- });
18269
- addedPairParticipantIds.push(participantId2);
18270
- }
17798
+ matchUpType,
17799
+ roundNumber,
17800
+ matchUpId,
17801
+ potential,
17802
+ schedule,
17803
+ drawId,
17804
+ score
17805
+ } = params;
17806
+ if (!schedule || !Object.keys(schedule).length)
17807
+ return;
17808
+ const ignoreMatchUp = matchUpStatus === BYE;
17809
+ if (!ignoreMatchUp) {
17810
+ participantMap[participantId].scheduleItems.push({
17811
+ ...schedule,
17812
+ scheduledDate: extractDate(schedule?.scheduledDate),
17813
+ scheduledTime: extractTime(schedule?.scheduledTime),
17814
+ scoreHasValue: scoreHasValue({ score }),
17815
+ matchUpStatus,
17816
+ roundPosition,
17817
+ structureId,
17818
+ matchUpType,
17819
+ roundNumber,
17820
+ matchUpId,
17821
+ potential,
17822
+ drawId
18271
17823
  });
18272
- const filteredRelevantParticipantIds = relevantParticipantIds.filter(
18273
- (opponent2) => {
18274
- return eventType !== TEAM_EVENT || eventType === TEAM_EVENT && [DOUBLES_MATCHUP, TEAM_MATCHUP].includes(matchUpType) && [PAIR, TEAM_PARTICIPANT].includes(opponent2.participantType) || eventType === TEAM_EVENT && [SINGLES_MATCHUP, DOUBLES_MATCHUP].includes(matchUpType) && [INDIVIDUAL].includes(opponent2.participantType);
18275
- }
18276
- );
18277
- filteredRelevantParticipantIds?.forEach(
18278
- ({ relevantParticipantId, participantType }) => {
18279
- const { entryStage, entryStatus, entryPosition } = drawEntry || {};
18280
- if (!participantIdMap[relevantParticipantId])
18281
- return;
18282
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
18283
- const positionAssignments = getDerivedPositionAssignments({
18284
- participantId: relevantParticipantId,
18285
- derivedDrawInfo,
18286
- drawId
18287
- });
18288
- const seedAssignments = getDerivedSeedAssignments({
18289
- participantId: relevantParticipantId,
18290
- derivedDrawInfo,
18291
- drawId
18292
- });
18293
- participantIdMap[relevantParticipantId].draws[drawId] = definedAttributes({
18294
- qualifyingDrawSize: derivedDrawInfo[drawId]?.qualifyingDrawSize,
18295
- drawSize: derivedDrawInfo[drawId]?.drawSize,
18296
- partnerParticipantIds: [],
18297
- positionAssignments,
18298
- seedAssignments,
18299
- entryPosition,
18300
- entryStatus,
18301
- entryStage,
18302
- drawName,
18303
- drawType,
18304
- eventId,
18305
- drawId
18306
- });
17824
+ }
17825
+ }
17826
+
17827
+ function addStructureParticipation({
17828
+ finishingPositionRange: matchUpFinishingPositionRanges = {},
17829
+ participantMap,
17830
+ finishingRound,
17831
+ participantWon,
17832
+ matchUpStatus,
17833
+ participantId,
17834
+ stageSequence,
17835
+ roundNumber,
17836
+ structureId,
17837
+ matchUpId,
17838
+ drawId,
17839
+ stage
17840
+ }) {
17841
+ const participantAggregator = participantMap[participantId];
17842
+ const diff = (range) => Math.abs(range[0] - range[1]);
17843
+ if (!participantAggregator.structureParticipation[structureId]) {
17844
+ participantAggregator.structureParticipation[structureId] = {
17845
+ rankingStage: stage,
17846
+ walkoverWinCount: 0,
17847
+ defaultWinCount: 0,
17848
+ stageSequence,
17849
+ winCount: 0,
17850
+ structureId,
17851
+ drawId
17852
+ };
17853
+ }
17854
+ const structureParticipation = participantAggregator.structureParticipation[structureId];
17855
+ const { winner, loser } = matchUpFinishingPositionRanges;
17856
+ const finishingPositionRange = participantWon ? winner : loser;
17857
+ if (participantWon) {
17858
+ structureParticipation.winCount += 1;
17859
+ if (matchUpStatus === WALKOVER$1) {
17860
+ structureParticipation.walkoverWinCount += 1;
17861
+ }
17862
+ if (matchUpStatus === DEFAULTED) {
17863
+ structureParticipation.defaultWinCount += 1;
17864
+ }
17865
+ }
17866
+ if (finishingPositionRange && (!structureParticipation.finishingPositionRange || diff(finishingPositionRange) < diff(structureParticipation.finishingPositionRange))) {
17867
+ structureParticipation.finishingPositionRange = finishingPositionRange;
17868
+ }
17869
+ if (finishingRound) {
17870
+ if (!structureParticipation.finishingRound || finishingRound < structureParticipation.finishingRound) {
17871
+ structureParticipation.finishingMatchUpId = matchUpId;
17872
+ structureParticipation.finishingRound = finishingRound;
17873
+ structureParticipation.roundNumber = roundNumber;
17874
+ }
17875
+ if (finishingRound === 1) {
17876
+ structureParticipation.participantWon = participantWon;
17877
+ }
17878
+ }
17879
+ }
17880
+
17881
+ function processSides(params) {
17882
+ const {
17883
+ withScheduleTimes,
17884
+ scheduleAnalysis,
17885
+ withTeamMatchUps,
17886
+ participantMap,
17887
+ withOpponents,
17888
+ withMatchUps,
17889
+ withEvents,
17890
+ withDraws,
17891
+ finishingPositionRange,
17892
+ finishingRound,
17893
+ matchUpStatus,
17894
+ stageSequence,
17895
+ roundNumber,
17896
+ structureId,
17897
+ score,
17898
+ stage,
17899
+ withRankingProfile,
17900
+ tieWinningSide,
17901
+ roundPosition,
17902
+ matchUpTieId,
17903
+ matchUpSides,
17904
+ collectionId,
17905
+ matchUpType,
17906
+ winningSide,
17907
+ matchUpId,
17908
+ schedule,
17909
+ eventId,
17910
+ drawId,
17911
+ sides
17912
+ } = params;
17913
+ const opponents = withOpponents && sides?.length === 2 && Object.assign(
17914
+ {},
17915
+ ...sides.map(({ sideNumber }, i) => {
17916
+ const opponentParticipantId = sides[1 - i].participantId;
17917
+ return sideNumber && {
17918
+ [sideNumber]: opponentParticipantId
17919
+ };
17920
+ }).filter(Boolean)
17921
+ );
17922
+ for (const side of sides) {
17923
+ const { participantId, sideNumber, bye } = side;
17924
+ if (bye)
17925
+ continue;
17926
+ const participantWon = winningSide === sideNumber;
17927
+ const getOpponentInfo = (opponentParticipantId) => {
17928
+ const opponent = participantMap[opponentParticipantId]?.participant;
17929
+ const participantType = opponent?.participantType;
17930
+ const info = [
17931
+ {
17932
+ participantId: opponentParticipantId,
17933
+ participantType
18307
17934
  }
18308
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
18309
- participantIdMap[relevantParticipantId].events[eventId] = {
18310
- partnerParticipantIds: [],
18311
- drawIds: [],
18312
- eventName,
18313
- eventId
18314
- };
17935
+ ];
17936
+ if (participantType !== TEAM_PARTICIPANT) {
17937
+ for (const participantId2 of opponent?.individualParticipantIds || []) {
17938
+ const participant = participantMap[participantId2]?.participant;
17939
+ info.push({
17940
+ participantType: participant?.participantType,
17941
+ participantId: participantId2
17942
+ });
18315
17943
  }
18316
- const eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
18317
- if (eventDrawIds && !eventDrawIds?.includes(drawId)) {
18318
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(
18319
- drawId
17944
+ }
17945
+ return info;
17946
+ };
17947
+ const addMatchUp = (participantId2, opponentParticipantId) => {
17948
+ if (withMatchUps) {
17949
+ participantMap[participantId2].matchUps[matchUpId] = {
17950
+ participantWon,
17951
+ matchUpType,
17952
+ structureId,
17953
+ sideNumber,
17954
+ matchUpId,
17955
+ eventId,
17956
+ drawId,
17957
+ stage
17958
+ };
17959
+ if (withOpponents) {
17960
+ const opponentParticipantInfo = getOpponentInfo(
17961
+ opponentParticipantId
18320
17962
  );
17963
+ participantMap[participantId2].matchUps[matchUpId].opponentParticipantInfo = opponentParticipantInfo;
18321
17964
  }
18322
- let partnerParticipantId;
18323
- if (participantType === INDIVIDUAL && matchUpType === DOUBLES_MATCHUP) {
18324
- const relevantParticipantInfo = filteredRelevantParticipantIds.find(
18325
- (participantInfo) => {
18326
- return participantInfo.relevantParticipantId !== relevantParticipantId && participantInfo.participantType === INDIVIDUAL;
18327
- }
18328
- );
18329
- partnerParticipantId = relevantParticipantInfo?.relevantParticipantId;
17965
+ if (collectionId) {
17966
+ participantMap[participantId2].matchUps[matchUpId].collectionId = collectionId;
18330
17967
  }
18331
- const filteredRelevantOpponents = relevantOpponents?.filter(
18332
- (opponent2) => matchUpType === TEAM_MATCHUP && participantType === TEAM_PARTICIPANT && opponent2.participantType === TEAM_PARTICIPANT || matchUpType === SINGLES_MATCHUP && opponent2.participantType === INDIVIDUAL || matchUpType === DOUBLES_MATCHUP && (participantType === INDIVIDUAL ? [INDIVIDUAL, PAIR].includes(opponent2.participantType) : (
18333
- // for PAIR participants only show PAIR opponenents
18334
- opponent2.participantType === PAIR
18335
- ))
18336
- ) || [];
18337
- filteredRelevantOpponents.forEach(
18338
- ({
18339
- relevantParticipantId: opponentParticipantId2,
18340
- participantType: opponentParticipantType
18341
- }) => {
18342
- if (!participantIdMap[relevantParticipantId].opponents) {
18343
- participantIdMap[relevantParticipantId].opponents = {};
18344
- }
18345
- participantIdMap[relevantParticipantId].opponents[opponentParticipantId2] = {
18346
- eventId,
18347
- drawId,
18348
- matchUpId,
18349
- participantType: opponentParticipantType,
18350
- participantId: opponentParticipantId2
18351
- };
18352
- }
17968
+ }
17969
+ if (withOpponents && opponentParticipantId) {
17970
+ participantMap[participantId2].opponents[opponentParticipantId] = {
17971
+ participantId: opponentParticipantId,
17972
+ matchUpId,
17973
+ eventId,
17974
+ drawId
17975
+ };
17976
+ }
17977
+ if (withRankingProfile) {
17978
+ addStructureParticipation({
17979
+ finishingPositionRange,
17980
+ participantMap,
17981
+ participantWon,
17982
+ finishingRound,
17983
+ matchUpStatus,
17984
+ participantId: participantId2,
17985
+ stageSequence,
17986
+ roundNumber,
17987
+ structureId,
17988
+ matchUpId,
17989
+ drawId,
17990
+ stage
17991
+ });
17992
+ }
17993
+ if (scheduleAnalysis || withScheduleTimes) {
17994
+ addScheduleItem({
17995
+ participantMap,
17996
+ participantId: participantId2,
17997
+ matchUpStatus,
17998
+ roundPosition,
17999
+ matchUpType,
18000
+ roundNumber,
18001
+ structureId,
18002
+ matchUpId,
18003
+ schedule,
18004
+ drawId,
18005
+ score
18006
+ });
18007
+ }
18008
+ };
18009
+ const addPartner = ({ participant, partnerParticipantId }) => {
18010
+ const addPartnerParticiapntId = (element, partnerParticipantId2) => {
18011
+ if (element) {
18012
+ if (!element.partnerParticipantIds)
18013
+ element.partnerParticipantIds = [];
18014
+ if (!element.partnerParticipantIds.includes(partnerParticipantId2))
18015
+ element.partnerParticipantIds.push(partnerParticipantId2);
18016
+ }
18017
+ };
18018
+ if (withDraws)
18019
+ addPartnerParticiapntId(
18020
+ participant?.draws?.[drawId],
18021
+ partnerParticipantId
18353
18022
  );
18354
- const opponentParticipantInfo = filteredRelevantOpponents.map(
18355
- ({ relevantParticipantId: relevantParticipantId2, participantType: participantType2 }) => ({
18356
- participantId: relevantParticipantId2,
18357
- participantType: participantType2
18358
- })
18023
+ if (withEvents) {
18024
+ addPartnerParticiapntId(
18025
+ participant?.events?.[eventId],
18026
+ partnerParticipantId
18359
18027
  );
18360
- const includeMatchUp = matchUpType !== TEAM_MATCHUP && [INDIVIDUAL, PAIR].includes(participantType) || matchUpType === TEAM_MATCHUP && participantType === TEAM_PARTICIPANT;
18361
- if (includeMatchUp)
18362
- participantIdMap[relevantParticipantId].matchUps[matchUpId] = definedAttributes({
18363
- collectionId,
18364
- collectionPosition,
18365
- drawId,
18028
+ }
18029
+ if (withMatchUps) {
18030
+ addPartnerParticiapntId(
18031
+ participant?.matchUps?.[matchUpId],
18032
+ partnerParticipantId
18033
+ );
18034
+ }
18035
+ };
18036
+ if (participantId && participantMap[participantId]) {
18037
+ const opponentParticipantId = opponents?.[sideNumber];
18038
+ addMatchUp(participantId, opponentParticipantId);
18039
+ const isPair = participantMap[participantId]?.participant.participantType === PAIR;
18040
+ const individualParticipantIds = participantMap[participantId]?.participant.individualParticipantIds || [];
18041
+ if (matchUpTieId) {
18042
+ if (withTeamMatchUps) {
18043
+ const addTeamMatchUp = (participantId2) => participantMap[participantId2].matchUps[matchUpTieId] = {
18044
+ participantWon: tieWinningSide === sideNumber,
18045
+ matchUpType: TypeEnum.Team,
18046
+ matchUpId: matchUpTieId,
18047
+ sideNumber
18048
+ };
18049
+ addTeamMatchUp(participantId);
18050
+ individualParticipantIds.forEach(addTeamMatchUp);
18051
+ }
18052
+ if (withDraws && !participantMap[participantId].draws[drawId]) {
18053
+ const teamParticipantId = matchUpSides.find(
18054
+ (s) => s.sideNumber === sideNumber
18055
+ )?.participant?.participantId;
18056
+ const teamEntryStatus = participantMap[teamParticipantId]?.draws?.[drawId]?.entryStatus;
18057
+ const addDrawData = (participantId2) => participantMap[participantId2].draws[drawId] = {
18058
+ entryStatus: teamEntryStatus,
18059
+ // add positions played in lineUp collections
18366
18060
  eventId,
18367
- eventType,
18368
- eventDrawsCount,
18369
- finishingRound,
18370
- finishingPositionRange: finishingPositionRange2,
18371
- loserTo,
18372
- matchUpId,
18373
- matchUpType,
18374
- matchUpFormat,
18375
- matchUpStatus,
18376
- matchUpStatusCodes,
18377
- matchUpTieId,
18378
- opponentParticipantInfo,
18379
- participantWon,
18380
- partnerParticipantId,
18381
- perspectiveScoreString: participantScore,
18382
- processCodes,
18383
- roundName,
18384
- roundNumber,
18385
- roundPosition,
18386
- schedule,
18387
- score,
18388
- sides,
18389
- stage,
18390
- stageSequence,
18391
- structureName,
18392
- structureId,
18393
- tieFormat,
18394
- tournamentId,
18395
- winnerTo,
18396
- winningSide
18397
- });
18398
- if (partnerParticipantId) {
18399
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantIds.push(partnerParticipantId);
18400
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantIds.push(partnerParticipantId);
18401
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantId = partnerParticipantId;
18402
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantId = partnerParticipantId;
18061
+ drawId
18062
+ };
18063
+ addDrawData(participantId);
18064
+ individualParticipantIds.forEach(addDrawData);
18403
18065
  }
18404
- if (winningSide) {
18066
+ }
18067
+ if (isPair) {
18068
+ individualParticipantIds.forEach(
18069
+ (participantId2) => participantMap[participantId2] && addMatchUp(participantId2, opponentParticipantId)
18070
+ );
18071
+ individualParticipantIds.forEach((participantId2, i) => {
18072
+ const partnerParticipantId = individualParticipantIds[1 - i];
18073
+ const participant = participantMap[participantId2];
18074
+ participant && addPartner({ participant, partnerParticipantId });
18075
+ });
18076
+ if (withEvents && matchUpSides) {
18077
+ const teamParticipantId = matchUpSides.find(
18078
+ (s) => s.sideNumber === sideNumber
18079
+ )?.participant?.participantId;
18080
+ if (teamParticipantId) {
18081
+ const teamEntry = participantMap[teamParticipantId]?.events[eventId];
18082
+ if (teamEntry) {
18083
+ participantMap[participantId].events[eventId] = { ...teamEntry };
18084
+ individualParticipantIds.forEach(
18085
+ (individualParticiapntId) => participantMap[individualParticiapntId].events[eventId] = {
18086
+ ...teamEntry
18087
+ }
18088
+ );
18089
+ } else {
18090
+ console.log("Missing teamEntry", { eventId, teamParticipantId });
18091
+ }
18092
+ }
18093
+ }
18094
+ }
18095
+ if (winningSide) {
18096
+ const processParticipantId = (id) => {
18405
18097
  if (participantWon) {
18406
- participantIdMap[relevantParticipantId].wins++;
18098
+ participantMap[id].counters[matchUpType].wins += 1;
18099
+ participantMap[id].counters.wins += 1;
18100
+ if (matchUpStatus === WALKOVER$1) {
18101
+ participantMap[id].counters[matchUpType].walkoverWins += 1;
18102
+ participantMap[id].counters.walkoverWins += 1;
18103
+ }
18104
+ if (matchUpStatus === DEFAULTED) {
18105
+ participantMap[id].counters[matchUpType].defaultWins += 1;
18106
+ participantMap[id].counters.defaultWins += 1;
18107
+ }
18407
18108
  } else {
18408
- participantIdMap[relevantParticipantId].losses++;
18109
+ participantMap[id].counters[matchUpType].losses += 1;
18110
+ participantMap[id].counters.losses += 1;
18111
+ if (matchUpStatus === WALKOVER$1) {
18112
+ participantMap[id].counters[matchUpType].walkovers += 1;
18113
+ participantMap[id].counters.walkovers += 1;
18114
+ }
18115
+ if (matchUpStatus === DEFAULTED) {
18116
+ participantMap[id].counters[matchUpType].defaults += 1;
18117
+ participantMap[id].counters.defaults += 1;
18118
+ }
18409
18119
  }
18410
- }
18120
+ };
18121
+ processParticipantId(participantId);
18122
+ individualParticipantIds.forEach(processParticipantId);
18411
18123
  }
18412
- );
18413
- });
18414
- if (Array.isArray(matchUp.potentialParticipants)) {
18415
- const potentialParticipantIds = getParticipantIds(
18416
- matchUp.potentialParticipants.flat()
18417
- );
18418
- potentialParticipantIds?.forEach((participantId) => {
18419
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
18420
- relevantParticipantIds?.forEach(({ relevantParticipantId }) => {
18421
- participantIdMap[relevantParticipantId].potentialMatchUps[matchUpId] = definedAttributes({
18422
- drawId,
18423
- eventId,
18424
- eventType,
18425
- matchUpId,
18426
- matchUpType,
18427
- matchUpFormat,
18428
- roundName,
18429
- roundNumber,
18430
- roundPosition,
18431
- schedule,
18432
- tieFormat,
18433
- structureName,
18434
- tournamentId,
18435
- potential: true
18436
- });
18437
- });
18438
- });
18124
+ }
18439
18125
  }
18440
18126
  }
18441
18127
 
18442
- function addParticipantContext(params) {
18443
- const participantIdsWithConflicts = [];
18444
- const eventsPublishStatuses = {};
18445
- const derivedDrawInfo = {};
18446
- const participantIdMap = {};
18447
- const initializeParticipantId = (participantId) => {
18448
- if (!participantIdMap[participantId])
18449
- participantIdMap[participantId] = {
18450
- groupParticipantIds: [],
18451
- teamParticipantIds: [],
18452
- pairParticipantIds: [],
18453
- potentialMatchUps: {},
18454
- scheduleItems: [],
18455
- opponents: {},
18456
- matchUps: {},
18457
- events: {},
18458
- groups: [],
18459
- teams: [],
18460
- draws: {},
18461
- losses: 0,
18462
- wins: 0
18463
- };
18464
- };
18465
- const { tournamentRecord, participantFilters, allTournamentParticipants } = params;
18466
- const { relevantParticipantIdsMap } = getRelevantParticipantIdsMap({
18467
- processParticipantId: initializeParticipantId,
18468
- tournamentRecord
18469
- });
18128
+ function getParticipantEntries(params) {
18129
+ const {
18130
+ participantFilters,
18131
+ convertExtensions,
18132
+ policyDefinitions,
18133
+ tournamentRecord,
18134
+ usePublishState,
18135
+ contextProfile,
18136
+ participantMap,
18137
+ withPotentialMatchUps,
18138
+ withRankingProfile,
18139
+ withScheduleTimes,
18140
+ withScheduleItems,
18141
+ scheduleAnalysis,
18142
+ withTeamMatchUps,
18143
+ withStatistics,
18144
+ withOpponents,
18145
+ withMatchUps,
18146
+ withSeeding,
18147
+ withEvents,
18148
+ withDraws
18149
+ } = params;
18150
+ if (withScheduleItems)
18151
+ console.log({ withScheduleItems });
18470
18152
  const targetParticipantIds = participantFilters?.participantIds;
18471
18153
  const getRelevantParticipantIds = (participantId) => {
18472
- const relevantParticipantIds = participantId && relevantParticipantIdsMap[participantId] || [];
18154
+ const relevantParticipantIds = [participantId];
18473
18155
  relevantParticipantIds.push(participantId);
18156
+ participantMap[participantId]?.participant.individualParticipantIds?.forEach(
18157
+ (individualParticiapntId) => relevantParticipantIds.push(individualParticiapntId)
18158
+ );
18474
18159
  return relevantParticipantIds.some(
18475
- (obj) => !targetParticipantIds || targetParticipantIds.includes(obj.relevantParticipantId)
18160
+ (obj) => !targetParticipantIds?.length || targetParticipantIds.includes(obj.relevantParticipantId)
18476
18161
  ) ? relevantParticipantIds : [];
18477
18162
  };
18478
- params.withGroupings && allTournamentParticipants.forEach((participant) => {
18479
- if (participant.participantType === GROUP) {
18480
- const groupParticipantId = participant.participantId;
18481
- participant?.individualParticipantIds?.forEach((participantId) => {
18482
- if (!participantIdMap[participantId].groupParticipantIds.includes(
18483
- groupParticipantId
18484
- )) {
18485
- participantIdMap[participantId].groupParticipantIds.push(
18486
- groupParticipantId
18487
- );
18488
- participantIdMap[participantId].groups.push({
18489
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
18490
- participantOtherName: participant.participantOtherName,
18491
- participantName: participant.participantName,
18492
- participantId: participant.participantId
18493
- });
18163
+ const withOpts = {
18164
+ withMatchUps: withMatchUps || withRankingProfile,
18165
+ withEvents: withEvents || withRankingProfile,
18166
+ withDraws: withDraws || withRankingProfile,
18167
+ withPotentialMatchUps,
18168
+ withRankingProfile,
18169
+ withScheduleTimes,
18170
+ scheduleAnalysis,
18171
+ withTeamMatchUps,
18172
+ withStatistics,
18173
+ participantMap,
18174
+ withOpponents,
18175
+ withSeeding
18176
+ };
18177
+ const participantIdsWithConflicts = [];
18178
+ const mappedMatchUps = {};
18179
+ const matchUps = [];
18180
+ const eventsPublishStatuses = {};
18181
+ const derivedEventInfo = {};
18182
+ const derivedDrawInfo = {};
18183
+ const getRanking = ({ eventType, scaleNames, participantId }) => participantMap[participantId].participant?.rankings?.[eventType]?.find(
18184
+ (ranking) => scaleNames.includes(ranking.scaleName)
18185
+ )?.scaleValue;
18186
+ for (const event of tournamentRecord?.events || []) {
18187
+ if (participantFilters?.eventIds && !participantFilters.eventIds.includes(event.eventId))
18188
+ continue;
18189
+ const {
18190
+ drawDefinitions = [],
18191
+ extensions = [],
18192
+ eventType,
18193
+ eventName,
18194
+ category,
18195
+ entries,
18196
+ eventId,
18197
+ gender
18198
+ } = event;
18199
+ const { flightProfile } = getFlightProfile({ event });
18200
+ const flights = flightProfile?.flights ?? [];
18201
+ const publishStatuses = getEventPublishStatuses({ event });
18202
+ const publishedSeeding = publishStatuses?.publishedSeeding;
18203
+ if (publishStatuses)
18204
+ eventsPublishStatuses[eventId] = publishStatuses;
18205
+ if (withEvents || withSeeding || withRankingProfile) {
18206
+ const extensionConversions = convertExtensions ? Object.assign({}, ...extensionsToAttributes(extensions)) : {};
18207
+ derivedEventInfo[eventId] = {
18208
+ ...extensionConversions,
18209
+ eventName,
18210
+ eventType,
18211
+ category,
18212
+ eventId,
18213
+ gender
18214
+ };
18215
+ const scaleNames = [
18216
+ category?.categoryName,
18217
+ category?.ageCategoryCode
18218
+ ].filter(Boolean);
18219
+ for (const entry of entries) {
18220
+ const { participantId } = entry;
18221
+ if (!participantId || !participantMap[participantId])
18222
+ continue;
18223
+ const ranking = getRanking({ eventType, scaleNames, participantId });
18224
+ let seedAssignments, seedValue;
18225
+ if (withSeeding) {
18226
+ const participant = participantMap[participantId].participant;
18227
+ ({ seedAssignments, seedValue } = getEventSeedAssignments({
18228
+ publishedSeeding,
18229
+ usePublishState,
18230
+ withSeeding,
18231
+ participant,
18232
+ event
18233
+ }));
18494
18234
  }
18495
- });
18235
+ const addEventEntry = (id) => {
18236
+ if (participantMap[id]?.events?.[eventId])
18237
+ return;
18238
+ const participant = participantMap[id];
18239
+ processEventEntry({
18240
+ extensionConversions,
18241
+ seedAssignments,
18242
+ participant,
18243
+ withSeeding,
18244
+ seedValue,
18245
+ eventId,
18246
+ ranking,
18247
+ entry
18248
+ });
18249
+ };
18250
+ addEventEntry(participantId);
18251
+ const individualParticipantIds = participantMap[participantId].participant.individualParticipantIds || [];
18252
+ individualParticipantIds.forEach(addEventEntry);
18253
+ }
18496
18254
  }
18497
- if (participant.participantType === TEAM$2) {
18498
- const teamParticipantId = participant.participantId;
18499
- participant?.individualParticipantIds?.forEach((participantId) => {
18500
- if (!participantIdMap[participantId]?.teamParticipantIds?.includes(
18501
- teamParticipantId
18502
- )) {
18503
- participantIdMap[participantId]?.teamParticipantIds.push(
18504
- teamParticipantId
18505
- );
18506
- participantIdMap[participantId]?.teams.push({
18507
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
18508
- participantOtherName: participant.participantOtherName,
18509
- participantName: participant.participantName,
18510
- participantId: participant.participantId,
18511
- teamId: participant.teamId
18255
+ const eventPublishedSeeding = eventsPublishStatuses?.[eventId]?.publishedSeeding;
18256
+ if (withDraws || withRankingProfile || withSeeding) {
18257
+ const getSeedingMap = (assignments) => assignments ? Object.assign(
18258
+ {},
18259
+ ...assignments.map(
18260
+ ({ participantId, seedValue, seedNumber }) => ({
18261
+ [participantId]: { seedValue, seedNumber }
18262
+ })
18263
+ )
18264
+ ) : void 0;
18265
+ const drawIds = unique([
18266
+ ...drawDefinitions.map(extractAttributes("drawId")),
18267
+ ...flights.map(extractAttributes("drawId"))
18268
+ ]);
18269
+ for (const drawId of drawIds) {
18270
+ const drawDefinition = drawDefinitions.find(
18271
+ (drawDefinition2) => drawDefinition2.drawId === drawId
18272
+ );
18273
+ const flight = flights?.find((flight2) => flight2.drawId === drawId);
18274
+ const entries2 = drawDefinition?.entries || flight?.drawEntries;
18275
+ const {
18276
+ structures = [],
18277
+ drawOrder,
18278
+ drawName,
18279
+ drawType
18280
+ } = drawDefinition ?? {};
18281
+ const flightNumber = flight?.flightNumber;
18282
+ const scaleNames = [
18283
+ category?.categoryName,
18284
+ category?.ageCategoryCode
18285
+ ].filter(Boolean);
18286
+ const orderedStructureIds = (drawDefinition?.structures || []).sort((a, b) => structureSort(a, b)).map(({ structureId, structures: structures2 }) => {
18287
+ return [
18288
+ structureId,
18289
+ ...(structures2 || []).map(({ structureId: structureId2 }) => structureId2)
18290
+ ];
18291
+ }).flat(Infinity);
18292
+ let qualifyingPositionAssignments, qualifyingSeedAssignments, mainPositionAssignments, mainSeedAssignments, drawSize = 0;
18293
+ const assignedParticipantIds = structures.filter(
18294
+ ({ stage, stageSequence }) => stage === MAIN && stageSequence === 1 || stage === QUALIFYING
18295
+ ).flatMap((structure) => {
18296
+ const { seedAssignments, stageSequence, stage } = structure;
18297
+ const { positionAssignments } = getPositionAssignments({
18298
+ structure
18512
18299
  });
18300
+ if (stage === MAIN) {
18301
+ drawSize = positionAssignments?.length ?? 0;
18302
+ mainPositionAssignments = positionAssignments;
18303
+ mainSeedAssignments = seedAssignments;
18304
+ } else if (stageSequence === 1) {
18305
+ qualifyingPositionAssignments = positionAssignments;
18306
+ qualifyingSeedAssignments = seedAssignments;
18307
+ }
18308
+ return positionAssignments;
18309
+ }).map(({ participantId }) => participantId).filter(Boolean);
18310
+ const mainSeedingMap = getSeedingMap(mainSeedAssignments);
18311
+ const qualifyingSeedingMap = getSeedingMap(qualifyingSeedAssignments);
18312
+ const relevantEntries = !drawDefinition ? entries2 : entries2.filter(
18313
+ ({ participantId }) => assignedParticipantIds.includes(participantId)
18314
+ );
18315
+ const seedingPublished = !usePublishState || eventPublishedSeeding?.published && (eventPublishedSeeding?.drawIds?.length === 0 || eventPublishedSeeding?.drawIds?.includes(drawId));
18316
+ for (const entry of relevantEntries) {
18317
+ const { entryStatus, entryStage, entryPosition, participantId } = entry;
18318
+ const ranking = getRanking({
18319
+ participantId,
18320
+ scaleNames,
18321
+ eventType
18322
+ });
18323
+ const addDrawEntry = (id) => {
18324
+ if (participantMap[id].draws?.[drawId])
18325
+ return;
18326
+ const includeSeeding = withSeeding && seedingPublished;
18327
+ const seedAssignments = includeSeeding ? {} : void 0;
18328
+ const mainSeeding = includeSeeding ? mainSeedingMap?.[participantId]?.seedValue || mainSeedingMap?.[participantId]?.seedNumber : void 0;
18329
+ const mainSeedingAssignments = mainSeeding ? mainSeedingMap?.[participantId] : void 0;
18330
+ const qualifyingSeeding = includeSeeding ? qualifyingSeedingMap?.[participantId]?.seedValue || qualifyingSeedingMap?.[participantId]?.seedNumber : void 0;
18331
+ const qualifyingSeedingAssignments = qualifyingSeeding ? qualifyingSeedingMap?.[participantId] : void 0;
18332
+ if (seedAssignments && mainSeeding)
18333
+ seedAssignments[MAIN] = mainSeedingAssignments;
18334
+ if (seedAssignments && qualifyingSeeding)
18335
+ seedAssignments[QUALIFYING] = qualifyingSeedingAssignments;
18336
+ const seedValue = mainSeeding || qualifyingSeeding;
18337
+ if (seedValue) {
18338
+ if (!participantMap[id].participant.seedings[eventType])
18339
+ participantMap[id].participant.seedings[eventType] = [];
18340
+ if (mainSeedingAssignments) {
18341
+ participantMap[id].participant.seedings[eventType].push({
18342
+ ...mainSeedingAssignments,
18343
+ scaleName: drawId
18344
+ });
18345
+ }
18346
+ if (qualifyingSeedingAssignments) {
18347
+ participantMap[id].participant.seedings[eventType].push({
18348
+ ...qualifyingSeedingAssignments,
18349
+ scaleName: drawId
18350
+ });
18351
+ }
18352
+ if (seedAssignments) {
18353
+ if (!participantMap[id].events[eventId].seedAssignments)
18354
+ participantMap[id].events[eventId].seedAssignments = {};
18355
+ Object.keys(seedAssignments).forEach(
18356
+ (stage) => participantMap[id].events[eventId].seedAssignments[stage] = seedAssignments[stage]
18357
+ );
18358
+ }
18359
+ }
18360
+ if ((withEvents || withRankingProfile) && participantMap[id] && eventId) {
18361
+ if (!participantMap[id].events[eventId])
18362
+ participantMap[id].events[eventId] = {};
18363
+ if (includeSeeding) {
18364
+ participantMap[id].events[eventId].seedValue = seedValue;
18365
+ } else if (participantMap[id].events[eventId].seedValue) {
18366
+ participantMap[id].events[eventId].seedValue = void 0;
18367
+ }
18368
+ }
18369
+ if (withDraws || withRankingProfile) {
18370
+ participantMap[id].draws[drawId] = definedAttributes(
18371
+ {
18372
+ seedAssignments,
18373
+ entryPosition,
18374
+ entryStatus,
18375
+ entryStage,
18376
+ eventId,
18377
+ ranking,
18378
+ drawId
18379
+ },
18380
+ false,
18381
+ false,
18382
+ true
18383
+ );
18384
+ }
18385
+ };
18386
+ if (![UNGROUPED, UNPAIRED].includes(entryStatus)) {
18387
+ addDrawEntry(participantId);
18388
+ const individualParticipantIds = participantMap[participantId].participant.individualParticipantIds || [];
18389
+ individualParticipantIds?.forEach(addDrawEntry);
18390
+ }
18513
18391
  }
18514
- });
18392
+ derivedDrawInfo[drawId] = {
18393
+ qualifyingPositionAssignments,
18394
+ qualifyingSeedAssignments,
18395
+ mainPositionAssignments,
18396
+ qualifyingSeedingMap,
18397
+ mainSeedAssignments,
18398
+ orderedStructureIds,
18399
+ mainSeedingMap,
18400
+ flightNumber,
18401
+ drawOrder,
18402
+ drawName,
18403
+ drawType,
18404
+ drawSize,
18405
+ drawId
18406
+ // qualifyingDrawSize,
18407
+ };
18408
+ }
18515
18409
  }
18516
- if (participant.participantType === PAIR) {
18517
- const pairParticipantId = participant.participantId;
18518
- participant?.individualParticipantIds?.forEach((participantId) => {
18519
- if (participantIdMap[participantId] && !participantIdMap[participantId].pairParticipantIds.includes(
18520
- pairParticipantId
18521
- )) {
18522
- participantIdMap[participantId].pairParticipantIds.push(
18523
- pairParticipantId
18524
- );
18410
+ if (withRankingProfile || scheduleAnalysis || withTeamMatchUps || withStatistics || withOpponents || withMatchUps || withDraws) {
18411
+ const nextMatchUps = !!scheduleAnalysis || withPotentialMatchUps;
18412
+ const eventMatchUps = allEventMatchUps({
18413
+ afterRecoveryTimes: !!scheduleAnalysis,
18414
+ policyDefinitions,
18415
+ tournamentRecord,
18416
+ inContext: true,
18417
+ contextProfile,
18418
+ participantMap,
18419
+ nextMatchUps,
18420
+ event
18421
+ })?.matchUps ?? [];
18422
+ for (const matchUp of eventMatchUps) {
18423
+ const {
18424
+ finishingPositionRange,
18425
+ potentialParticipants,
18426
+ tieMatchUps = [],
18427
+ sides = [],
18428
+ winningSide,
18429
+ matchUpType,
18430
+ matchUpId,
18431
+ eventId: eventId2,
18432
+ drawId,
18433
+ collectionId,
18434
+ stageSequence,
18435
+ finishingRound,
18436
+ matchUpStatus,
18437
+ roundPosition,
18438
+ roundNumber,
18439
+ structureId,
18440
+ schedule,
18441
+ score,
18442
+ stage
18443
+ } = matchUp;
18444
+ mappedMatchUps[matchUpId] = matchUp;
18445
+ const baseAttrs = {
18446
+ finishingPositionRange,
18447
+ finishingRound,
18448
+ stageSequence,
18449
+ roundPosition,
18450
+ collectionId,
18451
+ roundNumber,
18452
+ structureId,
18453
+ schedule,
18454
+ eventId: eventId2,
18455
+ drawId,
18456
+ score,
18457
+ stage
18458
+ };
18459
+ processSides({
18460
+ ...baseAttrs,
18461
+ ...withOpts,
18462
+ matchUpStatus,
18463
+ winningSide,
18464
+ matchUpType,
18465
+ matchUpId,
18466
+ sides
18467
+ });
18468
+ for (const tieMatchUp of tieMatchUps) {
18469
+ const {
18470
+ winningSide: tieMatchUpWinningSide,
18471
+ sides: tieMatchUpSides = [],
18472
+ matchUpId: tieMatchUpId,
18473
+ matchUpStatus: matchUpStatus2,
18474
+ matchUpType: matchUpType2
18475
+ } = tieMatchUp;
18476
+ processSides({
18477
+ ...baseAttrs,
18478
+ ...withOpts,
18479
+ winningSide: tieMatchUpWinningSide,
18480
+ tieWinningSide: winningSide,
18481
+ matchUpTieId: matchUpId,
18482
+ matchUpId: tieMatchUpId,
18483
+ sides: tieMatchUpSides,
18484
+ matchUpSides: sides,
18485
+ matchUpStatus: matchUpStatus2,
18486
+ matchUpType: matchUpType2
18487
+ });
18525
18488
  }
18526
- });
18527
- }
18528
- });
18529
- if (params.withMatchUps) {
18530
- getMatchUpDependencies({ tournamentRecord });
18531
- }
18532
- if (params.withScheduleItems || params.scheduleAnalysis || params.withStatistics || params.withOpponents || params.withMatchUps || params.withSeeding || params.withEvents || params.withDraws) {
18533
- params.tournamentEvents?.forEach((rawEvent) => {
18534
- const event = makeDeepCopy(rawEvent, true, true);
18535
- const flightProfile = getFlightProfile({ event }).flightProfile;
18536
- const eventDrawsCount = flightProfile?.flights?.length || event.drawDefinitions?.length || 0;
18537
- (event.drawDefinitions || []).forEach((drawDefinition, i) => {
18538
- if (event?.eventType === TEAM$2) {
18539
- const { extension } = findExtension$1({
18540
- element: rawEvent.drawDefinitions[i],
18541
- // rawEvent because deepCopy has converted extensions
18542
- name: LINEUPS
18489
+ if (Array.isArray(potentialParticipants) && (nextMatchUps || !!scheduleAnalysis || withScheduleTimes)) {
18490
+ const potentialParticipantIds = potentialParticipants.flat().map(extractAttributes("participantId")).filter(Boolean);
18491
+ potentialParticipantIds?.forEach((participantId) => {
18492
+ const relevantParticipantIds = getRelevantParticipantIds(participantId);
18493
+ relevantParticipantIds?.forEach((relevantParticipantId) => {
18494
+ if (!participantMap[relevantParticipantId]) {
18495
+ return;
18496
+ }
18497
+ participantMap[relevantParticipantId].potentialMatchUps[matchUpId] = definedAttributes({
18498
+ tournamentId: tournamentRecord?.tournamentId,
18499
+ matchUpId,
18500
+ eventId: eventId2,
18501
+ drawId
18502
+ });
18503
+ });
18504
+ if (!!scheduleAnalysis || withScheduleTimes) {
18505
+ addScheduleItem({
18506
+ potential: true,
18507
+ participantMap,
18508
+ participantId,
18509
+ matchUpStatus,
18510
+ roundPosition,
18511
+ structureId,
18512
+ matchUpType,
18513
+ roundNumber,
18514
+ matchUpId,
18515
+ schedule,
18516
+ drawId,
18517
+ score
18518
+ });
18519
+ }
18543
18520
  });
18544
- if (extension)
18545
- drawDefinition.extensions = [extension];
18546
18521
  }
18547
- });
18548
- const { eventId, eventName, eventType, category } = event;
18549
- const eventInfo = { eventId, eventName, eventType, category };
18550
- const extensionKeys = event && Object.keys(event).filter((key) => key.startsWith("_"));
18551
- extensionKeys?.forEach(
18552
- (extensionKey) => eventInfo[extensionKey] = event[extensionKey]
18553
- );
18554
- const eventEntries = event.entries || [];
18555
- const itemType = `${PUBLISH}.${STATUS}`;
18556
- const { timeItem } = getEventTimeItem({
18557
- itemType,
18558
- event
18559
- });
18560
- if (timeItem?.itemValue?.PUBLIC) {
18561
- const { drawIds: publishedDrawIds = [], seeding } = timeItem.itemValue.PUBLIC || {};
18562
- const publishedSeeding = {
18563
- published: void 0,
18564
- // seeding can be present for all entries in an event when no flights have been defined
18565
- seedingScaleNames: [],
18566
- drawIds: []
18567
- // seeding can be specific to drawIds
18568
- };
18569
- if (seeding)
18570
- Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
18571
- eventsPublishStatuses[eventId] = {
18572
- publishedDrawIds,
18573
- publishedSeeding
18522
+ }
18523
+ matchUps.push(...eventMatchUps);
18524
+ }
18525
+ }
18526
+ if (withStatistics || withRankingProfile || !!scheduleAnalysis) {
18527
+ const aggregators = Object.values(participantMap);
18528
+ for (const participantAggregator of aggregators) {
18529
+ const {
18530
+ wins,
18531
+ losses,
18532
+ [SINGLES$1]: { wins: singlesWins, losses: singlesLosses },
18533
+ [DOUBLES$1]: { wins: doublesWins, losses: doublesLosses }
18534
+ } = participantAggregator.counters;
18535
+ const addStatValue = (statCode, wins2, losses2) => {
18536
+ const denominator = wins2 + losses2;
18537
+ const numerator = wins2;
18538
+ const statValue = denominator && numerator / denominator;
18539
+ participantAggregator.statistics[statCode] = {
18540
+ denominator,
18541
+ numerator,
18542
+ statValue,
18543
+ statCode
18574
18544
  };
18545
+ };
18546
+ if (withStatistics) {
18547
+ addStatValue(WIN_RATIO$1, wins, losses);
18548
+ addStatValue(`${WIN_RATIO$1}.${SINGLES$1}`, singlesWins, singlesLosses);
18549
+ addStatValue(`${WIN_RATIO$1}.${DOUBLES$1}`, doublesWins, doublesLosses);
18575
18550
  }
18576
- const disallowedConstants = [
18577
- ...Object.values(extensionConstants)
18578
- ];
18579
- const disallowedKeys = disallowedConstants.map(
18580
- (constant) => `_${constant}`
18581
- );
18582
- const filteredEventInfo = eventInfo && Object.keys(eventInfo).filter((key) => !disallowedKeys.includes(key)).reduce((obj, key) => {
18583
- obj[key] = eventInfo[key];
18584
- return obj;
18585
- }, {});
18586
- eventEntries?.filter((entry) => entry?.participantId).forEach((entry) => {
18587
- const { participantId, entryStage, entryStatus, entryPosition } = entry;
18588
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
18589
- relevantParticipantIds?.forEach(({ relevantParticipantId }) => {
18590
- if (!participantIdMap[relevantParticipantId])
18591
- initializeParticipantId(relevantParticipantId);
18592
- participantIdMap[relevantParticipantId].events[eventId] = {
18593
- ...filteredEventInfo,
18594
- partnerParticipantIds: [],
18595
- entryPosition,
18596
- entryStatus,
18597
- entryStage,
18598
- drawIds: [],
18599
- eventId
18600
- };
18601
- });
18602
- });
18603
- const addDrawData = ({ drawEntry, drawId }) => {
18604
- const { participantId, entryStage, entryStatus, entryPosition } = drawEntry;
18605
- const relevantParticipantIds = getRelevantParticipantIds(participantId);
18606
- relevantParticipantIds?.forEach(({ relevantParticipantId }) => {
18607
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
18608
- participantIdMap[relevantParticipantId].events[eventId] = {
18609
- ...filteredEventInfo,
18610
- partnerParticipantIds: [],
18611
- entryPosition,
18612
- entryStatus,
18613
- entryStage,
18614
- drawIds: [],
18615
- eventId
18616
- };
18617
- }
18618
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
18619
- const positionAssignments = getDerivedPositionAssignments({
18620
- participantId: relevantParticipantId,
18621
- derivedDrawInfo,
18622
- drawId
18623
- });
18624
- const seedAssignments = getDerivedSeedAssignments({
18625
- participantId: relevantParticipantId,
18626
- derivedDrawInfo,
18627
- drawId
18628
- });
18629
- participantIdMap[relevantParticipantId].draws[drawId] = definedAttributes({
18630
- qualifyingDrawSize: derivedDrawInfo[drawId]?.qualifyingDrawSize,
18631
- drawSize: derivedDrawInfo[drawId]?.drawSize,
18632
- partnerParticipantIds: [],
18633
- positionAssignments,
18634
- eventDrawsCount,
18635
- seedAssignments,
18636
- entryPosition,
18637
- entryStatus,
18638
- entryStage,
18639
- eventId,
18640
- drawId
18641
- });
18642
- }
18643
- const eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
18644
- if (eventDrawIds && !eventDrawIds?.includes(drawId)) {
18645
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
18551
+ if (withRankingProfile) {
18552
+ const diff = (range = []) => Math.abs(range[0] - range[1]);
18553
+ for (const drawId of Object.keys(participantAggregator.draws)) {
18554
+ const { orderedStructureIds = [], flightNumber } = derivedDrawInfo[drawId] || {};
18555
+ if (participantAggregator.structureParticipation && orderedStructureIds.length) {
18556
+ let finishingPositionRange;
18557
+ let nonQualifyingOrder = 0;
18558
+ const orderedParticipation = orderedStructureIds.map((structureId) => {
18559
+ const participation = participantAggregator.structureParticipation[structureId];
18560
+ if (!participation)
18561
+ return;
18562
+ if (!finishingPositionRange)
18563
+ finishingPositionRange = participation?.finishingPositionRange;
18564
+ if (diff(finishingPositionRange) > diff(participation?.finishingPositionRange))
18565
+ finishingPositionRange = participation?.finishingPositionRange;
18566
+ const notQualifying = participation.stage !== QUALIFYING;
18567
+ if (notQualifying)
18568
+ nonQualifyingOrder += 1;
18569
+ const participationOrder = notQualifying ? nonQualifyingOrder : void 0;
18570
+ return definedAttributes({
18571
+ ...participation,
18572
+ participationOrder,
18573
+ flightNumber
18574
+ });
18575
+ }).filter(Boolean);
18576
+ if (participantAggregator.draws[drawId]) {
18577
+ participantAggregator.draws[drawId].finishingPositionRange = finishingPositionRange;
18578
+ participantAggregator.draws[drawId].structureParticipation = orderedParticipation;
18579
+ }
18646
18580
  }
18647
- });
18648
- };
18649
- const drawIdsWithDefinitions = event.drawDefinitions?.map(({ drawId }) => drawId) || [];
18650
- eventInfo._flightProfile?.flights?.forEach((flight) => {
18651
- const { drawId, drawEntries } = flight;
18652
- if (!drawIdsWithDefinitions.includes(drawId)) {
18653
- drawEntries?.forEach(
18654
- (drawEntry) => addDrawData({ drawEntry, drawId })
18655
- );
18656
18581
  }
18657
- });
18658
- const { drawDetails, derivedInfo } = getDrawDetails({
18659
- eventEntries,
18660
- event
18661
- });
18662
- Object.assign(derivedDrawInfo, derivedInfo);
18663
- if (event.eventType === TEAM$2 || // for TEAM events some individual attributes can only be derived by processing
18664
- params.withScheduleItems || params.scheduleAnalysis || params.withStatistics || params.withOpponents || params.withMatchUps || params.withDraws) {
18665
- const matchUps = allEventMatchUps({
18666
- afterRecoveryTimes: params.scheduleAnalysis,
18667
- participants: allTournamentParticipants,
18668
- nextMatchUps: true,
18669
- tournamentRecord,
18670
- inContext: true,
18671
- event
18672
- })?.matchUps;
18673
- matchUps?.forEach(
18674
- (matchUp) => processMatchUp({
18675
- relevantParticipantIdsMap,
18676
- participantFilters,
18677
- participantIdMap,
18678
- derivedDrawInfo,
18679
- eventDrawsCount,
18680
- drawDetails,
18681
- eventType,
18682
- matchUp
18683
- })
18684
- );
18685
18582
  }
18686
- });
18687
- }
18688
- params.tournamentParticipants?.forEach((participant) => {
18689
- const { scheduleConflicts, scheduleItems } = annotateParticipant({
18690
- ...params,
18691
- eventsPublishStatuses,
18692
- participantIdMap,
18693
- derivedDrawInfo,
18694
- participant
18695
- });
18696
- if (params.withSignInStatus) {
18697
- const { timeItem } = getTimeItem({
18698
- itemType: SIGN_IN_STATUS,
18699
- element: participant
18700
- });
18701
- participant.signedIn = timeItem?.itemValue === SIGNED_IN;
18702
- }
18703
- if (params.withScheduleItems) {
18704
- participant.scheduleItems = scheduleItems;
18705
- }
18706
- if (params.scheduleAnalysis) {
18707
- participant.scheduleConflicts = scheduleConflicts;
18708
- if (scheduleConflicts?.length && !participantIdsWithConflicts.includes(participant.participantId)) {
18709
- participantIdsWithConflicts.push(participant.participantId);
18583
+ if (scheduleAnalysis) {
18584
+ const scheduledMinutesDifference = isObject(scheduleAnalysis) ? scheduleAnalysis.scheduledMinutesDifference : 0;
18585
+ const scheduleItems = participantAggregator.scheduleItems || [];
18586
+ const potentialMatchUps = participantAggregator.potentialMatchUps || {};
18587
+ const dateItems = scheduleItems.reduce((dateItems2, scheduleItem) => {
18588
+ const { scheduledDate, scheduledTime } = scheduleItem;
18589
+ if (!dateItems2[scheduledDate])
18590
+ dateItems2[scheduledDate] = [];
18591
+ if (scheduledTime)
18592
+ dateItems2[scheduledDate].push(scheduleItem);
18593
+ return dateItems2;
18594
+ }, {});
18595
+ Object.values(dateItems).forEach((items) => items.sort(timeSort));
18596
+ for (const scheduleItem of scheduleItems) {
18597
+ const {
18598
+ typeChangeTimeAfterRecovery,
18599
+ timeAfterRecovery,
18600
+ scheduledDate,
18601
+ scheduledTime
18602
+ } = scheduleItem;
18603
+ const scheduleItemsToConsider = dateItems[scheduledDate];
18604
+ const scheduledMinutes = timeStringMinutes(scheduledTime);
18605
+ for (const consideredItem of scheduleItemsToConsider) {
18606
+ const ignoreItem = consideredItem.matchUpId === scheduleItem.matchUpId || [WALKOVER$1, DEFAULTED].includes(consideredItem.matchUpStatus) && !consideredItem.scoreHasValue;
18607
+ if (ignoreItem)
18608
+ continue;
18609
+ const typeChange = scheduleItem.matchUpType !== consideredItem.matchUpType;
18610
+ const notBeforeTime = typeChange ? typeChangeTimeAfterRecovery || timeAfterRecovery : timeAfterRecovery;
18611
+ const sameDraw = scheduleItem.drawId === consideredItem.drawId;
18612
+ const bothPotential = potentialMatchUps[scheduleItem.matchUpId] && potentialMatchUps[consideredItem.matchUpId];
18613
+ const nextMinutes = timeStringMinutes(consideredItem.scheduledTime);
18614
+ const minutesDifference = Math.abs(nextMinutes - scheduledMinutes);
18615
+ const timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference) ? minutesDifference <= scheduledMinutesDifference : timeStringMinutes(notBeforeTime) > timeStringMinutes(consideredItem.scheduledTime);
18616
+ if (timeOverlap && !(bothPotential && sameDraw)) {
18617
+ participantAggregator.scheduleConflicts.push({
18618
+ priorScheduledMatchUpId: consideredItem.matchUpId,
18619
+ matchUpIdWithConflict: scheduleItem.matchUpId
18620
+ });
18621
+ }
18622
+ }
18623
+ }
18624
+ const pid = participantAggregator.participant.participantId;
18625
+ if (participantAggregator.scheduleConflicts.length) {
18626
+ participantIdsWithConflicts.push(pid);
18627
+ }
18628
+ participantMap[pid].scheduleConflicts = participantAggregator.scheduleConflicts;
18710
18629
  }
18711
18630
  }
18712
- if (params.withGroupings !== false) {
18713
- const participantAttributes = participantIdMap[participant.participantId];
18714
- participant.groupParticipantIds = participantAttributes?.groupParticipantIds;
18715
- participant.pairParticipantIds = participantAttributes?.pairParticipantIds;
18716
- participant.teamParticipantIds = participantAttributes?.teamParticipantIds;
18717
- participant.groups = participantAttributes?.groups;
18718
- participant.teams = participantAttributes?.teams;
18719
- }
18720
- if (params.withTeamMatchUps) ;
18721
- });
18722
- return { participantIdsWithConflicts, eventsPublishStatuses };
18631
+ }
18632
+ return {
18633
+ participantIdsWithConflicts,
18634
+ eventsPublishStatuses,
18635
+ derivedEventInfo,
18636
+ derivedDrawInfo,
18637
+ mappedMatchUps,
18638
+ participantMap,
18639
+ matchUps
18640
+ };
18723
18641
  }
18724
18642
 
18725
18643
  function filterParticipants({
@@ -18839,117 +18757,134 @@ function getEventEntries({ eventEntryStatuses, tournamentEvents }) {
18839
18757
  );
18840
18758
  }
18841
18759
 
18842
- function getTournamentParticipants(params) {
18760
+ function getParticipants(params) {
18843
18761
  const {
18762
+ withIndividualParticipants,
18844
18763
  participantFilters = {},
18764
+ withPotentialMatchUps,
18765
+ withRankingProfile,
18845
18766
  convertExtensions,
18846
18767
  policyDefinitions,
18847
18768
  withScheduleItems,
18769
+ tournamentRecord,
18848
18770
  scheduleAnalysis,
18849
18771
  withSignInStatus,
18850
18772
  withTeamMatchUps,
18851
- // not implemented
18852
- tournamentRecord,
18853
- usePublishState,
18854
18773
  withScaleValues,
18774
+ usePublishState,
18775
+ contextProfile,
18855
18776
  withStatistics,
18856
- withGroupings,
18857
18777
  withOpponents,
18858
18778
  withMatchUps,
18779
+ internalUse,
18859
18780
  withSeeding,
18860
18781
  withEvents,
18861
18782
  withDraws,
18862
- inContext,
18863
18783
  withISO2,
18864
18784
  withIOC
18865
18785
  } = params;
18866
18786
  if (!tournamentRecord)
18867
18787
  return { error: MISSING_TOURNAMENT_RECORD };
18868
- if (!tournamentRecord.participants)
18869
- return { error: MISSING_PARTICIPANTS };
18870
- const allTournamentParticipants = tournamentRecord.participants.map(
18871
- // (participant) => makeDeepCopy(participant, convertExtensions, true)
18872
- (participant) => makeDeepCopy(participant, convertExtensions)
18873
- // removed until Mongo/Mongoose issues resolved
18874
- );
18875
- if (typeof participantFilters !== "object")
18876
- return { error: INVALID_OBJECT, participantFilters };
18877
- if (inContext) {
18878
- allTournamentParticipants?.forEach((participant) => {
18879
- if ([PAIR, TEAM, GROUP].includes(participant.participantType)) {
18880
- participant.individualParticipants = participant.individualParticipantIds?.map((participantId) => {
18881
- const targetParticipant = tournamentRecord.participants.find(
18882
- (p) => p.participantId === participantId
18883
- );
18884
- const individualParticipant = makeDeepCopy(
18885
- targetParticipant,
18886
- convertExtensions,
18887
- true
18788
+ if (withMatchUps || withRankingProfile) {
18789
+ getMatchUpDependencies({ tournamentRecord });
18790
+ }
18791
+ let { participantMap } = getParticipantMap({
18792
+ withIndividualParticipants,
18793
+ convertExtensions,
18794
+ tournamentRecord,
18795
+ withSignInStatus,
18796
+ withScaleValues,
18797
+ internalUse,
18798
+ withISO2,
18799
+ withIOC
18800
+ });
18801
+ const entriesResult = getParticipantEntries({
18802
+ withMatchUps: withMatchUps ?? withRankingProfile,
18803
+ withEvents: withEvents ?? withRankingProfile,
18804
+ withDraws: withDraws ?? withRankingProfile,
18805
+ withPotentialMatchUps,
18806
+ participantFilters,
18807
+ withRankingProfile,
18808
+ convertExtensions,
18809
+ withScheduleItems,
18810
+ policyDefinitions,
18811
+ tournamentRecord,
18812
+ scheduleAnalysis,
18813
+ withTeamMatchUps,
18814
+ usePublishState,
18815
+ withStatistics,
18816
+ participantMap,
18817
+ withOpponents,
18818
+ contextProfile,
18819
+ withSeeding
18820
+ });
18821
+ const {
18822
+ participantIdsWithConflicts,
18823
+ eventsPublishStatuses,
18824
+ derivedEventInfo,
18825
+ derivedDrawInfo,
18826
+ mappedMatchUps
18827
+ } = entriesResult;
18828
+ const matchUps = entriesResult.matchUps;
18829
+ participantMap = entriesResult.participantMap;
18830
+ const nextMatchUps = scheduleAnalysis ?? withPotentialMatchUps;
18831
+ const processedParticipants = Object.values(participantMap).map(
18832
+ ({
18833
+ potentialMatchUps,
18834
+ scheduleConflicts,
18835
+ participant,
18836
+ statistics,
18837
+ opponents,
18838
+ matchUps: matchUps2,
18839
+ events,
18840
+ draws
18841
+ }) => {
18842
+ const participantDraws = Object.values(draws);
18843
+ const participantOpponents = Object.values(opponents);
18844
+ if (withOpponents) {
18845
+ participantDraws?.forEach((draw) => {
18846
+ draw.opponents = participantOpponents.filter(
18847
+ (opponent) => opponent.drawId === draw.drawId
18888
18848
  );
18889
- if (withScaleValues) {
18890
- const { ratings, rankings } = getScaleValues({
18891
- participant: individualParticipant
18892
- });
18893
- individualParticipant.ratings = ratings;
18894
- individualParticipant.rankings = rankings;
18895
- }
18896
- if (withIOC || withISO2)
18897
- addNationalityCode({
18898
- participant: individualParticipant,
18899
- withISO2,
18900
- withIOC
18901
- });
18902
- return individualParticipant;
18903
18849
  });
18904
18850
  }
18905
- });
18906
- }
18907
- let tournamentParticipants = participantFilters ? filterParticipants({
18908
- participants: allTournamentParticipants,
18851
+ return definedAttributes(
18852
+ {
18853
+ ...participant,
18854
+ scheduleConflicts: scheduleAnalysis ? scheduleConflicts : void 0,
18855
+ draws: withDraws || withRankingProfile ? participantDraws : void 0,
18856
+ events: withEvents || withRankingProfile ? Object.values(events) : void 0,
18857
+ matchUps: withMatchUps || withRankingProfile ? Object.values(matchUps2) : void 0,
18858
+ opponents: withOpponents ? participantOpponents : void 0,
18859
+ potentialMatchUps: nextMatchUps ? Object.values(potentialMatchUps) : void 0,
18860
+ statistics: withStatistics ? Object.values(statistics) : void 0
18861
+ },
18862
+ false,
18863
+ false,
18864
+ true
18865
+ );
18866
+ }
18867
+ );
18868
+ const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
18869
+ const template = participantAttributes?.participant;
18870
+ const filteredParticipants = filterParticipants({
18871
+ participants: processedParticipants,
18909
18872
  participantFilters,
18910
18873
  tournamentRecord
18911
- }) : allTournamentParticipants;
18912
- let participantIdsWithConflicts, eventsPublishStatuses;
18913
- const addContext = withScheduleItems || withSignInStatus || scheduleAnalysis || withScaleValues || withStatistics || withGroupings || withOpponents || withMatchUps || withSeeding || withEvents || withDraws || withISO2 || withIOC;
18914
- if (addContext) {
18915
- const result = addParticipantContext({
18916
- tournamentEvents: tournamentRecord.events,
18917
- allTournamentParticipants,
18918
- tournamentParticipants,
18919
- participantFilters,
18920
- withScheduleItems,
18921
- withSignInStatus,
18922
- tournamentRecord,
18923
- scheduleAnalysis,
18924
- withTeamMatchUps,
18925
- usePublishState,
18926
- withScaleValues,
18927
- withStatistics,
18928
- withGroupings,
18929
- withOpponents,
18930
- withMatchUps,
18931
- withSeeding,
18932
- withEvents,
18933
- withDraws,
18934
- withISO2,
18935
- withIOC
18936
- });
18937
- participantIdsWithConflicts = result?.participantIdsWithConflicts;
18938
- eventsPublishStatuses = result?.eventsPublishStatuses;
18939
- }
18940
- const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
18941
- if (participantAttributes?.participant) {
18942
- tournamentParticipants = tournamentParticipants.map(
18943
- (participant) => attributeFilter({
18944
- template: participantAttributes.participant,
18945
- source: participant
18946
- })
18947
- );
18948
- }
18874
+ });
18875
+ const participants = template ? filteredParticipants.map(
18876
+ (source) => attributeFilter({ source, template })
18877
+ ) : filteredParticipants;
18949
18878
  return {
18950
18879
  participantIdsWithConflicts,
18951
- tournamentParticipants,
18952
- eventsPublishStatuses
18880
+ eventsPublishStatuses,
18881
+ derivedEventInfo,
18882
+ derivedDrawInfo,
18883
+ mappedMatchUps,
18884
+ participantMap,
18885
+ participants,
18886
+ ...SUCCESS,
18887
+ matchUps
18953
18888
  };
18954
18889
  }
18955
18890
 
@@ -19120,11 +19055,11 @@ function createGroupParticipant({
19120
19055
  info: "Invalid individualParticipantIds",
19121
19056
  error: INVALID_VALUES
19122
19057
  };
19123
- const { tournamentParticipants } = getTournamentParticipants({
19058
+ const participants = getParticipants({
19124
19059
  participantFilters: { participantTypes: [INDIVIDUAL] },
19125
19060
  tournamentRecord
19126
- });
19127
- const tournamentIndividualParticipantIds = tournamentParticipants.map(
19061
+ }).participants ?? [];
19062
+ const tournamentIndividualParticipantIds = participants.map(
19128
19063
  (participant) => participant.participantId
19129
19064
  );
19130
19065
  for (const participantId2 of individualParticipantIds) {
@@ -19542,10 +19477,10 @@ function generateVoluntaryConsolation$1(params) {
19542
19477
  let drawDefinition = params?.drawDefinition;
19543
19478
  if (!drawDefinition)
19544
19479
  return { error: MISSING_DRAW_DEFINITION };
19545
- const tournamentParticipants = getTournamentParticipants({
19546
- tournamentRecord,
19547
- inContext: true
19548
- })?.tournamentParticipants;
19480
+ const participants = tournamentRecord ? getParticipants({
19481
+ withIndividualParticipants: true,
19482
+ tournamentRecord
19483
+ })?.participants : [];
19549
19484
  const stage = VOLUNTARY_CONSOLATION;
19550
19485
  const entries = getStageEntries({
19551
19486
  stageSequence: 1,
@@ -19636,10 +19571,10 @@ function generateVoluntaryConsolation$1(params) {
19636
19571
  if (automated) {
19637
19572
  automatedPositioning$1({
19638
19573
  seedingProfile: params.seedingProfile,
19639
- participants: tournamentParticipants,
19640
19574
  applyPositioning,
19641
19575
  tournamentRecord,
19642
19576
  drawDefinition,
19577
+ participants,
19643
19578
  structureId,
19644
19579
  placeByes,
19645
19580
  drawSize,
@@ -20916,9 +20851,7 @@ function addDrawDefinition(params) {
20916
20851
  });
20917
20852
  if (relevantFlight && !drawEntriesPresentInFlight) {
20918
20853
  return decorateResult({
20919
- result: {
20920
- error: INVALID_DRAW_DEFINITION
20921
- },
20854
+ result: { error: INVALID_DRAW_DEFINITION },
20922
20855
  context: {
20923
20856
  drawEntriesPresentInFlight,
20924
20857
  matchingEventEntries,
@@ -21285,11 +21218,17 @@ const definitionTemplate = () => ({
21285
21218
 
21286
21219
  function newDrawDefinition({
21287
21220
  drawId = UUID(),
21221
+ processCodes,
21288
21222
  matchUpType,
21289
21223
  drawType
21290
21224
  }) {
21291
21225
  const drawDefinition = definitionTemplate();
21292
- return Object.assign(drawDefinition, { drawId, drawType, matchUpType });
21226
+ return Object.assign(drawDefinition, {
21227
+ processCodes,
21228
+ matchUpType,
21229
+ drawType,
21230
+ drawId
21231
+ });
21293
21232
  }
21294
21233
 
21295
21234
  var collectionDefinitions$g = [
@@ -23003,9 +22942,9 @@ function generateDrawDefinition(params) {
23003
22942
  }).appliedPolicies ?? {};
23004
22943
  const drawTypeCoercion = params.drawTypeCoercion ?? appliedPolicies?.[POLICY_TYPE_DRAWS]?.drawTypeCoercion ?? true;
23005
22944
  const drawType = drawTypeCoercion && params.drawSize === 2 && DrawTypeEnum.SingleElimination || params.drawType || DrawTypeEnum.SingleElimination;
23006
- const { tournamentParticipants: participants } = getTournamentParticipants({
23007
- tournamentRecord,
23008
- inContext: true
22945
+ const { participants } = getParticipants({
22946
+ withIndividualParticipants: true,
22947
+ tournamentRecord
23009
22948
  });
23010
22949
  const enforceGender = params.enforceGender ?? policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender;
23011
22950
  const allowedDrawTypes = !ignoreAllowedDrawTypes && tournamentRecord && getAllowedDrawTypes({
@@ -23082,7 +23021,11 @@ function generateDrawDefinition(params) {
23082
23021
  return decorateResult({ result: { error: INVALID_VALUES }, stack });
23083
23022
  if (existingDrawDefinition && drawType !== existingDrawDefinition.drawType)
23084
23023
  existingDrawDefinition.drawType = drawType;
23085
- let drawDefinition = existingDrawDefinition ?? newDrawDefinition({ drawType, drawId: params.drawId });
23024
+ let drawDefinition = existingDrawDefinition ?? newDrawDefinition({
23025
+ drawType,
23026
+ drawId: params.drawId,
23027
+ processCodes: params.processCodes
23028
+ });
23086
23029
  if (matchUpFormat || tieFormat) {
23087
23030
  const equivalentInScope = matchUpFormat && event?.matchUpFormat === matchUpFormat || event?.tieFormat && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat);
23088
23031
  if (!equivalentInScope) {