tods-competition-factory 1.7.5 → 1.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.7.5';
365
+ return '1.7.7';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -2017,6 +2017,9 @@ function handleCaughtError(_a) {
2017
2017
  });
2018
2018
  }
2019
2019
 
2020
+ function isString(obj) {
2021
+ return typeof obj === 'string';
2022
+ }
2020
2023
  function isObject(obj) {
2021
2024
  return typeof obj === 'object';
2022
2025
  }
@@ -5289,7 +5292,7 @@ var _a$j, _b$6;
5289
5292
  var POLICY_COMPETITIVE_BANDS_DEFAULT = (_a$j = {},
5290
5293
  _a$j[POLICY_TYPE_COMPETITIVE_BANDS] = {
5291
5294
  policyName: 'Competitive Bands Default',
5292
- competitiveProfile: (_b$6 = {},
5295
+ profileBands: (_b$6 = {},
5293
5296
  _b$6[DECISIVE] = 20,
5294
5297
  _b$6[ROUTINE] = 50,
5295
5298
  _b$6),
@@ -5341,9 +5344,10 @@ function getCollectionPositionMatchUps(_a) {
5341
5344
 
5342
5345
  var add = function (a, b) { return (a || 0) + (b || 0); };
5343
5346
  function getBand(spread, bandProfiles) {
5344
- return ((isNaN(spread) && WALKOVER$1) ||
5345
- (spread <= bandProfiles[DECISIVE] && DECISIVE) ||
5346
- (spread <= bandProfiles[ROUTINE] && ROUTINE) ||
5347
+ var spreadValue = Array.isArray(spread) ? spread[0] : spread;
5348
+ return ((isNaN(spreadValue) && WALKOVER$1) ||
5349
+ (spreadValue <= bandProfiles[DECISIVE] && DECISIVE) ||
5350
+ (spreadValue <= bandProfiles[ROUTINE] && ROUTINE) ||
5347
5351
  COMPETITIVE);
5348
5352
  }
5349
5353
  function getScoreComponents(_a) {
@@ -5374,7 +5378,7 @@ function pctSpread(pcts) {
5374
5378
  return pcts
5375
5379
  .map(gamesPercent)
5376
5380
  .sort()
5377
- .map(function (p) { return p.toFixed(2); });
5381
+ .map(function (p) { return parseFloat(p.toFixed(2)); });
5378
5382
  }
5379
5383
 
5380
5384
  function findPolicy(_a) {
@@ -5392,27 +5396,28 @@ function findPolicy(_a) {
5392
5396
  : { error: POLICY_NOT_FOUND };
5393
5397
  }
5394
5398
 
5395
- function getMatchUpCompetitiveness(_a) {
5396
- var competitiveProfile = _a.competitiveProfile, tournamentRecord = _a.tournamentRecord, matchUp = _a.matchUp;
5399
+ function getMatchUpCompetitiveProfile(_a) {
5400
+ var profileBands = _a.profileBands, tournamentRecord = _a.tournamentRecord, matchUp = _a.matchUp;
5397
5401
  if (!matchUp)
5398
5402
  return { error: MISSING_MATCHUP };
5399
5403
  var score = matchUp.score, winningSide = matchUp.winningSide;
5400
5404
  if (!winningSide)
5401
5405
  return { error: INVALID_VALUES };
5402
- var policy = !competitiveProfile &&
5406
+ var policy = !profileBands &&
5403
5407
  tournamentRecord &&
5404
5408
  findPolicy({
5405
5409
  policyType: POLICY_TYPE_COMPETITIVE_BANDS,
5406
5410
  tournamentRecord: tournamentRecord,
5407
5411
  }).policy;
5408
- var bandProfiles = competitiveProfile ||
5409
- (policy === null || policy === void 0 ? void 0 : policy.competitiveProfile) ||
5412
+ var bandProfiles = profileBands ||
5413
+ (policy === null || policy === void 0 ? void 0 : policy.profileBands) ||
5410
5414
  POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS]
5411
- .competitiveProfile;
5415
+ .profileBands;
5412
5416
  var scoreComponents = getScoreComponents({ score: score });
5413
5417
  var spread = pctSpread([scoreComponents]);
5414
5418
  var competitiveness = getBand(spread, bandProfiles);
5415
- return __assign(__assign({}, SUCCESS), { competitiveness: competitiveness });
5419
+ var pctSpreadValue = Array.isArray(spread) ? spread[0] : spread;
5420
+ return __assign(__assign({}, SUCCESS), { competitiveness: competitiveness, pctSpread: pctSpreadValue });
5416
5421
  }
5417
5422
 
5418
5423
  function findMatchupFormatAverageTimes(params) {
@@ -9016,6 +9021,9 @@ var _a$h, _b$4;
9016
9021
  var POLICY_ROUND_NAMING_DEFAULT = (_a$h = {},
9017
9022
  _a$h[POLICY_TYPE_ROUND_NAMING] = {
9018
9023
  policyName: 'Round Naming Default',
9024
+ namingConventions: {
9025
+ round: 'Round',
9026
+ },
9019
9027
  abbreviatedRoundNamingMap: {
9020
9028
  // key is matchUpsCount for the round
9021
9029
  1: 'F',
@@ -9056,6 +9064,10 @@ function getRoundContextProfile(_a) {
9056
9064
  defaultRoundNamingPolicy.abbreviatedRoundNamingMap ||
9057
9065
  {};
9058
9066
  var roundNamePrefix = (roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) || defaultRoundNamingPolicy.affixes;
9067
+ var roundNumberAffix = roundNamePrefix.roundNumber || defaultRoundNamingPolicy.affixes.roundNumber;
9068
+ var namingConventions = (roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.namingConventions) ||
9069
+ defaultRoundNamingPolicy.namingConventions;
9070
+ var roundNameFallback = namingConventions.round;
9059
9071
  var stageInitial = stage && stage !== MAIN && stage[0];
9060
9072
  var stageConstants = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.stageConstants;
9061
9073
  var stageConstant = (stage && (stageConstants === null || stageConstants === void 0 ? void 0 : stageConstants[stage])) || stageInitial;
@@ -9063,8 +9075,8 @@ function getRoundContextProfile(_a) {
9063
9075
  if (isRoundRobin || isAdHocStructure || isLuckyStructure) {
9064
9076
  Object.assign.apply(Object, __spreadArray([roundNamingProfile], __read(roundProfileKeys.map(function (key) {
9065
9077
  var _a;
9066
- var roundName = "Round ".concat(key);
9067
- var abbreviatedRoundName = "R".concat(key);
9078
+ var roundName = "".concat(roundNameFallback, " ").concat(key);
9079
+ var abbreviatedRoundName = "".concat(roundNumberAffix).concat(key);
9068
9080
  return _a = {}, _a[key] = { roundName: roundName, abbreviatedRoundName: abbreviatedRoundName }, _a;
9069
9081
  })), false));
9070
9082
  }
@@ -9436,8 +9448,8 @@ function getAllStructureMatchUps(_a) {
9436
9448
  (((_m = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.processCodes) === null || _m === void 0 ? void 0 : _m.length) && (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.processCodes)) ||
9437
9449
  (((_o = event === null || event === void 0 ? void 0 : event.processCodes) === null || _o === void 0 ? void 0 : _o.length) && (event === null || event === void 0 ? void 0 : event.processCodes)) ||
9438
9450
  (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.processCodes);
9439
- var competitiveness = (contextProfile === null || contextProfile === void 0 ? void 0 : contextProfile.withCompetitiveness) &&
9440
- getMatchUpCompetitiveness(__assign(__assign({}, contextContent), { matchUp: matchUp })).competitiveness;
9451
+ var competitiveProfile = (contextProfile === null || contextProfile === void 0 ? void 0 : contextProfile.withCompetitiveness) &&
9452
+ getMatchUpCompetitiveProfile(__assign(__assign({}, contextContent), { matchUp: matchUp }));
9441
9453
  // necessry for SINGLES/DOUBLES matchUps that are part of TEAM tournaments
9442
9454
  var finishingPositionRange = matchUp.finishingPositionRange ||
9443
9455
  additionalContext.finishingPositionRange;
@@ -9456,7 +9468,7 @@ function getAllStructureMatchUps(_a) {
9456
9468
  finishingPositionRange: finishingPositionRange,
9457
9469
  abbreviatedRoundName: abbreviatedRoundName,
9458
9470
  drawPositionsRange: drawPositionsRange,
9459
- competitiveness: competitiveness,
9471
+ competitiveProfile: competitiveProfile,
9460
9472
  structureName: structureName,
9461
9473
  stageSequence: stageSequence,
9462
9474
  drawPositions: drawPositions,
@@ -14954,13 +14966,19 @@ var ratingConstants = {
14954
14966
 
14955
14967
  var _a$g;
14956
14968
  var ratingsParameters = (_a$g = {},
14957
- _a$g[ELO] = { range: [0, 3000], decimalsCount: 0, defaultInitialization: 1500 },
14969
+ _a$g[ELO] = {
14970
+ defaultInitialization: 1500,
14971
+ decimalsCount: 0,
14972
+ range: [0, 3000],
14973
+ ascending: true,
14974
+ },
14958
14975
  _a$g[NTRP] = {
14959
14976
  accessors: ['ntrpRating', 'dntrpRatingHundredths'],
14960
14977
  attributes: { ustaRatingType: '' },
14961
14978
  accessor: 'dntrpRatingHundredths',
14962
14979
  defaultInitialization: 3,
14963
14980
  decimalsCount: 1,
14981
+ ascending: true,
14964
14982
  range: [1, 7],
14965
14983
  },
14966
14984
  _a$g[UTR] = {
@@ -14968,6 +14986,7 @@ var ratingsParameters = (_a$g = {},
14968
14986
  accessors: ['utrRating'],
14969
14987
  accessor: 'utrRating',
14970
14988
  decimalsCount: 2,
14989
+ ascending: true,
14971
14990
  range: [1, 16],
14972
14991
  },
14973
14992
  _a$g[WTN] = {
@@ -14975,6 +14994,7 @@ var ratingsParameters = (_a$g = {},
14975
14994
  accessors: ['wtnRating', 'confidence'],
14976
14995
  defaultInitialization: 23,
14977
14996
  accessor: 'wtnRating',
14997
+ ascending: false,
14978
14998
  decimalsCount: 2,
14979
14999
  range: [40, 1],
14980
15000
  },
@@ -28564,8 +28584,8 @@ function modifyMatchUpFormatTiming$1(_a) {
28564
28584
  var tournamentScheduling = (extension === null || extension === void 0 ? void 0 : extension.value) || {};
28565
28585
  var value = modifyScheduling(__assign(__assign({}, tournamentScheduling), { matchUpFormat: matchUpFormat, averageTimes: averageTimes, recoveryTimes: recoveryTimes }));
28566
28586
  addTournamentExtension({
28567
- tournamentRecord: tournamentRecord,
28568
28587
  extension: { name: name, value: value },
28588
+ tournamentRecord: tournamentRecord,
28569
28589
  });
28570
28590
  }
28571
28591
  return __assign({}, SUCCESS);
@@ -34844,7 +34864,7 @@ function checkSchedulingProfile$1(_a) {
34844
34864
 
34845
34865
  function scheduledSortedMatchUps(_a) {
34846
34866
  var e_1, _b, e_2, _c, e_3, _d, e_4, _e;
34847
- var _f = _a.matchUps, matchUps = _f === void 0 ? [] : _f, schedulingProfile = _a.schedulingProfile;
34867
+ var schedulingProfile = _a.schedulingProfile, _f = _a.matchUps, matchUps = _f === void 0 ? [] : _f;
34848
34868
  var profileHash = {};
34849
34869
  // hash is used to store a sort order value for scheduled rounds
34850
34870
  var getHash = function (_a) {
@@ -50543,6 +50563,10 @@ function removeDelegatedOutcome$1(_a) {
50543
50563
  });
50544
50564
  }
50545
50565
 
50566
+ function stringSort(a, b) {
50567
+ return (a || '').localeCompare(b || '');
50568
+ }
50569
+
50546
50570
  function generateCandidate(_a) {
50547
50571
  var _b = _a.maxIterations, maxIterations = _b === void 0 ? 4000 : _b, // cap the processing intensity of the candidate generator
50548
50572
  valueSortedPairings = _a.valueSortedPairings, // pairings sorted by value from low to high
@@ -50686,7 +50710,7 @@ function roundCandidate(_a) {
50686
50710
  return { value: candidateValue, participantIdPairings: participantIdPairings, maxDelta: maxDelta, maxDiff: maxDiff };
50687
50711
  }
50688
50712
  function pairingHash(id1, id2) {
50689
- return [id1, id2].sort().join('|');
50713
+ return [id1, id2].sort(stringSort).join('|');
50690
50714
  }
50691
50715
 
50692
50716
  function getPairingsData(_a) {
@@ -51377,8 +51401,10 @@ function attachPolicies(_a) {
51377
51401
  if (!drawDefinition.extensions)
51378
51402
  drawDefinition.extensions = [];
51379
51403
  var appliedPolicies = (_c = (_b = getAppliedPolicies({ drawDefinition: drawDefinition })) === null || _b === void 0 ? void 0 : _b.appliedPolicies) !== null && _c !== void 0 ? _c : {};
51404
+ var validReplacements = [POLICY_TYPE_ROUND_NAMING, POLICY_TYPE_DISPLAY];
51380
51405
  var applied = Object.keys(policyDefinitions).every(function (policyType) {
51381
- if (!appliedPolicies[policyType]) {
51406
+ if (!appliedPolicies[policyType] ||
51407
+ validReplacements.includes(policyType)) {
51382
51408
  appliedPolicies[policyType] = policyDefinitions[policyType];
51383
51409
  return true;
51384
51410
  }
@@ -57365,6 +57391,30 @@ function setTournamentStatus(_a) {
57365
57391
  return __assign({}, SUCCESS);
57366
57392
  }
57367
57393
 
57394
+ // TODO: ability to add onlineResources to other items, e.g. organisations, participants, persons, venues, courts
57395
+ function addOnlineResource(_a) {
57396
+ var tournamentRecord = _a.tournamentRecord, onlineResource = _a.onlineResource;
57397
+ if (!tournamentRecord)
57398
+ return { error: MISSING_TOURNAMENT_RECORD };
57399
+ if (!onlineResource)
57400
+ return { error: MISSING_VALUE };
57401
+ if (!tournamentRecord.onlineResources)
57402
+ tournamentRecord.onlineResources = [];
57403
+ // TODO: onlineResource validation
57404
+ tournamentRecord.onlineResources.push(onlineResource);
57405
+ return __assign({}, SUCCESS);
57406
+ /**
57407
+ [
57408
+ {
57409
+ identifier:
57410
+ resourceSubType: 'IMAGE',
57411
+ name: 'tournamentImage',
57412
+ resourceType: 'URL',
57413
+ },
57414
+ ];
57415
+ */
57416
+ }
57417
+
57368
57418
  function analyzeDraws(_a) {
57369
57419
  var _b;
57370
57420
  var tournamentRecord = _a.tournamentRecord;
@@ -57722,10 +57772,11 @@ function removeInvalidScheduling(_a) {
57722
57772
 
57723
57773
  // undocumented access to mocksEngine method
57724
57774
  var tournamentGovernor = {
57725
- addNotes: addNotes,
57726
- removeNotes: removeNotes,
57727
- analyzeDraws: analyzeDraws,
57728
57775
  analyzeTournament: analyzeTournament,
57776
+ analyzeDraws: analyzeDraws,
57777
+ addOnlineResource: addOnlineResource,
57778
+ removeNotes: removeNotes,
57779
+ addNotes: addNotes,
57729
57780
  completeDrawMatchUps: completeDrawMatchUps,
57730
57781
  getRounds: getRounds,
57731
57782
  getProfileRounds: getProfileRounds,
@@ -61121,13 +61172,6 @@ function deleteFlightAndFlightDraw(_a) {
61121
61172
  return refreshEventDrawOrder({ tournamentRecord: tournamentRecord, event: event });
61122
61173
  }
61123
61174
 
61124
- function generateAdHocMatchUps(params) {
61125
- return generateAdHocMatchUps$1(params);
61126
- }
61127
- function addAdHocMatchUps(params) {
61128
- return addAdHocMatchUps$1(params);
61129
- }
61130
-
61131
61175
  function attachFlightProfile(_a) {
61132
61176
  var _b;
61133
61177
  var deleteExisting = _a.deleteExisting, event = _a.event, flightProfile = _a.flightProfile;
@@ -61325,6 +61369,85 @@ function deleteAdHocMatchUps(params) {
61325
61369
  return deleteAdHocMatchUps$1(params);
61326
61370
  }
61327
61371
 
61372
+ function modifyDrawName(_a) {
61373
+ var _b;
61374
+ var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, flightProfile = _a.flightProfile, drawName = _a.drawName, drawId = _a.drawId, event = _a.event;
61375
+ if (!drawName || typeof drawName !== 'string')
61376
+ return decorateResult({
61377
+ result: { error: INVALID_VALUES },
61378
+ context: { drawName: drawName },
61379
+ });
61380
+ if (!flightProfile) {
61381
+ flightProfile = getFlightProfile({ event: event }).flightProfile;
61382
+ }
61383
+ var flight = (_b = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _b === void 0 ? void 0 : _b.find(function (flight) { return flight.drawId === drawId; });
61384
+ if (flight) {
61385
+ flight.drawName = drawName;
61386
+ var extension = {
61387
+ name: FLIGHT_PROFILE,
61388
+ value: __assign(__assign({}, flightProfile), { flights: flightProfile.flights }),
61389
+ };
61390
+ addEventExtension$1({ event: event, extension: extension });
61391
+ }
61392
+ if (drawDefinition) {
61393
+ drawDefinition.drawName = drawName;
61394
+ modifyDrawNotice({
61395
+ tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
61396
+ drawDefinition: drawDefinition,
61397
+ });
61398
+ }
61399
+ if (!flight && !drawDefinition) {
61400
+ return { error: MISSING_DRAW_DEFINITION };
61401
+ }
61402
+ return __assign(__assign({}, SUCCESS), { flight: flight });
61403
+ }
61404
+
61405
+ function modifyDrawDefinition(_a) {
61406
+ var _b;
61407
+ var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, drawUpdates = _a.drawUpdates, drawId = _a.drawId, event = _a.event;
61408
+ if (!isObject(drawUpdates))
61409
+ return { error: INVALID_END_TIME };
61410
+ var flightProfile = getFlightProfile({ event: event }).flightProfile;
61411
+ var nameResult = drawUpdates.drawName &&
61412
+ modifyDrawName({
61413
+ drawName: drawUpdates.drawName,
61414
+ tournamentRecord: tournamentRecord,
61415
+ drawDefinition: drawDefinition,
61416
+ flightProfile: flightProfile,
61417
+ drawId: drawId,
61418
+ event: event,
61419
+ });
61420
+ if (nameResult === null || nameResult === void 0 ? void 0 : nameResult.error)
61421
+ return nameResult === null || nameResult === void 0 ? void 0 : nameResult.error;
61422
+ var flight = (nameResult === null || nameResult === void 0 ? void 0 : nameResult.flight) ||
61423
+ ((_b = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _b === void 0 ? void 0 : _b.find(function (flight) { return flight.drawId === drawId; }));
61424
+ if (!flight && !drawDefinition) {
61425
+ return { error: MISSING_DRAW_DEFINITION };
61426
+ }
61427
+ if (flight) {
61428
+ // TODO: any relevant changes to flightProfile
61429
+ var extension = {
61430
+ name: FLIGHT_PROFILE,
61431
+ value: __assign(__assign({}, flightProfile), { flights: flightProfile.flights }),
61432
+ };
61433
+ addEventExtension$1({ event: event, extension: extension });
61434
+ }
61435
+ if (drawDefinition) {
61436
+ if (drawUpdates.policyDefinitions) {
61437
+ attachPolicies({
61438
+ policyDefinitions: drawUpdates.policyDefinitions,
61439
+ drawDefinition: drawDefinition,
61440
+ });
61441
+ }
61442
+ // TODO: any relevant changes to drawDefinition
61443
+ modifyDrawNotice({
61444
+ tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
61445
+ drawDefinition: drawDefinition,
61446
+ });
61447
+ }
61448
+ return __assign({}, SUCCESS);
61449
+ }
61450
+
61328
61451
  function resetDrawDefinition(_a) {
61329
61452
  var e_1, _b, e_2, _c;
61330
61453
  var _d;
@@ -61530,31 +61653,6 @@ function setOrderOfFinish(params) {
61530
61653
  return setOrderOfFinish$1(params);
61531
61654
  }
61532
61655
 
61533
- function modifyDrawName(_a) {
61534
- var _b;
61535
- var event = _a.event, drawId = _a.drawId, drawDefinition = _a.drawDefinition, drawName = _a.drawName;
61536
- if (!drawName || typeof drawName !== 'string')
61537
- return { error: INVALID_VALUES, drawName: drawName };
61538
- var flightProfile = getFlightProfile({ event: event }).flightProfile;
61539
- var flight = (_b = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _b === void 0 ? void 0 : _b.find(function (flight) { return flight.drawId === drawId; });
61540
- if (flight) {
61541
- flight.drawName = drawName;
61542
- var extension = {
61543
- name: FLIGHT_PROFILE,
61544
- value: __assign(__assign({}, flightProfile), { flights: flightProfile.flights }),
61545
- };
61546
- addEventExtension$1({ event: event, extension: extension });
61547
- }
61548
- if (drawDefinition) {
61549
- drawDefinition.drawName = drawName;
61550
- modifyDrawNotice({ drawDefinition: drawDefinition });
61551
- }
61552
- if (!flight && !drawDefinition) {
61553
- return { error: MISSING_DRAW_DEFINITION };
61554
- }
61555
- return __assign({}, SUCCESS);
61556
- }
61557
-
61558
61656
  function modifyEventEntries(_a) {
61559
61657
  var _b;
61560
61658
  var _c = _a.entryStatus, entryStatus = _c === void 0 ? DIRECT_ACCEPTANCE : _c, _d = _a.unpairedParticipantIds, unpairedParticipantIds = _d === void 0 ? [] : _d, _e = _a.participantIdPairs, participantIdPairs = _e === void 0 ? [] : _e, _f = _a.entryStage, entryStage = _f === void 0 ? MAIN : _f, tournamentRecord = _a.tournamentRecord, event = _a.event;
@@ -61678,6 +61776,13 @@ function addFlight(_a) {
61678
61776
  return addEventExtension$1({ event: event, extension: extension });
61679
61777
  }
61680
61778
 
61779
+ function generateAdHocMatchUps(params) {
61780
+ return generateAdHocMatchUps$1(params);
61781
+ }
61782
+ function addAdHocMatchUps(params) {
61783
+ return addAdHocMatchUps$1(params);
61784
+ }
61785
+
61681
61786
  function attachConsolationStructures(params) {
61682
61787
  return attachStructures(__assign(__assign({}, params), { itemType: 'attachConsolationStructures' }));
61683
61788
  }
@@ -63003,6 +63108,71 @@ function enableTieAutoCalc(params) {
63003
63108
  return enableTieAutoCalc$1(params);
63004
63109
  }
63005
63110
 
63111
+ function modifyEvent(_a) {
63112
+ var _b;
63113
+ var tournamentRecord = _a.tournamentRecord, eventUpdates = _a.eventUpdates, eventId = _a.eventId, event = _a.event;
63114
+ if (!tournamentRecord)
63115
+ return { error: MISSING_TOURNAMENT_RECORD };
63116
+ if (!isString(eventId) || !isObject(eventUpdates))
63117
+ return { error: INVALID_VALUES };
63118
+ var enteredParticipantIds = ((_b = event === null || event === void 0 ? void 0 : event.entries) === null || _b === void 0 ? void 0 : _b.filter(function (_a) {
63119
+ var entryStatus = _a.entryStatus;
63120
+ var status = entryStatus;
63121
+ return __spreadArray(__spreadArray([], __read(STRUCTURE_SELECTED_STATUSES), false), [ALTERNATE], false).includes(status);
63122
+ }).map(function (_a) {
63123
+ var participantId = _a.participantId;
63124
+ return participantId;
63125
+ })) || [];
63126
+ var enteredParticipants = enteredParticipantIds
63127
+ ? getParticipants$1({
63128
+ participantFilters: { participantIds: enteredParticipantIds },
63129
+ withIndividualParticipants: true,
63130
+ tournamentRecord: tournamentRecord,
63131
+ }).participants || []
63132
+ : [];
63133
+ var genderAccumulator = [];
63134
+ var enteredParticipantTypes = enteredParticipants.reduce(function (types, participant) {
63135
+ var _a, _b;
63136
+ var genders = ((_a = participant.person) === null || _a === void 0 ? void 0 : _a.sex)
63137
+ ? [participant.person.sex]
63138
+ : ((_b = participant.individualParticpants) === null || _b === void 0 ? void 0 : _b.map(function (p) { var _a; return (_a = p.person) === null || _a === void 0 ? void 0 : _a.sex; })) || [];
63139
+ genderAccumulator.push.apply(genderAccumulator, __spreadArray([], __read(genders), false));
63140
+ return !types.includes(participant.participantType)
63141
+ ? types.concat(participant.participantType)
63142
+ : types;
63143
+ }, []);
63144
+ var enteredParticipantGenders = unique(genderAccumulator);
63145
+ var validGender = !enteredParticipantGenders.length ||
63146
+ [MIXED, ANY].includes(eventUpdates.gender || '') ||
63147
+ (enteredParticipantGenders.length === 1 &&
63148
+ enteredParticipantGenders[0] === eventUpdates.gender);
63149
+ if (eventUpdates.gender && !validGender)
63150
+ return decorateResult({
63151
+ context: { gender: eventUpdates.gender },
63152
+ result: { error: INVALID_VALUES },
63153
+ });
63154
+ var validEventTypes = (enteredParticipantTypes.includes(TEAM$1) && [TEAM$1]) ||
63155
+ (enteredParticipantTypes.includes(INDIVIDUAL) && [SINGLES]) ||
63156
+ (enteredParticipantTypes.includes(PAIR) && [DOUBLES]) || [
63157
+ DOUBLES,
63158
+ SINGLES,
63159
+ TEAM$1,
63160
+ ];
63161
+ var validEventType = validEventTypes.includes(eventUpdates.eventType || '');
63162
+ if (eventUpdates.eventType && !validEventType)
63163
+ return decorateResult({
63164
+ context: { participantType: eventUpdates.eventType },
63165
+ result: { error: INVALID_VALUES },
63166
+ });
63167
+ if (eventUpdates.eventType)
63168
+ event.eventType === eventUpdates.eventType;
63169
+ if (eventUpdates.eventName)
63170
+ event.eventName = eventUpdates.eventName;
63171
+ if (eventUpdates.gender)
63172
+ event.gender = eventUpdates.gender;
63173
+ return __assign({}, SUCCESS);
63174
+ }
63175
+
63006
63176
  var eventGovernor = {
63007
63177
  generateQualifyingStructure: generateQualifyingStructure,
63008
63178
  attachQualifyingStructure: attachQualifyingStructure,
@@ -63023,11 +63193,12 @@ var eventGovernor = {
63023
63193
  modifyTieFormat: modifyTieFormat$1,
63024
63194
  resetScorecard: resetScorecard,
63025
63195
  resetTieFormat: resetTieFormat$1,
63026
- addEvent: addEvent,
63027
- deleteEvents: deleteEvents,
63028
- setEventDates: setEventDates,
63029
63196
  setEventStartDate: setEventStartDate,
63030
63197
  setEventEndDate: setEventEndDate,
63198
+ setEventDates: setEventDates,
63199
+ deleteEvents: deleteEvents,
63200
+ modifyEvent: modifyEvent,
63201
+ addEvent: addEvent,
63031
63202
  removeSeededParticipant: removeSeededParticipant,
63032
63203
  removeScaleValues: removeScaleValues,
63033
63204
  checkValidEntries: checkValidEntries,
@@ -63038,6 +63209,7 @@ var eventGovernor = {
63038
63209
  getAvailablePlayoffProfiles: getAvailablePlayoffProfiles,
63039
63210
  deleteDrawDefinitions: deleteDrawDefinitions,
63040
63211
  addPlayoffStructures: addPlayoffStructures,
63212
+ modifyDrawDefinition: modifyDrawDefinition,
63041
63213
  addDrawDefinition: addDrawDefinition$1,
63042
63214
  removeStructure: removeStructure,
63043
63215
  modifyDrawName: modifyDrawName,
@@ -63138,21 +63310,30 @@ function getMaxEntryPosition(params) {
63138
63310
  }
63139
63311
 
63140
63312
  function getPredictiveAccuracy(params) {
63141
- var _a, _b, _c, _d;
63313
+ var _a, _b, _c, _d, _e, _f, _g;
63142
63314
  var matchUps = params.matchUps;
63143
- var tournamentRecord = params.tournamentRecord, _e = params.ascending, ascending = _e === void 0 ? true : _e, drawDefinition = params.drawDefinition, excludeMargin = params.excludeMargin, exclusionRule = params.exclusionRule, valueAccessor = params.valueAccessor, zoneDoubling = params.zoneDoubling, matchUpType = params.matchUpType, zoneMargin = params.zoneMargin, scaleName = params.scaleName, eventId = params.eventId, drawId = params.drawId, event = params.event;
63315
+ var tournamentRecord = params.tournamentRecord, drawDefinition = params.drawDefinition, excludeMargin = params.excludeMargin, exclusionRule = params.exclusionRule, zoneDoubling = params.zoneDoubling, matchUpType = params.matchUpType, scaleName = params.scaleName, eventId = params.eventId, zonePct = params.zonePct, drawId = params.drawId, event = params.event;
63144
63316
  if (!tournamentRecord && !matchUps)
63145
63317
  return { error: MISSING_TOURNAMENT_RECORD };
63146
63318
  if (matchUpType && ![SINGLES$1, DOUBLES$1].includes(matchUpType))
63147
63319
  return { error: INVALID_VALUES, info: { matchUpType: matchUpType } };
63148
63320
  if (matchUps && !validMatchUps(matchUps))
63149
63321
  return { error: INVALID_VALUES, context: { matchUps: matchUps } };
63322
+ var scaleProfile = ratingsParameters[scaleName];
63323
+ var ascending = (_b = (_a = scaleProfile === null || scaleProfile === void 0 ? void 0 : scaleProfile.ascending) !== null && _a !== void 0 ? _a : params.ascending) !== null && _b !== void 0 ? _b : false;
63324
+ var valueAccessor = (_c = scaleProfile === null || scaleProfile === void 0 ? void 0 : scaleProfile.accessor) !== null && _c !== void 0 ? _c : params.valueAccessor;
63325
+ var ratingsRangeDifference = Array.isArray(scaleProfile === null || scaleProfile === void 0 ? void 0 : scaleProfile.range)
63326
+ ? Math.abs(scaleProfile.range[0] - scaleProfile.range[1])
63327
+ : 0;
63328
+ var zoneMargin = isConvertableInteger(zonePct) && ratingsRangeDifference
63329
+ ? (zonePct || 0 / 100) * ratingsRangeDifference
63330
+ : params.zoneMargin || ratingsRangeDifference;
63150
63331
  var contextProfile = { withScaleValues: true, withCompetitiveness: true };
63151
63332
  var contextFilters = {
63152
63333
  matchUpTypes: matchUpType ? [matchUpType] : [SINGLES$1, DOUBLES$1],
63153
63334
  };
63154
63335
  var participants = tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants;
63155
- if ((_a = matchUps === null || matchUps === void 0 ? void 0 : matchUps[0]) === null || _a === void 0 ? void 0 : _a.hasContext) {
63336
+ if ((_d = matchUps === null || matchUps === void 0 ? void 0 : matchUps[0]) === null || _d === void 0 ? void 0 : _d.hasContext) {
63156
63337
  if (drawId) {
63157
63338
  matchUps = matchUps.filter(function (matchUp) { return matchUp.drawId === drawId; });
63158
63339
  }
@@ -63165,27 +63346,27 @@ function getPredictiveAccuracy(params) {
63165
63346
  (drawId && !drawDefinition && []) ||
63166
63347
  (!drawId && eventId && !event && []) ||
63167
63348
  (drawId &&
63168
- ((_b = allDrawMatchUps$1({
63349
+ ((_e = allDrawMatchUps$1({
63169
63350
  inContext: true,
63170
63351
  drawDefinition: drawDefinition,
63171
63352
  contextFilters: contextFilters,
63172
63353
  contextProfile: contextProfile,
63173
63354
  participants: participants,
63174
- })) === null || _b === void 0 ? void 0 : _b.matchUps)) ||
63355
+ })) === null || _e === void 0 ? void 0 : _e.matchUps)) ||
63175
63356
  (!drawId &&
63176
63357
  eventId &&
63177
- ((_c = allEventMatchUps({
63358
+ ((_f = allEventMatchUps({
63178
63359
  inContext: true,
63179
63360
  contextFilters: contextFilters,
63180
63361
  contextProfile: contextProfile,
63181
63362
  participants: participants,
63182
63363
  event: event,
63183
- })) === null || _c === void 0 ? void 0 : _c.matchUps)) ||
63184
- ((_d = allTournamentMatchUps({
63364
+ })) === null || _f === void 0 ? void 0 : _f.matchUps)) ||
63365
+ ((_g = allTournamentMatchUps({
63185
63366
  tournamentRecord: tournamentRecord,
63186
63367
  contextFilters: contextFilters,
63187
63368
  contextProfile: contextProfile,
63188
- })) === null || _d === void 0 ? void 0 : _d.matchUps) ||
63369
+ })) === null || _g === void 0 ? void 0 : _g.matchUps) ||
63189
63370
  [];
63190
63371
  }
63191
63372
  if (matchUpType) {
@@ -63193,7 +63374,7 @@ function getPredictiveAccuracy(params) {
63193
63374
  }
63194
63375
  var relevantMatchUps = matchUps.filter(function (_a) {
63195
63376
  var winningSide = _a.winningSide, score = _a.score, sides = _a.sides, matchUpStatus = _a.matchUpStatus;
63196
- return ![RETIRED$1, DEFAULTED, WALKOVER$2, DEAD_RUBBER, ABANDONED$1].includes(matchUpStatus) &&
63377
+ return ![RETIRED$1, DEFAULTED, WALKOVER$2, DEAD_RUBBER, ABANDONED$1].includes(matchUpStatus || '') &&
63197
63378
  scoreHasValue({ score: score }) &&
63198
63379
  (sides === null || sides === void 0 ? void 0 : sides.length) === 2 &&
63199
63380
  winningSide;
@@ -63206,11 +63387,13 @@ function getPredictiveAccuracy(params) {
63206
63387
  ascending: ascending,
63207
63388
  scaleName: scaleName,
63208
63389
  });
63209
- var marginCalc = !zoneDoubling || matchUpType === SINGLES$1 ? zoneMargin : zoneMargin * 2;
63210
- var zoneData = zoneMargin &&
63211
- relevantMatchUps
63390
+ var marginCalc = !zoneDoubling || matchUpType === SINGLES$1
63391
+ ? zoneMargin
63392
+ : (zoneMargin || 0) * 2;
63393
+ var zoneData = zoneMargin
63394
+ ? relevantMatchUps
63212
63395
  .map(function (_a) {
63213
- var competitiveness = _a.competitiveness, matchUpType = _a.matchUpType, score = _a.score, sides = _a.sides;
63396
+ var competitiveProfile = _a.competitiveProfile, matchUpType = _a.matchUpType, score = _a.score, sides = _a.sides;
63214
63397
  var sideValues = getSideValues({
63215
63398
  valueAccessor: valueAccessor,
63216
63399
  matchUpType: matchUpType,
@@ -63218,13 +63401,18 @@ function getPredictiveAccuracy(params) {
63218
63401
  sides: sides,
63219
63402
  });
63220
63403
  var valuesGap = Math.abs(sideValues[0].value - sideValues[1].value);
63221
- return { competitiveness: competitiveness, score: score, valuesGap: valuesGap };
63404
+ return {
63405
+ competitiveness: competitiveProfile === null || competitiveProfile === void 0 ? void 0 : competitiveProfile.competitiveness,
63406
+ valuesGap: valuesGap,
63407
+ score: score,
63408
+ };
63222
63409
  })
63223
63410
  .filter(function (_a) {
63224
63411
  var valuesGap = _a.valuesGap;
63225
63412
  return valuesGap <= marginCalc;
63226
- });
63227
- var zoneBands = (zoneData === null || zoneData === void 0 ? void 0 : zoneData.length) && getGroupingBands({ zoneData: zoneData });
63413
+ })
63414
+ : [];
63415
+ var zoneBands = getGroupingBands({ zoneData: zoneData });
63228
63416
  var totalZoneMatchUps = zoneBands && [].concat(Object.values(zoneBands)).flat().length;
63229
63417
  var zoneDistribution = totalZoneMatchUps && Object.assign.apply(Object, __spreadArray([{}], __read(Object.keys(zoneBands).map(function (key) {
63230
63418
  var _a;
@@ -63397,7 +63585,7 @@ function getGroupingAccuracy(_a) {
63397
63585
  continue;
63398
63586
  }
63399
63587
  var valuesGap = sideValues[winningIndex].value - sideValues[1 - winningIndex].value;
63400
- var floatMargin = parseFloat(excludeMargin);
63588
+ var floatMargin = parseFloat(excludeMargin || 0);
63401
63589
  var excludeGap = floatMargin && Math.abs(valuesGap) < floatMargin;
63402
63590
  if (excludeGap) {
63403
63591
  accuracy.excluded.push({
@@ -63410,8 +63598,8 @@ function getGroupingAccuracy(_a) {
63410
63598
  });
63411
63599
  continue;
63412
63600
  }
63413
- // when ascending is true winning value will be less than losing value
63414
- var signedGap = ascending ? valuesGap * -1 : valuesGap;
63601
+ // when ascending is true winning value will be greater than losing value
63602
+ var signedGap = ascending ? valuesGap : valuesGap * -1;
63415
63603
  var winningScoreString = winningSide === 1 ? score === null || score === void 0 ? void 0 : score.scoreStringSide1 : score === null || score === void 0 ? void 0 : score.scoreStringSide2;
63416
63604
  if (signedGap > 0) {
63417
63605
  accuracy.affirmative.push({
@@ -63506,18 +63694,18 @@ function getMatchUpFormat(_a) {
63506
63694
 
63507
63695
  function getMatchUpsStats(_a) {
63508
63696
  var _b, _c;
63509
- var competitiveProfile = _a.competitiveProfile, tournamentRecord = _a.tournamentRecord, matchUps = _a.matchUps;
63697
+ var profileBands = _a.profileBands, tournamentRecord = _a.tournamentRecord, matchUps = _a.matchUps;
63510
63698
  if (!validMatchUps(matchUps))
63511
63699
  return { error: MISSING_MATCHUPS };
63512
- var policy = !competitiveProfile &&
63700
+ var policy = !profileBands &&
63513
63701
  findPolicy({
63514
63702
  policyType: POLICY_TYPE_COMPETITIVE_BANDS,
63515
63703
  tournamentRecord: tournamentRecord,
63516
63704
  }).policy;
63517
- var bandProfiles = competitiveProfile ||
63518
- (policy === null || policy === void 0 ? void 0 : policy.competitiveProfile) ||
63705
+ var bandProfiles = profileBands ||
63706
+ (policy === null || policy === void 0 ? void 0 : policy.profileBands) ||
63519
63707
  POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS]
63520
- .competitiveProfile;
63708
+ .profileBands;
63521
63709
  var relevantMatchUps = matchUps.filter(function (_a) {
63522
63710
  var winningSide = _a.winningSide;
63523
63711
  return winningSide;
@@ -63710,7 +63898,7 @@ var queryGovernor = {
63710
63898
  getPositionAssignments: getPositionAssignments,
63711
63899
  isValidMatchUpFormat: isValid,
63712
63900
  getMaxEntryPosition: getMaxEntryPosition,
63713
- getMatchUpCompetitiveness: getMatchUpCompetitiveness,
63901
+ getMatchUpCompetitiveProfile: getMatchUpCompetitiveProfile,
63714
63902
  findVenue: findVenue,
63715
63903
  getCourts: getCourts,
63716
63904
  getVenuesAndCourts: getVenuesAndCourts$1,