tods-competition-factory 1.7.2 → 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 +350 -223
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.mjs +1 -1
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +1 -1
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +303 -187
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +336 -233
- 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.4';
|
|
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';
|
|
@@ -7409,7 +7410,7 @@ function getRoundMatchUps$1(_a) {
|
|
|
7409
7410
|
.map(function (key) { return ensureInt(key); })
|
|
7410
7411
|
.filter(function (f) { return !isNaN(f); });
|
|
7411
7412
|
roundNumbers.forEach(function (roundNumber) {
|
|
7412
|
-
var _a, _b, _c;
|
|
7413
|
+
var _a, _b, _c, _d, _e;
|
|
7413
7414
|
var currentRoundMatchUps = roundMatchUps[roundNumber].sort(function (a, b) { return a.roundPosition - b.roundPosition; });
|
|
7414
7415
|
var currentRoundDrawPositions = currentRoundMatchUps
|
|
7415
7416
|
.map(function (matchUp) { return (matchUp === null || matchUp === void 0 ? void 0 : matchUp.drawPositions) || []; })
|
|
@@ -7427,7 +7428,7 @@ function getRoundMatchUps$1(_a) {
|
|
|
7427
7428
|
roundProfile[roundNumber].abbreviatedRoundName =
|
|
7428
7429
|
(_c = finishingRoundMap[roundNumber]) === null || _c === void 0 ? void 0 : _c.abbreviatedRoundName;
|
|
7429
7430
|
roundProfile[roundNumber].finishingPositionRange =
|
|
7430
|
-
roundMatchUps[roundNumber][0].finishingPositionRange;
|
|
7431
|
+
(_e = (_d = roundMatchUps[roundNumber]) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.finishingPositionRange;
|
|
7431
7432
|
if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
|
|
7432
7433
|
var orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
|
|
7433
7434
|
var pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
|
|
@@ -14954,21 +14955,27 @@ var _a$g;
|
|
|
14954
14955
|
var ratingsParameters = (_a$g = {},
|
|
14955
14956
|
_a$g[ELO] = { range: [0, 3000], decimalsCount: 0, defaultInitialization: 1500 },
|
|
14956
14957
|
_a$g[NTRP] = {
|
|
14957
|
-
range: [1, 7],
|
|
14958
|
-
decimalsCount: 1,
|
|
14959
|
-
defaultInitialization: 3,
|
|
14960
|
-
accessor: 'dntrpRatingHundredths',
|
|
14961
14958
|
accessors: ['ntrpRating', 'dntrpRatingHundredths'],
|
|
14962
14959
|
attributes: { ustaRatingType: '' },
|
|
14960
|
+
accessor: 'dntrpRatingHundredths',
|
|
14961
|
+
defaultInitialization: 3,
|
|
14962
|
+
decimalsCount: 1,
|
|
14963
|
+
range: [1, 7],
|
|
14963
14964
|
},
|
|
14964
|
-
_a$g[UTR] = {
|
|
14965
|
-
|
|
14966
|
-
|
|
14965
|
+
_a$g[UTR] = {
|
|
14966
|
+
defaultInitialization: 6,
|
|
14967
|
+
accessors: ['utrRating'],
|
|
14968
|
+
accessor: 'utrRating',
|
|
14967
14969
|
decimalsCount: 2,
|
|
14970
|
+
range: [1, 16],
|
|
14971
|
+
},
|
|
14972
|
+
_a$g[WTN] = {
|
|
14973
|
+
attributes: { confidence: { generator: true, range: [60, 100] } },
|
|
14974
|
+
accessors: ['wtnRating', 'confidence'],
|
|
14968
14975
|
defaultInitialization: 23,
|
|
14969
14976
|
accessor: 'wtnRating',
|
|
14970
|
-
|
|
14971
|
-
|
|
14977
|
+
decimalsCount: 2,
|
|
14978
|
+
range: [40, 1],
|
|
14972
14979
|
},
|
|
14973
14980
|
_a$g);
|
|
14974
14981
|
|
|
@@ -31250,10 +31257,12 @@ function getParticipantEntries(params) {
|
|
|
31250
31257
|
if (!participation)
|
|
31251
31258
|
return;
|
|
31252
31259
|
if (!finishingPositionRange_1)
|
|
31253
|
-
finishingPositionRange_1 =
|
|
31260
|
+
finishingPositionRange_1 =
|
|
31261
|
+
participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
|
|
31254
31262
|
if (diff_1(finishingPositionRange_1) >
|
|
31255
|
-
diff_1(participation.finishingPositionRange))
|
|
31256
|
-
finishingPositionRange_1 =
|
|
31263
|
+
diff_1(participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange))
|
|
31264
|
+
finishingPositionRange_1 =
|
|
31265
|
+
participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
|
|
31257
31266
|
var notQualifying = participation.stage !== QUALIFYING;
|
|
31258
31267
|
if (notQualifying)
|
|
31259
31268
|
nonQualifyingOrder_1 += 1;
|
|
@@ -31263,10 +31272,12 @@ function getParticipantEntries(params) {
|
|
|
31263
31272
|
return definedAttributes(__assign(__assign({}, participation), { participationOrder: participationOrder, flightNumber: flightNumber }));
|
|
31264
31273
|
})
|
|
31265
31274
|
.filter(Boolean);
|
|
31266
|
-
participantAggregator.draws[drawId]
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
|
|
31275
|
+
if (participantAggregator.draws[drawId]) {
|
|
31276
|
+
participantAggregator.draws[drawId].finishingPositionRange =
|
|
31277
|
+
finishingPositionRange_1;
|
|
31278
|
+
participantAggregator.draws[drawId].structureParticipation =
|
|
31279
|
+
orderedParticipation;
|
|
31280
|
+
}
|
|
31270
31281
|
}
|
|
31271
31282
|
};
|
|
31272
31283
|
try {
|
|
@@ -43021,7 +43032,7 @@ function feedInLinks(_a) {
|
|
|
43021
43032
|
}
|
|
43022
43033
|
|
|
43023
43034
|
function generateCurtisConsolation(params) {
|
|
43024
|
-
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;
|
|
43035
|
+
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;
|
|
43025
43036
|
var mainParams = {
|
|
43026
43037
|
finishingPositionOffset: finishingPositionOffset,
|
|
43027
43038
|
matchUpType: matchUpType,
|
|
@@ -43048,8 +43059,9 @@ function generateCurtisConsolation(params) {
|
|
|
43048
43059
|
var consolationItems = feedRoundOffsets.map(function (roundOffset, index) {
|
|
43049
43060
|
var stageSequence = index + 1;
|
|
43050
43061
|
var consolationStructure = consolationFeedStructure({
|
|
43051
|
-
structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43052
43062
|
idPrefix: idPrefix && "".concat(idPrefix, "-c").concat(index),
|
|
43063
|
+
structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43064
|
+
structureNameMap: structureNameMap,
|
|
43053
43065
|
stageSequence: stageSequence,
|
|
43054
43066
|
roundOffset: roundOffset,
|
|
43055
43067
|
matchUpType: matchUpType,
|
|
@@ -43082,9 +43094,9 @@ function generateCurtisConsolation(params) {
|
|
|
43082
43094
|
isMock: isMock,
|
|
43083
43095
|
}).matchUps;
|
|
43084
43096
|
var playoffStructure = structureTemplate({
|
|
43097
|
+
structureName: (structureNameMap === null || structureNameMap === void 0 ? void 0 : structureNameMap[PLAY_OFF]) || PLAY_OFF,
|
|
43085
43098
|
structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43086
43099
|
matchUps: playoffMatchUps,
|
|
43087
|
-
structureName: PLAY_OFF,
|
|
43088
43100
|
stageSequence: 2,
|
|
43089
43101
|
stage: PLAY_OFF,
|
|
43090
43102
|
matchUpType: matchUpType,
|
|
@@ -43108,7 +43120,7 @@ function generateCurtisConsolation(params) {
|
|
|
43108
43120
|
return __assign({ structures: structures, links: links }, SUCCESS);
|
|
43109
43121
|
}
|
|
43110
43122
|
function consolationFeedStructure(_a) {
|
|
43111
|
-
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;
|
|
43123
|
+
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;
|
|
43112
43124
|
var consolationDrawPositions = drawSize / (2 * Math.pow(2, roundOffset));
|
|
43113
43125
|
var _d = feedInMatchUps({
|
|
43114
43126
|
finishingPositionOffset: consolationDrawPositions,
|
|
@@ -43120,7 +43132,8 @@ function consolationFeedStructure(_a) {
|
|
|
43120
43132
|
isMock: isMock,
|
|
43121
43133
|
uuids: uuids,
|
|
43122
43134
|
}), consolationMatchUps = _d.matchUps, consolationRoundsCount = _d.roundsCount;
|
|
43123
|
-
var
|
|
43135
|
+
var defaultName = "".concat(CONSOLATION, " ").concat(index + 1);
|
|
43136
|
+
var structureName = (structureNameMap === null || structureNameMap === void 0 ? void 0 : structureNameMap[defaultName]) || defaultName;
|
|
43124
43137
|
var consolationStructure = structureTemplate({
|
|
43125
43138
|
matchUps: consolationMatchUps,
|
|
43126
43139
|
stage: CONSOLATION,
|
|
@@ -43379,6 +43392,7 @@ function processPlayoffGroups(_a) {
|
|
|
43379
43392
|
}
|
|
43380
43393
|
var params = {
|
|
43381
43394
|
structureId: (_c = playoffGroup.structureId) !== null && _c !== void 0 ? _c : uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
|
|
43395
|
+
structureNameMap: playoffGroup.structureNameMap,
|
|
43382
43396
|
structureName: playoffGroup.structureName,
|
|
43383
43397
|
idPrefix: idPrefix && "".concat(idPrefix, "-po"),
|
|
43384
43398
|
appliedPolicies: policyDefinitions,
|
|
@@ -47878,20 +47892,32 @@ function removeStructure(_a) {
|
|
|
47878
47892
|
}
|
|
47879
47893
|
|
|
47880
47894
|
function generateAdHocMatchUps$1(_a) {
|
|
47881
|
-
var _b, _c, _d, _e, _f, _g;
|
|
47882
|
-
var participantIdPairings = _a.participantIdPairings,
|
|
47895
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
47896
|
+
var participantIdPairings = _a.participantIdPairings, _k = _a.addToStructure, addToStructure = _k === void 0 ? true : _k, tournamentRecord = _a.tournamentRecord, _l = _a.matchUpIds, matchUpIds = _l === void 0 ? [] : _l, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
|
|
47883
47897
|
if (typeof drawDefinition !== 'object')
|
|
47884
47898
|
return { error: MISSING_DRAW_DEFINITION };
|
|
47885
47899
|
if (!structureId && ((_b = drawDefinition.structures) === null || _b === void 0 ? void 0 : _b.length) === 1)
|
|
47886
47900
|
structureId = (_d = (_c = drawDefinition.structures) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.structureId;
|
|
47887
47901
|
if (typeof structureId !== 'string')
|
|
47888
47902
|
return { error: MISSING_STRUCTURE_ID };
|
|
47889
|
-
if
|
|
47890
|
-
|
|
47903
|
+
// if drawDefinition and structureId are provided it is possible to infer roundNumber
|
|
47904
|
+
var structure = (_e = drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (structure) { return structure.structureId === structureId; });
|
|
47905
|
+
if (!structure)
|
|
47906
|
+
return { error: STRUCTURE_NOT_FOUND };
|
|
47907
|
+
if (!matchUpsCount) {
|
|
47908
|
+
var selectedEntries = (_g = (_f = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _f === void 0 ? void 0 : _f.filter(function (entry) {
|
|
47891
47909
|
var entryStatus = entry.entryStatus;
|
|
47892
47910
|
return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
|
|
47893
|
-
})) !== null &&
|
|
47894
|
-
|
|
47911
|
+
})) !== null && _g !== void 0 ? _g : [];
|
|
47912
|
+
var roundMatchUpsCount = Math.floor((selectedEntries === null || selectedEntries === void 0 ? void 0 : selectedEntries.length) / 2) || 1;
|
|
47913
|
+
if (newRound) {
|
|
47914
|
+
matchUpsCount = roundMatchUpsCount;
|
|
47915
|
+
}
|
|
47916
|
+
else {
|
|
47917
|
+
var maxRemaining = roundMatchUpsCount - (((_h = structure.matchUps) === null || _h === void 0 ? void 0 : _h.length) || 0); // TODO: minus the number of existing matchUps in roundNumber
|
|
47918
|
+
if (maxRemaining > 0)
|
|
47919
|
+
matchUpsCount = maxRemaining;
|
|
47920
|
+
}
|
|
47895
47921
|
}
|
|
47896
47922
|
if ((participantIdPairings && !Array.isArray(participantIdPairings)) ||
|
|
47897
47923
|
(matchUpsCount && !isConvertableInteger(matchUpsCount)) ||
|
|
@@ -47899,10 +47925,8 @@ function generateAdHocMatchUps$1(_a) {
|
|
|
47899
47925
|
(!participantIdPairings && !matchUpsCount)) {
|
|
47900
47926
|
return { error: INVALID_VALUES, info: 'matchUpsCount or pairings error' };
|
|
47901
47927
|
}
|
|
47902
|
-
// if drawDefinition and structureId are provided it is possible to infer roundNumber
|
|
47903
|
-
var structure = (_g = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _g === void 0 ? void 0 : _g.find(function (structure) { return structure.structureId === structureId; });
|
|
47904
47928
|
var structureHasRoundPositions;
|
|
47905
|
-
var existingMatchUps = structure
|
|
47929
|
+
var existingMatchUps = (_j = structure.matchUps) !== null && _j !== void 0 ? _j : [];
|
|
47906
47930
|
var lastRoundNumber = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.reduce(function (roundNumber, matchUp) {
|
|
47907
47931
|
if (matchUp.roundPosition)
|
|
47908
47932
|
structureHasRoundPositions = true;
|
|
@@ -47913,14 +47937,14 @@ function generateAdHocMatchUps$1(_a) {
|
|
|
47913
47937
|
// structure must not be a container of other structures
|
|
47914
47938
|
// structure must not contain matchUps with roundPosition
|
|
47915
47939
|
// structure must not determine finishingPosition by ROUND_OUTCOME
|
|
47916
|
-
if (
|
|
47940
|
+
if (structure.structures ||
|
|
47917
47941
|
structureHasRoundPositions ||
|
|
47918
|
-
|
|
47942
|
+
structure.finishingPosition === ROUND_OUTCOME) {
|
|
47919
47943
|
return { error: INVALID_STRUCTURE };
|
|
47920
47944
|
}
|
|
47921
47945
|
if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
|
|
47922
47946
|
return { error: INVALID_VALUES, info: 'roundNumber error' };
|
|
47923
|
-
var nextRoundNumber = roundNumber !== null && roundNumber !== void 0 ? roundNumber : (newRound
|
|
47947
|
+
var nextRoundNumber = roundNumber !== null && roundNumber !== void 0 ? roundNumber : ((newRound && (lastRoundNumber !== null && lastRoundNumber !== void 0 ? lastRoundNumber : 0) + 1) || lastRoundNumber || 1);
|
|
47924
47948
|
participantIdPairings =
|
|
47925
47949
|
participantIdPairings !== null && participantIdPairings !== void 0 ? participantIdPairings : generateRange(0, matchUpsCount).map(function () { return ({
|
|
47926
47950
|
participantIds: [undefined, undefined],
|
|
@@ -50522,59 +50546,96 @@ function removeDelegatedOutcome$1(_a) {
|
|
|
50522
50546
|
}
|
|
50523
50547
|
|
|
50524
50548
|
function generateCandidate(_a) {
|
|
50525
|
-
var _b = _a.maxIterations, maxIterations = _b === void 0 ?
|
|
50549
|
+
var _b = _a.maxIterations, maxIterations = _b === void 0 ? 4000 : _b, // cap the processing intensity of the candidate generator
|
|
50526
50550
|
valueSortedPairings = _a.valueSortedPairings, // pairings sorted by value from low to high
|
|
50527
|
-
pairingValues = _a.pairingValues, deltaObjects = _a.deltaObjects;
|
|
50528
|
-
var
|
|
50551
|
+
pairingValues = _a.pairingValues, valueObjects = _a.valueObjects, deltaObjects = _a.deltaObjects;
|
|
50552
|
+
var pairingValueMap = Object.assign.apply(Object, __spreadArray([{}], __read(valueSortedPairings.map(function (rm) {
|
|
50529
50553
|
var _a;
|
|
50530
50554
|
return (_a = {}, _a[rm.pairing] = rm.value, _a);
|
|
50531
50555
|
})), false));
|
|
50556
|
+
var actors = Object.keys(pairingValues);
|
|
50557
|
+
var proposedCandidates = [];
|
|
50532
50558
|
// generate an initial candidate value with no stipulated pairings
|
|
50533
|
-
var
|
|
50534
|
-
|
|
50559
|
+
var initialProposal = roundCandidate({
|
|
50560
|
+
actorsCount: actors.length,
|
|
50535
50561
|
valueSortedPairings: valueSortedPairings,
|
|
50562
|
+
pairingValueMap: pairingValueMap,
|
|
50536
50563
|
deltaObjects: deltaObjects,
|
|
50564
|
+
valueObjects: valueObjects,
|
|
50537
50565
|
});
|
|
50538
|
-
var
|
|
50539
|
-
|
|
50566
|
+
var candidateHashes = [candidateHash(initialProposal)];
|
|
50567
|
+
proposedCandidates.push(initialProposal);
|
|
50568
|
+
var lowCandidateValue = initialProposal.value;
|
|
50569
|
+
var deltaCandidate = initialProposal;
|
|
50540
50570
|
// iterations is the number of loops over valueSortedPairings
|
|
50541
50571
|
var candidatesCount = 0;
|
|
50542
|
-
var iterations;
|
|
50543
|
-
// calculate the number of opponents to consider for each participantId
|
|
50572
|
+
var iterations = 0;
|
|
50544
50573
|
var opponentCount = actors.length;
|
|
50574
|
+
var calculatedIterations;
|
|
50575
|
+
// calculate the number of opponents to consider for each participantId
|
|
50545
50576
|
do {
|
|
50546
50577
|
opponentCount -= 1;
|
|
50547
|
-
|
|
50548
|
-
|
|
50549
|
-
|
|
50578
|
+
calculatedIterations = actors.length * pairingValues[actors[0]].length;
|
|
50579
|
+
} while (calculatedIterations > maxIterations && opponentCount > 5);
|
|
50580
|
+
// keep track of proposed pairings
|
|
50550
50581
|
var stipulatedPairs = [];
|
|
50551
50582
|
// for each actor generate a roundCandidate using opponentCount of pairing values
|
|
50552
50583
|
actors.forEach(function (actor) {
|
|
50553
50584
|
var participantIdPairings = pairingValues[actor];
|
|
50554
50585
|
// opponentCount limits the number of opponents to consider
|
|
50555
50586
|
participantIdPairings.slice(0, opponentCount).forEach(function (pairing) {
|
|
50587
|
+
iterations += 1;
|
|
50556
50588
|
var stipulatedPair = pairingHash(actor, pairing.opponent);
|
|
50557
50589
|
if (!stipulatedPairs.includes(stipulatedPair)) {
|
|
50558
50590
|
var proposed = roundCandidate({
|
|
50559
50591
|
// each roundCandidate starts with stipulated pairings
|
|
50560
50592
|
stipulated: [[actor, pairing.opponent]],
|
|
50561
|
-
|
|
50593
|
+
actorsCount: actors.length,
|
|
50562
50594
|
valueSortedPairings: valueSortedPairings,
|
|
50595
|
+
pairingValueMap: pairingValueMap,
|
|
50563
50596
|
deltaObjects: deltaObjects,
|
|
50597
|
+
valueObjects: valueObjects,
|
|
50564
50598
|
});
|
|
50565
|
-
|
|
50566
|
-
|
|
50567
|
-
|
|
50568
|
-
|
|
50569
|
-
|
|
50570
|
-
|
|
50599
|
+
// ensure no duplicate candidates are considered
|
|
50600
|
+
if (!candidateHashes.includes(candidateHash(proposed))) {
|
|
50601
|
+
candidateHashes.push(candidateHash(proposed));
|
|
50602
|
+
proposedCandidates.push(proposed);
|
|
50603
|
+
var maxDelta = proposed.maxDelta, value = proposed.value;
|
|
50604
|
+
if (maxDelta < deltaCandidate.maxDelta)
|
|
50605
|
+
deltaCandidate = proposed;
|
|
50606
|
+
if (value < lowCandidateValue ||
|
|
50607
|
+
(value === lowCandidateValue && Math.round(Math.random())) // randomize if equivalent values
|
|
50608
|
+
) {
|
|
50609
|
+
lowCandidateValue = value;
|
|
50610
|
+
}
|
|
50611
|
+
stipulatedPairs.push(stipulatedPair);
|
|
50612
|
+
candidatesCount += 1;
|
|
50613
|
+
}
|
|
50571
50614
|
}
|
|
50572
50615
|
});
|
|
50616
|
+
proposedCandidates = proposedCandidates.filter(function (proposed) { return Math.abs(proposed.value - lowCandidateValue) < 5; });
|
|
50573
50617
|
});
|
|
50574
|
-
|
|
50618
|
+
proposedCandidates.sort(function (a, b) { return a.maxDiff - b.maxDiff; });
|
|
50619
|
+
var candidate = randomPop(proposedCandidates);
|
|
50620
|
+
return {
|
|
50621
|
+
candidatesCount: candidatesCount,
|
|
50622
|
+
deltaCandidate: deltaCandidate,
|
|
50623
|
+
maxIterations: maxIterations,
|
|
50624
|
+
iterations: iterations,
|
|
50625
|
+
candidate: candidate,
|
|
50626
|
+
};
|
|
50627
|
+
}
|
|
50628
|
+
function candidateHash(candidate) {
|
|
50629
|
+
return candidate.participantIdPairings
|
|
50630
|
+
.map(function (_a) {
|
|
50631
|
+
var participantIds = _a.participantIds;
|
|
50632
|
+
return participantIds.sort().join('|');
|
|
50633
|
+
})
|
|
50634
|
+
.sort()
|
|
50635
|
+
.join('/');
|
|
50575
50636
|
}
|
|
50576
50637
|
function roundCandidate(_a) {
|
|
50577
|
-
var
|
|
50638
|
+
var valueSortedPairings = _a.valueSortedPairings, _b = _a.stipulated, stipulated = _b === void 0 ? [] : _b, pairingValueMap = _a.pairingValueMap, deltaObjects = _a.deltaObjects, valueObjects = _a.valueObjects, actorsCount = _a.actorsCount;
|
|
50578
50639
|
// roundPlayers starts with the stipulated pairing
|
|
50579
50640
|
var roundPlayers = [].concat.apply([], __spreadArray([], __read(stipulated), false));
|
|
50580
50641
|
// aggregates the pairings generated for a roundCandidate
|
|
@@ -50586,13 +50647,19 @@ function roundCandidate(_a) {
|
|
|
50586
50647
|
stipulated.filter(Boolean).forEach(function (participantIds) {
|
|
50587
50648
|
var _a = __read(participantIds, 2), p1 = _a[0], p2 = _a[1];
|
|
50588
50649
|
var pairing = pairingHash(p1, p2);
|
|
50589
|
-
var value =
|
|
50650
|
+
var value = pairingValueMap[pairing];
|
|
50590
50651
|
participantIdPairings.push({ participantIds: participantIds, value: value });
|
|
50591
|
-
candidateValue +=
|
|
50652
|
+
candidateValue += pairingValueMap[pairing];
|
|
50592
50653
|
});
|
|
50654
|
+
// valueSortedPairings is an array sorted from lowest value to highest value
|
|
50655
|
+
// introduce random shuffling of chunks of valueSortedPairings
|
|
50656
|
+
var consideredPairings = chunkArray(valueSortedPairings, actorsCount)
|
|
50657
|
+
.map(function (pairings) {
|
|
50658
|
+
return shuffleArray(pairings).map(function (pairing) { return (__assign(__assign({}, pairing), { value: pairing.value + Math.random() * Math.round(Math.random()) })); });
|
|
50659
|
+
})
|
|
50660
|
+
.flat();
|
|
50593
50661
|
// go through the valueSortedPairings (of all possible unique pairings)
|
|
50594
|
-
|
|
50595
|
-
valueSortedPairings.forEach(function (rankedPairing) {
|
|
50662
|
+
consideredPairings.forEach(function (rankedPairing) {
|
|
50596
50663
|
var participantIds = rankedPairing.pairing.split('|');
|
|
50597
50664
|
var opponentExists = participantIds.reduce(function (p, c) { return roundPlayers.includes(c) || p; }, false);
|
|
50598
50665
|
if (!opponentExists) {
|
|
@@ -50611,21 +50678,181 @@ function roundCandidate(_a) {
|
|
|
50611
50678
|
var delta = deltaObjects[hash];
|
|
50612
50679
|
return delta > p ? delta : p;
|
|
50613
50680
|
}, 0);
|
|
50614
|
-
|
|
50681
|
+
// determine the greatest delta in the candidate's pairings
|
|
50682
|
+
var maxDiff = participantIdPairings.reduce(function (p, c) {
|
|
50683
|
+
var _a = __read(c.participantIds, 2), p1 = _a[0], p2 = _a[1];
|
|
50684
|
+
var hash = pairingHash(p1, p2);
|
|
50685
|
+
var diff = valueObjects[hash];
|
|
50686
|
+
return diff > p ? diff : p;
|
|
50687
|
+
}, 0);
|
|
50688
|
+
return { value: candidateValue, participantIdPairings: participantIdPairings, maxDelta: maxDelta, maxDiff: maxDiff };
|
|
50615
50689
|
}
|
|
50616
50690
|
function pairingHash(id1, id2) {
|
|
50617
50691
|
return [id1, id2].sort().join('|');
|
|
50618
50692
|
}
|
|
50619
50693
|
|
|
50620
|
-
|
|
50621
|
-
var
|
|
50622
|
-
var
|
|
50694
|
+
function getPairingsData(_a) {
|
|
50695
|
+
var participantIds = _a.participantIds;
|
|
50696
|
+
var possiblePairings = {};
|
|
50697
|
+
var uniquePairings = [];
|
|
50698
|
+
participantIds.forEach(function (participantId) {
|
|
50699
|
+
possiblePairings[participantId] = participantIds.filter(function (id) { return id !== participantId; });
|
|
50700
|
+
possiblePairings[participantId].forEach(function (id) {
|
|
50701
|
+
var pairing = pairingHash(id, participantId);
|
|
50702
|
+
if (!uniquePairings.includes(pairing))
|
|
50703
|
+
uniquePairings.push(pairing);
|
|
50704
|
+
});
|
|
50705
|
+
});
|
|
50706
|
+
var deltaObjects = Object.assign.apply(Object, __spreadArray([{}], __read(uniquePairings.map(function (pairing) {
|
|
50707
|
+
var _a;
|
|
50708
|
+
return (_a = {}, _a[pairing] = 0, _a);
|
|
50709
|
+
})), false));
|
|
50710
|
+
return { uniquePairings: uniquePairings, possiblePairings: possiblePairings, deltaObjects: deltaObjects };
|
|
50711
|
+
}
|
|
50712
|
+
|
|
50713
|
+
function getEncounters(_a) {
|
|
50714
|
+
var e_1, _b;
|
|
50715
|
+
var matchUps = _a.matchUps;
|
|
50716
|
+
var encounters = [];
|
|
50717
|
+
try {
|
|
50718
|
+
for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
|
|
50719
|
+
var matchUp = matchUps_1_1.value;
|
|
50720
|
+
var participantIds = matchUp.sides.map(extractAttributes('participantId'));
|
|
50721
|
+
if (participantIds.length === 2) {
|
|
50722
|
+
var _c = __read(participantIds, 2), p1 = _c[0], p2 = _c[1];
|
|
50723
|
+
var pairing = pairingHash(p1, p2);
|
|
50724
|
+
if (!encounters.includes(pairing))
|
|
50725
|
+
encounters.push(pairing);
|
|
50726
|
+
}
|
|
50727
|
+
}
|
|
50728
|
+
}
|
|
50729
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
50730
|
+
finally {
|
|
50731
|
+
try {
|
|
50732
|
+
if (matchUps_1_1 && !matchUps_1_1.done && (_b = matchUps_1.return)) _b.call(matchUps_1);
|
|
50733
|
+
}
|
|
50734
|
+
finally { if (e_1) throw e_1.error; }
|
|
50735
|
+
}
|
|
50736
|
+
return { encounters: encounters };
|
|
50737
|
+
}
|
|
50738
|
+
|
|
50739
|
+
function getParticipantPairingValues(_a) {
|
|
50740
|
+
var e_1, _b;
|
|
50741
|
+
var possiblePairings = _a.possiblePairings, valueObjects = _a.valueObjects;
|
|
50742
|
+
var pairingValues = {};
|
|
50743
|
+
var _loop_1 = function (participantId) {
|
|
50744
|
+
var participantValues = possiblePairings[participantId].map(function (opponent) {
|
|
50745
|
+
return pairingValue(participantId, opponent);
|
|
50746
|
+
});
|
|
50747
|
+
pairingValues[participantId] = participantValues.sort(function (a, b) { return a.value - b.value; });
|
|
50748
|
+
};
|
|
50749
|
+
try {
|
|
50750
|
+
for (var _c = __values(Object.keys(possiblePairings)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
50751
|
+
var participantId = _d.value;
|
|
50752
|
+
_loop_1(participantId);
|
|
50753
|
+
}
|
|
50754
|
+
}
|
|
50755
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
50756
|
+
finally {
|
|
50757
|
+
try {
|
|
50758
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
50759
|
+
}
|
|
50760
|
+
finally { if (e_1) throw e_1.error; }
|
|
50761
|
+
}
|
|
50762
|
+
function pairingValue(participantId, opponent) {
|
|
50763
|
+
var key = pairingHash(participantId, opponent);
|
|
50764
|
+
return { opponent: opponent, value: valueObjects[key] };
|
|
50765
|
+
}
|
|
50766
|
+
return { pairingValues: pairingValues };
|
|
50767
|
+
}
|
|
50768
|
+
|
|
50623
50769
|
var DEFAULT_RATING = 0;
|
|
50770
|
+
function getSideRatings(_a) {
|
|
50771
|
+
var _b, _c;
|
|
50772
|
+
var tournamentParticipants = _a.tournamentParticipants, adHocRatings = _a.adHocRatings, eventType = _a.eventType, scaleName = _a.scaleName, pairing = _a.pairing;
|
|
50773
|
+
var defaultRating = (_c = (_b = ratingsParameters[scaleName]) === null || _b === void 0 ? void 0 : _b.defaultInitialization) !== null && _c !== void 0 ? _c : DEFAULT_RATING;
|
|
50774
|
+
return pairing.split('|').map(function (participantId) {
|
|
50775
|
+
var _a;
|
|
50776
|
+
if (eventType === DOUBLES) {
|
|
50777
|
+
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;
|
|
50778
|
+
return !individualParticipantIds
|
|
50779
|
+
? defaultRating * 2
|
|
50780
|
+
: individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.map(function (participantId) { return adHocRatings[participantId] || defaultRating; });
|
|
50781
|
+
}
|
|
50782
|
+
else {
|
|
50783
|
+
return adHocRatings[participantId] || defaultRating;
|
|
50784
|
+
}
|
|
50785
|
+
});
|
|
50786
|
+
}
|
|
50787
|
+
|
|
50788
|
+
function getPairings(_a) {
|
|
50789
|
+
var tournamentParticipants = _a.tournamentParticipants, _b = _a.adHocRatings, adHocRatings = _b === void 0 ? {} : _b, possiblePairings = _a.possiblePairings, // participant keyed; provides array of possible opponents
|
|
50790
|
+
uniquePairings = _a.uniquePairings, // hashes of all possible participantId pairings
|
|
50791
|
+
maxIterations = _a.maxIterations, deltaObjects = _a.deltaObjects, // difference in rating between paired participants
|
|
50792
|
+
valueObjects = _a.valueObjects, // calculated value of a pairing of participants, used for sorting pairings
|
|
50793
|
+
eventType = _a.eventType, scaleName = _a.scaleName, salted = _a.salted;
|
|
50794
|
+
// modify valueObjects by ratings ratingsDifference squared
|
|
50795
|
+
// update deltaObjects to reflect the current difference between participant's ratings
|
|
50796
|
+
uniquePairings.forEach(function (pairing) {
|
|
50797
|
+
var ratings = getSideRatings({
|
|
50798
|
+
tournamentParticipants: tournamentParticipants,
|
|
50799
|
+
adHocRatings: adHocRatings,
|
|
50800
|
+
scaleName: scaleName,
|
|
50801
|
+
eventType: eventType,
|
|
50802
|
+
pairing: pairing,
|
|
50803
|
+
});
|
|
50804
|
+
var salting = (typeof salted === 'number' && salted) || 0.5;
|
|
50805
|
+
var salt = (salted && (Math.round(Math.random()) ? salting : salting * -1)) || 0;
|
|
50806
|
+
var ratingsDifference = Math.abs(ratings[0] - ratings[1]) + salt;
|
|
50807
|
+
var pairingDelta = Math.abs(ratings[0] - ratings[1]);
|
|
50808
|
+
deltaObjects[pairing] = pairingDelta;
|
|
50809
|
+
if (!valueObjects[pairing])
|
|
50810
|
+
valueObjects[pairing] = 0;
|
|
50811
|
+
valueObjects[pairing] += ratingsDifference
|
|
50812
|
+
? Math.pow(ratingsDifference, 2)
|
|
50813
|
+
: 0;
|
|
50814
|
+
});
|
|
50815
|
+
/**
|
|
50816
|
+
* valueSortedPairings are uniquePairings sorted by the ratings difference of the pairings, lowest to highest
|
|
50817
|
+
*/
|
|
50818
|
+
var valueSortedPairings = uniquePairings
|
|
50819
|
+
.map(function (pairing) { return ({ pairing: pairing, value: valueObjects[pairing] }); })
|
|
50820
|
+
.sort(function (a, b) { return a.value - b.value; });
|
|
50821
|
+
/**
|
|
50822
|
+
* pairingValues is keyed by participantId and provides a value-sorted array of pairings for each participantId
|
|
50823
|
+
* 'actorId': [
|
|
50824
|
+
{ opponent: 'potentialId1', value: 1 },
|
|
50825
|
+
{ opponent: 'potentialId2', value: 1 },
|
|
50826
|
+
*/
|
|
50827
|
+
var pairingValues = getParticipantPairingValues({
|
|
50828
|
+
possiblePairings: possiblePairings,
|
|
50829
|
+
valueObjects: valueObjects,
|
|
50830
|
+
}).pairingValues;
|
|
50831
|
+
var _c = generateCandidate({
|
|
50832
|
+
valueSortedPairings: valueSortedPairings,
|
|
50833
|
+
maxIterations: maxIterations,
|
|
50834
|
+
pairingValues: pairingValues,
|
|
50835
|
+
deltaObjects: deltaObjects,
|
|
50836
|
+
valueObjects: valueObjects,
|
|
50837
|
+
}), candidate = _c.candidate, candidatesCount = _c.candidatesCount, deltaCandidate = _c.deltaCandidate, iterations = _c.iterations;
|
|
50838
|
+
var participantIdPairings = candidate.participantIdPairings;
|
|
50839
|
+
return {
|
|
50840
|
+
participantIdPairings: participantIdPairings,
|
|
50841
|
+
candidatesCount: candidatesCount,
|
|
50842
|
+
deltaCandidate: deltaCandidate,
|
|
50843
|
+
iterations: iterations,
|
|
50844
|
+
candidate: candidate,
|
|
50845
|
+
};
|
|
50846
|
+
}
|
|
50847
|
+
|
|
50848
|
+
// this should be in policyDefinitions
|
|
50849
|
+
var ENCOUNTER_VALUE = 100;
|
|
50850
|
+
var SAME_TEAM_VALUE = 100;
|
|
50624
50851
|
var MAX_ITERATIONS = 5000;
|
|
50625
50852
|
function generateDrawMaticRound(_a) {
|
|
50626
50853
|
var e_1, _b, e_2, _c, e_3, _d;
|
|
50627
50854
|
var _e, _f;
|
|
50628
|
-
var _g = _a.maxIterations, maxIterations = _g === void 0 ? MAX_ITERATIONS : _g, _h = _a.generateMatchUps, generateMatchUps = _h === void 0 ? true : _h, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, addToStructure = _a.addToStructure, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, structureId = _a.structureId, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure;
|
|
50855
|
+
var _g = _a.maxIterations, maxIterations = _g === void 0 ? MAX_ITERATIONS : _g, _h = _a.generateMatchUps, generateMatchUps = _h === void 0 ? true : _h, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, addToStructure = _a.addToStructure, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, structureId = _a.structureId, _j = _a.salted, salted = _j === void 0 ? 0.5 : _j, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure, scaleName = _a.scaleName;
|
|
50629
50856
|
if (!drawDefinition)
|
|
50630
50857
|
return { error: MISSING_DRAW_DEFINITION };
|
|
50631
50858
|
if (!structure && !structureId)
|
|
@@ -50704,9 +50931,9 @@ function generateDrawMaticRound(_a) {
|
|
|
50704
50931
|
// 'P-I-0|P-I-2': 0,
|
|
50705
50932
|
// 'P-I-0|P-I-3': 0
|
|
50706
50933
|
// }
|
|
50707
|
-
var
|
|
50934
|
+
var _k = getPairingsData({
|
|
50708
50935
|
participantIds: participantIds,
|
|
50709
|
-
}), uniquePairings =
|
|
50936
|
+
}), uniquePairings = _k.uniquePairings, possiblePairings = _k.possiblePairings, deltaObjects = _k.deltaObjects;
|
|
50710
50937
|
var params = {
|
|
50711
50938
|
tournamentParticipants: tournamentParticipants,
|
|
50712
50939
|
possiblePairings: possiblePairings,
|
|
@@ -50718,9 +50945,12 @@ function generateDrawMaticRound(_a) {
|
|
|
50718
50945
|
deltaObjects: deltaObjects,
|
|
50719
50946
|
valueObjects: valueObjects,
|
|
50720
50947
|
eventType: eventType,
|
|
50948
|
+
scaleName: scaleName,
|
|
50721
50949
|
structure: structure,
|
|
50950
|
+
salted: salted,
|
|
50722
50951
|
};
|
|
50723
|
-
var
|
|
50952
|
+
var _l = getPairings(params), candidatesCount = _l.candidatesCount, participantIdPairings = _l.participantIdPairings, iterations = _l.iterations;
|
|
50953
|
+
// console.log({ candidatesCount, participantIdPairings, iterations });
|
|
50724
50954
|
if (!candidatesCount)
|
|
50725
50955
|
return { error: NO_CANDIDATES };
|
|
50726
50956
|
var matchUps;
|
|
@@ -50740,144 +50970,11 @@ function generateDrawMaticRound(_a) {
|
|
|
50740
50970
|
}
|
|
50741
50971
|
return __assign(__assign({}, SUCCESS), { participantIdPairings: participantIdPairings, candidatesCount: candidatesCount, iterations: iterations, matchUps: matchUps });
|
|
50742
50972
|
}
|
|
50743
|
-
function getSideRatings(_a) {
|
|
50744
|
-
var tournamentParticipants = _a.tournamentParticipants, adHocRatings = _a.adHocRatings, eventType = _a.eventType, pairing = _a.pairing;
|
|
50745
|
-
return pairing.split('|').map(function (participantId) {
|
|
50746
|
-
var _a;
|
|
50747
|
-
if (eventType === DOUBLES) {
|
|
50748
|
-
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;
|
|
50749
|
-
return !individualParticipantIds
|
|
50750
|
-
? DEFAULT_RATING * 2
|
|
50751
|
-
: individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.map(function (participantId) { return adHocRatings[participantId || DEFAULT_RATING]; });
|
|
50752
|
-
}
|
|
50753
|
-
else {
|
|
50754
|
-
return adHocRatings[participantId] || DEFAULT_RATING;
|
|
50755
|
-
}
|
|
50756
|
-
});
|
|
50757
|
-
}
|
|
50758
|
-
function getPairings(_a) {
|
|
50759
|
-
var tournamentParticipants = _a.tournamentParticipants, _b = _a.adHocRatings, adHocRatings = _b === void 0 ? {} : _b, possiblePairings = _a.possiblePairings, // participant keyed; provides array of possible opponents
|
|
50760
|
-
uniquePairings = _a.uniquePairings, // hashes of all possible participantId pairings
|
|
50761
|
-
maxIterations = _a.maxIterations, deltaObjects = _a.deltaObjects, // difference in rating between paired participants
|
|
50762
|
-
valueObjects = _a.valueObjects, // calculated value of a pairing of participants, used for sorting pairings
|
|
50763
|
-
eventType = _a.eventType;
|
|
50764
|
-
// modify valueObjects by ratings ratingsDifference squared
|
|
50765
|
-
// update deltaObjects to reflect the current difference between participant's ratings
|
|
50766
|
-
uniquePairings.forEach(function (pairing) {
|
|
50767
|
-
var ratings = getSideRatings({
|
|
50768
|
-
tournamentParticipants: tournamentParticipants,
|
|
50769
|
-
adHocRatings: adHocRatings,
|
|
50770
|
-
eventType: eventType,
|
|
50771
|
-
pairing: pairing,
|
|
50772
|
-
});
|
|
50773
|
-
var ratingsDifference = Math.abs(ratings[0] - ratings[1]) + 1;
|
|
50774
|
-
deltaObjects[pairing] = Math.abs(ratings[0] - ratings[1]);
|
|
50775
|
-
if (!valueObjects[pairing])
|
|
50776
|
-
valueObjects[pairing] = 0;
|
|
50777
|
-
valueObjects[pairing] += Math.pow(ratingsDifference, 2);
|
|
50778
|
-
});
|
|
50779
|
-
/**
|
|
50780
|
-
* valueSortedPairings are uniquePairings sorted by the value of the pairings, lowest to highest
|
|
50781
|
-
*/
|
|
50782
|
-
var valueSortedPairings = uniquePairings
|
|
50783
|
-
.map(function (pairing) { return ({ pairing: pairing, value: valueObjects[pairing] }); })
|
|
50784
|
-
.sort(function (a, b) { return a.value - b.value; });
|
|
50785
|
-
/**
|
|
50786
|
-
* pairingValues is keyed by participantId and provides a value-sorted array of pairings for each participantId
|
|
50787
|
-
* 'actorId': [
|
|
50788
|
-
{ opponent: 'potentialId1', value: 1 },
|
|
50789
|
-
{ opponent: 'potentialId2', value: 1 },
|
|
50790
|
-
*/
|
|
50791
|
-
var pairingValues = getParticipantPairingValues({
|
|
50792
|
-
possiblePairings: possiblePairings,
|
|
50793
|
-
valueObjects: valueObjects,
|
|
50794
|
-
}).pairingValues;
|
|
50795
|
-
var _c = generateCandidate({
|
|
50796
|
-
valueSortedPairings: valueSortedPairings,
|
|
50797
|
-
maxIterations: maxIterations,
|
|
50798
|
-
pairingValues: pairingValues,
|
|
50799
|
-
deltaObjects: deltaObjects,
|
|
50800
|
-
}), candidate = _c.candidate, candidatesCount = _c.candidatesCount, iterations = _c.iterations;
|
|
50801
|
-
var participantIdPairings = candidate.participantIdPairings;
|
|
50802
|
-
return { candidatesCount: candidatesCount, participantIdPairings: participantIdPairings, iterations: iterations };
|
|
50803
|
-
}
|
|
50804
|
-
function getPairingsData(_a) {
|
|
50805
|
-
var participantIds = _a.participantIds;
|
|
50806
|
-
var possiblePairings = {};
|
|
50807
|
-
var uniquePairings = [];
|
|
50808
|
-
participantIds.forEach(function (participantId) {
|
|
50809
|
-
possiblePairings[participantId] = participantIds.filter(function (id) { return id !== participantId; });
|
|
50810
|
-
possiblePairings[participantId].forEach(function (id) {
|
|
50811
|
-
var pairing = pairingHash(id, participantId);
|
|
50812
|
-
if (!uniquePairings.includes(pairing))
|
|
50813
|
-
uniquePairings.push(pairing);
|
|
50814
|
-
});
|
|
50815
|
-
});
|
|
50816
|
-
var deltaObjects = Object.assign.apply(Object, __spreadArray([{}], __read(uniquePairings.map(function (pairing) {
|
|
50817
|
-
var _a;
|
|
50818
|
-
return (_a = {}, _a[pairing] = 0, _a);
|
|
50819
|
-
})), false));
|
|
50820
|
-
return { uniquePairings: uniquePairings, possiblePairings: possiblePairings, deltaObjects: deltaObjects };
|
|
50821
|
-
}
|
|
50822
|
-
function getEncounters(_a) {
|
|
50823
|
-
var e_4, _b;
|
|
50824
|
-
var matchUps = _a.matchUps;
|
|
50825
|
-
var encounters = [];
|
|
50826
|
-
try {
|
|
50827
|
-
for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
|
|
50828
|
-
var matchUp = matchUps_1_1.value;
|
|
50829
|
-
var participantIds = matchUp.sides.map(getParticipantId);
|
|
50830
|
-
if (participantIds.length === 2) {
|
|
50831
|
-
var _c = __read(participantIds, 2), p1 = _c[0], p2 = _c[1];
|
|
50832
|
-
var pairing = pairingHash(p1, p2);
|
|
50833
|
-
if (!encounters.includes(pairing))
|
|
50834
|
-
encounters.push(pairing);
|
|
50835
|
-
}
|
|
50836
|
-
}
|
|
50837
|
-
}
|
|
50838
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
50839
|
-
finally {
|
|
50840
|
-
try {
|
|
50841
|
-
if (matchUps_1_1 && !matchUps_1_1.done && (_b = matchUps_1.return)) _b.call(matchUps_1);
|
|
50842
|
-
}
|
|
50843
|
-
finally { if (e_4) throw e_4.error; }
|
|
50844
|
-
}
|
|
50845
|
-
return { encounters: encounters };
|
|
50846
|
-
}
|
|
50847
|
-
function getParticipantPairingValues(_a) {
|
|
50848
|
-
var e_5, _b;
|
|
50849
|
-
var possiblePairings = _a.possiblePairings, valueObjects = _a.valueObjects;
|
|
50850
|
-
var pairingValues = {};
|
|
50851
|
-
var _loop_1 = function (participantId) {
|
|
50852
|
-
var participantValues = possiblePairings[participantId].map(function (opponent) {
|
|
50853
|
-
return pairingValue(participantId, opponent);
|
|
50854
|
-
});
|
|
50855
|
-
pairingValues[participantId] = participantValues.sort(function (a, b) { return a.value - b.value; });
|
|
50856
|
-
};
|
|
50857
|
-
try {
|
|
50858
|
-
for (var _c = __values(Object.keys(possiblePairings)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
50859
|
-
var participantId = _d.value;
|
|
50860
|
-
_loop_1(participantId);
|
|
50861
|
-
}
|
|
50862
|
-
}
|
|
50863
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
50864
|
-
finally {
|
|
50865
|
-
try {
|
|
50866
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
50867
|
-
}
|
|
50868
|
-
finally { if (e_5) throw e_5.error; }
|
|
50869
|
-
}
|
|
50870
|
-
function pairingValue(participantId, opponent) {
|
|
50871
|
-
var key = pairingHash(participantId, opponent);
|
|
50872
|
-
return { opponent: opponent, value: valueObjects[key] };
|
|
50873
|
-
}
|
|
50874
|
-
return { pairingValues: pairingValues };
|
|
50875
|
-
}
|
|
50876
50973
|
|
|
50877
50974
|
function drawMatic$1(_a) {
|
|
50878
50975
|
var e_1, _b;
|
|
50879
50976
|
var _c, _d, _e, _f, _g;
|
|
50880
|
-
var tournamentParticipants = _a.tournamentParticipants, restrictEntryStatus = _a.restrictEntryStatus, tournamentRecord = _a.tournamentRecord, generateMatchUps = _a.generateMatchUps, addToStructure = _a.addToStructure, participantIds = _a.participantIds, 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
|
|
50977
|
+
var tournamentParticipants = _a.tournamentParticipants, restrictEntryStatus = _a.restrictEntryStatus, _h = _a.adHocRatings, adHocRatings = _h === void 0 ? {} : _h, tournamentRecord = _a.tournamentRecord, generateMatchUps = _a.generateMatchUps, addToStructure = _a.addToStructure, participantIds = _a.participantIds, 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
|
|
50881
50978
|
eventType = _a.eventType, event = _a.event;
|
|
50882
50979
|
if (typeof drawDefinition !== 'object' ||
|
|
50883
50980
|
(drawDefinition.drawType && drawDefinition.drawType !== AD_HOC)) {
|
|
@@ -50927,11 +51024,15 @@ function drawMatic$1(_a) {
|
|
|
50927
51024
|
return { error: INVALID_DRAW_DEFINITION };
|
|
50928
51025
|
tournamentParticipants =
|
|
50929
51026
|
(_g = tournamentParticipants !== null && tournamentParticipants !== void 0 ? tournamentParticipants : tournamentRecord.participants) !== null && _g !== void 0 ? _g : [];
|
|
50930
|
-
var adHocRatings = {};
|
|
50931
51027
|
var _loop_1 = function (participantId) {
|
|
50932
51028
|
var participant = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
|
|
50933
51029
|
// first see if there is already a dynamic value
|
|
50934
|
-
var scaleValue = getScaleValue({
|
|
51030
|
+
var scaleValue = getScaleValue({
|
|
51031
|
+
scaleName: "".concat(scaleName, ".").concat(DYNAMIC),
|
|
51032
|
+
scaleAccessor: scaleAccessor,
|
|
51033
|
+
participant: participant,
|
|
51034
|
+
eventType: eventType,
|
|
51035
|
+
});
|
|
50935
51036
|
// if no dynamic value found and a seeding scaleValue is provided...
|
|
50936
51037
|
if (!scaleValue && scaleName) {
|
|
50937
51038
|
scaleValue = getScaleValue({
|
|
@@ -50941,24 +51042,24 @@ function drawMatic$1(_a) {
|
|
|
50941
51042
|
eventType: eventType,
|
|
50942
51043
|
});
|
|
50943
51044
|
}
|
|
50944
|
-
if (scaleValue)
|
|
51045
|
+
if (scaleValue && !adHocRatings[participantId])
|
|
50945
51046
|
adHocRatings[participantId] = scaleValue;
|
|
50946
51047
|
};
|
|
50947
51048
|
try {
|
|
50948
|
-
for (var
|
|
50949
|
-
var participantId =
|
|
51049
|
+
for (var _j = __values(participantIds !== null && participantIds !== void 0 ? participantIds : []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
51050
|
+
var participantId = _k.value;
|
|
50950
51051
|
_loop_1(participantId);
|
|
50951
51052
|
}
|
|
50952
51053
|
}
|
|
50953
51054
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
50954
51055
|
finally {
|
|
50955
51056
|
try {
|
|
50956
|
-
if (
|
|
51057
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
50957
51058
|
}
|
|
50958
51059
|
finally { if (e_1) throw e_1.error; }
|
|
50959
51060
|
}
|
|
50960
51061
|
// TODO: update dynamic ratings based on matchUps present from last played round
|
|
50961
|
-
// use scaleEngine.
|
|
51062
|
+
// use scaleEngine.generateDynamicRatings(); see dynamicCalculations.test.ts
|
|
50962
51063
|
return generateDrawMaticRound({
|
|
50963
51064
|
tournamentParticipants: tournamentParticipants,
|
|
50964
51065
|
tournamentRecord: tournamentRecord,
|
|
@@ -50975,10 +51076,10 @@ function drawMatic$1(_a) {
|
|
|
50975
51076
|
}
|
|
50976
51077
|
function getScaleValue(_a) {
|
|
50977
51078
|
var _b;
|
|
50978
|
-
var _c = _a.
|
|
51079
|
+
var _c = _a.scaleType, scaleType = _c === void 0 ? RATING$2 : _c, scaleAccessor = _a.scaleAccessor, participant = _a.participant, scaleName = _a.scaleName, eventType = _a.eventType;
|
|
50979
51080
|
var scaleAttributes = {
|
|
50980
51081
|
eventType: eventType || TypeEnum.Singles,
|
|
50981
|
-
scaleType:
|
|
51082
|
+
scaleType: scaleType,
|
|
50982
51083
|
scaleName: scaleName,
|
|
50983
51084
|
};
|
|
50984
51085
|
var result = participant &&
|
|
@@ -64635,18 +64736,18 @@ function calculateNewRatings(params) {
|
|
|
64635
64736
|
var updatedWinnerRating = invertedScale
|
|
64636
64737
|
? ratingRange[0] - convertedUpdatedWinnerRating
|
|
64637
64738
|
: convertedUpdatedWinnerRating;
|
|
64638
|
-
var newWinnerRating = parseFloat(updatedWinnerRating).toFixed(decimalPlaces);
|
|
64739
|
+
var newWinnerRating = parseFloat(parseFloat(updatedWinnerRating).toFixed(decimalPlaces));
|
|
64639
64740
|
var updatedLoserRating = invertedScale
|
|
64640
64741
|
? ratingRange[0] - convertedUpdatedLoserRating
|
|
64641
64742
|
: convertedUpdatedLoserRating;
|
|
64642
|
-
var newLoserRating = parseFloat(updatedLoserRating).toFixed(decimalPlaces);
|
|
64743
|
+
var newLoserRating = parseFloat(parseFloat(updatedLoserRating).toFixed(decimalPlaces));
|
|
64643
64744
|
// if expected winner && percentageDifference > threshold don't change ratings
|
|
64644
64745
|
var percentageDifference = Math.max.apply(Math, __spreadArray([], __read(ratingRange), false)) ? Math.abs(winnerRating - loserRating) / Math.max.apply(Math, __spreadArray([], __read(ratingRange), false))
|
|
64645
64746
|
: 0;
|
|
64646
64747
|
if ((convertedUpdatedWinnerRating > convertedUpdatedLoserRating &&
|
|
64647
64748
|
percentageDifference > eloConfig.diffThreshold) ||
|
|
64648
|
-
|
|
64649
|
-
|
|
64749
|
+
newWinnerRating < 0 ||
|
|
64750
|
+
newLoserRating < 0) {
|
|
64650
64751
|
newWinnerRating = winnerRating;
|
|
64651
64752
|
newLoserRating = loserRating;
|
|
64652
64753
|
}
|
|
@@ -64661,10 +64762,10 @@ var aggregateSets = function (sets) {
|
|
|
64661
64762
|
}, [0, 0])) || [0, 0]);
|
|
64662
64763
|
};
|
|
64663
64764
|
|
|
64664
|
-
function
|
|
64765
|
+
function generateDynamicRatings(_a) {
|
|
64665
64766
|
var e_1, _b;
|
|
64666
64767
|
var _c, _d;
|
|
64667
|
-
var tournamentRecord = _a.tournamentRecord,
|
|
64768
|
+
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;
|
|
64668
64769
|
if (!tournamentRecord)
|
|
64669
64770
|
return { error: MISSING_TOURNAMENT_RECORD };
|
|
64670
64771
|
if (!Array.isArray(matchUpIds))
|
|
@@ -64682,7 +64783,7 @@ function processMatchUps(_a) {
|
|
|
64682
64783
|
inContext: true,
|
|
64683
64784
|
}).matchUps || [];
|
|
64684
64785
|
var _loop_1 = function (matchUp) {
|
|
64685
|
-
var e_2,
|
|
64786
|
+
var e_2, _j, e_3, _k, _l, _m;
|
|
64686
64787
|
var endDate = matchUp.endDate, matchUpFormat = matchUp.matchUpFormat, score = matchUp.score, sides = matchUp.sides, winningSide = matchUp.winningSide;
|
|
64687
64788
|
var matchUpType = matchUp.matchUpType;
|
|
64688
64789
|
var scaleAttributes = {
|
|
@@ -64690,7 +64791,7 @@ function processMatchUps(_a) {
|
|
|
64690
64791
|
scaleName: ratingType,
|
|
64691
64792
|
scaleType: RATING$2,
|
|
64692
64793
|
};
|
|
64693
|
-
var dynamicScaleName = "".concat(ratingType, ".
|
|
64794
|
+
var dynamicScaleName = "".concat(ratingType, ".").concat(DYNAMIC);
|
|
64694
64795
|
var dynamicScaleAttributes = {
|
|
64695
64796
|
scaleName: dynamicScaleName,
|
|
64696
64797
|
eventType: matchUpType,
|
|
@@ -64726,9 +64827,9 @@ function processMatchUps(_a) {
|
|
|
64726
64827
|
return (participantId && (_b = {},
|
|
64727
64828
|
_b[participantId] = (_c = dynamicScaleItem !== null && dynamicScaleItem !== void 0 ? dynamicScaleItem : scaleItem) !== null && _c !== void 0 ? _c : {
|
|
64728
64829
|
scaleName: outputScaleName,
|
|
64729
|
-
scaleType: RATING$2,
|
|
64730
64830
|
eventType: matchUpType,
|
|
64731
64831
|
scaleDate: endDate,
|
|
64832
|
+
scaleType: RATING$2,
|
|
64732
64833
|
scaleValue: scaleValue,
|
|
64733
64834
|
},
|
|
64734
64835
|
_b));
|
|
@@ -64763,31 +64864,33 @@ function processMatchUps(_a) {
|
|
|
64763
64864
|
var loserCountables = winningSide
|
|
64764
64865
|
? countables[3 - winningSide]
|
|
64765
64866
|
: [0, 0];
|
|
64766
|
-
var
|
|
64867
|
+
var _o = calculateNewRatings({
|
|
64767
64868
|
winnerCountables: winnerCountables,
|
|
64768
64869
|
loserCountables: loserCountables,
|
|
64769
64870
|
maxCountables: maxCountables,
|
|
64770
64871
|
winnerRating: winnerRating,
|
|
64771
64872
|
loserRating: loserRating,
|
|
64772
64873
|
ratingType: ratingType,
|
|
64773
|
-
}), newWinnerRating =
|
|
64874
|
+
}), newWinnerRating = _o.newWinnerRating, newLoserRating = _o.newLoserRating;
|
|
64774
64875
|
var newWinnerScaleValue = accessor
|
|
64775
|
-
? __assign(__assign({}, winnerScaleValue), (
|
|
64876
|
+
? __assign(__assign({}, winnerScaleValue), (_l = {}, _l[accessor] = newWinnerRating, _l)) : newWinnerRating;
|
|
64776
64877
|
var newLoserScaleValue = accessor
|
|
64777
|
-
? __assign(__assign({}, loserScaleValue), (
|
|
64878
|
+
? __assign(__assign({}, loserScaleValue), (_m = {}, _m[accessor] = newLoserRating, _m)) : newLoserRating;
|
|
64778
64879
|
scaleItemMap[winnerParticipantId].scaleValue = newWinnerScaleValue;
|
|
64779
64880
|
scaleItemMap[loserParticipantId].scaleValue = newLoserScaleValue;
|
|
64780
64881
|
var result = setParticipantScaleItem({
|
|
64781
|
-
scaleItem: __assign(__assign({}, scaleItemMap[winnerParticipantId]), { scaleName: outputScaleName }),
|
|
64782
64882
|
participantId: winnerParticipantId,
|
|
64883
|
+
removePriorValues: removePriorValues,
|
|
64783
64884
|
tournamentRecord: tournamentRecord,
|
|
64885
|
+
scaleItem: __assign(__assign({}, scaleItemMap[winnerParticipantId]), { scaleName: outputScaleName }),
|
|
64784
64886
|
});
|
|
64785
64887
|
if (result.error)
|
|
64786
64888
|
return { value: result };
|
|
64787
64889
|
result = setParticipantScaleItem({
|
|
64788
|
-
scaleItem: __assign(__assign({}, scaleItemMap[loserParticipantId]), { scaleName: outputScaleName }),
|
|
64789
64890
|
participantId: loserParticipantId,
|
|
64891
|
+
removePriorValues: removePriorValues,
|
|
64790
64892
|
tournamentRecord: tournamentRecord,
|
|
64893
|
+
scaleItem: __assign(__assign({}, scaleItemMap[loserParticipantId]), { scaleName: outputScaleName }),
|
|
64791
64894
|
});
|
|
64792
64895
|
if (result.error)
|
|
64793
64896
|
return { value: result };
|
|
@@ -64796,7 +64899,7 @@ function processMatchUps(_a) {
|
|
|
64796
64899
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
64797
64900
|
finally {
|
|
64798
64901
|
try {
|
|
64799
|
-
if (losingSideParticipantIds_1_1 && !losingSideParticipantIds_1_1.done && (
|
|
64902
|
+
if (losingSideParticipantIds_1_1 && !losingSideParticipantIds_1_1.done && (_k = losingSideParticipantIds_1.return)) _k.call(losingSideParticipantIds_1);
|
|
64800
64903
|
}
|
|
64801
64904
|
finally { if (e_3) throw e_3.error; }
|
|
64802
64905
|
}
|
|
@@ -64805,15 +64908,15 @@ function processMatchUps(_a) {
|
|
|
64805
64908
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
64806
64909
|
finally {
|
|
64807
64910
|
try {
|
|
64808
|
-
if (winningSideParticipantIds_1_1 && !winningSideParticipantIds_1_1.done && (
|
|
64911
|
+
if (winningSideParticipantIds_1_1 && !winningSideParticipantIds_1_1.done && (_j = winningSideParticipantIds_1.return)) _j.call(winningSideParticipantIds_1);
|
|
64809
64912
|
}
|
|
64810
64913
|
finally { if (e_2) throw e_2.error; }
|
|
64811
64914
|
}
|
|
64812
64915
|
Object.assign(modifiedScaleValues, scaleItemMap);
|
|
64813
64916
|
};
|
|
64814
64917
|
try {
|
|
64815
|
-
for (var
|
|
64816
|
-
var matchUp =
|
|
64918
|
+
for (var _g = __values(matchUps.sort(matchUpSort)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
64919
|
+
var matchUp = _h.value;
|
|
64817
64920
|
var state_1 = _loop_1(matchUp);
|
|
64818
64921
|
if (typeof state_1 === "object")
|
|
64819
64922
|
return state_1.value;
|
|
@@ -64822,7 +64925,7 @@ function processMatchUps(_a) {
|
|
|
64822
64925
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
64823
64926
|
finally {
|
|
64824
64927
|
try {
|
|
64825
|
-
if (
|
|
64928
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
64826
64929
|
}
|
|
64827
64930
|
finally { if (e_1) throw e_1.error; }
|
|
64828
64931
|
}
|
|
@@ -64835,7 +64938,7 @@ function processMatchUps(_a) {
|
|
|
64835
64938
|
|
|
64836
64939
|
var governor = {
|
|
64837
64940
|
calculateNewRatings: calculateNewRatings,
|
|
64838
|
-
|
|
64941
|
+
generateDynamicRatings: generateDynamicRatings,
|
|
64839
64942
|
};
|
|
64840
64943
|
|
|
64841
64944
|
var scaleEngine = (function () {
|