tods-competition-factory 1.7.4 → 1.7.6

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.4";
336
+ return "1.7.6";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -4163,7 +4163,7 @@ const WIN_RATIO$1 = "winRatio";
4163
4163
  const POLICY_COMPETITIVE_BANDS_DEFAULT = {
4164
4164
  [POLICY_TYPE_COMPETITIVE_BANDS]: {
4165
4165
  policyName: "Competitive Bands Default",
4166
- competitiveProfile: {
4166
+ profileBands: {
4167
4167
  [DECISIVE]: 20,
4168
4168
  [ROUTINE]: 50
4169
4169
  }
@@ -4248,7 +4248,7 @@ function gamesPercent(scoreComponents) {
4248
4248
  return Math.round(minGames / maxGames * 100);
4249
4249
  }
4250
4250
  function pctSpread(pcts) {
4251
- return pcts.map(gamesPercent).sort().map((p) => p.toFixed(2));
4251
+ return pcts.map(gamesPercent).sort().map((p) => parseFloat(p.toFixed(2)));
4252
4252
  }
4253
4253
 
4254
4254
  function findPolicy({
@@ -4269,8 +4269,8 @@ function findPolicy({
4269
4269
  return appliedPolicies?.[policyType] ? { policy: appliedPolicies[policyType] } : { error: POLICY_NOT_FOUND };
4270
4270
  }
4271
4271
 
4272
- function getMatchUpCompetitiveness({
4273
- competitiveProfile,
4272
+ function getMatchUpCompetitiveProfile({
4273
+ profileBands,
4274
4274
  tournamentRecord,
4275
4275
  matchUp
4276
4276
  }) {
@@ -4279,15 +4279,15 @@ function getMatchUpCompetitiveness({
4279
4279
  const { score, winningSide } = matchUp;
4280
4280
  if (!winningSide)
4281
4281
  return { error: INVALID_VALUES };
4282
- const policy = !competitiveProfile && tournamentRecord && findPolicy({
4282
+ const policy = !profileBands && tournamentRecord && findPolicy({
4283
4283
  policyType: POLICY_TYPE_COMPETITIVE_BANDS,
4284
4284
  tournamentRecord
4285
4285
  }).policy;
4286
- const bandProfiles = competitiveProfile || policy?.competitiveProfile || POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS].competitiveProfile;
4286
+ const bandProfiles = profileBands || policy?.profileBands || POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS].profileBands;
4287
4287
  const scoreComponents = getScoreComponents({ score });
4288
4288
  const spread = pctSpread([scoreComponents]);
4289
4289
  const competitiveness = getBand(spread, bandProfiles);
4290
- return { ...SUCCESS, competitiveness };
4290
+ return { ...SUCCESS, competitiveness, pctSpread: spread };
4291
4291
  }
4292
4292
 
4293
4293
  function findMatchupFormatAverageTimes(params) {
@@ -4429,14 +4429,15 @@ function getScaleValues({ participant }) {
4429
4429
  for (const itemType of itemTypes) {
4430
4430
  const scaleItem = latestScaleItem(itemType);
4431
4431
  if (scaleItem) {
4432
- const [, type, format, scaleName] = scaleItem.itemType.split(".");
4432
+ const [, type, format, scaleName, modifier] = scaleItem.itemType.split(".");
4433
+ const namedScale = modifier ? `${scaleName}.${modifier}` : scaleName;
4433
4434
  const scaleType = type === SEEDING$1 && "seedings" || type === RANKING$1 && "rankings" || "ratings";
4434
4435
  if (!scales[scaleType][format])
4435
4436
  scales[scaleType][format] = [];
4436
4437
  scales[scaleType][format].push({
4437
4438
  scaleValue: scaleItem.itemValue,
4438
4439
  scaleDate: scaleItem.itemDate,
4439
- scaleName
4440
+ scaleName: namedScale
4440
4441
  });
4441
4442
  }
4442
4443
  }
@@ -8011,7 +8012,7 @@ function getAllStructureMatchUps({
8011
8012
  ...collectionDefinition.category
8012
8013
  } : context?.category;
8013
8014
  const processCodes = matchUp.processCodes?.length && matchUp.processCodes || collectionDefinition?.processCodes?.length && collectionDefinition?.processCodes || structure?.processCodes?.length && structure?.processCodes || drawDefinition?.processCodes?.length && drawDefinition?.processCodes || event2?.processCodes?.length && event2?.processCodes || tournamentRecord?.processCodes;
8014
- const competitiveness = contextProfile?.withCompetitiveness && getMatchUpCompetitiveness({ ...contextContent, matchUp }).competitiveness;
8015
+ const competitiveProfile = contextProfile?.withCompetitiveness && getMatchUpCompetitiveProfile({ ...contextContent, matchUp });
8015
8016
  const finishingPositionRange = matchUp.finishingPositionRange || additionalContext.finishingPositionRange;
8016
8017
  const onlyDefined = (obj) => definedAttributes(obj, void 0, true);
8017
8018
  const matchUpWithContext = {
@@ -8027,7 +8028,7 @@ function getAllStructureMatchUps({
8027
8028
  finishingPositionRange,
8028
8029
  abbreviatedRoundName,
8029
8030
  drawPositionsRange,
8030
- competitiveness,
8031
+ competitiveProfile,
8031
8032
  structureName,
8032
8033
  stageSequence,
8033
8034
  drawPositions,
@@ -13380,13 +13381,19 @@ const ratingConstants = {
13380
13381
  };
13381
13382
 
13382
13383
  const ratingsParameters = {
13383
- [ELO]: { range: [0, 3e3], decimalsCount: 0, defaultInitialization: 1500 },
13384
+ [ELO]: {
13385
+ defaultInitialization: 1500,
13386
+ decimalsCount: 0,
13387
+ range: [0, 3e3],
13388
+ ascending: true
13389
+ },
13384
13390
  [NTRP]: {
13385
13391
  accessors: ["ntrpRating", "dntrpRatingHundredths"],
13386
13392
  attributes: { ustaRatingType: "" },
13387
13393
  accessor: "dntrpRatingHundredths",
13388
13394
  defaultInitialization: 3,
13389
13395
  decimalsCount: 1,
13396
+ ascending: true,
13390
13397
  range: [1, 7]
13391
13398
  },
13392
13399
  [UTR]: {
@@ -13394,6 +13401,7 @@ const ratingsParameters = {
13394
13401
  accessors: ["utrRating"],
13395
13402
  accessor: "utrRating",
13396
13403
  decimalsCount: 2,
13404
+ ascending: true,
13397
13405
  range: [1, 16]
13398
13406
  },
13399
13407
  [WTN]: {
@@ -13401,6 +13409,7 @@ const ratingsParameters = {
13401
13409
  accessors: ["wtnRating", "confidence"],
13402
13410
  defaultInitialization: 23,
13403
13411
  accessor: "wtnRating",
13412
+ ascending: false,
13404
13413
  decimalsCount: 2,
13405
13414
  range: [40, 1]
13406
13415
  }
@@ -32228,8 +32237,8 @@ function checkSchedulingProfile$1({ tournamentRecords }) {
32228
32237
  }
32229
32238
 
32230
32239
  function scheduledSortedMatchUps({
32231
- matchUps = [],
32232
- schedulingProfile
32240
+ schedulingProfile,
32241
+ matchUps = []
32233
32242
  }) {
32234
32243
  const profileHash = {};
32235
32244
  const getHash = ({ eventId, drawId, structureId, roundNumber }) => {
@@ -38822,7 +38831,7 @@ function treeMatchUps({
38822
38831
  uuids
38823
38832
  }));
38824
38833
  roundNumber++;
38825
- roundLimit = roundLimit || qualifyingRoundNumber || (qualifyingPositions ? drawSize / 2 / qualifyingPositions : void 0);
38834
+ roundLimit = roundLimit || qualifyingRoundNumber;
38826
38835
  while (roundNodes.length > 1) {
38827
38836
  if (qualifyingPositions && roundNodes.length === qualifyingPositions) {
38828
38837
  roundLimit = roundNumber - 1;
@@ -46723,6 +46732,10 @@ function removeDelegatedOutcome$1({ drawDefinition, event, matchUpId }) {
46723
46732
  });
46724
46733
  }
46725
46734
 
46735
+ function stringSort(a, b) {
46736
+ return (a || "").localeCompare(b || "");
46737
+ }
46738
+
46726
46739
  function generateCandidate({
46727
46740
  maxIterations = 4e3,
46728
46741
  // cap the processing intensity of the candidate generator
@@ -46857,7 +46870,7 @@ function roundCandidate({
46857
46870
  return { value: candidateValue, participantIdPairings, maxDelta, maxDiff };
46858
46871
  }
46859
46872
  function pairingHash(id1, id2) {
46860
- return [id1, id2].sort().join("|");
46873
+ return [id1, id2].sort(stringSort).join("|");
46861
46874
  }
46862
46875
 
46863
46876
  function getPairingsData({ participantIds }) {
@@ -46996,8 +47009,10 @@ function getPairings({
46996
47009
 
46997
47010
  const ENCOUNTER_VALUE = 100;
46998
47011
  const SAME_TEAM_VALUE = 100;
46999
- const MAX_ITERATIONS = 5e3;
47012
+ const MAX_ITERATIONS = 4e3;
47000
47013
  function generateDrawMaticRound({
47014
+ encounterValue = ENCOUNTER_VALUE,
47015
+ sameTeamValue = SAME_TEAM_VALUE,
47001
47016
  maxIterations = MAX_ITERATIONS,
47002
47017
  generateMatchUps = true,
47003
47018
  tournamentParticipants,
@@ -47030,7 +47045,7 @@ function generateDrawMaticRound({
47030
47045
  for (const pairing of encounters) {
47031
47046
  if (!valueObjects[pairing])
47032
47047
  valueObjects[pairing] = 0;
47033
- valueObjects[pairing] += ENCOUNTER_VALUE;
47048
+ valueObjects[pairing] += encounterValue;
47034
47049
  }
47035
47050
  const teamParticipants = tournamentParticipants?.filter(
47036
47051
  ({ participantType }) => participantType === TEAM
@@ -47042,7 +47057,7 @@ function generateDrawMaticRound({
47042
47057
  for (const pairing of uniquePairings2) {
47043
47058
  if (!valueObjects[pairing])
47044
47059
  valueObjects[pairing] = 0;
47045
- valueObjects[pairing] += SAME_TEAM_VALUE;
47060
+ valueObjects[pairing] += sameTeamValue;
47046
47061
  }
47047
47062
  }
47048
47063
  }
@@ -47064,7 +47079,7 @@ function generateDrawMaticRound({
47064
47079
  structure,
47065
47080
  salted
47066
47081
  };
47067
- const { candidatesCount, participantIdPairings, iterations } = getPairings(params);
47082
+ const { candidatesCount, participantIdPairings, iterations, candidate } = getPairings(params);
47068
47083
  if (!candidatesCount)
47069
47084
  return { error: NO_CANDIDATES };
47070
47085
  let matchUps;
@@ -47082,12 +47097,15 @@ function generateDrawMaticRound({
47082
47097
  return result;
47083
47098
  matchUps = result.matchUps;
47084
47099
  }
47100
+ const { maxDelta, maxDiff } = candidate;
47085
47101
  return {
47086
47102
  ...SUCCESS,
47087
47103
  participantIdPairings,
47088
47104
  candidatesCount,
47089
47105
  iterations,
47090
- matchUps
47106
+ matchUps,
47107
+ maxDelta,
47108
+ maxDiff
47091
47109
  };
47092
47110
  }
47093
47111
 
@@ -47095,10 +47113,12 @@ function drawMatic$1({
47095
47113
  tournamentParticipants,
47096
47114
  restrictEntryStatus,
47097
47115
  adHocRatings = {},
47098
- tournamentRecord,
47099
47116
  generateMatchUps,
47117
+ tournamentRecord,
47100
47118
  addToStructure,
47101
47119
  participantIds,
47120
+ encounterValue,
47121
+ sameTeamValue,
47102
47122
  drawDefinition,
47103
47123
  scaleAccessor,
47104
47124
  maxIterations,
@@ -47107,6 +47127,7 @@ function drawMatic$1({
47107
47127
  scaleName,
47108
47128
  // custom rating name to seed dynamic ratings
47109
47129
  eventType,
47130
+ salted,
47110
47131
  event
47111
47132
  }) {
47112
47133
  if (typeof drawDefinition !== "object" || drawDefinition.drawType && drawDefinition.drawType !== AD_HOC) {
@@ -47172,16 +47193,19 @@ function drawMatic$1({
47172
47193
  }
47173
47194
  return generateDrawMaticRound({
47174
47195
  tournamentParticipants,
47175
- tournamentRecord,
47176
47196
  generateMatchUps,
47177
- participantIds,
47197
+ tournamentRecord,
47178
47198
  addToStructure,
47199
+ participantIds,
47200
+ encounterValue,
47201
+ sameTeamValue,
47179
47202
  drawDefinition,
47180
47203
  maxIterations,
47181
47204
  adHocRatings,
47182
47205
  matchUpIds,
47183
47206
  structure,
47184
- eventType
47207
+ eventType,
47208
+ salted
47185
47209
  });
47186
47210
  }
47187
47211
  function getScaleValue({
@@ -52885,6 +52909,20 @@ function setTournamentStatus({ tournamentRecord, status }) {
52885
52909
  return { ...SUCCESS };
52886
52910
  }
52887
52911
 
52912
+ function addOnlineResource({
52913
+ tournamentRecord,
52914
+ onlineResource
52915
+ }) {
52916
+ if (!tournamentRecord)
52917
+ return { error: MISSING_TOURNAMENT_RECORD };
52918
+ if (!onlineResource)
52919
+ return { error: MISSING_VALUE };
52920
+ if (!tournamentRecord.onlineResources)
52921
+ tournamentRecord.onlineResources = [];
52922
+ tournamentRecord.onlineResources.push(onlineResource);
52923
+ return { ...SUCCESS };
52924
+ }
52925
+
52888
52926
  function analyzeDraws({ tournamentRecord }) {
52889
52927
  if (!tournamentRecord)
52890
52928
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -53163,10 +53201,11 @@ function removeInvalidScheduling({ tournamentRecord }) {
53163
53201
  }
53164
53202
 
53165
53203
  const tournamentGovernor = {
53166
- addNotes,
53167
- removeNotes,
53168
- analyzeDraws,
53169
53204
  analyzeTournament,
53205
+ analyzeDraws,
53206
+ addOnlineResource,
53207
+ removeNotes,
53208
+ addNotes,
53170
53209
  completeDrawMatchUps,
53171
53210
  getRounds,
53172
53211
  getProfileRounds,
@@ -58215,11 +58254,9 @@ function getPredictiveAccuracy(params) {
58215
58254
  let { matchUps } = params;
58216
58255
  const {
58217
58256
  tournamentRecord,
58218
- ascending = true,
58219
58257
  drawDefinition,
58220
58258
  excludeMargin,
58221
58259
  exclusionRule,
58222
- valueAccessor,
58223
58260
  zoneDoubling,
58224
58261
  matchUpType,
58225
58262
  zoneMargin,
@@ -58234,6 +58271,9 @@ function getPredictiveAccuracy(params) {
58234
58271
  return { error: INVALID_VALUES, info: { matchUpType } };
58235
58272
  if (matchUps && !validMatchUps(matchUps))
58236
58273
  return { error: INVALID_VALUES, context: { matchUps } };
58274
+ const scaleProfile = ratingsParameters[scaleName];
58275
+ const ascending = scaleProfile?.ascending ?? params.ascending ?? false;
58276
+ const valueAccessor = scaleProfile?.accessor ?? params.valueAccessor;
58237
58277
  const contextProfile = { withScaleValues: true, withCompetitiveness: true };
58238
58278
  const contextFilters = {
58239
58279
  matchUpTypes: matchUpType ? [matchUpType] : [SINGLES$1, DOUBLES$1]
@@ -58283,7 +58323,7 @@ function getPredictiveAccuracy(params) {
58283
58323
  scaleName
58284
58324
  });
58285
58325
  const marginCalc = !zoneDoubling || matchUpType === SINGLES$1 ? zoneMargin : zoneMargin * 2;
58286
- const zoneData = zoneMargin && relevantMatchUps.map(({ competitiveness, matchUpType: matchUpType2, score, sides }) => {
58326
+ const zoneData = zoneMargin && relevantMatchUps.map(({ competitiveProfile, matchUpType: matchUpType2, score, sides }) => {
58287
58327
  const sideValues = getSideValues({
58288
58328
  valueAccessor,
58289
58329
  matchUpType: matchUpType2,
@@ -58291,7 +58331,11 @@ function getPredictiveAccuracy(params) {
58291
58331
  sides
58292
58332
  });
58293
58333
  const valuesGap = Math.abs(sideValues[0].value - sideValues[1].value);
58294
- return { competitiveness, score, valuesGap };
58334
+ return {
58335
+ competitiveness: competitiveProfile?.competitiveness,
58336
+ valuesGap,
58337
+ score
58338
+ };
58295
58339
  }).filter(({ valuesGap }) => {
58296
58340
  return valuesGap <= marginCalc;
58297
58341
  });
@@ -58459,7 +58503,7 @@ function getGroupingAccuracy({
58459
58503
  });
58460
58504
  continue;
58461
58505
  }
58462
- const signedGap = ascending ? valuesGap * -1 : valuesGap;
58506
+ const signedGap = ascending ? valuesGap : valuesGap * -1;
58463
58507
  const winningScoreString = winningSide === 1 ? score?.scoreStringSide1 : score?.scoreStringSide2;
58464
58508
  if (signedGap > 0) {
58465
58509
  accuracy.affirmative.push({
@@ -58533,18 +58577,14 @@ function getMatchUpFormat({
58533
58577
  };
58534
58578
  }
58535
58579
 
58536
- function getMatchUpsStats({
58537
- competitiveProfile,
58538
- tournamentRecord,
58539
- matchUps
58540
- }) {
58580
+ function getMatchUpsStats({ profileBands, tournamentRecord, matchUps }) {
58541
58581
  if (!validMatchUps(matchUps))
58542
58582
  return { error: MISSING_MATCHUPS };
58543
- const policy = !competitiveProfile && findPolicy({
58583
+ const policy = !profileBands && findPolicy({
58544
58584
  policyType: POLICY_TYPE_COMPETITIVE_BANDS,
58545
58585
  tournamentRecord
58546
58586
  }).policy;
58547
- const bandProfiles = competitiveProfile || policy?.competitiveProfile || POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS].competitiveProfile;
58587
+ const bandProfiles = profileBands || policy?.profileBands || POLICY_COMPETITIVE_BANDS_DEFAULT[POLICY_TYPE_COMPETITIVE_BANDS].profileBands;
58548
58588
  const relevantMatchUps = matchUps.filter(({ winningSide }) => winningSide);
58549
58589
  const gamesMap = relevantMatchUps.map(getScoreComponents);
58550
58590
  const categorize = (p, spread) => {
@@ -58733,7 +58773,7 @@ const queryGovernor = {
58733
58773
  getPositionAssignments,
58734
58774
  isValidMatchUpFormat: isValid,
58735
58775
  getMaxEntryPosition,
58736
- getMatchUpCompetitiveness,
58776
+ getMatchUpCompetitiveProfile,
58737
58777
  findVenue,
58738
58778
  getCourts,
58739
58779
  getVenuesAndCourts: getVenuesAndCourts$1,