tods-competition-factory 1.7.6 → 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.
package/dist/index.mjs CHANGED
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.7.6";
336
+ return "1.7.7";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -1727,6 +1727,9 @@ function handleCaughtError({
1727
1727
  });
1728
1728
  }
1729
1729
 
1730
+ function isString(obj) {
1731
+ return typeof obj === "string";
1732
+ }
1730
1733
  function isObject(obj) {
1731
1734
  return typeof obj === "object";
1732
1735
  }
@@ -4217,7 +4220,8 @@ function getCollectionPositionMatchUps({ matchUps }) {
4217
4220
 
4218
4221
  const add = (a, b) => (a || 0) + (b || 0);
4219
4222
  function getBand(spread, bandProfiles) {
4220
- return isNaN(spread) && WALKOVER$1 || spread <= bandProfiles[DECISIVE] && DECISIVE || spread <= bandProfiles[ROUTINE] && ROUTINE || COMPETITIVE;
4223
+ const spreadValue = Array.isArray(spread) ? spread[0] : spread;
4224
+ return isNaN(spreadValue) && WALKOVER$1 || spreadValue <= bandProfiles[DECISIVE] && DECISIVE || spreadValue <= bandProfiles[ROUTINE] && ROUTINE || COMPETITIVE;
4221
4225
  }
4222
4226
  function getScoreComponents({ score }) {
4223
4227
  const sets = score?.sets || [];
@@ -4287,7 +4291,8 @@ function getMatchUpCompetitiveProfile({
4287
4291
  const scoreComponents = getScoreComponents({ score });
4288
4292
  const spread = pctSpread([scoreComponents]);
4289
4293
  const competitiveness = getBand(spread, bandProfiles);
4290
- return { ...SUCCESS, competitiveness, pctSpread: spread };
4294
+ const pctSpreadValue = Array.isArray(spread) ? spread[0] : spread;
4295
+ return { ...SUCCESS, competitiveness, pctSpread: pctSpreadValue };
4291
4296
  }
4292
4297
 
4293
4298
  function findMatchupFormatAverageTimes(params) {
@@ -7606,6 +7611,9 @@ function isAdHoc({ drawDefinition, structure }) {
7606
7611
  const POLICY_ROUND_NAMING_DEFAULT = {
7607
7612
  [POLICY_TYPE_ROUND_NAMING]: {
7608
7613
  policyName: "Round Naming Default",
7614
+ namingConventions: {
7615
+ round: "Round"
7616
+ },
7609
7617
  abbreviatedRoundNamingMap: {
7610
7618
  // key is matchUpsCount for the round
7611
7619
  1: "F",
@@ -7645,6 +7653,9 @@ function getRoundContextProfile({
7645
7653
  const roundNamingMap = roundNamingPolicy?.roundNamingMap || defaultRoundNamingPolicy.roundNamingMap || {};
7646
7654
  const abbreviatedRoundNamingMap = roundNamingPolicy?.abbreviatedRoundNamingMap || defaultRoundNamingPolicy.abbreviatedRoundNamingMap || {};
7647
7655
  const roundNamePrefix = roundNamingPolicy?.affixes || defaultRoundNamingPolicy.affixes;
7656
+ const roundNumberAffix = roundNamePrefix.roundNumber || defaultRoundNamingPolicy.affixes.roundNumber;
7657
+ const namingConventions = roundNamingPolicy?.namingConventions || defaultRoundNamingPolicy.namingConventions;
7658
+ const roundNameFallback = namingConventions.round;
7648
7659
  const stageInitial = stage && stage !== MAIN && stage[0];
7649
7660
  const stageConstants = roundNamingPolicy?.stageConstants;
7650
7661
  const stageConstant = stage && stageConstants?.[stage] || stageInitial;
@@ -7653,8 +7664,8 @@ function getRoundContextProfile({
7653
7664
  Object.assign(
7654
7665
  roundNamingProfile,
7655
7666
  ...roundProfileKeys.map((key) => {
7656
- const roundName = `Round ${key}`;
7657
- const abbreviatedRoundName = `R${key}`;
7667
+ const roundName = `${roundNameFallback} ${key}`;
7668
+ const abbreviatedRoundName = `${roundNumberAffix}${key}`;
7658
7669
  return { [key]: { roundName, abbreviatedRoundName } };
7659
7670
  })
7660
7671
  );
@@ -26381,8 +26392,8 @@ function modifyMatchUpFormatTiming$1({
26381
26392
  recoveryTimes
26382
26393
  });
26383
26394
  addTournamentExtension({
26384
- tournamentRecord,
26385
- extension: { name, value }
26395
+ extension: { name, value },
26396
+ tournamentRecord
26386
26397
  });
26387
26398
  }
26388
26399
  return { ...SUCCESS };
@@ -47470,7 +47481,10 @@ const matchUpGovernor = {
47470
47481
  validateScore
47471
47482
  };
47472
47483
 
47473
- function attachPolicies({ drawDefinition, policyDefinitions }) {
47484
+ function attachPolicies({
47485
+ drawDefinition,
47486
+ policyDefinitions
47487
+ }) {
47474
47488
  if (!drawDefinition) {
47475
47489
  return { error: MISSING_DRAW_DEFINITION };
47476
47490
  }
@@ -47480,8 +47494,9 @@ function attachPolicies({ drawDefinition, policyDefinitions }) {
47480
47494
  if (!drawDefinition.extensions)
47481
47495
  drawDefinition.extensions = [];
47482
47496
  const appliedPolicies = getAppliedPolicies({ drawDefinition })?.appliedPolicies ?? {};
47497
+ const validReplacements = [POLICY_TYPE_ROUND_NAMING, POLICY_TYPE_DISPLAY];
47483
47498
  const applied = Object.keys(policyDefinitions).every((policyType) => {
47484
- if (!appliedPolicies[policyType]) {
47499
+ if (!appliedPolicies[policyType] || validReplacements.includes(policyType)) {
47485
47500
  appliedPolicies[policyType] = policyDefinitions[policyType];
47486
47501
  return true;
47487
47502
  } else {
@@ -56423,13 +56438,6 @@ function deleteFlightAndFlightDraw({
56423
56438
  return refreshEventDrawOrder({ tournamentRecord, event });
56424
56439
  }
56425
56440
 
56426
- function generateAdHocMatchUps(params) {
56427
- return generateAdHocMatchUps$1(params);
56428
- }
56429
- function addAdHocMatchUps(params) {
56430
- return addAdHocMatchUps$1(params);
56431
- }
56432
-
56433
56441
  function attachFlightProfile({ deleteExisting, event, flightProfile }) {
56434
56442
  const stack = "attachFlightProfile";
56435
56443
  if (!flightProfile)
@@ -56635,6 +56643,98 @@ function deleteAdHocMatchUps(params) {
56635
56643
  return deleteAdHocMatchUps$1(params);
56636
56644
  }
56637
56645
 
56646
+ function modifyDrawName({
56647
+ tournamentRecord,
56648
+ drawDefinition,
56649
+ flightProfile,
56650
+ drawName,
56651
+ drawId,
56652
+ event
56653
+ }) {
56654
+ if (!drawName || typeof drawName !== "string")
56655
+ return decorateResult({
56656
+ result: { error: INVALID_VALUES },
56657
+ context: { drawName }
56658
+ });
56659
+ if (!flightProfile) {
56660
+ flightProfile = getFlightProfile({ event }).flightProfile;
56661
+ }
56662
+ const flight = flightProfile?.flights?.find(
56663
+ (flight2) => flight2.drawId === drawId
56664
+ );
56665
+ if (flight) {
56666
+ flight.drawName = drawName;
56667
+ const extension = {
56668
+ name: FLIGHT_PROFILE,
56669
+ value: {
56670
+ ...flightProfile,
56671
+ flights: flightProfile.flights
56672
+ }
56673
+ };
56674
+ addEventExtension$1({ event, extension });
56675
+ }
56676
+ if (drawDefinition) {
56677
+ drawDefinition.drawName = drawName;
56678
+ modifyDrawNotice({
56679
+ tournamentId: tournamentRecord?.tournamentId,
56680
+ drawDefinition
56681
+ });
56682
+ }
56683
+ if (!flight && !drawDefinition) {
56684
+ return { error: MISSING_DRAW_DEFINITION };
56685
+ }
56686
+ return { ...SUCCESS, flight };
56687
+ }
56688
+
56689
+ function modifyDrawDefinition({
56690
+ tournamentRecord,
56691
+ drawDefinition,
56692
+ drawUpdates,
56693
+ drawId,
56694
+ event
56695
+ }) {
56696
+ if (!isObject(drawUpdates))
56697
+ return { error: INVALID_END_TIME };
56698
+ const flightProfile = getFlightProfile({ event }).flightProfile;
56699
+ const nameResult = drawUpdates.drawName && modifyDrawName({
56700
+ drawName: drawUpdates.drawName,
56701
+ tournamentRecord,
56702
+ drawDefinition,
56703
+ flightProfile,
56704
+ drawId,
56705
+ event
56706
+ });
56707
+ if (nameResult?.error)
56708
+ return nameResult?.error;
56709
+ const flight = nameResult?.flight || flightProfile?.flights?.find((flight2) => flight2.drawId === drawId);
56710
+ if (!flight && !drawDefinition) {
56711
+ return { error: MISSING_DRAW_DEFINITION };
56712
+ }
56713
+ if (flight) {
56714
+ const extension = {
56715
+ name: FLIGHT_PROFILE,
56716
+ value: {
56717
+ ...flightProfile,
56718
+ flights: flightProfile.flights
56719
+ }
56720
+ };
56721
+ addEventExtension$1({ event, extension });
56722
+ }
56723
+ if (drawDefinition) {
56724
+ if (drawUpdates.policyDefinitions) {
56725
+ attachPolicies({
56726
+ policyDefinitions: drawUpdates.policyDefinitions,
56727
+ drawDefinition
56728
+ });
56729
+ }
56730
+ modifyDrawNotice({
56731
+ tournamentId: tournamentRecord?.tournamentId,
56732
+ drawDefinition
56733
+ });
56734
+ }
56735
+ return { ...SUCCESS };
56736
+ }
56737
+
56638
56738
  function resetDrawDefinition({
56639
56739
  tournamentRecord,
56640
56740
  removeScheduling,
@@ -56795,34 +56895,6 @@ function setOrderOfFinish(params) {
56795
56895
  return setOrderOfFinish$1(params);
56796
56896
  }
56797
56897
 
56798
- function modifyDrawName({ event, drawId, drawDefinition, drawName }) {
56799
- if (!drawName || typeof drawName !== "string")
56800
- return { error: INVALID_VALUES, drawName };
56801
- const { flightProfile } = getFlightProfile({ event });
56802
- const flight = flightProfile?.flights?.find(
56803
- (flight2) => flight2.drawId === drawId
56804
- );
56805
- if (flight) {
56806
- flight.drawName = drawName;
56807
- const extension = {
56808
- name: FLIGHT_PROFILE,
56809
- value: {
56810
- ...flightProfile,
56811
- flights: flightProfile.flights
56812
- }
56813
- };
56814
- addEventExtension$1({ event, extension });
56815
- }
56816
- if (drawDefinition) {
56817
- drawDefinition.drawName = drawName;
56818
- modifyDrawNotice({ drawDefinition });
56819
- }
56820
- if (!flight && !drawDefinition) {
56821
- return { error: MISSING_DRAW_DEFINITION };
56822
- }
56823
- return { ...SUCCESS };
56824
- }
56825
-
56826
56898
  function modifyEventEntries({
56827
56899
  entryStatus = DIRECT_ACCEPTANCE,
56828
56900
  unpairedParticipantIds = [],
@@ -56958,6 +57030,13 @@ function addFlight({
56958
57030
  return addEventExtension$1({ event, extension });
56959
57031
  }
56960
57032
 
57033
+ function generateAdHocMatchUps(params) {
57034
+ return generateAdHocMatchUps$1(params);
57035
+ }
57036
+ function addAdHocMatchUps(params) {
57037
+ return addAdHocMatchUps$1(params);
57038
+ }
57039
+
56961
57040
  function attachConsolationStructures(params) {
56962
57041
  return attachStructures({
56963
57042
  ...params,
@@ -58119,6 +58198,61 @@ function enableTieAutoCalc(params) {
58119
58198
  return enableTieAutoCalc$1(params);
58120
58199
  }
58121
58200
 
58201
+ function modifyEvent({
58202
+ tournamentRecord,
58203
+ eventUpdates,
58204
+ eventId,
58205
+ event
58206
+ }) {
58207
+ if (!tournamentRecord)
58208
+ return { error: MISSING_TOURNAMENT_RECORD };
58209
+ if (!isString(eventId) || !isObject(eventUpdates))
58210
+ return { error: INVALID_VALUES };
58211
+ const enteredParticipantIds = event?.entries?.filter(({ entryStatus }) => {
58212
+ const status = entryStatus;
58213
+ return [...STRUCTURE_SELECTED_STATUSES, ALTERNATE].includes(status);
58214
+ }).map(({ participantId }) => participantId) || [];
58215
+ const enteredParticipants = enteredParticipantIds ? getParticipants$1({
58216
+ participantFilters: { participantIds: enteredParticipantIds },
58217
+ withIndividualParticipants: true,
58218
+ tournamentRecord
58219
+ }).participants || [] : [];
58220
+ const genderAccumulator = [];
58221
+ const enteredParticipantTypes = enteredParticipants.reduce(
58222
+ (types, participant) => {
58223
+ const genders = participant.person?.sex ? [participant.person.sex] : participant.individualParticpants?.map((p) => p.person?.sex) || [];
58224
+ genderAccumulator.push(...genders);
58225
+ return !types.includes(participant.participantType) ? types.concat(participant.participantType) : types;
58226
+ },
58227
+ []
58228
+ );
58229
+ const enteredParticipantGenders = unique(genderAccumulator);
58230
+ const validGender = !enteredParticipantGenders.length || [MIXED, ANY].includes(eventUpdates.gender || "") || enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender;
58231
+ if (eventUpdates.gender && !validGender)
58232
+ return decorateResult({
58233
+ context: { gender: eventUpdates.gender },
58234
+ result: { error: INVALID_VALUES }
58235
+ });
58236
+ const validEventTypes = enteredParticipantTypes.includes(TEAM$1) && [TEAM$1] || enteredParticipantTypes.includes(INDIVIDUAL) && [SINGLES] || enteredParticipantTypes.includes(PAIR) && [DOUBLES] || [
58237
+ DOUBLES,
58238
+ SINGLES,
58239
+ TEAM$1
58240
+ ];
58241
+ const validEventType = validEventTypes.includes(eventUpdates.eventType || "");
58242
+ if (eventUpdates.eventType && !validEventType)
58243
+ return decorateResult({
58244
+ context: { participantType: eventUpdates.eventType },
58245
+ result: { error: INVALID_VALUES }
58246
+ });
58247
+ if (eventUpdates.eventType)
58248
+ event.eventType === eventUpdates.eventType;
58249
+ if (eventUpdates.eventName)
58250
+ event.eventName = eventUpdates.eventName;
58251
+ if (eventUpdates.gender)
58252
+ event.gender = eventUpdates.gender;
58253
+ return { ...SUCCESS };
58254
+ }
58255
+
58122
58256
  const eventGovernor = {
58123
58257
  generateQualifyingStructure,
58124
58258
  attachQualifyingStructure,
@@ -58139,11 +58273,12 @@ const eventGovernor = {
58139
58273
  modifyTieFormat: modifyTieFormat$1,
58140
58274
  resetScorecard,
58141
58275
  resetTieFormat: resetTieFormat$1,
58142
- addEvent,
58143
- deleteEvents,
58144
- setEventDates,
58145
58276
  setEventStartDate,
58146
58277
  setEventEndDate,
58278
+ setEventDates,
58279
+ deleteEvents,
58280
+ modifyEvent,
58281
+ addEvent,
58147
58282
  removeSeededParticipant,
58148
58283
  removeScaleValues,
58149
58284
  checkValidEntries,
@@ -58155,6 +58290,7 @@ const eventGovernor = {
58155
58290
  getAvailablePlayoffProfiles,
58156
58291
  deleteDrawDefinitions,
58157
58292
  addPlayoffStructures,
58293
+ modifyDrawDefinition,
58158
58294
  addDrawDefinition: addDrawDefinition$1,
58159
58295
  removeStructure,
58160
58296
  modifyDrawName,
@@ -58259,9 +58395,9 @@ function getPredictiveAccuracy(params) {
58259
58395
  exclusionRule,
58260
58396
  zoneDoubling,
58261
58397
  matchUpType,
58262
- zoneMargin,
58263
58398
  scaleName,
58264
58399
  eventId,
58400
+ zonePct,
58265
58401
  drawId,
58266
58402
  event
58267
58403
  } = params;
@@ -58274,6 +58410,8 @@ function getPredictiveAccuracy(params) {
58274
58410
  const scaleProfile = ratingsParameters[scaleName];
58275
58411
  const ascending = scaleProfile?.ascending ?? params.ascending ?? false;
58276
58412
  const valueAccessor = scaleProfile?.accessor ?? params.valueAccessor;
58413
+ const ratingsRangeDifference = Array.isArray(scaleProfile?.range) ? Math.abs(scaleProfile.range[0] - scaleProfile.range[1]) : 0;
58414
+ const zoneMargin = isConvertableInteger(zonePct) && ratingsRangeDifference ? (zonePct || 0 / 100) * ratingsRangeDifference : params.zoneMargin || ratingsRangeDifference;
58277
58415
  const contextProfile = { withScaleValues: true, withCompetitiveness: true };
58278
58416
  const contextFilters = {
58279
58417
  matchUpTypes: matchUpType ? [matchUpType] : [SINGLES$1, DOUBLES$1]
@@ -58311,7 +58449,7 @@ function getPredictiveAccuracy(params) {
58311
58449
  }
58312
58450
  const relevantMatchUps = matchUps.filter(
58313
58451
  ({ winningSide, score, sides, matchUpStatus }) => ![RETIRED$1, DEFAULTED, WALKOVER$2, DEAD_RUBBER, ABANDONED$1].includes(
58314
- matchUpStatus
58452
+ matchUpStatus || ""
58315
58453
  ) && scoreHasValue({ score }) && sides?.length === 2 && winningSide
58316
58454
  );
58317
58455
  const accuracy = getGroupingAccuracy({
@@ -58322,8 +58460,8 @@ function getPredictiveAccuracy(params) {
58322
58460
  ascending,
58323
58461
  scaleName
58324
58462
  });
58325
- const marginCalc = !zoneDoubling || matchUpType === SINGLES$1 ? zoneMargin : zoneMargin * 2;
58326
- const zoneData = zoneMargin && relevantMatchUps.map(({ competitiveProfile, matchUpType: matchUpType2, score, sides }) => {
58463
+ const marginCalc = !zoneDoubling || matchUpType === SINGLES$1 ? zoneMargin : (zoneMargin || 0) * 2;
58464
+ const zoneData = zoneMargin ? relevantMatchUps.map(({ competitiveProfile, matchUpType: matchUpType2, score, sides }) => {
58327
58465
  const sideValues = getSideValues({
58328
58466
  valueAccessor,
58329
58467
  matchUpType: matchUpType2,
@@ -58338,8 +58476,8 @@ function getPredictiveAccuracy(params) {
58338
58476
  };
58339
58477
  }).filter(({ valuesGap }) => {
58340
58478
  return valuesGap <= marginCalc;
58341
- });
58342
- const zoneBands = zoneData?.length && getGroupingBands({ zoneData });
58479
+ }) : [];
58480
+ const zoneBands = getGroupingBands({ zoneData });
58343
58481
  const totalZoneMatchUps = zoneBands && [].concat(Object.values(zoneBands)).flat().length;
58344
58482
  const zoneDistribution = totalZoneMatchUps && Object.assign(
58345
58483
  {},
@@ -58490,7 +58628,7 @@ function getGroupingAccuracy({
58490
58628
  continue;
58491
58629
  }
58492
58630
  const valuesGap = sideValues[winningIndex].value - sideValues[1 - winningIndex].value;
58493
- const floatMargin = parseFloat(excludeMargin);
58631
+ const floatMargin = parseFloat(excludeMargin || 0);
58494
58632
  const excludeGap = floatMargin && Math.abs(valuesGap) < floatMargin;
58495
58633
  if (excludeGap) {
58496
58634
  accuracy.excluded.push({