tods-competition-factory 1.7.3 → 1.7.4
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/forge/generate.d.ts +7 -2
- package/dist/forge/generate.mjs +332 -214
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +278 -173
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +301 -212
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
|
|
|
333
333
|
};
|
|
334
334
|
|
|
335
335
|
function factoryVersion() {
|
|
336
|
-
return "1.7.
|
|
336
|
+
return "1.7.4";
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
function getObjectTieFormat(obj) {
|
|
@@ -4404,6 +4404,7 @@ function getMatchUpFormatAverageTimes({
|
|
|
4404
4404
|
});
|
|
4405
4405
|
}
|
|
4406
4406
|
|
|
4407
|
+
const DYNAMIC = "DYNAMIC";
|
|
4407
4408
|
const RANKING$1 = "RANKING";
|
|
4408
4409
|
const RATING$2 = "RATING";
|
|
4409
4410
|
const SCALE$1 = "SCALE";
|
|
@@ -13381,21 +13382,27 @@ const ratingConstants = {
|
|
|
13381
13382
|
const ratingsParameters = {
|
|
13382
13383
|
[ELO]: { range: [0, 3e3], decimalsCount: 0, defaultInitialization: 1500 },
|
|
13383
13384
|
[NTRP]: {
|
|
13384
|
-
range: [1, 7],
|
|
13385
|
-
decimalsCount: 1,
|
|
13386
|
-
defaultInitialization: 3,
|
|
13387
|
-
accessor: "dntrpRatingHundredths",
|
|
13388
13385
|
accessors: ["ntrpRating", "dntrpRatingHundredths"],
|
|
13389
|
-
attributes: { ustaRatingType: "" }
|
|
13386
|
+
attributes: { ustaRatingType: "" },
|
|
13387
|
+
accessor: "dntrpRatingHundredths",
|
|
13388
|
+
defaultInitialization: 3,
|
|
13389
|
+
decimalsCount: 1,
|
|
13390
|
+
range: [1, 7]
|
|
13390
13391
|
},
|
|
13391
|
-
[UTR]: {
|
|
13392
|
-
|
|
13393
|
-
|
|
13392
|
+
[UTR]: {
|
|
13393
|
+
defaultInitialization: 6,
|
|
13394
|
+
accessors: ["utrRating"],
|
|
13395
|
+
accessor: "utrRating",
|
|
13394
13396
|
decimalsCount: 2,
|
|
13397
|
+
range: [1, 16]
|
|
13398
|
+
},
|
|
13399
|
+
[WTN]: {
|
|
13400
|
+
attributes: { confidence: { generator: true, range: [60, 100] } },
|
|
13401
|
+
accessors: ["wtnRating", "confidence"],
|
|
13395
13402
|
defaultInitialization: 23,
|
|
13396
13403
|
accessor: "wtnRating",
|
|
13397
|
-
|
|
13398
|
-
|
|
13404
|
+
decimalsCount: 2,
|
|
13405
|
+
range: [40, 1]
|
|
13399
13406
|
}
|
|
13400
13407
|
};
|
|
13401
13408
|
|
|
@@ -39656,6 +39663,7 @@ function generateCurtisConsolation(params) {
|
|
|
39656
39663
|
finishingPositionOffset,
|
|
39657
39664
|
structureName = MAIN,
|
|
39658
39665
|
stageSequence = 1,
|
|
39666
|
+
structureNameMap,
|
|
39659
39667
|
staggeredEntry,
|
|
39660
39668
|
stage = MAIN,
|
|
39661
39669
|
matchUpType,
|
|
@@ -39689,8 +39697,9 @@ function generateCurtisConsolation(params) {
|
|
|
39689
39697
|
const consolationItems = feedRoundOffsets.map((roundOffset, index) => {
|
|
39690
39698
|
const stageSequence2 = index + 1;
|
|
39691
39699
|
const { consolationStructure } = consolationFeedStructure({
|
|
39692
|
-
structureId: uuids?.pop(),
|
|
39693
39700
|
idPrefix: idPrefix && `${idPrefix}-c${index}`,
|
|
39701
|
+
structureId: uuids?.pop(),
|
|
39702
|
+
structureNameMap,
|
|
39694
39703
|
stageSequence: stageSequence2,
|
|
39695
39704
|
roundOffset,
|
|
39696
39705
|
matchUpType,
|
|
@@ -39719,9 +39728,9 @@ function generateCurtisConsolation(params) {
|
|
|
39719
39728
|
isMock
|
|
39720
39729
|
});
|
|
39721
39730
|
const playoffStructure = structureTemplate({
|
|
39731
|
+
structureName: structureNameMap?.[PLAY_OFF] || PLAY_OFF,
|
|
39722
39732
|
structureId: uuids?.pop(),
|
|
39723
39733
|
matchUps: playoffMatchUps,
|
|
39724
|
-
structureName: PLAY_OFF,
|
|
39725
39734
|
stageSequence: 2,
|
|
39726
39735
|
stage: PLAY_OFF,
|
|
39727
39736
|
matchUpType
|
|
@@ -39746,6 +39755,7 @@ function generateCurtisConsolation(params) {
|
|
|
39746
39755
|
}
|
|
39747
39756
|
function consolationFeedStructure({
|
|
39748
39757
|
stageSequence = 1,
|
|
39758
|
+
structureNameMap,
|
|
39749
39759
|
roundOffset = 0,
|
|
39750
39760
|
matchUpType,
|
|
39751
39761
|
structureId,
|
|
@@ -39766,7 +39776,8 @@ function consolationFeedStructure({
|
|
|
39766
39776
|
isMock,
|
|
39767
39777
|
uuids
|
|
39768
39778
|
});
|
|
39769
|
-
const
|
|
39779
|
+
const defaultName = `${CONSOLATION} ${index + 1}`;
|
|
39780
|
+
const structureName = structureNameMap?.[defaultName] || defaultName;
|
|
39770
39781
|
const consolationStructure = structureTemplate({
|
|
39771
39782
|
matchUps: consolationMatchUps,
|
|
39772
39783
|
stage: CONSOLATION,
|
|
@@ -40051,6 +40062,7 @@ function processPlayoffGroups({
|
|
|
40051
40062
|
}
|
|
40052
40063
|
const params = {
|
|
40053
40064
|
structureId: playoffGroup.structureId ?? uuids?.pop(),
|
|
40065
|
+
structureNameMap: playoffGroup.structureNameMap,
|
|
40054
40066
|
structureName: playoffGroup.structureName,
|
|
40055
40067
|
idPrefix: idPrefix && `${idPrefix}-po`,
|
|
40056
40068
|
appliedPolicies: policyDefinitions,
|
|
@@ -46712,60 +46724,93 @@ function removeDelegatedOutcome$1({ drawDefinition, event, matchUpId }) {
|
|
|
46712
46724
|
}
|
|
46713
46725
|
|
|
46714
46726
|
function generateCandidate({
|
|
46715
|
-
maxIterations =
|
|
46727
|
+
maxIterations = 4e3,
|
|
46716
46728
|
// cap the processing intensity of the candidate generator
|
|
46717
46729
|
valueSortedPairings,
|
|
46718
46730
|
// pairings sorted by value from low to high
|
|
46719
46731
|
pairingValues,
|
|
46732
|
+
valueObjects,
|
|
46720
46733
|
deltaObjects
|
|
46721
46734
|
}) {
|
|
46722
|
-
const
|
|
46735
|
+
const pairingValueMap = Object.assign(
|
|
46723
46736
|
{},
|
|
46724
46737
|
...valueSortedPairings.map((rm) => ({ [rm.pairing]: rm.value }))
|
|
46725
46738
|
);
|
|
46726
|
-
|
|
46727
|
-
|
|
46739
|
+
const actors = Object.keys(pairingValues);
|
|
46740
|
+
let proposedCandidates = [];
|
|
46741
|
+
const initialProposal = roundCandidate({
|
|
46742
|
+
actorsCount: actors.length,
|
|
46728
46743
|
valueSortedPairings,
|
|
46729
|
-
|
|
46744
|
+
pairingValueMap,
|
|
46745
|
+
deltaObjects,
|
|
46746
|
+
valueObjects
|
|
46730
46747
|
});
|
|
46731
|
-
|
|
46732
|
-
|
|
46748
|
+
const candidateHashes = [candidateHash(initialProposal)];
|
|
46749
|
+
proposedCandidates.push(initialProposal);
|
|
46750
|
+
let lowCandidateValue = initialProposal.value;
|
|
46751
|
+
let deltaCandidate = initialProposal;
|
|
46733
46752
|
let candidatesCount = 0;
|
|
46734
|
-
let iterations;
|
|
46753
|
+
let iterations = 0;
|
|
46735
46754
|
let opponentCount = actors.length;
|
|
46755
|
+
let calculatedIterations;
|
|
46736
46756
|
do {
|
|
46737
46757
|
opponentCount -= 1;
|
|
46738
|
-
|
|
46739
|
-
} while (
|
|
46758
|
+
calculatedIterations = actors.length * pairingValues[actors[0]].length;
|
|
46759
|
+
} while (calculatedIterations > maxIterations && opponentCount > 5);
|
|
46740
46760
|
const stipulatedPairs = [];
|
|
46741
46761
|
actors.forEach((actor) => {
|
|
46742
46762
|
const participantIdPairings = pairingValues[actor];
|
|
46743
46763
|
participantIdPairings.slice(0, opponentCount).forEach((pairing) => {
|
|
46764
|
+
iterations += 1;
|
|
46744
46765
|
const stipulatedPair = pairingHash(actor, pairing.opponent);
|
|
46745
46766
|
if (!stipulatedPairs.includes(stipulatedPair)) {
|
|
46746
46767
|
const proposed = roundCandidate({
|
|
46747
46768
|
// each roundCandidate starts with stipulated pairings
|
|
46748
46769
|
stipulated: [[actor, pairing.opponent]],
|
|
46749
|
-
|
|
46770
|
+
actorsCount: actors.length,
|
|
46750
46771
|
valueSortedPairings,
|
|
46751
|
-
|
|
46772
|
+
pairingValueMap,
|
|
46773
|
+
deltaObjects,
|
|
46774
|
+
valueObjects
|
|
46752
46775
|
});
|
|
46753
|
-
if (proposed
|
|
46754
|
-
|
|
46755
|
-
|
|
46756
|
-
|
|
46757
|
-
|
|
46758
|
-
|
|
46776
|
+
if (!candidateHashes.includes(candidateHash(proposed))) {
|
|
46777
|
+
candidateHashes.push(candidateHash(proposed));
|
|
46778
|
+
proposedCandidates.push(proposed);
|
|
46779
|
+
const { maxDelta, value } = proposed;
|
|
46780
|
+
if (maxDelta < deltaCandidate.maxDelta)
|
|
46781
|
+
deltaCandidate = proposed;
|
|
46782
|
+
if (value < lowCandidateValue || value === lowCandidateValue && Math.round(Math.random())) {
|
|
46783
|
+
lowCandidateValue = value;
|
|
46784
|
+
}
|
|
46785
|
+
stipulatedPairs.push(stipulatedPair);
|
|
46786
|
+
candidatesCount += 1;
|
|
46787
|
+
}
|
|
46759
46788
|
}
|
|
46760
46789
|
});
|
|
46790
|
+
proposedCandidates = proposedCandidates.filter(
|
|
46791
|
+
(proposed) => Math.abs(proposed.value - lowCandidateValue) < 5
|
|
46792
|
+
);
|
|
46761
46793
|
});
|
|
46762
|
-
|
|
46794
|
+
proposedCandidates.sort((a, b) => a.maxDiff - b.maxDiff);
|
|
46795
|
+
const candidate = randomPop(proposedCandidates);
|
|
46796
|
+
return {
|
|
46797
|
+
candidatesCount,
|
|
46798
|
+
deltaCandidate,
|
|
46799
|
+
maxIterations,
|
|
46800
|
+
iterations,
|
|
46801
|
+
candidate
|
|
46802
|
+
};
|
|
46803
|
+
}
|
|
46804
|
+
function candidateHash(candidate) {
|
|
46805
|
+
return candidate.participantIdPairings.map(({ participantIds }) => participantIds.sort().join("|")).sort().join("/");
|
|
46763
46806
|
}
|
|
46764
46807
|
function roundCandidate({
|
|
46765
|
-
rankedMatchUpValues,
|
|
46766
46808
|
valueSortedPairings,
|
|
46767
46809
|
stipulated = [],
|
|
46768
|
-
|
|
46810
|
+
pairingValueMap,
|
|
46811
|
+
deltaObjects,
|
|
46812
|
+
valueObjects,
|
|
46813
|
+
actorsCount
|
|
46769
46814
|
}) {
|
|
46770
46815
|
const roundPlayers = [].concat(...stipulated);
|
|
46771
46816
|
const participantIdPairings = [];
|
|
@@ -46773,11 +46818,17 @@ function roundCandidate({
|
|
|
46773
46818
|
stipulated.filter(Boolean).forEach((participantIds) => {
|
|
46774
46819
|
const [p1, p2] = participantIds;
|
|
46775
46820
|
const pairing = pairingHash(p1, p2);
|
|
46776
|
-
const value =
|
|
46821
|
+
const value = pairingValueMap[pairing];
|
|
46777
46822
|
participantIdPairings.push({ participantIds, value });
|
|
46778
|
-
candidateValue +=
|
|
46823
|
+
candidateValue += pairingValueMap[pairing];
|
|
46779
46824
|
});
|
|
46780
|
-
valueSortedPairings.
|
|
46825
|
+
const consideredPairings = chunkArray(valueSortedPairings, actorsCount).map(
|
|
46826
|
+
(pairings) => shuffleArray(pairings).map((pairing) => ({
|
|
46827
|
+
...pairing,
|
|
46828
|
+
value: pairing.value + Math.random() * Math.round(Math.random())
|
|
46829
|
+
}))
|
|
46830
|
+
).flat();
|
|
46831
|
+
consideredPairings.forEach((rankedPairing) => {
|
|
46781
46832
|
const participantIds = rankedPairing.pairing.split("|");
|
|
46782
46833
|
const opponentExists = participantIds.reduce(
|
|
46783
46834
|
(p, c) => roundPlayers.includes(c) || p,
|
|
@@ -46797,15 +46848,154 @@ function roundCandidate({
|
|
|
46797
46848
|
const delta = deltaObjects[hash];
|
|
46798
46849
|
return delta > p ? delta : p;
|
|
46799
46850
|
}, 0);
|
|
46800
|
-
|
|
46851
|
+
const maxDiff = participantIdPairings.reduce((p, c) => {
|
|
46852
|
+
const [p1, p2] = c.participantIds;
|
|
46853
|
+
const hash = pairingHash(p1, p2);
|
|
46854
|
+
const diff = valueObjects[hash];
|
|
46855
|
+
return diff > p ? diff : p;
|
|
46856
|
+
}, 0);
|
|
46857
|
+
return { value: candidateValue, participantIdPairings, maxDelta, maxDiff };
|
|
46801
46858
|
}
|
|
46802
46859
|
function pairingHash(id1, id2) {
|
|
46803
46860
|
return [id1, id2].sort().join("|");
|
|
46804
46861
|
}
|
|
46805
46862
|
|
|
46806
|
-
|
|
46807
|
-
const
|
|
46863
|
+
function getPairingsData({ participantIds }) {
|
|
46864
|
+
const possiblePairings = {};
|
|
46865
|
+
const uniquePairings = [];
|
|
46866
|
+
participantIds.forEach((participantId) => {
|
|
46867
|
+
possiblePairings[participantId] = participantIds.filter(
|
|
46868
|
+
(id) => id !== participantId
|
|
46869
|
+
);
|
|
46870
|
+
possiblePairings[participantId].forEach((id) => {
|
|
46871
|
+
const pairing = pairingHash(id, participantId);
|
|
46872
|
+
if (!uniquePairings.includes(pairing))
|
|
46873
|
+
uniquePairings.push(pairing);
|
|
46874
|
+
});
|
|
46875
|
+
});
|
|
46876
|
+
const deltaObjects = Object.assign(
|
|
46877
|
+
{},
|
|
46878
|
+
...uniquePairings.map((pairing) => ({ [pairing]: 0 }))
|
|
46879
|
+
);
|
|
46880
|
+
return { uniquePairings, possiblePairings, deltaObjects };
|
|
46881
|
+
}
|
|
46882
|
+
|
|
46883
|
+
function getEncounters({ matchUps }) {
|
|
46884
|
+
const encounters = [];
|
|
46885
|
+
for (const matchUp of matchUps) {
|
|
46886
|
+
const participantIds = matchUp.sides.map(
|
|
46887
|
+
extractAttributes("participantId")
|
|
46888
|
+
);
|
|
46889
|
+
if (participantIds.length === 2) {
|
|
46890
|
+
const [p1, p2] = participantIds;
|
|
46891
|
+
const pairing = pairingHash(p1, p2);
|
|
46892
|
+
if (!encounters.includes(pairing))
|
|
46893
|
+
encounters.push(pairing);
|
|
46894
|
+
}
|
|
46895
|
+
}
|
|
46896
|
+
return { encounters };
|
|
46897
|
+
}
|
|
46898
|
+
|
|
46899
|
+
function getParticipantPairingValues({
|
|
46900
|
+
possiblePairings,
|
|
46901
|
+
valueObjects
|
|
46902
|
+
}) {
|
|
46903
|
+
const pairingValues = {};
|
|
46904
|
+
for (const participantId of Object.keys(possiblePairings)) {
|
|
46905
|
+
const participantValues = possiblePairings[participantId].map(
|
|
46906
|
+
(opponent) => pairingValue(participantId, opponent)
|
|
46907
|
+
);
|
|
46908
|
+
pairingValues[participantId] = participantValues.sort(
|
|
46909
|
+
(a, b) => a.value - b.value
|
|
46910
|
+
);
|
|
46911
|
+
}
|
|
46912
|
+
function pairingValue(participantId, opponent) {
|
|
46913
|
+
const key = pairingHash(participantId, opponent);
|
|
46914
|
+
return { opponent, value: valueObjects[key] };
|
|
46915
|
+
}
|
|
46916
|
+
return { pairingValues };
|
|
46917
|
+
}
|
|
46918
|
+
|
|
46808
46919
|
const DEFAULT_RATING = 0;
|
|
46920
|
+
function getSideRatings({
|
|
46921
|
+
tournamentParticipants,
|
|
46922
|
+
adHocRatings,
|
|
46923
|
+
eventType,
|
|
46924
|
+
scaleName,
|
|
46925
|
+
pairing
|
|
46926
|
+
}) {
|
|
46927
|
+
const defaultRating = ratingsParameters[scaleName]?.defaultInitialization ?? DEFAULT_RATING;
|
|
46928
|
+
return pairing.split("|").map((participantId) => {
|
|
46929
|
+
if (eventType === DOUBLES) {
|
|
46930
|
+
const individualParticipantIds = tournamentParticipants?.find(
|
|
46931
|
+
(participant) => participant.participantId === participantId
|
|
46932
|
+
)?.individualParticipantIds;
|
|
46933
|
+
return !individualParticipantIds ? defaultRating * 2 : individualParticipantIds?.map(
|
|
46934
|
+
(participantId2) => adHocRatings[participantId2] || defaultRating
|
|
46935
|
+
);
|
|
46936
|
+
} else {
|
|
46937
|
+
return adHocRatings[participantId] || defaultRating;
|
|
46938
|
+
}
|
|
46939
|
+
});
|
|
46940
|
+
}
|
|
46941
|
+
|
|
46942
|
+
function getPairings({
|
|
46943
|
+
tournamentParticipants,
|
|
46944
|
+
adHocRatings = {},
|
|
46945
|
+
possiblePairings,
|
|
46946
|
+
// participant keyed; provides array of possible opponents
|
|
46947
|
+
uniquePairings,
|
|
46948
|
+
// hashes of all possible participantId pairings
|
|
46949
|
+
maxIterations,
|
|
46950
|
+
deltaObjects,
|
|
46951
|
+
// difference in rating between paired participants
|
|
46952
|
+
valueObjects,
|
|
46953
|
+
// calculated value of a pairing of participants, used for sorting pairings
|
|
46954
|
+
eventType,
|
|
46955
|
+
scaleName,
|
|
46956
|
+
salted
|
|
46957
|
+
}) {
|
|
46958
|
+
uniquePairings.forEach((pairing) => {
|
|
46959
|
+
const ratings = getSideRatings({
|
|
46960
|
+
tournamentParticipants,
|
|
46961
|
+
adHocRatings,
|
|
46962
|
+
scaleName,
|
|
46963
|
+
eventType,
|
|
46964
|
+
pairing
|
|
46965
|
+
});
|
|
46966
|
+
const salting = typeof salted === "number" && salted || 0.5;
|
|
46967
|
+
const salt = salted && (Math.round(Math.random()) ? salting : salting * -1) || 0;
|
|
46968
|
+
const ratingsDifference = Math.abs(ratings[0] - ratings[1]) + salt;
|
|
46969
|
+
const pairingDelta = Math.abs(ratings[0] - ratings[1]);
|
|
46970
|
+
deltaObjects[pairing] = pairingDelta;
|
|
46971
|
+
if (!valueObjects[pairing])
|
|
46972
|
+
valueObjects[pairing] = 0;
|
|
46973
|
+
valueObjects[pairing] += ratingsDifference ? Math.pow(ratingsDifference, 2) : 0;
|
|
46974
|
+
});
|
|
46975
|
+
const valueSortedPairings = uniquePairings.map((pairing) => ({ pairing, value: valueObjects[pairing] })).sort((a, b) => a.value - b.value);
|
|
46976
|
+
const { pairingValues } = getParticipantPairingValues({
|
|
46977
|
+
possiblePairings,
|
|
46978
|
+
valueObjects
|
|
46979
|
+
});
|
|
46980
|
+
const { candidate, candidatesCount, deltaCandidate, iterations } = generateCandidate({
|
|
46981
|
+
valueSortedPairings,
|
|
46982
|
+
maxIterations,
|
|
46983
|
+
pairingValues,
|
|
46984
|
+
deltaObjects,
|
|
46985
|
+
valueObjects
|
|
46986
|
+
});
|
|
46987
|
+
const { participantIdPairings } = candidate;
|
|
46988
|
+
return {
|
|
46989
|
+
participantIdPairings,
|
|
46990
|
+
candidatesCount,
|
|
46991
|
+
deltaCandidate,
|
|
46992
|
+
iterations,
|
|
46993
|
+
candidate
|
|
46994
|
+
};
|
|
46995
|
+
}
|
|
46996
|
+
|
|
46997
|
+
const ENCOUNTER_VALUE = 100;
|
|
46998
|
+
const SAME_TEAM_VALUE = 100;
|
|
46809
46999
|
const MAX_ITERATIONS = 5e3;
|
|
46810
47000
|
function generateDrawMaticRound({
|
|
46811
47001
|
maxIterations = MAX_ITERATIONS,
|
|
@@ -46817,9 +47007,11 @@ function generateDrawMaticRound({
|
|
|
46817
47007
|
drawDefinition,
|
|
46818
47008
|
adHocRatings,
|
|
46819
47009
|
structureId,
|
|
47010
|
+
salted = 0.5,
|
|
46820
47011
|
matchUpIds,
|
|
46821
47012
|
eventType,
|
|
46822
|
-
structure
|
|
47013
|
+
structure,
|
|
47014
|
+
scaleName
|
|
46823
47015
|
}) {
|
|
46824
47016
|
if (!drawDefinition)
|
|
46825
47017
|
return { error: MISSING_DRAW_DEFINITION };
|
|
@@ -46868,7 +47060,9 @@ function generateDrawMaticRound({
|
|
|
46868
47060
|
deltaObjects,
|
|
46869
47061
|
valueObjects,
|
|
46870
47062
|
eventType,
|
|
46871
|
-
|
|
47063
|
+
scaleName,
|
|
47064
|
+
structure,
|
|
47065
|
+
salted
|
|
46872
47066
|
};
|
|
46873
47067
|
const { candidatesCount, participantIdPairings, iterations } = getPairings(params);
|
|
46874
47068
|
if (!candidatesCount)
|
|
@@ -46896,118 +47090,11 @@ function generateDrawMaticRound({
|
|
|
46896
47090
|
matchUps
|
|
46897
47091
|
};
|
|
46898
47092
|
}
|
|
46899
|
-
function getSideRatings({
|
|
46900
|
-
tournamentParticipants,
|
|
46901
|
-
adHocRatings,
|
|
46902
|
-
eventType,
|
|
46903
|
-
pairing
|
|
46904
|
-
}) {
|
|
46905
|
-
return pairing.split("|").map((participantId) => {
|
|
46906
|
-
if (eventType === DOUBLES) {
|
|
46907
|
-
const individualParticipantIds = tournamentParticipants?.find(
|
|
46908
|
-
(participant) => participant.participantId === participantId
|
|
46909
|
-
)?.individualParticipantIds;
|
|
46910
|
-
return !individualParticipantIds ? DEFAULT_RATING * 2 : individualParticipantIds?.map(
|
|
46911
|
-
(participantId2) => adHocRatings[participantId2 || DEFAULT_RATING]
|
|
46912
|
-
);
|
|
46913
|
-
} else {
|
|
46914
|
-
return adHocRatings[participantId] || DEFAULT_RATING;
|
|
46915
|
-
}
|
|
46916
|
-
});
|
|
46917
|
-
}
|
|
46918
|
-
function getPairings({
|
|
46919
|
-
tournamentParticipants,
|
|
46920
|
-
adHocRatings = {},
|
|
46921
|
-
possiblePairings,
|
|
46922
|
-
// participant keyed; provides array of possible opponents
|
|
46923
|
-
uniquePairings,
|
|
46924
|
-
// hashes of all possible participantId pairings
|
|
46925
|
-
maxIterations,
|
|
46926
|
-
deltaObjects,
|
|
46927
|
-
// difference in rating between paired participants
|
|
46928
|
-
valueObjects,
|
|
46929
|
-
// calculated value of a pairing of participants, used for sorting pairings
|
|
46930
|
-
eventType
|
|
46931
|
-
}) {
|
|
46932
|
-
uniquePairings.forEach((pairing) => {
|
|
46933
|
-
const ratings = getSideRatings({
|
|
46934
|
-
tournamentParticipants,
|
|
46935
|
-
adHocRatings,
|
|
46936
|
-
eventType,
|
|
46937
|
-
pairing
|
|
46938
|
-
});
|
|
46939
|
-
const ratingsDifference = Math.abs(ratings[0] - ratings[1]) + 1;
|
|
46940
|
-
deltaObjects[pairing] = Math.abs(ratings[0] - ratings[1]);
|
|
46941
|
-
if (!valueObjects[pairing])
|
|
46942
|
-
valueObjects[pairing] = 0;
|
|
46943
|
-
valueObjects[pairing] += Math.pow(ratingsDifference, 2);
|
|
46944
|
-
});
|
|
46945
|
-
const valueSortedPairings = uniquePairings.map((pairing) => ({ pairing, value: valueObjects[pairing] })).sort((a, b) => a.value - b.value);
|
|
46946
|
-
const { pairingValues } = getParticipantPairingValues({
|
|
46947
|
-
possiblePairings,
|
|
46948
|
-
valueObjects
|
|
46949
|
-
});
|
|
46950
|
-
const { candidate, candidatesCount, iterations } = generateCandidate({
|
|
46951
|
-
valueSortedPairings,
|
|
46952
|
-
maxIterations,
|
|
46953
|
-
pairingValues,
|
|
46954
|
-
deltaObjects
|
|
46955
|
-
});
|
|
46956
|
-
const { participantIdPairings } = candidate;
|
|
46957
|
-
return { candidatesCount, participantIdPairings, iterations };
|
|
46958
|
-
}
|
|
46959
|
-
function getPairingsData({ participantIds }) {
|
|
46960
|
-
const possiblePairings = {};
|
|
46961
|
-
const uniquePairings = [];
|
|
46962
|
-
participantIds.forEach((participantId) => {
|
|
46963
|
-
possiblePairings[participantId] = participantIds.filter(
|
|
46964
|
-
(id) => id !== participantId
|
|
46965
|
-
);
|
|
46966
|
-
possiblePairings[participantId].forEach((id) => {
|
|
46967
|
-
const pairing = pairingHash(id, participantId);
|
|
46968
|
-
if (!uniquePairings.includes(pairing))
|
|
46969
|
-
uniquePairings.push(pairing);
|
|
46970
|
-
});
|
|
46971
|
-
});
|
|
46972
|
-
const deltaObjects = Object.assign(
|
|
46973
|
-
{},
|
|
46974
|
-
...uniquePairings.map((pairing) => ({ [pairing]: 0 }))
|
|
46975
|
-
);
|
|
46976
|
-
return { uniquePairings, possiblePairings, deltaObjects };
|
|
46977
|
-
}
|
|
46978
|
-
function getEncounters({ matchUps }) {
|
|
46979
|
-
const encounters = [];
|
|
46980
|
-
for (const matchUp of matchUps) {
|
|
46981
|
-
const participantIds = matchUp.sides.map(getParticipantId);
|
|
46982
|
-
if (participantIds.length === 2) {
|
|
46983
|
-
const [p1, p2] = participantIds;
|
|
46984
|
-
const pairing = pairingHash(p1, p2);
|
|
46985
|
-
if (!encounters.includes(pairing))
|
|
46986
|
-
encounters.push(pairing);
|
|
46987
|
-
}
|
|
46988
|
-
}
|
|
46989
|
-
return { encounters };
|
|
46990
|
-
}
|
|
46991
|
-
function getParticipantPairingValues({ possiblePairings, valueObjects }) {
|
|
46992
|
-
const pairingValues = {};
|
|
46993
|
-
for (const participantId of Object.keys(possiblePairings)) {
|
|
46994
|
-
const participantValues = possiblePairings[participantId].map(
|
|
46995
|
-
(opponent) => pairingValue(participantId, opponent)
|
|
46996
|
-
);
|
|
46997
|
-
pairingValues[participantId] = participantValues.sort(
|
|
46998
|
-
(a, b) => a.value - b.value
|
|
46999
|
-
);
|
|
47000
|
-
}
|
|
47001
|
-
function pairingValue(participantId, opponent) {
|
|
47002
|
-
const key = pairingHash(participantId, opponent);
|
|
47003
|
-
return { opponent, value: valueObjects[key] };
|
|
47004
|
-
}
|
|
47005
|
-
return { pairingValues };
|
|
47006
|
-
}
|
|
47007
47093
|
|
|
47008
47094
|
function drawMatic$1({
|
|
47009
47095
|
tournamentParticipants,
|
|
47010
47096
|
restrictEntryStatus,
|
|
47097
|
+
adHocRatings = {},
|
|
47011
47098
|
tournamentRecord,
|
|
47012
47099
|
generateMatchUps,
|
|
47013
47100
|
addToStructure,
|
|
@@ -47062,12 +47149,16 @@ function drawMatic$1({
|
|
|
47062
47149
|
if (!structureIsAdHoc)
|
|
47063
47150
|
return { error: INVALID_DRAW_DEFINITION };
|
|
47064
47151
|
tournamentParticipants = tournamentParticipants ?? tournamentRecord.participants ?? [];
|
|
47065
|
-
const adHocRatings = {};
|
|
47066
47152
|
for (const participantId of participantIds ?? []) {
|
|
47067
47153
|
const participant = tournamentParticipants?.find(
|
|
47068
47154
|
(participant2) => participant2.participantId === participantId
|
|
47069
47155
|
);
|
|
47070
|
-
let scaleValue = getScaleValue({
|
|
47156
|
+
let scaleValue = getScaleValue({
|
|
47157
|
+
scaleName: `${scaleName}.${DYNAMIC}`,
|
|
47158
|
+
scaleAccessor,
|
|
47159
|
+
participant,
|
|
47160
|
+
eventType
|
|
47161
|
+
});
|
|
47071
47162
|
if (!scaleValue && scaleName) {
|
|
47072
47163
|
scaleValue = getScaleValue({
|
|
47073
47164
|
scaleAccessor,
|
|
@@ -47076,7 +47167,7 @@ function drawMatic$1({
|
|
|
47076
47167
|
eventType
|
|
47077
47168
|
});
|
|
47078
47169
|
}
|
|
47079
|
-
if (scaleValue)
|
|
47170
|
+
if (scaleValue && !adHocRatings[participantId])
|
|
47080
47171
|
adHocRatings[participantId] = scaleValue;
|
|
47081
47172
|
}
|
|
47082
47173
|
return generateDrawMaticRound({
|
|
@@ -47094,14 +47185,15 @@ function drawMatic$1({
|
|
|
47094
47185
|
});
|
|
47095
47186
|
}
|
|
47096
47187
|
function getScaleValue({
|
|
47097
|
-
|
|
47098
|
-
scaleName = "dynamic",
|
|
47188
|
+
scaleType = RATING$2,
|
|
47099
47189
|
scaleAccessor,
|
|
47100
|
-
participant
|
|
47190
|
+
participant,
|
|
47191
|
+
scaleName,
|
|
47192
|
+
eventType
|
|
47101
47193
|
}) {
|
|
47102
47194
|
const scaleAttributes = {
|
|
47103
47195
|
eventType: eventType || TypeEnum.Singles,
|
|
47104
|
-
scaleType
|
|
47196
|
+
scaleType,
|
|
47105
47197
|
scaleName
|
|
47106
47198
|
};
|
|
47107
47199
|
const result = participant && participantScaleItem({
|
|
@@ -59475,11 +59567,15 @@ function calculateNewRatings(params) {
|
|
|
59475
59567
|
targetRange: consideredRange
|
|
59476
59568
|
});
|
|
59477
59569
|
const updatedWinnerRating = invertedScale ? ratingRange[0] - convertedUpdatedWinnerRating : convertedUpdatedWinnerRating;
|
|
59478
|
-
let newWinnerRating = parseFloat(
|
|
59570
|
+
let newWinnerRating = parseFloat(
|
|
59571
|
+
parseFloat(updatedWinnerRating).toFixed(decimalPlaces)
|
|
59572
|
+
);
|
|
59479
59573
|
const updatedLoserRating = invertedScale ? ratingRange[0] - convertedUpdatedLoserRating : convertedUpdatedLoserRating;
|
|
59480
|
-
let newLoserRating = parseFloat(
|
|
59574
|
+
let newLoserRating = parseFloat(
|
|
59575
|
+
parseFloat(updatedLoserRating).toFixed(decimalPlaces)
|
|
59576
|
+
);
|
|
59481
59577
|
const percentageDifference = Math.max(...ratingRange) ? Math.abs(winnerRating - loserRating) / Math.max(...ratingRange) : 0;
|
|
59482
|
-
if (convertedUpdatedWinnerRating > convertedUpdatedLoserRating && percentageDifference > eloConfig.diffThreshold ||
|
|
59578
|
+
if (convertedUpdatedWinnerRating > convertedUpdatedLoserRating && percentageDifference > eloConfig.diffThreshold || newWinnerRating < 0 || newLoserRating < 0) {
|
|
59483
59579
|
newWinnerRating = winnerRating;
|
|
59484
59580
|
newLoserRating = loserRating;
|
|
59485
59581
|
}
|
|
@@ -59497,7 +59593,8 @@ const aggregateSets = (sets) => {
|
|
|
59497
59593
|
) || [0, 0];
|
|
59498
59594
|
};
|
|
59499
59595
|
|
|
59500
|
-
function
|
|
59596
|
+
function generateDynamicRatings({
|
|
59597
|
+
removePriorValues = true,
|
|
59501
59598
|
tournamentRecord,
|
|
59502
59599
|
ratingType = ELO,
|
|
59503
59600
|
considerGames,
|
|
@@ -59528,7 +59625,7 @@ function processMatchUps({
|
|
|
59528
59625
|
scaleName: ratingType,
|
|
59529
59626
|
scaleType: RATING$2
|
|
59530
59627
|
};
|
|
59531
|
-
const dynamicScaleName = `${ratingType}
|
|
59628
|
+
const dynamicScaleName = `${ratingType}.${DYNAMIC}`;
|
|
59532
59629
|
const dynamicScaleAttributes = {
|
|
59533
59630
|
scaleName: dynamicScaleName,
|
|
59534
59631
|
eventType: matchUpType,
|
|
@@ -59564,9 +59661,9 @@ function processMatchUps({
|
|
|
59564
59661
|
return participantId && {
|
|
59565
59662
|
[participantId]: dynamicScaleItem ?? scaleItem ?? {
|
|
59566
59663
|
scaleName: outputScaleName,
|
|
59567
|
-
scaleType: RATING$2,
|
|
59568
59664
|
eventType: matchUpType,
|
|
59569
59665
|
scaleDate: endDate,
|
|
59666
|
+
scaleType: RATING$2,
|
|
59570
59667
|
scaleValue
|
|
59571
59668
|
}
|
|
59572
59669
|
};
|
|
@@ -59595,27 +59692,35 @@ function processMatchUps({
|
|
|
59595
59692
|
loserRating,
|
|
59596
59693
|
ratingType
|
|
59597
59694
|
});
|
|
59598
|
-
const newWinnerScaleValue = accessor ? {
|
|
59599
|
-
|
|
59695
|
+
const newWinnerScaleValue = accessor ? {
|
|
59696
|
+
...winnerScaleValue,
|
|
59697
|
+
[accessor]: newWinnerRating
|
|
59698
|
+
} : newWinnerRating;
|
|
59699
|
+
const newLoserScaleValue = accessor ? {
|
|
59700
|
+
...loserScaleValue,
|
|
59701
|
+
[accessor]: newLoserRating
|
|
59702
|
+
} : newLoserRating;
|
|
59600
59703
|
scaleItemMap[winnerParticipantId].scaleValue = newWinnerScaleValue;
|
|
59601
59704
|
scaleItemMap[loserParticipantId].scaleValue = newLoserScaleValue;
|
|
59602
59705
|
let result = setParticipantScaleItem({
|
|
59706
|
+
participantId: winnerParticipantId,
|
|
59707
|
+
removePriorValues,
|
|
59708
|
+
tournamentRecord,
|
|
59603
59709
|
scaleItem: {
|
|
59604
59710
|
...scaleItemMap[winnerParticipantId],
|
|
59605
59711
|
scaleName: outputScaleName
|
|
59606
|
-
}
|
|
59607
|
-
participantId: winnerParticipantId,
|
|
59608
|
-
tournamentRecord
|
|
59712
|
+
}
|
|
59609
59713
|
});
|
|
59610
59714
|
if (result.error)
|
|
59611
59715
|
return result;
|
|
59612
59716
|
result = setParticipantScaleItem({
|
|
59717
|
+
participantId: loserParticipantId,
|
|
59718
|
+
removePriorValues,
|
|
59719
|
+
tournamentRecord,
|
|
59613
59720
|
scaleItem: {
|
|
59614
59721
|
...scaleItemMap[loserParticipantId],
|
|
59615
59722
|
scaleName: outputScaleName
|
|
59616
|
-
}
|
|
59617
|
-
participantId: loserParticipantId,
|
|
59618
|
-
tournamentRecord
|
|
59723
|
+
}
|
|
59619
59724
|
});
|
|
59620
59725
|
if (result.error)
|
|
59621
59726
|
return result;
|
|
@@ -59629,7 +59734,7 @@ function processMatchUps({
|
|
|
59629
59734
|
|
|
59630
59735
|
const governor = {
|
|
59631
59736
|
calculateNewRatings,
|
|
59632
|
-
|
|
59737
|
+
generateDynamicRatings
|
|
59633
59738
|
};
|
|
59634
59739
|
|
|
59635
59740
|
const scaleEngine = (() => {
|