tods-competition-factory 2.0.37 → 2.0.39

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.37';
6
+ return '2.0.39';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -19907,6 +19907,14 @@ function calculatePercentages({ participantResults, matchUpFormat, tallyPolicy,
19907
19907
  });
19908
19908
  }
19909
19909
 
19910
+ function convertRange({ value, sourceRange, targetRange }) {
19911
+ const minSourceRange = Math.min(...sourceRange);
19912
+ const maxSourceRange = Math.max(...sourceRange);
19913
+ const minTargetRange = Math.min(...targetRange);
19914
+ const maxTargetRange = Math.max(...targetRange);
19915
+ return (((value - minSourceRange) * (maxTargetRange - minTargetRange)) / (maxSourceRange - minSourceRange) + minTargetRange);
19916
+ }
19917
+
19910
19918
  const ELO = 'ELO';
19911
19919
  const NTRP = 'NTRP';
19912
19920
  const TRN = 'TRN';
@@ -19955,10 +19963,6 @@ const ratingsParameters = {
19955
19963
  },
19956
19964
  };
19957
19965
 
19958
- function convertRange({ value, sourceRange, targetRange }) {
19959
- return (((value - sourceRange[0]) * (targetRange[1] - targetRange[0])) / (sourceRange[1] - sourceRange[0]) + targetRange[0]);
19960
- }
19961
-
19962
19966
  function getRatingConvertedToELO({ sourceRatingType, sourceRating }) {
19963
19967
  const sourceRatingRange = ratingsParameters[sourceRatingType].range;
19964
19968
  const invertedScale = sourceRatingRange[0] > sourceRatingRange[1];
@@ -19973,14 +19977,15 @@ function getRatingConvertedFromELO({ targetRatingType, sourceRating }) {
19973
19977
  const decimalPlaces = ratingsParameters[targetRatingType].decimalsCount || 0;
19974
19978
  const targetRatingRange = ratingsParameters[targetRatingType].range;
19975
19979
  const invertedScale = targetRatingRange[0] > targetRatingRange[1];
19980
+ const maxTargetRatingRange = Math.max(...targetRatingRange);
19976
19981
  const eloRatingRange = ratingsParameters[ELO].range;
19977
19982
  const result = convertRange({
19978
19983
  targetRange: targetRatingRange,
19979
19984
  sourceRange: eloRatingRange,
19980
19985
  value: sourceRating,
19981
19986
  });
19982
- const convertedRating = parseFloat(parseFloat(result).toFixed(decimalPlaces));
19983
- return invertedScale ? targetRatingRange[0] - convertedRating : convertedRating;
19987
+ const convertedRating = parseFloat(result.toFixed(decimalPlaces));
19988
+ return invertedScale ? maxTargetRatingRange - convertedRating : convertedRating;
19984
19989
  }
19985
19990
 
19986
19991
  function getConvertedRating(params) {
@@ -19999,14 +20004,15 @@ function getConvertedRating(params) {
19999
20004
  params.ratings[matchUpType][0];
20000
20005
  if (sourceRatings[0] === targetRatingType)
20001
20006
  return sourceRatingObject;
20007
+ const sourceRatingType = sourceRatingObject.scaleName;
20002
20008
  const accessor = ratingsParameters[sourceRatingObject.scaleName].accessor;
20003
- const value = accessor ? sourceRatingObject.scaleValue[accessor] : sourceRatingObject.scaleValue;
20004
- const eloValue = getRatingConvertedToELO({ sourceRatingType: sourceRatingObject.scaleName, sourceRating: value });
20009
+ const sourceRating = accessor ? sourceRatingObject.scaleValue[accessor] : sourceRatingObject.scaleValue;
20010
+ const eloValue = getRatingConvertedToELO({ sourceRatingType, sourceRating });
20005
20011
  const convertedRating = getRatingConvertedFromELO({
20006
20012
  targetRatingType: targetRatingType,
20007
20013
  sourceRating: eloValue,
20008
20014
  });
20009
- return { convertedRating };
20015
+ return { convertedRating, sourceRating };
20010
20016
  }
20011
20017
 
20012
20018
  function getParticipantResults({ participantIds, pressureRating, matchUpFormat, tallyPolicy, perPlayer, matchUps, }) {
@@ -20272,8 +20278,8 @@ function processMatchUp({ winningParticipantId, manualGamesOverride, losingParti
20272
20278
  const gamesWonSide2 = score?.sets?.reduce((total, set) => total + (set.side2Score ?? 0), 0);
20273
20279
  const side1 = sides.find(({ sideNumber }) => sideNumber === 1);
20274
20280
  const side2 = sides.find(({ sideNumber }) => sideNumber === 2);
20275
- const side1ConvertedRating = getConvertedRating({ ratings: side1?.participant?.ratings }).convertedRating;
20276
- const side2ConvertedRating = getConvertedRating({ ratings: side2?.participant?.ratings }).convertedRating;
20281
+ const { convertedRating: side1ConvertedRating } = getConvertedRating({ ratings: side1?.participant?.ratings });
20282
+ const { convertedRating: side2ConvertedRating } = getConvertedRating({ ratings: side2?.participant?.ratings });
20277
20283
  const side1Value = gamesWonSide1 * side2ConvertedRating;
20278
20284
  const side2Value = gamesWonSide2 * side1ConvertedRating;
20279
20285
  participantResults[side1?.participantId].pressureScores.push(fixed2(side1Value / (side1Value + side2Value)));