tods-competition-factory 1.7.3 → 1.7.5
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 +15 -3
- package/dist/forge/generate.mjs +356 -226
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.mjs +3 -2
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +3 -2
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +302 -185
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +315 -225
- 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
|
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
|
|
|
362
362
|
};
|
|
363
363
|
|
|
364
364
|
function factoryVersion() {
|
|
365
|
-
return '1.7.
|
|
365
|
+
return '1.7.5';
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
/******************************************************************************
|
|
@@ -5511,6 +5511,7 @@ function getMatchUpFormatAverageTimes(_a) {
|
|
|
5511
5511
|
});
|
|
5512
5512
|
}
|
|
5513
5513
|
|
|
5514
|
+
var DYNAMIC = 'DYNAMIC';
|
|
5514
5515
|
var RANKING$1 = 'RANKING';
|
|
5515
5516
|
var RATING$2 = 'RATING';
|
|
5516
5517
|
var SCALE$1 = 'SCALE';
|
|
@@ -5551,7 +5552,8 @@ function getScaleValues(_a) {
|
|
|
5551
5552
|
var itemType = itemTypes_1_1.value;
|
|
5552
5553
|
var scaleItem = latestScaleItem(itemType);
|
|
5553
5554
|
if (scaleItem) {
|
|
5554
|
-
var _d = __read(scaleItem.itemType.split('.'),
|
|
5555
|
+
var _d = __read(scaleItem.itemType.split('.'), 5), type = _d[1], format = _d[2], scaleName = _d[3], modifier = _d[4];
|
|
5556
|
+
var namedScale = modifier ? "".concat(scaleName, ".").concat(modifier) : scaleName;
|
|
5555
5557
|
var scaleType = (type === SEEDING$1 && 'seedings') ||
|
|
5556
5558
|
(type === RANKING$1 && 'rankings') ||
|
|
5557
5559
|
'ratings';
|
|
@@ -5560,7 +5562,7 @@ function getScaleValues(_a) {
|
|
|
5560
5562
|
scales[scaleType][format].push({
|
|
5561
5563
|
scaleValue: scaleItem.itemValue,
|
|
5562
5564
|
scaleDate: scaleItem.itemDate,
|
|
5563
|
-
scaleName:
|
|
5565
|
+
scaleName: namedScale,
|
|
5564
5566
|
});
|
|
5565
5567
|
}
|
|
5566
5568
|
}
|
|
@@ -14954,21 +14956,27 @@ var _a$g;
|
|
|
14954
14956
|
var ratingsParameters = (_a$g = {},
|
|
14955
14957
|
_a$g[ELO] = { range: [0, 3000], decimalsCount: 0, defaultInitialization: 1500 },
|
|
14956
14958
|
_a$g[NTRP] = {
|
|
14957
|
-
range: [1, 7],
|
|
14958
|
-
decimalsCount: 1,
|
|
14959
|
-
defaultInitialization: 3,
|
|
14960
|
-
accessor: 'dntrpRatingHundredths',
|
|
14961
14959
|
accessors: ['ntrpRating', 'dntrpRatingHundredths'],
|
|
14962
14960
|
attributes: { ustaRatingType: '' },
|
|
14961
|
+
accessor: 'dntrpRatingHundredths',
|
|
14962
|
+
defaultInitialization: 3,
|
|
14963
|
+
decimalsCount: 1,
|
|
14964
|
+
range: [1, 7],
|
|
14963
14965
|
},
|
|
14964
|
-
_a$g[UTR] = {
|
|
14965
|
-
|
|
14966
|
-
|
|
14966
|
+
_a$g[UTR] = {
|
|
14967
|
+
defaultInitialization: 6,
|
|
14968
|
+
accessors: ['utrRating'],
|
|
14969
|
+
accessor: 'utrRating',
|
|
14967
14970
|
decimalsCount: 2,
|
|
14971
|
+
range: [1, 16],
|
|
14972
|
+
},
|
|
14973
|
+
_a$g[WTN] = {
|
|
14974
|
+
attributes: { confidence: { generator: true, range: [60, 100] } },
|
|
14975
|
+
accessors: ['wtnRating', 'confidence'],
|
|
14968
14976
|
defaultInitialization: 23,
|
|
14969
14977
|
accessor: 'wtnRating',
|
|
14970
|
-
|
|
14971
|
-
|
|
14978
|
+
decimalsCount: 2,
|
|
14979
|
+
range: [40, 1],
|
|
14972
14980
|
},
|
|
14973
14981
|
_a$g);
|
|
14974
14982
|
|
|
@@ -42135,10 +42143,7 @@ function treeMatchUps(_a) {
|
|
|
42135
42143
|
uuids: uuids,
|
|
42136
42144
|
}), roundNodes = _b.roundNodes, matchUps = _b.matchUps);
|
|
42137
42145
|
roundNumber++;
|
|
42138
|
-
roundLimit =
|
|
42139
|
-
roundLimit ||
|
|
42140
|
-
qualifyingRoundNumber ||
|
|
42141
|
-
(qualifyingPositions ? drawSize / 2 / qualifyingPositions : undefined);
|
|
42146
|
+
roundLimit = roundLimit || qualifyingRoundNumber;
|
|
42142
42147
|
while (roundNodes.length > 1) {
|
|
42143
42148
|
if (qualifyingPositions && roundNodes.length === qualifyingPositions) {
|
|
42144
42149
|
roundLimit = roundNumber - 1;
|
|
@@ -43025,7 +43030,7 @@ function feedInLinks(_a) {
|
|
|
43025
43030
|
}
|
|
43026
43031
|
|
|
43027
43032
|
function generateCurtisConsolation(params) {
|
|
43028
|
-
var finishingPositionOffset = params.finishingPositionOffset, _a = params.structureName, structureName = _a === void 0 ? MAIN : _a, _b = params.stageSequence, stageSequence = _b === void 0 ? 1 : _b, staggeredEntry = params.staggeredEntry, _c = params.stage, stage = _c === void 0 ? MAIN : _c, matchUpType = params.matchUpType, structureId = params.structureId, drawSize = params.drawSize, idPrefix = params.idPrefix, isMock = params.isMock, uuids = params.uuids;
|
|
43033
|
+
var finishingPositionOffset = params.finishingPositionOffset, _a = params.structureName, structureName = _a === void 0 ? MAIN : _a, _b = params.stageSequence, stageSequence = _b === void 0 ? 1 : _b, structureNameMap = params.structureNameMap, staggeredEntry = params.staggeredEntry, _c = params.stage, stage = _c === void 0 ? MAIN : _c, matchUpType = params.matchUpType, structureId = params.structureId, drawSize = params.drawSize, idPrefix = params.idPrefix, isMock = params.isMock, uuids = params.uuids;
|
|
43029
43034
|
var mainParams = {
|
|
43030
43035
|
finishingPositionOffset: finishingPositionOffset,
|
|
43031
43036
|
matchUpType: matchUpType,
|
|
@@ -43052,8 +43057,9 @@ function generateCurtisConsolation(params) {
|
|
|
43052
43057
|
var consolationItems = feedRoundOffsets.map(function (roundOffset, index) {
|
|
43053
43058
|
var stageSequence = index + 1;
|
|
43054
43059
|
var consolationStructure = consolationFeedStructure({
|
|
43055
|
-
structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43056
43060
|
idPrefix: idPrefix && "".concat(idPrefix, "-c").concat(index),
|
|
43061
|
+
structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43062
|
+
structureNameMap: structureNameMap,
|
|
43057
43063
|
stageSequence: stageSequence,
|
|
43058
43064
|
roundOffset: roundOffset,
|
|
43059
43065
|
matchUpType: matchUpType,
|
|
@@ -43086,9 +43092,9 @@ function generateCurtisConsolation(params) {
|
|
|
43086
43092
|
isMock: isMock,
|
|
43087
43093
|
}).matchUps;
|
|
43088
43094
|
var playoffStructure = structureTemplate({
|
|
43095
|
+
structureName: (structureNameMap === null || structureNameMap === void 0 ? void 0 : structureNameMap[PLAY_OFF]) || PLAY_OFF,
|
|
43089
43096
|
structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43090
43097
|
matchUps: playoffMatchUps,
|
|
43091
|
-
structureName: PLAY_OFF,
|
|
43092
43098
|
stageSequence: 2,
|
|
43093
43099
|
stage: PLAY_OFF,
|
|
43094
43100
|
matchUpType: matchUpType,
|
|
@@ -43112,7 +43118,7 @@ function generateCurtisConsolation(params) {
|
|
|
43112
43118
|
return __assign({ structures: structures, links: links }, SUCCESS);
|
|
43113
43119
|
}
|
|
43114
43120
|
function consolationFeedStructure(_a) {
|
|
43115
|
-
var _b = _a.stageSequence, stageSequence = _b === void 0 ? 1 : _b, _c = _a.roundOffset, roundOffset = _c === void 0 ? 0 : _c, matchUpType = _a.matchUpType, structureId = _a.structureId, idPrefix = _a.idPrefix, drawSize = _a.drawSize, isMock = _a.isMock, index = _a.index, uuids = _a.uuids;
|
|
43121
|
+
var _b = _a.stageSequence, stageSequence = _b === void 0 ? 1 : _b, structureNameMap = _a.structureNameMap, _c = _a.roundOffset, roundOffset = _c === void 0 ? 0 : _c, matchUpType = _a.matchUpType, structureId = _a.structureId, idPrefix = _a.idPrefix, drawSize = _a.drawSize, isMock = _a.isMock, index = _a.index, uuids = _a.uuids;
|
|
43116
43122
|
var consolationDrawPositions = drawSize / (2 * Math.pow(2, roundOffset));
|
|
43117
43123
|
var _d = feedInMatchUps({
|
|
43118
43124
|
finishingPositionOffset: consolationDrawPositions,
|
|
@@ -43124,7 +43130,8 @@ function consolationFeedStructure(_a) {
|
|
|
43124
43130
|
isMock: isMock,
|
|
43125
43131
|
uuids: uuids,
|
|
43126
43132
|
}), consolationMatchUps = _d.matchUps, consolationRoundsCount = _d.roundsCount;
|
|
43127
|
-
var
|
|
43133
|
+
var defaultName = "".concat(CONSOLATION, " ").concat(index + 1);
|
|
43134
|
+
var structureName = (structureNameMap === null || structureNameMap === void 0 ? void 0 : structureNameMap[defaultName]) || defaultName;
|
|
43128
43135
|
var consolationStructure = structureTemplate({
|
|
43129
43136
|
matchUps: consolationMatchUps,
|
|
43130
43137
|
stage: CONSOLATION,
|
|
@@ -43383,6 +43390,7 @@ function processPlayoffGroups(_a) {
|
|
|
43383
43390
|
}
|
|
43384
43391
|
var params = {
|
|
43385
43392
|
structureId: (_c = playoffGroup.structureId) !== null && _c !== void 0 ? _c : uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43393
|
+
structureNameMap: playoffGroup.structureNameMap,
|
|
43386
43394
|
structureName: playoffGroup.structureName,
|
|
43387
43395
|
idPrefix: idPrefix && "".concat(idPrefix, "-po"),
|
|
43388
43396
|
appliedPolicies: policyDefinitions,
|
|
@@ -50536,59 +50544,96 @@ function removeDelegatedOutcome$1(_a) {
|
|
|
50536
50544
|
}
|
|
50537
50545
|
|
|
50538
50546
|
function generateCandidate(_a) {
|
|
50539
|
-
var _b = _a.maxIterations, maxIterations = _b === void 0 ?
|
|
50547
|
+
var _b = _a.maxIterations, maxIterations = _b === void 0 ? 4000 : _b, // cap the processing intensity of the candidate generator
|
|
50540
50548
|
valueSortedPairings = _a.valueSortedPairings, // pairings sorted by value from low to high
|
|
50541
|
-
pairingValues = _a.pairingValues, deltaObjects = _a.deltaObjects;
|
|
50542
|
-
var
|
|
50549
|
+
pairingValues = _a.pairingValues, valueObjects = _a.valueObjects, deltaObjects = _a.deltaObjects;
|
|
50550
|
+
var pairingValueMap = Object.assign.apply(Object, __spreadArray([{}], __read(valueSortedPairings.map(function (rm) {
|
|
50543
50551
|
var _a;
|
|
50544
50552
|
return (_a = {}, _a[rm.pairing] = rm.value, _a);
|
|
50545
50553
|
})), false));
|
|
50554
|
+
var actors = Object.keys(pairingValues);
|
|
50555
|
+
var proposedCandidates = [];
|
|
50546
50556
|
// generate an initial candidate value with no stipulated pairings
|
|
50547
|
-
var
|
|
50548
|
-
|
|
50557
|
+
var initialProposal = roundCandidate({
|
|
50558
|
+
actorsCount: actors.length,
|
|
50549
50559
|
valueSortedPairings: valueSortedPairings,
|
|
50560
|
+
pairingValueMap: pairingValueMap,
|
|
50550
50561
|
deltaObjects: deltaObjects,
|
|
50562
|
+
valueObjects: valueObjects,
|
|
50551
50563
|
});
|
|
50552
|
-
var
|
|
50553
|
-
|
|
50564
|
+
var candidateHashes = [candidateHash(initialProposal)];
|
|
50565
|
+
proposedCandidates.push(initialProposal);
|
|
50566
|
+
var lowCandidateValue = initialProposal.value;
|
|
50567
|
+
var deltaCandidate = initialProposal;
|
|
50554
50568
|
// iterations is the number of loops over valueSortedPairings
|
|
50555
50569
|
var candidatesCount = 0;
|
|
50556
|
-
var iterations;
|
|
50557
|
-
// calculate the number of opponents to consider for each participantId
|
|
50570
|
+
var iterations = 0;
|
|
50558
50571
|
var opponentCount = actors.length;
|
|
50572
|
+
var calculatedIterations;
|
|
50573
|
+
// calculate the number of opponents to consider for each participantId
|
|
50559
50574
|
do {
|
|
50560
50575
|
opponentCount -= 1;
|
|
50561
|
-
|
|
50562
|
-
|
|
50563
|
-
|
|
50576
|
+
calculatedIterations = actors.length * pairingValues[actors[0]].length;
|
|
50577
|
+
} while (calculatedIterations > maxIterations && opponentCount > 5);
|
|
50578
|
+
// keep track of proposed pairings
|
|
50564
50579
|
var stipulatedPairs = [];
|
|
50565
50580
|
// for each actor generate a roundCandidate using opponentCount of pairing values
|
|
50566
50581
|
actors.forEach(function (actor) {
|
|
50567
50582
|
var participantIdPairings = pairingValues[actor];
|
|
50568
50583
|
// opponentCount limits the number of opponents to consider
|
|
50569
50584
|
participantIdPairings.slice(0, opponentCount).forEach(function (pairing) {
|
|
50585
|
+
iterations += 1;
|
|
50570
50586
|
var stipulatedPair = pairingHash(actor, pairing.opponent);
|
|
50571
50587
|
if (!stipulatedPairs.includes(stipulatedPair)) {
|
|
50572
50588
|
var proposed = roundCandidate({
|
|
50573
50589
|
// each roundCandidate starts with stipulated pairings
|
|
50574
50590
|
stipulated: [[actor, pairing.opponent]],
|
|
50575
|
-
|
|
50591
|
+
actorsCount: actors.length,
|
|
50576
50592
|
valueSortedPairings: valueSortedPairings,
|
|
50593
|
+
pairingValueMap: pairingValueMap,
|
|
50577
50594
|
deltaObjects: deltaObjects,
|
|
50595
|
+
valueObjects: valueObjects,
|
|
50578
50596
|
});
|
|
50579
|
-
|
|
50580
|
-
|
|
50581
|
-
|
|
50582
|
-
|
|
50583
|
-
|
|
50584
|
-
|
|
50597
|
+
// ensure no duplicate candidates are considered
|
|
50598
|
+
if (!candidateHashes.includes(candidateHash(proposed))) {
|
|
50599
|
+
candidateHashes.push(candidateHash(proposed));
|
|
50600
|
+
proposedCandidates.push(proposed);
|
|
50601
|
+
var maxDelta = proposed.maxDelta, value = proposed.value;
|
|
50602
|
+
if (maxDelta < deltaCandidate.maxDelta)
|
|
50603
|
+
deltaCandidate = proposed;
|
|
50604
|
+
if (value < lowCandidateValue ||
|
|
50605
|
+
(value === lowCandidateValue && Math.round(Math.random())) // randomize if equivalent values
|
|
50606
|
+
) {
|
|
50607
|
+
lowCandidateValue = value;
|
|
50608
|
+
}
|
|
50609
|
+
stipulatedPairs.push(stipulatedPair);
|
|
50610
|
+
candidatesCount += 1;
|
|
50611
|
+
}
|
|
50585
50612
|
}
|
|
50586
50613
|
});
|
|
50614
|
+
proposedCandidates = proposedCandidates.filter(function (proposed) { return Math.abs(proposed.value - lowCandidateValue) < 5; });
|
|
50587
50615
|
});
|
|
50588
|
-
|
|
50616
|
+
proposedCandidates.sort(function (a, b) { return a.maxDiff - b.maxDiff; });
|
|
50617
|
+
var candidate = randomPop(proposedCandidates);
|
|
50618
|
+
return {
|
|
50619
|
+
candidatesCount: candidatesCount,
|
|
50620
|
+
deltaCandidate: deltaCandidate,
|
|
50621
|
+
maxIterations: maxIterations,
|
|
50622
|
+
iterations: iterations,
|
|
50623
|
+
candidate: candidate,
|
|
50624
|
+
};
|
|
50625
|
+
}
|
|
50626
|
+
function candidateHash(candidate) {
|
|
50627
|
+
return candidate.participantIdPairings
|
|
50628
|
+
.map(function (_a) {
|
|
50629
|
+
var participantIds = _a.participantIds;
|
|
50630
|
+
return participantIds.sort().join('|');
|
|
50631
|
+
})
|
|
50632
|
+
.sort()
|
|
50633
|
+
.join('/');
|
|
50589
50634
|
}
|
|
50590
50635
|
function roundCandidate(_a) {
|
|
50591
|
-
var
|
|
50636
|
+
var valueSortedPairings = _a.valueSortedPairings, _b = _a.stipulated, stipulated = _b === void 0 ? [] : _b, pairingValueMap = _a.pairingValueMap, deltaObjects = _a.deltaObjects, valueObjects = _a.valueObjects, actorsCount = _a.actorsCount;
|
|
50592
50637
|
// roundPlayers starts with the stipulated pairing
|
|
50593
50638
|
var roundPlayers = [].concat.apply([], __spreadArray([], __read(stipulated), false));
|
|
50594
50639
|
// aggregates the pairings generated for a roundCandidate
|
|
@@ -50600,13 +50645,19 @@ function roundCandidate(_a) {
|
|
|
50600
50645
|
stipulated.filter(Boolean).forEach(function (participantIds) {
|
|
50601
50646
|
var _a = __read(participantIds, 2), p1 = _a[0], p2 = _a[1];
|
|
50602
50647
|
var pairing = pairingHash(p1, p2);
|
|
50603
|
-
var value =
|
|
50648
|
+
var value = pairingValueMap[pairing];
|
|
50604
50649
|
participantIdPairings.push({ participantIds: participantIds, value: value });
|
|
50605
|
-
candidateValue +=
|
|
50650
|
+
candidateValue += pairingValueMap[pairing];
|
|
50606
50651
|
});
|
|
50652
|
+
// valueSortedPairings is an array sorted from lowest value to highest value
|
|
50653
|
+
// introduce random shuffling of chunks of valueSortedPairings
|
|
50654
|
+
var consideredPairings = chunkArray(valueSortedPairings, actorsCount)
|
|
50655
|
+
.map(function (pairings) {
|
|
50656
|
+
return shuffleArray(pairings).map(function (pairing) { return (__assign(__assign({}, pairing), { value: pairing.value + Math.random() * Math.round(Math.random()) })); });
|
|
50657
|
+
})
|
|
50658
|
+
.flat();
|
|
50607
50659
|
// go through the valueSortedPairings (of all possible unique pairings)
|
|
50608
|
-
|
|
50609
|
-
valueSortedPairings.forEach(function (rankedPairing) {
|
|
50660
|
+
consideredPairings.forEach(function (rankedPairing) {
|
|
50610
50661
|
var participantIds = rankedPairing.pairing.split('|');
|
|
50611
50662
|
var opponentExists = participantIds.reduce(function (p, c) { return roundPlayers.includes(c) || p; }, false);
|
|
50612
50663
|
if (!opponentExists) {
|
|
@@ -50625,21 +50676,181 @@ function roundCandidate(_a) {
|
|
|
50625
50676
|
var delta = deltaObjects[hash];
|
|
50626
50677
|
return delta > p ? delta : p;
|
|
50627
50678
|
}, 0);
|
|
50628
|
-
|
|
50679
|
+
// determine the greatest delta in the candidate's pairings
|
|
50680
|
+
var maxDiff = participantIdPairings.reduce(function (p, c) {
|
|
50681
|
+
var _a = __read(c.participantIds, 2), p1 = _a[0], p2 = _a[1];
|
|
50682
|
+
var hash = pairingHash(p1, p2);
|
|
50683
|
+
var diff = valueObjects[hash];
|
|
50684
|
+
return diff > p ? diff : p;
|
|
50685
|
+
}, 0);
|
|
50686
|
+
return { value: candidateValue, participantIdPairings: participantIdPairings, maxDelta: maxDelta, maxDiff: maxDiff };
|
|
50629
50687
|
}
|
|
50630
50688
|
function pairingHash(id1, id2) {
|
|
50631
50689
|
return [id1, id2].sort().join('|');
|
|
50632
50690
|
}
|
|
50633
50691
|
|
|
50634
|
-
|
|
50635
|
-
var
|
|
50636
|
-
var
|
|
50692
|
+
function getPairingsData(_a) {
|
|
50693
|
+
var participantIds = _a.participantIds;
|
|
50694
|
+
var possiblePairings = {};
|
|
50695
|
+
var uniquePairings = [];
|
|
50696
|
+
participantIds.forEach(function (participantId) {
|
|
50697
|
+
possiblePairings[participantId] = participantIds.filter(function (id) { return id !== participantId; });
|
|
50698
|
+
possiblePairings[participantId].forEach(function (id) {
|
|
50699
|
+
var pairing = pairingHash(id, participantId);
|
|
50700
|
+
if (!uniquePairings.includes(pairing))
|
|
50701
|
+
uniquePairings.push(pairing);
|
|
50702
|
+
});
|
|
50703
|
+
});
|
|
50704
|
+
var deltaObjects = Object.assign.apply(Object, __spreadArray([{}], __read(uniquePairings.map(function (pairing) {
|
|
50705
|
+
var _a;
|
|
50706
|
+
return (_a = {}, _a[pairing] = 0, _a);
|
|
50707
|
+
})), false));
|
|
50708
|
+
return { uniquePairings: uniquePairings, possiblePairings: possiblePairings, deltaObjects: deltaObjects };
|
|
50709
|
+
}
|
|
50710
|
+
|
|
50711
|
+
function getEncounters(_a) {
|
|
50712
|
+
var e_1, _b;
|
|
50713
|
+
var matchUps = _a.matchUps;
|
|
50714
|
+
var encounters = [];
|
|
50715
|
+
try {
|
|
50716
|
+
for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
|
|
50717
|
+
var matchUp = matchUps_1_1.value;
|
|
50718
|
+
var participantIds = matchUp.sides.map(extractAttributes('participantId'));
|
|
50719
|
+
if (participantIds.length === 2) {
|
|
50720
|
+
var _c = __read(participantIds, 2), p1 = _c[0], p2 = _c[1];
|
|
50721
|
+
var pairing = pairingHash(p1, p2);
|
|
50722
|
+
if (!encounters.includes(pairing))
|
|
50723
|
+
encounters.push(pairing);
|
|
50724
|
+
}
|
|
50725
|
+
}
|
|
50726
|
+
}
|
|
50727
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
50728
|
+
finally {
|
|
50729
|
+
try {
|
|
50730
|
+
if (matchUps_1_1 && !matchUps_1_1.done && (_b = matchUps_1.return)) _b.call(matchUps_1);
|
|
50731
|
+
}
|
|
50732
|
+
finally { if (e_1) throw e_1.error; }
|
|
50733
|
+
}
|
|
50734
|
+
return { encounters: encounters };
|
|
50735
|
+
}
|
|
50736
|
+
|
|
50737
|
+
function getParticipantPairingValues(_a) {
|
|
50738
|
+
var e_1, _b;
|
|
50739
|
+
var possiblePairings = _a.possiblePairings, valueObjects = _a.valueObjects;
|
|
50740
|
+
var pairingValues = {};
|
|
50741
|
+
var _loop_1 = function (participantId) {
|
|
50742
|
+
var participantValues = possiblePairings[participantId].map(function (opponent) {
|
|
50743
|
+
return pairingValue(participantId, opponent);
|
|
50744
|
+
});
|
|
50745
|
+
pairingValues[participantId] = participantValues.sort(function (a, b) { return a.value - b.value; });
|
|
50746
|
+
};
|
|
50747
|
+
try {
|
|
50748
|
+
for (var _c = __values(Object.keys(possiblePairings)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
50749
|
+
var participantId = _d.value;
|
|
50750
|
+
_loop_1(participantId);
|
|
50751
|
+
}
|
|
50752
|
+
}
|
|
50753
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
50754
|
+
finally {
|
|
50755
|
+
try {
|
|
50756
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
50757
|
+
}
|
|
50758
|
+
finally { if (e_1) throw e_1.error; }
|
|
50759
|
+
}
|
|
50760
|
+
function pairingValue(participantId, opponent) {
|
|
50761
|
+
var key = pairingHash(participantId, opponent);
|
|
50762
|
+
return { opponent: opponent, value: valueObjects[key] };
|
|
50763
|
+
}
|
|
50764
|
+
return { pairingValues: pairingValues };
|
|
50765
|
+
}
|
|
50766
|
+
|
|
50637
50767
|
var DEFAULT_RATING = 0;
|
|
50638
|
-
|
|
50768
|
+
function getSideRatings(_a) {
|
|
50769
|
+
var _b, _c;
|
|
50770
|
+
var tournamentParticipants = _a.tournamentParticipants, adHocRatings = _a.adHocRatings, eventType = _a.eventType, scaleName = _a.scaleName, pairing = _a.pairing;
|
|
50771
|
+
var defaultRating = (_c = (_b = ratingsParameters[scaleName]) === null || _b === void 0 ? void 0 : _b.defaultInitialization) !== null && _c !== void 0 ? _c : DEFAULT_RATING;
|
|
50772
|
+
return pairing.split('|').map(function (participantId) {
|
|
50773
|
+
var _a;
|
|
50774
|
+
if (eventType === DOUBLES) {
|
|
50775
|
+
var individualParticipantIds = (_a = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (participant) { return participant.participantId === participantId; })) === null || _a === void 0 ? void 0 : _a.individualParticipantIds;
|
|
50776
|
+
return !individualParticipantIds
|
|
50777
|
+
? defaultRating * 2
|
|
50778
|
+
: individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.map(function (participantId) { return adHocRatings[participantId] || defaultRating; });
|
|
50779
|
+
}
|
|
50780
|
+
else {
|
|
50781
|
+
return adHocRatings[participantId] || defaultRating;
|
|
50782
|
+
}
|
|
50783
|
+
});
|
|
50784
|
+
}
|
|
50785
|
+
|
|
50786
|
+
function getPairings(_a) {
|
|
50787
|
+
var tournamentParticipants = _a.tournamentParticipants, _b = _a.adHocRatings, adHocRatings = _b === void 0 ? {} : _b, possiblePairings = _a.possiblePairings, // participant keyed; provides array of possible opponents
|
|
50788
|
+
uniquePairings = _a.uniquePairings, // hashes of all possible participantId pairings
|
|
50789
|
+
maxIterations = _a.maxIterations, deltaObjects = _a.deltaObjects, // difference in rating between paired participants
|
|
50790
|
+
valueObjects = _a.valueObjects, // calculated value of a pairing of participants, used for sorting pairings
|
|
50791
|
+
eventType = _a.eventType, scaleName = _a.scaleName, salted = _a.salted;
|
|
50792
|
+
// modify valueObjects by ratings ratingsDifference squared
|
|
50793
|
+
// update deltaObjects to reflect the current difference between participant's ratings
|
|
50794
|
+
uniquePairings.forEach(function (pairing) {
|
|
50795
|
+
var ratings = getSideRatings({
|
|
50796
|
+
tournamentParticipants: tournamentParticipants,
|
|
50797
|
+
adHocRatings: adHocRatings,
|
|
50798
|
+
scaleName: scaleName,
|
|
50799
|
+
eventType: eventType,
|
|
50800
|
+
pairing: pairing,
|
|
50801
|
+
});
|
|
50802
|
+
var salting = (typeof salted === 'number' && salted) || 0.5;
|
|
50803
|
+
var salt = (salted && (Math.round(Math.random()) ? salting : salting * -1)) || 0;
|
|
50804
|
+
var ratingsDifference = Math.abs(ratings[0] - ratings[1]) + salt;
|
|
50805
|
+
var pairingDelta = Math.abs(ratings[0] - ratings[1]);
|
|
50806
|
+
deltaObjects[pairing] = pairingDelta;
|
|
50807
|
+
if (!valueObjects[pairing])
|
|
50808
|
+
valueObjects[pairing] = 0;
|
|
50809
|
+
valueObjects[pairing] += ratingsDifference
|
|
50810
|
+
? Math.pow(ratingsDifference, 2)
|
|
50811
|
+
: 0;
|
|
50812
|
+
});
|
|
50813
|
+
/**
|
|
50814
|
+
* valueSortedPairings are uniquePairings sorted by the ratings difference of the pairings, lowest to highest
|
|
50815
|
+
*/
|
|
50816
|
+
var valueSortedPairings = uniquePairings
|
|
50817
|
+
.map(function (pairing) { return ({ pairing: pairing, value: valueObjects[pairing] }); })
|
|
50818
|
+
.sort(function (a, b) { return a.value - b.value; });
|
|
50819
|
+
/**
|
|
50820
|
+
* pairingValues is keyed by participantId and provides a value-sorted array of pairings for each participantId
|
|
50821
|
+
* 'actorId': [
|
|
50822
|
+
{ opponent: 'potentialId1', value: 1 },
|
|
50823
|
+
{ opponent: 'potentialId2', value: 1 },
|
|
50824
|
+
*/
|
|
50825
|
+
var pairingValues = getParticipantPairingValues({
|
|
50826
|
+
possiblePairings: possiblePairings,
|
|
50827
|
+
valueObjects: valueObjects,
|
|
50828
|
+
}).pairingValues;
|
|
50829
|
+
var _c = generateCandidate({
|
|
50830
|
+
valueSortedPairings: valueSortedPairings,
|
|
50831
|
+
maxIterations: maxIterations,
|
|
50832
|
+
pairingValues: pairingValues,
|
|
50833
|
+
deltaObjects: deltaObjects,
|
|
50834
|
+
valueObjects: valueObjects,
|
|
50835
|
+
}), candidate = _c.candidate, candidatesCount = _c.candidatesCount, deltaCandidate = _c.deltaCandidate, iterations = _c.iterations;
|
|
50836
|
+
var participantIdPairings = candidate.participantIdPairings;
|
|
50837
|
+
return {
|
|
50838
|
+
participantIdPairings: participantIdPairings,
|
|
50839
|
+
candidatesCount: candidatesCount,
|
|
50840
|
+
deltaCandidate: deltaCandidate,
|
|
50841
|
+
iterations: iterations,
|
|
50842
|
+
candidate: candidate,
|
|
50843
|
+
};
|
|
50844
|
+
}
|
|
50845
|
+
|
|
50846
|
+
// this should be in policyDefinitions
|
|
50847
|
+
var ENCOUNTER_VALUE = 100;
|
|
50848
|
+
var SAME_TEAM_VALUE = 100;
|
|
50849
|
+
var MAX_ITERATIONS = 4000;
|
|
50639
50850
|
function generateDrawMaticRound(_a) {
|
|
50640
50851
|
var e_1, _b, e_2, _c, e_3, _d;
|
|
50641
50852
|
var _e, _f;
|
|
50642
|
-
var _g = _a.
|
|
50853
|
+
var _g = _a.encounterValue, encounterValue = _g === void 0 ? ENCOUNTER_VALUE : _g, _h = _a.sameTeamValue, sameTeamValue = _h === void 0 ? SAME_TEAM_VALUE : _h, _j = _a.maxIterations, maxIterations = _j === void 0 ? MAX_ITERATIONS : _j, _k = _a.generateMatchUps, generateMatchUps = _k === void 0 ? true : _k, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, addToStructure = _a.addToStructure, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, structureId = _a.structureId, _l = _a.salted, salted = _l === void 0 ? 0.5 : _l, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure, scaleName = _a.scaleName;
|
|
50643
50854
|
if (!drawDefinition)
|
|
50644
50855
|
return { error: MISSING_DRAW_DEFINITION };
|
|
50645
50856
|
if (!structure && !structureId)
|
|
@@ -50666,7 +50877,7 @@ function generateDrawMaticRound(_a) {
|
|
|
50666
50877
|
var pairing = encounters_1_1.value;
|
|
50667
50878
|
if (!valueObjects[pairing])
|
|
50668
50879
|
valueObjects[pairing] = 0;
|
|
50669
|
-
valueObjects[pairing] +=
|
|
50880
|
+
valueObjects[pairing] += encounterValue;
|
|
50670
50881
|
}
|
|
50671
50882
|
}
|
|
50672
50883
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -50692,7 +50903,7 @@ function generateDrawMaticRound(_a) {
|
|
|
50692
50903
|
var pairing = uniquePairings_1_1.value;
|
|
50693
50904
|
if (!valueObjects[pairing])
|
|
50694
50905
|
valueObjects[pairing] = 0;
|
|
50695
|
-
valueObjects[pairing] +=
|
|
50906
|
+
valueObjects[pairing] += sameTeamValue;
|
|
50696
50907
|
}
|
|
50697
50908
|
}
|
|
50698
50909
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -50718,9 +50929,9 @@ function generateDrawMaticRound(_a) {
|
|
|
50718
50929
|
// 'P-I-0|P-I-2': 0,
|
|
50719
50930
|
// 'P-I-0|P-I-3': 0
|
|
50720
50931
|
// }
|
|
50721
|
-
var
|
|
50932
|
+
var _m = getPairingsData({
|
|
50722
50933
|
participantIds: participantIds,
|
|
50723
|
-
}), uniquePairings =
|
|
50934
|
+
}), uniquePairings = _m.uniquePairings, possiblePairings = _m.possiblePairings, deltaObjects = _m.deltaObjects;
|
|
50724
50935
|
var params = {
|
|
50725
50936
|
tournamentParticipants: tournamentParticipants,
|
|
50726
50937
|
possiblePairings: possiblePairings,
|
|
@@ -50732,9 +50943,11 @@ function generateDrawMaticRound(_a) {
|
|
|
50732
50943
|
deltaObjects: deltaObjects,
|
|
50733
50944
|
valueObjects: valueObjects,
|
|
50734
50945
|
eventType: eventType,
|
|
50946
|
+
scaleName: scaleName,
|
|
50735
50947
|
structure: structure,
|
|
50948
|
+
salted: salted,
|
|
50736
50949
|
};
|
|
50737
|
-
var
|
|
50950
|
+
var _o = getPairings(params), candidatesCount = _o.candidatesCount, participantIdPairings = _o.participantIdPairings, iterations = _o.iterations, candidate = _o.candidate;
|
|
50738
50951
|
if (!candidatesCount)
|
|
50739
50952
|
return { error: NO_CANDIDATES };
|
|
50740
50953
|
var matchUps;
|
|
@@ -50752,147 +50965,15 @@ function generateDrawMaticRound(_a) {
|
|
|
50752
50965
|
return result;
|
|
50753
50966
|
matchUps = result.matchUps;
|
|
50754
50967
|
}
|
|
50755
|
-
|
|
50756
|
-
}
|
|
50757
|
-
function getSideRatings(_a) {
|
|
50758
|
-
var tournamentParticipants = _a.tournamentParticipants, adHocRatings = _a.adHocRatings, eventType = _a.eventType, pairing = _a.pairing;
|
|
50759
|
-
return pairing.split('|').map(function (participantId) {
|
|
50760
|
-
var _a;
|
|
50761
|
-
if (eventType === DOUBLES) {
|
|
50762
|
-
var individualParticipantIds = (_a = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (participant) { return participant.participantId === participantId; })) === null || _a === void 0 ? void 0 : _a.individualParticipantIds;
|
|
50763
|
-
return !individualParticipantIds
|
|
50764
|
-
? DEFAULT_RATING * 2
|
|
50765
|
-
: individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.map(function (participantId) { return adHocRatings[participantId || DEFAULT_RATING]; });
|
|
50766
|
-
}
|
|
50767
|
-
else {
|
|
50768
|
-
return adHocRatings[participantId] || DEFAULT_RATING;
|
|
50769
|
-
}
|
|
50770
|
-
});
|
|
50771
|
-
}
|
|
50772
|
-
function getPairings(_a) {
|
|
50773
|
-
var tournamentParticipants = _a.tournamentParticipants, _b = _a.adHocRatings, adHocRatings = _b === void 0 ? {} : _b, possiblePairings = _a.possiblePairings, // participant keyed; provides array of possible opponents
|
|
50774
|
-
uniquePairings = _a.uniquePairings, // hashes of all possible participantId pairings
|
|
50775
|
-
maxIterations = _a.maxIterations, deltaObjects = _a.deltaObjects, // difference in rating between paired participants
|
|
50776
|
-
valueObjects = _a.valueObjects, // calculated value of a pairing of participants, used for sorting pairings
|
|
50777
|
-
eventType = _a.eventType;
|
|
50778
|
-
// modify valueObjects by ratings ratingsDifference squared
|
|
50779
|
-
// update deltaObjects to reflect the current difference between participant's ratings
|
|
50780
|
-
uniquePairings.forEach(function (pairing) {
|
|
50781
|
-
var ratings = getSideRatings({
|
|
50782
|
-
tournamentParticipants: tournamentParticipants,
|
|
50783
|
-
adHocRatings: adHocRatings,
|
|
50784
|
-
eventType: eventType,
|
|
50785
|
-
pairing: pairing,
|
|
50786
|
-
});
|
|
50787
|
-
var ratingsDifference = Math.abs(ratings[0] - ratings[1]) + 1;
|
|
50788
|
-
deltaObjects[pairing] = Math.abs(ratings[0] - ratings[1]);
|
|
50789
|
-
if (!valueObjects[pairing])
|
|
50790
|
-
valueObjects[pairing] = 0;
|
|
50791
|
-
valueObjects[pairing] += Math.pow(ratingsDifference, 2);
|
|
50792
|
-
});
|
|
50793
|
-
/**
|
|
50794
|
-
* valueSortedPairings are uniquePairings sorted by the value of the pairings, lowest to highest
|
|
50795
|
-
*/
|
|
50796
|
-
var valueSortedPairings = uniquePairings
|
|
50797
|
-
.map(function (pairing) { return ({ pairing: pairing, value: valueObjects[pairing] }); })
|
|
50798
|
-
.sort(function (a, b) { return a.value - b.value; });
|
|
50799
|
-
/**
|
|
50800
|
-
* pairingValues is keyed by participantId and provides a value-sorted array of pairings for each participantId
|
|
50801
|
-
* 'actorId': [
|
|
50802
|
-
{ opponent: 'potentialId1', value: 1 },
|
|
50803
|
-
{ opponent: 'potentialId2', value: 1 },
|
|
50804
|
-
*/
|
|
50805
|
-
var pairingValues = getParticipantPairingValues({
|
|
50806
|
-
possiblePairings: possiblePairings,
|
|
50807
|
-
valueObjects: valueObjects,
|
|
50808
|
-
}).pairingValues;
|
|
50809
|
-
var _c = generateCandidate({
|
|
50810
|
-
valueSortedPairings: valueSortedPairings,
|
|
50811
|
-
maxIterations: maxIterations,
|
|
50812
|
-
pairingValues: pairingValues,
|
|
50813
|
-
deltaObjects: deltaObjects,
|
|
50814
|
-
}), candidate = _c.candidate, candidatesCount = _c.candidatesCount, iterations = _c.iterations;
|
|
50815
|
-
var participantIdPairings = candidate.participantIdPairings;
|
|
50816
|
-
return { candidatesCount: candidatesCount, participantIdPairings: participantIdPairings, iterations: iterations };
|
|
50817
|
-
}
|
|
50818
|
-
function getPairingsData(_a) {
|
|
50819
|
-
var participantIds = _a.participantIds;
|
|
50820
|
-
var possiblePairings = {};
|
|
50821
|
-
var uniquePairings = [];
|
|
50822
|
-
participantIds.forEach(function (participantId) {
|
|
50823
|
-
possiblePairings[participantId] = participantIds.filter(function (id) { return id !== participantId; });
|
|
50824
|
-
possiblePairings[participantId].forEach(function (id) {
|
|
50825
|
-
var pairing = pairingHash(id, participantId);
|
|
50826
|
-
if (!uniquePairings.includes(pairing))
|
|
50827
|
-
uniquePairings.push(pairing);
|
|
50828
|
-
});
|
|
50829
|
-
});
|
|
50830
|
-
var deltaObjects = Object.assign.apply(Object, __spreadArray([{}], __read(uniquePairings.map(function (pairing) {
|
|
50831
|
-
var _a;
|
|
50832
|
-
return (_a = {}, _a[pairing] = 0, _a);
|
|
50833
|
-
})), false));
|
|
50834
|
-
return { uniquePairings: uniquePairings, possiblePairings: possiblePairings, deltaObjects: deltaObjects };
|
|
50835
|
-
}
|
|
50836
|
-
function getEncounters(_a) {
|
|
50837
|
-
var e_4, _b;
|
|
50838
|
-
var matchUps = _a.matchUps;
|
|
50839
|
-
var encounters = [];
|
|
50840
|
-
try {
|
|
50841
|
-
for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
|
|
50842
|
-
var matchUp = matchUps_1_1.value;
|
|
50843
|
-
var participantIds = matchUp.sides.map(getParticipantId);
|
|
50844
|
-
if (participantIds.length === 2) {
|
|
50845
|
-
var _c = __read(participantIds, 2), p1 = _c[0], p2 = _c[1];
|
|
50846
|
-
var pairing = pairingHash(p1, p2);
|
|
50847
|
-
if (!encounters.includes(pairing))
|
|
50848
|
-
encounters.push(pairing);
|
|
50849
|
-
}
|
|
50850
|
-
}
|
|
50851
|
-
}
|
|
50852
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
50853
|
-
finally {
|
|
50854
|
-
try {
|
|
50855
|
-
if (matchUps_1_1 && !matchUps_1_1.done && (_b = matchUps_1.return)) _b.call(matchUps_1);
|
|
50856
|
-
}
|
|
50857
|
-
finally { if (e_4) throw e_4.error; }
|
|
50858
|
-
}
|
|
50859
|
-
return { encounters: encounters };
|
|
50860
|
-
}
|
|
50861
|
-
function getParticipantPairingValues(_a) {
|
|
50862
|
-
var e_5, _b;
|
|
50863
|
-
var possiblePairings = _a.possiblePairings, valueObjects = _a.valueObjects;
|
|
50864
|
-
var pairingValues = {};
|
|
50865
|
-
var _loop_1 = function (participantId) {
|
|
50866
|
-
var participantValues = possiblePairings[participantId].map(function (opponent) {
|
|
50867
|
-
return pairingValue(participantId, opponent);
|
|
50868
|
-
});
|
|
50869
|
-
pairingValues[participantId] = participantValues.sort(function (a, b) { return a.value - b.value; });
|
|
50870
|
-
};
|
|
50871
|
-
try {
|
|
50872
|
-
for (var _c = __values(Object.keys(possiblePairings)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
50873
|
-
var participantId = _d.value;
|
|
50874
|
-
_loop_1(participantId);
|
|
50875
|
-
}
|
|
50876
|
-
}
|
|
50877
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
50878
|
-
finally {
|
|
50879
|
-
try {
|
|
50880
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
50881
|
-
}
|
|
50882
|
-
finally { if (e_5) throw e_5.error; }
|
|
50883
|
-
}
|
|
50884
|
-
function pairingValue(participantId, opponent) {
|
|
50885
|
-
var key = pairingHash(participantId, opponent);
|
|
50886
|
-
return { opponent: opponent, value: valueObjects[key] };
|
|
50887
|
-
}
|
|
50888
|
-
return { pairingValues: pairingValues };
|
|
50968
|
+
var maxDelta = candidate.maxDelta, maxDiff = candidate.maxDiff;
|
|
50969
|
+
return __assign(__assign({}, SUCCESS), { participantIdPairings: participantIdPairings, candidatesCount: candidatesCount, iterations: iterations, matchUps: matchUps, maxDelta: maxDelta, maxDiff: maxDiff });
|
|
50889
50970
|
}
|
|
50890
50971
|
|
|
50891
50972
|
function drawMatic$1(_a) {
|
|
50892
50973
|
var e_1, _b;
|
|
50893
50974
|
var _c, _d, _e, _f, _g;
|
|
50894
|
-
var tournamentParticipants = _a.tournamentParticipants, restrictEntryStatus = _a.restrictEntryStatus,
|
|
50895
|
-
eventType = _a.eventType, event = _a.event;
|
|
50975
|
+
var tournamentParticipants = _a.tournamentParticipants, restrictEntryStatus = _a.restrictEntryStatus, _h = _a.adHocRatings, adHocRatings = _h === void 0 ? {} : _h, generateMatchUps = _a.generateMatchUps, tournamentRecord = _a.tournamentRecord, addToStructure = _a.addToStructure, participantIds = _a.participantIds, encounterValue = _a.encounterValue, sameTeamValue = _a.sameTeamValue, drawDefinition = _a.drawDefinition, scaleAccessor = _a.scaleAccessor, maxIterations = _a.maxIterations, structureId = _a.structureId, matchUpIds = _a.matchUpIds, scaleName = _a.scaleName, // custom rating name to seed dynamic ratings
|
|
50976
|
+
eventType = _a.eventType, salted = _a.salted, event = _a.event;
|
|
50896
50977
|
if (typeof drawDefinition !== 'object' ||
|
|
50897
50978
|
(drawDefinition.drawType && drawDefinition.drawType !== AD_HOC)) {
|
|
50898
50979
|
return { error: INVALID_DRAW_DEFINITION };
|
|
@@ -50941,11 +51022,15 @@ function drawMatic$1(_a) {
|
|
|
50941
51022
|
return { error: INVALID_DRAW_DEFINITION };
|
|
50942
51023
|
tournamentParticipants =
|
|
50943
51024
|
(_g = tournamentParticipants !== null && tournamentParticipants !== void 0 ? tournamentParticipants : tournamentRecord.participants) !== null && _g !== void 0 ? _g : [];
|
|
50944
|
-
var adHocRatings = {};
|
|
50945
51025
|
var _loop_1 = function (participantId) {
|
|
50946
51026
|
var participant = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
|
|
50947
51027
|
// first see if there is already a dynamic value
|
|
50948
|
-
var scaleValue = getScaleValue({
|
|
51028
|
+
var scaleValue = getScaleValue({
|
|
51029
|
+
scaleName: "".concat(scaleName, ".").concat(DYNAMIC),
|
|
51030
|
+
scaleAccessor: scaleAccessor,
|
|
51031
|
+
participant: participant,
|
|
51032
|
+
eventType: eventType,
|
|
51033
|
+
});
|
|
50949
51034
|
// if no dynamic value found and a seeding scaleValue is provided...
|
|
50950
51035
|
if (!scaleValue && scaleName) {
|
|
50951
51036
|
scaleValue = getScaleValue({
|
|
@@ -50955,44 +51040,47 @@ function drawMatic$1(_a) {
|
|
|
50955
51040
|
eventType: eventType,
|
|
50956
51041
|
});
|
|
50957
51042
|
}
|
|
50958
|
-
if (scaleValue)
|
|
51043
|
+
if (scaleValue && !adHocRatings[participantId])
|
|
50959
51044
|
adHocRatings[participantId] = scaleValue;
|
|
50960
51045
|
};
|
|
50961
51046
|
try {
|
|
50962
|
-
for (var
|
|
50963
|
-
var participantId =
|
|
51047
|
+
for (var _j = __values(participantIds !== null && participantIds !== void 0 ? participantIds : []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
51048
|
+
var participantId = _k.value;
|
|
50964
51049
|
_loop_1(participantId);
|
|
50965
51050
|
}
|
|
50966
51051
|
}
|
|
50967
51052
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
50968
51053
|
finally {
|
|
50969
51054
|
try {
|
|
50970
|
-
if (
|
|
51055
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
50971
51056
|
}
|
|
50972
51057
|
finally { if (e_1) throw e_1.error; }
|
|
50973
51058
|
}
|
|
50974
51059
|
// TODO: update dynamic ratings based on matchUps present from last played round
|
|
50975
|
-
// use scaleEngine.
|
|
51060
|
+
// use scaleEngine.generateDynamicRatings(); see dynamicCalculations.test.ts
|
|
50976
51061
|
return generateDrawMaticRound({
|
|
50977
51062
|
tournamentParticipants: tournamentParticipants,
|
|
50978
|
-
tournamentRecord: tournamentRecord,
|
|
50979
51063
|
generateMatchUps: generateMatchUps,
|
|
50980
|
-
|
|
51064
|
+
tournamentRecord: tournamentRecord,
|
|
50981
51065
|
addToStructure: addToStructure,
|
|
51066
|
+
participantIds: participantIds,
|
|
51067
|
+
encounterValue: encounterValue,
|
|
51068
|
+
sameTeamValue: sameTeamValue,
|
|
50982
51069
|
drawDefinition: drawDefinition,
|
|
50983
51070
|
maxIterations: maxIterations,
|
|
50984
51071
|
adHocRatings: adHocRatings,
|
|
50985
51072
|
matchUpIds: matchUpIds,
|
|
50986
51073
|
structure: structure,
|
|
50987
51074
|
eventType: eventType,
|
|
51075
|
+
salted: salted,
|
|
50988
51076
|
});
|
|
50989
51077
|
}
|
|
50990
51078
|
function getScaleValue(_a) {
|
|
50991
51079
|
var _b;
|
|
50992
|
-
var _c = _a.
|
|
51080
|
+
var _c = _a.scaleType, scaleType = _c === void 0 ? RATING$2 : _c, scaleAccessor = _a.scaleAccessor, participant = _a.participant, scaleName = _a.scaleName, eventType = _a.eventType;
|
|
50993
51081
|
var scaleAttributes = {
|
|
50994
51082
|
eventType: eventType || TypeEnum.Singles,
|
|
50995
|
-
scaleType:
|
|
51083
|
+
scaleType: scaleType,
|
|
50996
51084
|
scaleName: scaleName,
|
|
50997
51085
|
};
|
|
50998
51086
|
var result = participant &&
|
|
@@ -64649,18 +64737,18 @@ function calculateNewRatings(params) {
|
|
|
64649
64737
|
var updatedWinnerRating = invertedScale
|
|
64650
64738
|
? ratingRange[0] - convertedUpdatedWinnerRating
|
|
64651
64739
|
: convertedUpdatedWinnerRating;
|
|
64652
|
-
var newWinnerRating = parseFloat(updatedWinnerRating).toFixed(decimalPlaces);
|
|
64740
|
+
var newWinnerRating = parseFloat(parseFloat(updatedWinnerRating).toFixed(decimalPlaces));
|
|
64653
64741
|
var updatedLoserRating = invertedScale
|
|
64654
64742
|
? ratingRange[0] - convertedUpdatedLoserRating
|
|
64655
64743
|
: convertedUpdatedLoserRating;
|
|
64656
|
-
var newLoserRating = parseFloat(updatedLoserRating).toFixed(decimalPlaces);
|
|
64744
|
+
var newLoserRating = parseFloat(parseFloat(updatedLoserRating).toFixed(decimalPlaces));
|
|
64657
64745
|
// if expected winner && percentageDifference > threshold don't change ratings
|
|
64658
64746
|
var percentageDifference = Math.max.apply(Math, __spreadArray([], __read(ratingRange), false)) ? Math.abs(winnerRating - loserRating) / Math.max.apply(Math, __spreadArray([], __read(ratingRange), false))
|
|
64659
64747
|
: 0;
|
|
64660
64748
|
if ((convertedUpdatedWinnerRating > convertedUpdatedLoserRating &&
|
|
64661
64749
|
percentageDifference > eloConfig.diffThreshold) ||
|
|
64662
|
-
|
|
64663
|
-
|
|
64750
|
+
newWinnerRating < 0 ||
|
|
64751
|
+
newLoserRating < 0) {
|
|
64664
64752
|
newWinnerRating = winnerRating;
|
|
64665
64753
|
newLoserRating = loserRating;
|
|
64666
64754
|
}
|
|
@@ -64675,10 +64763,10 @@ var aggregateSets = function (sets) {
|
|
|
64675
64763
|
}, [0, 0])) || [0, 0]);
|
|
64676
64764
|
};
|
|
64677
64765
|
|
|
64678
|
-
function
|
|
64766
|
+
function generateDynamicRatings(_a) {
|
|
64679
64767
|
var e_1, _b;
|
|
64680
64768
|
var _c, _d;
|
|
64681
|
-
var tournamentRecord = _a.tournamentRecord,
|
|
64769
|
+
var _e = _a.removePriorValues, removePriorValues = _e === void 0 ? true : _e, tournamentRecord = _a.tournamentRecord, _f = _a.ratingType, ratingType = _f === void 0 ? ELO : _f, considerGames = _a.considerGames, matchUpIds = _a.matchUpIds, asDynamic = _a.asDynamic;
|
|
64682
64770
|
if (!tournamentRecord)
|
|
64683
64771
|
return { error: MISSING_TOURNAMENT_RECORD };
|
|
64684
64772
|
if (!Array.isArray(matchUpIds))
|
|
@@ -64696,7 +64784,7 @@ function processMatchUps(_a) {
|
|
|
64696
64784
|
inContext: true,
|
|
64697
64785
|
}).matchUps || [];
|
|
64698
64786
|
var _loop_1 = function (matchUp) {
|
|
64699
|
-
var e_2,
|
|
64787
|
+
var e_2, _j, e_3, _k, _l, _m;
|
|
64700
64788
|
var endDate = matchUp.endDate, matchUpFormat = matchUp.matchUpFormat, score = matchUp.score, sides = matchUp.sides, winningSide = matchUp.winningSide;
|
|
64701
64789
|
var matchUpType = matchUp.matchUpType;
|
|
64702
64790
|
var scaleAttributes = {
|
|
@@ -64704,7 +64792,7 @@ function processMatchUps(_a) {
|
|
|
64704
64792
|
scaleName: ratingType,
|
|
64705
64793
|
scaleType: RATING$2,
|
|
64706
64794
|
};
|
|
64707
|
-
var dynamicScaleName = "".concat(ratingType, ".
|
|
64795
|
+
var dynamicScaleName = "".concat(ratingType, ".").concat(DYNAMIC);
|
|
64708
64796
|
var dynamicScaleAttributes = {
|
|
64709
64797
|
scaleName: dynamicScaleName,
|
|
64710
64798
|
eventType: matchUpType,
|
|
@@ -64740,9 +64828,9 @@ function processMatchUps(_a) {
|
|
|
64740
64828
|
return (participantId && (_b = {},
|
|
64741
64829
|
_b[participantId] = (_c = dynamicScaleItem !== null && dynamicScaleItem !== void 0 ? dynamicScaleItem : scaleItem) !== null && _c !== void 0 ? _c : {
|
|
64742
64830
|
scaleName: outputScaleName,
|
|
64743
|
-
scaleType: RATING$2,
|
|
64744
64831
|
eventType: matchUpType,
|
|
64745
64832
|
scaleDate: endDate,
|
|
64833
|
+
scaleType: RATING$2,
|
|
64746
64834
|
scaleValue: scaleValue,
|
|
64747
64835
|
},
|
|
64748
64836
|
_b));
|
|
@@ -64777,31 +64865,33 @@ function processMatchUps(_a) {
|
|
|
64777
64865
|
var loserCountables = winningSide
|
|
64778
64866
|
? countables[3 - winningSide]
|
|
64779
64867
|
: [0, 0];
|
|
64780
|
-
var
|
|
64868
|
+
var _o = calculateNewRatings({
|
|
64781
64869
|
winnerCountables: winnerCountables,
|
|
64782
64870
|
loserCountables: loserCountables,
|
|
64783
64871
|
maxCountables: maxCountables,
|
|
64784
64872
|
winnerRating: winnerRating,
|
|
64785
64873
|
loserRating: loserRating,
|
|
64786
64874
|
ratingType: ratingType,
|
|
64787
|
-
}), newWinnerRating =
|
|
64875
|
+
}), newWinnerRating = _o.newWinnerRating, newLoserRating = _o.newLoserRating;
|
|
64788
64876
|
var newWinnerScaleValue = accessor
|
|
64789
|
-
? __assign(__assign({}, winnerScaleValue), (
|
|
64877
|
+
? __assign(__assign({}, winnerScaleValue), (_l = {}, _l[accessor] = newWinnerRating, _l)) : newWinnerRating;
|
|
64790
64878
|
var newLoserScaleValue = accessor
|
|
64791
|
-
? __assign(__assign({}, loserScaleValue), (
|
|
64879
|
+
? __assign(__assign({}, loserScaleValue), (_m = {}, _m[accessor] = newLoserRating, _m)) : newLoserRating;
|
|
64792
64880
|
scaleItemMap[winnerParticipantId].scaleValue = newWinnerScaleValue;
|
|
64793
64881
|
scaleItemMap[loserParticipantId].scaleValue = newLoserScaleValue;
|
|
64794
64882
|
var result = setParticipantScaleItem({
|
|
64795
|
-
scaleItem: __assign(__assign({}, scaleItemMap[winnerParticipantId]), { scaleName: outputScaleName }),
|
|
64796
64883
|
participantId: winnerParticipantId,
|
|
64884
|
+
removePriorValues: removePriorValues,
|
|
64797
64885
|
tournamentRecord: tournamentRecord,
|
|
64886
|
+
scaleItem: __assign(__assign({}, scaleItemMap[winnerParticipantId]), { scaleName: outputScaleName }),
|
|
64798
64887
|
});
|
|
64799
64888
|
if (result.error)
|
|
64800
64889
|
return { value: result };
|
|
64801
64890
|
result = setParticipantScaleItem({
|
|
64802
|
-
scaleItem: __assign(__assign({}, scaleItemMap[loserParticipantId]), { scaleName: outputScaleName }),
|
|
64803
64891
|
participantId: loserParticipantId,
|
|
64892
|
+
removePriorValues: removePriorValues,
|
|
64804
64893
|
tournamentRecord: tournamentRecord,
|
|
64894
|
+
scaleItem: __assign(__assign({}, scaleItemMap[loserParticipantId]), { scaleName: outputScaleName }),
|
|
64805
64895
|
});
|
|
64806
64896
|
if (result.error)
|
|
64807
64897
|
return { value: result };
|
|
@@ -64810,7 +64900,7 @@ function processMatchUps(_a) {
|
|
|
64810
64900
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
64811
64901
|
finally {
|
|
64812
64902
|
try {
|
|
64813
|
-
if (losingSideParticipantIds_1_1 && !losingSideParticipantIds_1_1.done && (
|
|
64903
|
+
if (losingSideParticipantIds_1_1 && !losingSideParticipantIds_1_1.done && (_k = losingSideParticipantIds_1.return)) _k.call(losingSideParticipantIds_1);
|
|
64814
64904
|
}
|
|
64815
64905
|
finally { if (e_3) throw e_3.error; }
|
|
64816
64906
|
}
|
|
@@ -64819,15 +64909,15 @@ function processMatchUps(_a) {
|
|
|
64819
64909
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
64820
64910
|
finally {
|
|
64821
64911
|
try {
|
|
64822
|
-
if (winningSideParticipantIds_1_1 && !winningSideParticipantIds_1_1.done && (
|
|
64912
|
+
if (winningSideParticipantIds_1_1 && !winningSideParticipantIds_1_1.done && (_j = winningSideParticipantIds_1.return)) _j.call(winningSideParticipantIds_1);
|
|
64823
64913
|
}
|
|
64824
64914
|
finally { if (e_2) throw e_2.error; }
|
|
64825
64915
|
}
|
|
64826
64916
|
Object.assign(modifiedScaleValues, scaleItemMap);
|
|
64827
64917
|
};
|
|
64828
64918
|
try {
|
|
64829
|
-
for (var
|
|
64830
|
-
var matchUp =
|
|
64919
|
+
for (var _g = __values(matchUps.sort(matchUpSort)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
64920
|
+
var matchUp = _h.value;
|
|
64831
64921
|
var state_1 = _loop_1(matchUp);
|
|
64832
64922
|
if (typeof state_1 === "object")
|
|
64833
64923
|
return state_1.value;
|
|
@@ -64836,7 +64926,7 @@ function processMatchUps(_a) {
|
|
|
64836
64926
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
64837
64927
|
finally {
|
|
64838
64928
|
try {
|
|
64839
|
-
if (
|
|
64929
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
64840
64930
|
}
|
|
64841
64931
|
finally { if (e_1) throw e_1.error; }
|
|
64842
64932
|
}
|
|
@@ -64849,7 +64939,7 @@ function processMatchUps(_a) {
|
|
|
64849
64939
|
|
|
64850
64940
|
var governor = {
|
|
64851
64941
|
calculateNewRatings: calculateNewRatings,
|
|
64852
|
-
|
|
64942
|
+
generateDynamicRatings: generateDynamicRatings,
|
|
64853
64943
|
};
|
|
64854
64944
|
|
|
64855
64945
|
var scaleEngine = (function () {
|