tods-competition-factory 2.0.49 → 2.0.51

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.0.49';
6
+ return '2.0.51';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -1783,6 +1783,27 @@ function decorateResult({ context, result, stack, info }) {
1783
1783
  return result ?? { success: true };
1784
1784
  }
1785
1785
 
1786
+ const SINGLES$1 = 'SINGLES';
1787
+ const SINGLES_EVENT = 'SINGLES';
1788
+ const DOUBLES$1 = 'DOUBLES';
1789
+ const DOUBLES_EVENT = 'DOUBLES';
1790
+ const TEAM$2 = 'TEAM';
1791
+ const TEAM_EVENT = 'TEAM';
1792
+ const AGE = 'AGE';
1793
+ const RATING$2 = 'RATING';
1794
+ const BOTH = 'BOTH';
1795
+ const eventConstants = {
1796
+ AGE,
1797
+ BOTH,
1798
+ DOUBLES: DOUBLES$1,
1799
+ DOUBLES_EVENT,
1800
+ RATING: RATING$2,
1801
+ SINGLES: SINGLES$1,
1802
+ SINGLES_EVENT,
1803
+ TEAM_EVENT,
1804
+ TEAM: TEAM$2,
1805
+ };
1806
+
1786
1807
  const TOURNAMENT_RECORDS = 'tournamentRecords';
1787
1808
  const POLICY_DEFINITIONS = 'policyDefinitions';
1788
1809
  const TOURNAMENT_RECORD = 'tournamentRecord';
@@ -1798,6 +1819,7 @@ const MATCHUP_IDS = 'matchUpIds';
1798
1819
  const POLICY_TYPE = 'policyType';
1799
1820
  const STRUCTURES = 'structures';
1800
1821
  const MATCHUP_ID = 'matchUpId';
1822
+ const EVENT_TYPE = 'eventType';
1801
1823
  const IN_CONTEXT = 'inContext';
1802
1824
  const STRUCTURE = 'structure';
1803
1825
  const COURT_IDS = 'courtIds';
@@ -1825,6 +1847,9 @@ const OF_TYPE = '_ofType';
1825
1847
  const ANY_OF = '_anyOf';
1826
1848
  const ONE_OF = '_oneOf';
1827
1849
 
1850
+ const validators = {
1851
+ [EVENT_TYPE]: (value) => [SINGLES$1, DOUBLES$1, TEAM$2].includes(value),
1852
+ };
1828
1853
  const errors = {
1829
1854
  [TOURNAMENT_RECORDS]: MISSING_TOURNAMENT_RECORDS,
1830
1855
  [TOURNAMENT_RECORD]: MISSING_TOURNAMENT_RECORD,
@@ -1836,6 +1861,7 @@ const errors = {
1836
1861
  [STRUCTURE_ID]: MISSING_STRUCTURE_ID,
1837
1862
  [MATCHUP_IDS]: MISSING_MATCHUP_IDS,
1838
1863
  [PARTICIPANT]: MISSING_PARTICIPANT,
1864
+ [EVENT_TYPE]: INVALID_EVENT_TYPE,
1839
1865
  [STRUCTURES]: MISSING_STRUCTURES,
1840
1866
  [MATCHUP_ID]: MISSING_MATCHUP_ID,
1841
1867
  [STRUCTURE]: MISSING_STRUCTURE,
@@ -1923,7 +1949,9 @@ function findParamError(params, requiredParams) {
1923
1949
  const faliedTypeCheck = params[param] !== undefined && !_validate && invalidType(params, param, _ofType);
1924
1950
  const paramNotPresent = attrs[param] && [undefined, null].includes(params[param]);
1925
1951
  const invalid = invalidValidationFunction || faliedTypeCheck || paramNotPresent;
1926
- const hasError = invalid || (_validate && params[param] !== undefined && !checkValidation(params[param], _validate));
1952
+ const hasError = invalid ||
1953
+ (_validate && params[param] !== undefined && !checkValidation(params[param], _validate)) ||
1954
+ (validators[param] && !validators[param](params[param]));
1927
1955
  if (hasError) {
1928
1956
  errorParam = param;
1929
1957
  paramInfo = _info;
@@ -1947,27 +1975,6 @@ function checkValidation(value, validate) {
1947
1975
  return true;
1948
1976
  }
1949
1977
 
1950
- const SINGLES$1 = 'SINGLES';
1951
- const SINGLES_EVENT = 'SINGLES';
1952
- const DOUBLES$1 = 'DOUBLES';
1953
- const DOUBLES_EVENT = 'DOUBLES';
1954
- const TEAM$2 = 'TEAM';
1955
- const TEAM_EVENT = 'TEAM';
1956
- const AGE = 'AGE';
1957
- const RATING$2 = 'RATING';
1958
- const BOTH = 'BOTH';
1959
- const eventConstants = {
1960
- AGE,
1961
- BOTH,
1962
- DOUBLES: DOUBLES$1,
1963
- DOUBLES_EVENT,
1964
- RATING: RATING$2,
1965
- SINGLES: SINGLES$1,
1966
- SINGLES_EVENT,
1967
- TEAM_EVENT,
1968
- TEAM: TEAM$2,
1969
- };
1970
-
1971
1978
  const DYNAMIC = 'DYNAMIC';
1972
1979
  const RANKING$1 = 'RANKING';
1973
1980
  const RATING$1 = 'RATING';
@@ -2710,8 +2717,8 @@ const APPLIED_POLICIES = 'appliedPolicies';
2710
2717
  const CONTEXT = 'context';
2711
2718
  const DELEGATED_OUTCOME = 'delegatedOutcome';
2712
2719
  const DISABLED = 'disabled';
2713
- const DISABLE_LINKS = 'disableLinks';
2714
2720
  const DISABLE_AUTO_CALC = 'disableAutoCalc';
2721
+ const DISABLE_LINKS = 'disableLinks';
2715
2722
  const DISPLAY = 'display';
2716
2723
  const DRAW_DELETIONS = 'drawDeletions';
2717
2724
  const DRAW_PROFILE = 'drawProfile';
@@ -2728,6 +2735,7 @@ const PARTICIPANT_REPRESENTATIVES = 'participantRepresentatives';
2728
2735
  const PERSON_REQUESTS = 'personRequests';
2729
2736
  const POSITION_ACTIONS = 'positionActions';
2730
2737
  const RANKING_POINTS = 'rankingPoints';
2738
+ const REGISTRATION$1 = 'registration';
2731
2739
  const ROUND_TARGET = 'roundTarget';
2732
2740
  const SCHEDULE_LIMITS = 'scheduleLimits';
2733
2741
  const SCHEDULE_TIMING = 'scheduleTiming';
@@ -2759,6 +2767,7 @@ const extensionConstants = {
2759
2767
  PERSON_REQUESTS,
2760
2768
  POSITION_ACTIONS,
2761
2769
  RANKING_POINTS,
2770
+ REGISTRATION: REGISTRATION$1,
2762
2771
  ROUND_TARGET,
2763
2772
  SCHEDULE_LIMITS,
2764
2773
  SCHEDULE_TIMING,
@@ -2772,9 +2781,11 @@ const extensionConstants = {
2772
2781
  const internalExtensions = [
2773
2782
  DELEGATED_OUTCOME,
2774
2783
  DISABLED,
2784
+ DISABLE_AUTO_CALC,
2775
2785
  DISABLE_LINKS,
2776
2786
  FLIGHT_PROFILE,
2777
2787
  LINEUPS,
2788
+ LINKED_TOURNAMENTS,
2778
2789
  MATCHUP_HISTORY,
2779
2790
  PARTICIPANT_REPRESENTATIVES,
2780
2791
  PERSON_REQUESTS,
@@ -2784,6 +2795,7 @@ const internalExtensions = [
2784
2795
  SCHEDULING_PROFILE,
2785
2796
  SUB_ORDER,
2786
2797
  TALLY,
2798
+ TIE_FORMAT_MODIFICATIONS,
2787
2799
  ];
2788
2800
 
2789
2801
  function linkTournaments({ tournamentRecords }) {
@@ -26492,9 +26504,14 @@ function addParticipantScaleItem({ removePriorValues, participant, scaleItem })
26492
26504
  return { ...SUCCESS, valueChanged, newValue: scaleItem.scaleValue };
26493
26505
  }
26494
26506
 
26495
- function addDynamicRatings({ tournamentRecord, modifiedScaleValues, removePriorValues }) {
26496
- if (!tournamentRecord)
26497
- return { error: MISSING_TOURNAMENT_RECORD };
26507
+ function addDynamicRatings(params) {
26508
+ const { tournamentRecord, modifiedScaleValues, removePriorValues } = params;
26509
+ const paramsCheck = checkRequiredParameters(params, [
26510
+ { [TOURNAMENT_RECORD]: true },
26511
+ { modifiedScaleValues: true, [OF_TYPE]: OBJECT },
26512
+ ]);
26513
+ if (paramsCheck.error)
26514
+ return paramsCheck;
26498
26515
  for (const participantId in modifiedScaleValues) {
26499
26516
  const result = setParticipantScaleItem({
26500
26517
  scaleItem: modifiedScaleValues[participantId],
@@ -26505,6 +26522,7 @@ function addDynamicRatings({ tournamentRecord, modifiedScaleValues, removePriorV
26505
26522
  if (result.error)
26506
26523
  return result;
26507
26524
  }
26525
+ return { ...SUCCESS };
26508
26526
  }
26509
26527
 
26510
26528
  function getParticipantScaleItem(params) {
@@ -26616,24 +26634,30 @@ const aggregateSets = (sets) => {
26616
26634
  };
26617
26635
 
26618
26636
  function generateDynamicRatings(params) {
26619
- const { updateParticipantRatings, removePriorValues = true, tournamentRecord, ratingType = ELO, considerGames, matchUpIds, asDynamic, } = params;
26620
- if (!tournamentRecord)
26621
- return { error: MISSING_TOURNAMENT_RECORD };
26622
- if (!Array.isArray(matchUpIds))
26623
- return { error: MISSING_MATCHUPS };
26624
- if (typeof ratingType !== 'string')
26625
- return { error: INVALID_VALUES, ratingType };
26626
- if (!ratingsParameters[ratingType])
26627
- return { error: INVALID_VALUES };
26637
+ const paramsCheck = checkRequiredParameters(params, [
26638
+ { [TOURNAMENT_RECORD]: true },
26639
+ { matchUpIds: true, [OF_TYPE]: ARRAY, [ERROR]: MISSING_MATCHUP_IDS },
26640
+ { ratingType: false, [VALIDATE]: (value) => ratingsParameters[value] },
26641
+ ]);
26642
+ if (paramsCheck.error)
26643
+ return paramsCheck;
26644
+ const { updateParticipantRatings, removePriorValues = true, tournamentRecord, ratingType = ELO, refreshDynamic, considerGames, drawDefinition, matchUpIds, asDynamic, } = params;
26628
26645
  const ratingParameter = ratingsParameters[ratingType];
26629
26646
  const { accessor } = ratingParameter;
26630
26647
  const modifiedScaleValues = {};
26631
- const matchUps = params.matchUps ??
26648
+ const matchUps = (params.matchUps ||
26649
+ (refreshDynamic &&
26650
+ allDrawMatchUps({
26651
+ drawDefinition,
26652
+ tournamentRecord,
26653
+ inContext: true,
26654
+ matchUpFilters: { matchUpStatuses: completedMatchUpStatuses },
26655
+ }).matchUps) ||
26632
26656
  allTournamentMatchUps({
26633
26657
  matchUpFilters: { matchUpIds, matchUpStatuses: completedMatchUpStatuses },
26634
26658
  tournamentRecord,
26635
26659
  inContext: true,
26636
- }).matchUps ??
26660
+ }).matchUps) ??
26637
26661
  [];
26638
26662
  const dynamicScaleName = `${ratingType}.${DYNAMIC}`;
26639
26663
  const outputScaleName = asDynamic ? dynamicScaleName : ratingType;
@@ -26662,16 +26686,20 @@ function generateDynamicRatings(params) {
26662
26686
  const scaleItemMap = Object.assign({}, ...Object.values(sideParticipantIds)
26663
26687
  .flat()
26664
26688
  .map((participantId) => {
26665
- const { scaleItem: dynamicScaleItem } = getParticipantScaleItem({
26666
- scaleAttributes: dynamicScaleAttributes,
26667
- tournamentRecord,
26668
- participantId,
26669
- });
26670
- const { scaleItem } = getParticipantScaleItem({
26689
+ const existingModifiedScaleValue = modifiedScaleValues[participantId];
26690
+ const useDynamic = !refreshDynamic || existingModifiedScaleValue;
26691
+ const dynamicScaleItem = useDynamic
26692
+ ? getParticipantScaleItem({
26693
+ scaleAttributes: dynamicScaleAttributes,
26694
+ tournamentRecord,
26695
+ participantId,
26696
+ }).scaleItem
26697
+ : undefined;
26698
+ const scaleItem = getParticipantScaleItem({
26671
26699
  tournamentRecord,
26672
26700
  scaleAttributes,
26673
26701
  participantId,
26674
- });
26702
+ }).scaleItem;
26675
26703
  const scaleValue = accessor ? { [accessor]: undefined } : undefined;
26676
26704
  return (participantId && {
26677
26705
  [participantId]: dynamicScaleItem ??
@@ -27032,7 +27060,7 @@ function getPairings({ tournamentParticipants, adHocRatings = {}, possiblePairin
27032
27060
  const ENCOUNTER_VALUE = 100;
27033
27061
  const SAME_TEAM_VALUE = 100;
27034
27062
  const MAX_ITERATIONS = 4000;
27035
- function generateDrawMaticRound({ encounterValue = ENCOUNTER_VALUE, sameTeamValue = SAME_TEAM_VALUE, maxIterations = MAX_ITERATIONS, updateParticipantRatings, generateMatchUps = true, ignoreLastRoundNumber, iterationMatchUps, tournamentRecord, dynamicRatings, participantIds, drawDefinition, adHocRatings, salted = 0.5, roundNumber, structureId, matchUpIds, eventType, structure, scaleName, idPrefix, isMock, event, }) {
27063
+ function generateDrawMaticRound({ encounterValue = ENCOUNTER_VALUE, sameTeamValue = SAME_TEAM_VALUE, maxIterations = MAX_ITERATIONS, updateParticipantRatings, generateMatchUps = true, ignoreLastRoundNumber, iterationMatchUps, tournamentRecord, dynamicRatings, refreshDynamic, participantIds, drawDefinition, adHocRatings, salted = 0.5, roundNumber, structureId, matchUpIds, eventType, structure, scaleName, idPrefix, isMock, event, }) {
27036
27064
  if (!drawDefinition)
27037
27065
  return { error: MISSING_DRAW_DEFINITION };
27038
27066
  if (!structure && !structureId)
@@ -27056,10 +27084,12 @@ function generateDrawMaticRound({ encounterValue = ENCOUNTER_VALUE, sameTeamValu
27056
27084
  ?.filter(({ roundNumber }) => roundNumber === lastRoundNumber)
27057
27085
  .map(({ matchUpId }) => matchUpId);
27058
27086
  const result = generateDynamicRatings({
27059
- ratingType: scaleName || event?.category?.ratingType,
27087
+ ratingType: scaleName ?? event?.category?.ratingType,
27060
27088
  updateParticipantRatings,
27061
27089
  tournamentRecord,
27062
27090
  asDynamic: true,
27091
+ refreshDynamic,
27092
+ drawDefinition,
27063
27093
  matchUpIds,
27064
27094
  });
27065
27095
  if (result.error)
@@ -32242,7 +32272,7 @@ function drawMatic(params) {
32242
32272
  const structureResult = getAdHocStructure(params);
32243
32273
  if (structureResult.error)
32244
32274
  return structureResult;
32245
- const adHocRatings = getAdHocRatings(params);
32275
+ let adHocRatings = getAdHocRatings(params);
32246
32276
  const isMock = params.tournamentRecord?.isMock ?? params.isMock;
32247
32277
  const eventType = params.eventType ?? params.event?.eventType;
32248
32278
  const matchUps = [];
@@ -32263,6 +32293,8 @@ function drawMatic(params) {
32263
32293
  if (result.error)
32264
32294
  return result;
32265
32295
  const { matchUps: roundMatchUps, ...roundResult } = result;
32296
+ if (roundResult.modifiedScaleValues)
32297
+ adHocRatings = roundResult.modifiedScaleValues;
32266
32298
  roundResults.push({ ...roundResult, iteration, matchUpsCount: roundMatchUps?.length });
32267
32299
  roundNumber = (roundResult?.roundNumber ?? 1) + 1;
32268
32300
  if (roundMatchUps?.length) {
@@ -38119,17 +38151,19 @@ function modifyEventPublishStatus({ removePriorValues = true, status = PUBLIC, s
38119
38151
  }
38120
38152
 
38121
38153
  function publishEvent(params) {
38154
+ const paramsCheck = checkRequiredParameters(params, [
38155
+ { [TOURNAMENT_RECORD]: true, [EVENT]: true },
38156
+ { eventDataParams: false, [OF_TYPE]: OBJECT },
38157
+ ]);
38158
+ if (paramsCheck.error)
38159
+ return paramsCheck;
38122
38160
  const { includePositionAssignments, removePriorValues, tournamentRecord, status = PUBLIC, event, drawIdsToRemove, drawIdsToAdd, } = params;
38123
- if (!tournamentRecord)
38124
- return { error: MISSING_TOURNAMENT_RECORD };
38125
- if (!event)
38126
- return { error: MISSING_EVENT };
38127
38161
  const { appliedPolicies } = getAppliedPolicies({ tournamentRecord, event });
38128
38162
  const policyDefinitions = {
38129
38163
  ...appliedPolicies,
38130
38164
  ...params.policyDefinitions,
38131
38165
  };
38132
- const eventDrawIds = event.drawDefinitions?.map(({ drawId }) => drawId) ?? [];
38166
+ const eventDrawIds = event?.drawDefinitions?.map(({ drawId }) => drawId) ?? [];
38133
38167
  const keyedDrawIds = params.drawDetails ? Object.keys(params.drawDetails) : [];
38134
38168
  const specifiedDrawIds = keyedDrawIds.length ? [] : params.drawIds;
38135
38169
  const drawIdsToValidate = (drawIdsToAdd ?? []).concat(...(drawIdsToRemove ?? []), ...(specifiedDrawIds ?? []), ...keyedDrawIds);
@@ -38175,7 +38209,7 @@ function publishEvent(params) {
38175
38209
  stageDetails,
38176
38210
  };
38177
38211
  if (structureIdsToAdd.length || structureIdsToRemove.length) {
38178
- const drawStructureIds = (event.drawDefinitions?.find((drawDefinition) => drawDefinition.drawId === drawId)?.structures ?? []).map(({ structureId }) => structureId);
38212
+ const drawStructureIds = (event?.drawDefinitions?.find((drawDefinition) => drawDefinition.drawId === drawId)?.structures ?? []).map(({ structureId }) => structureId);
38179
38213
  const structureIdsToValidate = (structureIdsToAdd ?? []).concat(structureIdsToRemove ?? []);
38180
38214
  const invalidStructureIds = structureIdsToValidate.filter((structureId) => !drawStructureIds.includes(structureId));
38181
38215
  if (invalidStructureIds.length) {
@@ -38195,7 +38229,7 @@ function publishEvent(params) {
38195
38229
  }
38196
38230
  drawDetails[drawId].structureDetails = structureDetails;
38197
38231
  }
38198
- const drawStages = (event.drawDefinitions?.find((drawDefinition) => drawDefinition.drawId === drawId)?.structures ?? []).map(({ stage }) => stage);
38232
+ const drawStages = (event?.drawDefinitions?.find((drawDefinition) => drawDefinition.drawId === drawId)?.structures ?? []).map(({ stage }) => stage);
38199
38233
  if (stagesToAdd.length) {
38200
38234
  for (const stage of stagesToAdd) {
38201
38235
  stageDetails[stage] = { published: true };
@@ -38232,6 +38266,7 @@ function publishEvent(params) {
38232
38266
  const eventData = notify || params.returnEventData
38233
38267
  ? getEventData({
38234
38268
  includePositionAssignments,
38269
+ ...params.eventDataParams,
38235
38270
  usePublishState: true,
38236
38271
  tournamentRecord,
38237
38272
  policyDefinitions,
@@ -38414,6 +38449,7 @@ function deleteDrawDefinitions(params) {
38414
38449
  addDrawDeletionTelemetry({ appliedPolicies, event, deletedDrawsDetail, auditData });
38415
38450
  if (autoPublish && publishedDrawsDeleted) {
38416
38451
  const result = publishEvent({
38452
+ ...params.eventDataParams,
38417
38453
  drawIdsToRemove: drawIds,
38418
38454
  policyDefinitions,
38419
38455
  tournamentRecord,
@@ -47550,7 +47586,7 @@ function nameMocks({ nameRoot = 'TEAM', count = 1 } = {}) {
47550
47586
 
47551
47587
  function generateParticipants(params) {
47552
47588
  let { rankingRange, scaledParticipantsCount, } = params;
47553
- const { ratingsParameters: ratingsParameters$1 = ratingsParameters, valuesInstanceLimit, consideredDate, category, nationalityCodesCount, nationalityCodeType, nationalityCodes, participantsCount = 32, participantType, personIds, idPrefix, uuids, personExtensions, addressProps, gendersCount, matchUpType, personData, sex, inContext, withISO2, withIOC, scaleAllParticipants, } = params;
47589
+ const { ratingsParameters: ratingsParameters$1 = ratingsParameters, valuesInstanceLimit, consideredDate, categories, category, nationalityCodesCount, nationalityCodeType, nationalityCodes, participantsCount = 32, participantType, personIds, idPrefix, uuids, personExtensions, addressProps, gendersCount, matchUpType, personData, sex, inContext, withISO2, withIOC, scaleAllParticipants, } = params;
47554
47590
  const doubles = participantType === PAIR || matchUpType === DOUBLES_MATCHUP;
47555
47591
  const team = participantType === TEAM || matchUpType === TEAM;
47556
47592
  if (rankingRange &&
@@ -47577,57 +47613,28 @@ function generateParticipants(params) {
47577
47613
  if (result.error)
47578
47614
  return result;
47579
47615
  const { nationalityCodes: personNationalityCodes, persons: mockedPersons } = result;
47580
- let doublesRankings = [], singlesRankings = [], singlesRatings = [], doublesRatings = [];
47581
- if (typeof category === 'object') {
47582
- const { categoryName, ageCategoryCode, ratingType } = category;
47583
- if ((categoryName || ageCategoryCode) && !ratingType) {
47584
- const [start, end] = rankingRange || [];
47585
- singlesRankings = shuffleArray(generateRange(start, end)).slice(0, scaledParticipantsCount || randomInt(20, 30));
47586
- if ([PAIR, TEAM].includes(participantType)) {
47587
- const [start, end] = rankingRange || [];
47588
- doublesRankings = shuffleArray(generateRange(start, end)).slice(0, scaledParticipantsCount || randomInt(20, 30));
47589
- }
47590
- }
47591
- if (ratingType && ratingsParameters$1[ratingType]) {
47592
- const { ratingMax, ratingMin, ratingAttributes } = category;
47593
- const ratingParameters = {
47594
- ...ratingsParameters$1[ratingType],
47595
- ...(ratingAttributes || {}),
47596
- };
47597
- const { attributes = {}, decimalsCount, accessors, range, step } = ratingParameters;
47598
- const getAttributes = (attributes) => {
47599
- const generatedAttributes = {};
47600
- const attributeKeys = Object.keys(attributes || {});
47601
- for (const attribute of attributeKeys) {
47602
- const attributeValue = attributes[attribute];
47603
- if (typeof attributeValue === 'object' && attributeValue.generator) {
47604
- const { range } = attributeValue;
47605
- const [min, max] = range.slice().sort();
47606
- generatedAttributes[attribute] = randomInt(min, max);
47607
- }
47608
- else {
47609
- generatedAttributes[attribute] = attributeValue;
47610
- }
47611
- }
47612
- return generatedAttributes;
47613
- };
47614
- const inverted = range[0] > range[1];
47615
- const skew = inverted ? 2 : 0.5;
47616
- const [min, max] = range.slice().sort();
47617
- const generateRatings = () => generateRange(0, 2000)
47618
- .map(() => skewedDistribution(min, max, skew, step, decimalsCount))
47619
- .filter((rating) => (!ratingMax || rating <= ratingMax) && (!ratingMin || rating >= ratingMin))
47620
- .slice(0, scaledParticipantsCount || randomInt(20, 30))
47621
- .map((scaleValue) => {
47622
- return !accessors
47623
- ? scaleValue
47624
- : Object.assign({}, ...accessors.map((accessor) => ({ [accessor]: scaleValue })), getAttributes(attributes));
47616
+ const doublesRankings = {}, singlesRankings = {}, singlesRatings = {}, doublesRatings = {};
47617
+ const assignResult = (result) => {
47618
+ Object.assign(doublesRankings, result.doublesRankings);
47619
+ Object.assign(singlesRankings, result.singlesRankings);
47620
+ Object.assign(doublesRatings, result.doublesRatings);
47621
+ Object.assign(singlesRatings, result.singlesRatings);
47622
+ };
47623
+ if (isObject(category)) {
47624
+ const result = genRatings({ category, scaledParticipantsCount, ratingsParameters: ratingsParameters$1, participantType, rankingRange });
47625
+ assignResult(result);
47626
+ }
47627
+ if (Array.isArray(categories)) {
47628
+ categories.forEach((category) => {
47629
+ const result = genRatings({
47630
+ scaledParticipantsCount,
47631
+ ratingsParameters: ratingsParameters$1,
47632
+ participantType,
47633
+ rankingRange,
47634
+ category,
47625
47635
  });
47626
- singlesRatings = generateRatings();
47627
- if ([PAIR, TEAM].includes(participantType)) {
47628
- doublesRatings = generateRatings();
47629
- }
47630
- }
47636
+ assignResult(result);
47637
+ });
47631
47638
  }
47632
47639
  const countryCodes = countries.filter((country) => nationalityCodeType === 'IOC' ? country.ioc || country.iso : country.iso);
47633
47640
  function getMin(count) {
@@ -47752,9 +47759,10 @@ function generateParticipants(params) {
47752
47759
  if (country?.label)
47753
47760
  participant.person.countryName = country.label;
47754
47761
  }
47755
- if (category) {
47756
- const singlesRanking = singlesRankings[participantIndex];
47757
- const doublesRanking = doublesRankings[participantIndex];
47762
+ const processCategory = (category) => {
47763
+ const scaleName = category.categoryName || category.ratingType || category.ageCategoryCode;
47764
+ const singlesRanking = singlesRankings[scaleName]?.[participantIndex];
47765
+ const doublesRanking = doublesRankings[scaleName]?.[participantIndex];
47758
47766
  addScaleItem({
47759
47767
  scaleValue: singlesRanking,
47760
47768
  eventType: SINGLES_EVENT,
@@ -47769,8 +47777,8 @@ function generateParticipants(params) {
47769
47777
  participant,
47770
47778
  category,
47771
47779
  });
47772
- const singlesRating = singlesRatings[participantIndex];
47773
- const doublesRating = doublesRatings[participantIndex];
47780
+ const singlesRating = singlesRatings[scaleName]?.[participantIndex];
47781
+ const doublesRating = doublesRatings[scaleName]?.[participantIndex];
47774
47782
  addScaleItem({
47775
47783
  scaleValue: singlesRating,
47776
47784
  eventType: SINGLES_EVENT,
@@ -47785,6 +47793,12 @@ function generateParticipants(params) {
47785
47793
  participant,
47786
47794
  category,
47787
47795
  });
47796
+ };
47797
+ if (Array.isArray(categories)) {
47798
+ categories.forEach((category) => processCategory(category));
47799
+ }
47800
+ else if (category) {
47801
+ processCategory(category);
47788
47802
  }
47789
47803
  return participant;
47790
47804
  }
@@ -47799,6 +47813,62 @@ function addScaleItem({ scaleValue: itemValue, participant, eventType, scaleType
47799
47813
  participant.timeItems.push(timeItem);
47800
47814
  }
47801
47815
  }
47816
+ function genRatings(params) {
47817
+ const { category, scaledParticipantsCount, ratingsParameters, participantType } = params;
47818
+ const rankingRange = category.rankingRange || params.rankingRange || [1, 1000];
47819
+ const doublesRankings = {}, singlesRankings = {}, singlesRatings = {}, doublesRatings = {};
47820
+ const { categoryName, ageCategoryCode, ratingType } = category;
47821
+ const scaleName = category.categoryName || category.ratingType || category.ageCategoryCode;
47822
+ if ((categoryName || ageCategoryCode) && !ratingType) {
47823
+ const [start, end] = rankingRange || [];
47824
+ singlesRankings[scaleName] = shuffleArray(generateRange(start, end)).slice(0, scaledParticipantsCount || randomInt(20, 30));
47825
+ if ([PAIR, TEAM].includes(participantType)) {
47826
+ const [start, end] = rankingRange || [];
47827
+ doublesRankings[scaleName] = shuffleArray(generateRange(start, end)).slice(0, scaledParticipantsCount || randomInt(20, 30));
47828
+ }
47829
+ }
47830
+ if (ratingType && ratingsParameters[ratingType]) {
47831
+ const { ratingMax, ratingMin, ratingAttributes } = category;
47832
+ const ratingParameters = {
47833
+ ...ratingsParameters[ratingType],
47834
+ ...(ratingAttributes || {}),
47835
+ };
47836
+ const { attributes = {}, decimalsCount, accessors, range, step } = ratingParameters;
47837
+ const getAttributes = (attributes) => {
47838
+ const generatedAttributes = {};
47839
+ const attributeKeys = Object.keys(attributes || {});
47840
+ for (const attribute of attributeKeys) {
47841
+ const attributeValue = attributes[attribute];
47842
+ if (typeof attributeValue === 'object' && attributeValue.generator) {
47843
+ const { range } = attributeValue;
47844
+ const [min, max] = range.slice().sort();
47845
+ generatedAttributes[attribute] = randomInt(min, max);
47846
+ }
47847
+ else {
47848
+ generatedAttributes[attribute] = attributeValue;
47849
+ }
47850
+ }
47851
+ return generatedAttributes;
47852
+ };
47853
+ const inverted = range[0] > range[1];
47854
+ const skew = inverted ? 2 : 0.5;
47855
+ const [min, max] = range.slice().sort();
47856
+ const generateRatings = () => generateRange(0, 2000)
47857
+ .map(() => skewedDistribution(min, max, skew, step, decimalsCount))
47858
+ .filter((rating) => (!ratingMax || rating <= ratingMax) && (!ratingMin || rating >= ratingMin))
47859
+ .slice(0, scaledParticipantsCount || randomInt(20, 30))
47860
+ .map((scaleValue) => {
47861
+ return !accessors
47862
+ ? scaleValue
47863
+ : Object.assign({}, ...accessors.map((accessor) => ({ [accessor]: scaleValue })), getAttributes(attributes));
47864
+ });
47865
+ singlesRatings[scaleName] = generateRatings();
47866
+ if ([PAIR, TEAM].includes(participantType)) {
47867
+ doublesRatings[scaleName] = generateRatings();
47868
+ }
47869
+ }
47870
+ return { singlesRankings, doublesRankings, singlesRatings, doublesRatings };
47871
+ }
47802
47872
 
47803
47873
  function processTieFormat(params) {
47804
47874
  const { alternatesCount = 0, tieFormatName, drawSize } = params;
@@ -51038,6 +51108,25 @@ function scaledTeamAssignment({ clearExistingAssignments = true, individualParti
51038
51108
  return { ...SUCCESS, scaledParticipants };
51039
51109
  }
51040
51110
 
51111
+ function removeRatings(params) {
51112
+ const paramsCheck = checkRequiredParameters(params, [
51113
+ { [TOURNAMENT_RECORD]: true, [EVENT_TYPE]: true },
51114
+ { ratingType: false, [VALIDATE]: (value) => ratingsParameters[value] },
51115
+ ]);
51116
+ if (paramsCheck.error)
51117
+ return paramsCheck;
51118
+ const dynamicScaleName = `${params.ratingType}.${DYNAMIC}`;
51119
+ const ratingType = params.asDynamic ? dynamicScaleName : params.ratingType;
51120
+ const itemType = [SCALE$1, RATING$1, params.eventType, ratingType].join('.');
51121
+ const participants = params.tournamentRecord.participants ?? [];
51122
+ for (const participant of participants) {
51123
+ if (participant.timeItems) {
51124
+ participant.timeItems = participant.timeItems.filter((timeItem) => timeItem.itemType !== itemType);
51125
+ }
51126
+ }
51127
+ return { ...SUCCESS };
51128
+ }
51129
+
51041
51130
  function removePenalty(params) {
51042
51131
  const { tournamentRecords } = params;
51043
51132
  if (typeof tournamentRecords !== 'object' || !Object.keys(tournamentRecords).length)
@@ -51404,6 +51493,7 @@ var mutate$5 = {
51404
51493
  removeParticipantIdsFromAllTeams: removeParticipantIdsFromAllTeams,
51405
51494
  removePenalty: removePenalty,
51406
51495
  removePersonRequests: removePersonRequests,
51496
+ removeRatings: removeRatings,
51407
51497
  scaledTeamAssignment: scaledTeamAssignment,
51408
51498
  setParticipantScaleItem: setParticipantScaleItem,
51409
51499
  setParticipantScaleItems: setParticipantScaleItems
@@ -51449,6 +51539,7 @@ var index$8 = {
51449
51539
  removeParticipantIdsFromAllTeams: removeParticipantIdsFromAllTeams,
51450
51540
  removePenalty: removePenalty,
51451
51541
  removePersonRequests: removePersonRequests,
51542
+ removeRatings: removeRatings,
51452
51543
  scaledTeamAssignment: scaledTeamAssignment,
51453
51544
  setParticipantScaleItem: setParticipantScaleItem,
51454
51545
  setParticipantScaleItems: setParticipantScaleItems,
@@ -57389,26 +57480,35 @@ const mocksEngine = (() => {
57389
57480
  governors.forEach((governor) => {
57390
57481
  Object.keys(governor).forEach((method) => {
57391
57482
  engine[method] = (params) => {
57392
- try {
57483
+ if (getDevContext()) {
57393
57484
  const invocationResult = engineInvoke(governor[method], params);
57394
57485
  if (!invocationResult?.error && params?.setState && invocationResult?.tournamentRecord) {
57395
57486
  setState$1(invocationResult.tournamentRecord);
57396
57487
  }
57397
57488
  return invocationResult;
57398
57489
  }
57399
- catch (err) {
57400
- let error;
57401
- if (typeof err === 'string') {
57402
- error = err.toUpperCase();
57490
+ else {
57491
+ try {
57492
+ const invocationResult = engineInvoke(governor[method], params);
57493
+ if (!invocationResult?.error && params?.setState && invocationResult?.tournamentRecord) {
57494
+ setState$1(invocationResult.tournamentRecord);
57495
+ }
57496
+ return invocationResult;
57403
57497
  }
57404
- else if (err instanceof Error) {
57405
- error = err.message;
57498
+ catch (err) {
57499
+ let error;
57500
+ if (typeof err === 'string') {
57501
+ error = err.toUpperCase();
57502
+ }
57503
+ else if (err instanceof Error) {
57504
+ error = err.message;
57505
+ }
57506
+ console.log('ERROR', {
57507
+ params: JSON.stringify(params),
57508
+ method,
57509
+ error,
57510
+ });
57406
57511
  }
57407
- console.log('ERROR', {
57408
- params: JSON.stringify(params),
57409
- method,
57410
- error,
57411
- });
57412
57512
  }
57413
57513
  };
57414
57514
  });