tods-competition-factory 1.8.16 → 1.8.18

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.
@@ -2905,7 +2905,7 @@ var matchUpFormatCode = {
2905
2905
  };
2906
2906
 
2907
2907
  function factoryVersion() {
2908
- return '1.8.16';
2908
+ return '1.8.18';
2909
2909
  }
2910
2910
 
2911
2911
  function getObjectTieFormat(obj) {
@@ -5758,7 +5758,7 @@ function findPolicy(_a) {
5758
5758
  }
5759
5759
 
5760
5760
  function getMatchUpCompetitiveProfile(_a) {
5761
- var profileBands = _a.profileBands, tournamentRecord = _a.tournamentRecord, matchUp = _a.matchUp;
5761
+ var tournamentRecord = _a.tournamentRecord, profileBands = _a.profileBands, matchUp = _a.matchUp;
5762
5762
  if (!matchUp)
5763
5763
  return { error: MISSING_MATCHUP };
5764
5764
  var score = matchUp.score, winningSide = matchUp.winningSide;
@@ -17577,8 +17577,8 @@ function allTournamentMatchUps(params) {
17577
17577
  if (!participants) {
17578
17578
  (_a = hydrateParticipants({
17579
17579
  participantsProfile: participantsProfile,
17580
- policyDefinitions: policyDefinitions,
17581
17580
  useParticipantMap: useParticipantMap,
17581
+ policyDefinitions: policyDefinitions,
17582
17582
  tournamentRecord: tournamentRecord,
17583
17583
  contextProfile: contextProfile,
17584
17584
  inContext: inContext,
@@ -57162,16 +57162,6 @@ function getTieMatchUpContext(_a) {
57162
57162
  return __assign({ inContextDualMatchUp: inContextDualMatchUp, inContextTieMatchUp: inContextTieMatchUp, relevantAssignments: relevantAssignments, collectionPosition: collectionPosition, teamParticipants: teamParticipants, collectionId: collectionId, matchUpType: matchUpType, dualMatchUp: dualMatchUp, tieMatchUp: tieMatchUp, tieFormat: tieFormat, structure: structure }, SUCCESS);
57163
57163
  }
57164
57164
 
57165
- /**
57166
- * @param {object} tournamentRecord
57167
- * @param {string} participantId
57168
- * @param {object} drawDefinition
57169
- * @param {string} tieMatchUpId
57170
- * @param {number=} sideNumber
57171
- * @param {string} matchUpId
57172
- * @param {string=} drawId
57173
- * @param {object} event
57174
- */
57175
57165
  function assignTieMatchUpParticipantId(params) {
57176
57166
  var e_1, _a;
57177
57167
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
@@ -59252,6 +59242,434 @@ function getEntryStatusReports(_a) {
59252
59242
  };
59253
59243
  }
59254
59244
 
59245
+ function getParticipantStats(_a) {
59246
+ var e_1, _b, e_2, _c, e_3, _d, e_4, _e, e_5, _f, e_6, _g, e_7, _h;
59247
+ var _j, _k, _l, _m, _o, _p;
59248
+ var withCompetitiveProfiles = _a.withCompetitiveProfiles, opponentParticipantId = _a.opponentParticipantId, withIndividualStats = _a.withIndividualStats, teamParticipantId = _a.teamParticipantId, tournamentRecord = _a.tournamentRecord, withScaleValues = _a.withScaleValues, tallyPolicy = _a.tallyPolicy, matchUps = _a.matchUps;
59249
+ if (!tournamentRecord)
59250
+ return { error: MISSING_TOURNAMENT_RECORD };
59251
+ if (matchUps && !Array.isArray(matchUps))
59252
+ return { error: INVALID_MATCHUP };
59253
+ var participantsProfile = withScaleValues ? { withScaleValues: withScaleValues } : undefined;
59254
+ matchUps =
59255
+ matchUps ||
59256
+ allTournamentMatchUps({ tournamentRecord: tournamentRecord, participantsProfile: participantsProfile }).matchUps;
59257
+ if (!(matchUps === null || matchUps === void 0 ? void 0 : matchUps.length))
59258
+ return { error: MISSING_MATCHUPS };
59259
+ var teamParticipantIds = [];
59260
+ if (opponentParticipantId)
59261
+ teamParticipantIds.push(opponentParticipantId);
59262
+ if (teamParticipantId)
59263
+ teamParticipantIds.push(teamParticipantId);
59264
+ var participantFilters = !teamParticipantIds.length
59265
+ ? { participantTypes: [TEAM_PARTICIPANT] }
59266
+ : { participantIds: teamParticipantIds };
59267
+ var teamParticipants = (_j = getParticipants$1({ participantFilters: participantFilters, tournamentRecord: tournamentRecord }).participants) !== null && _j !== void 0 ? _j : [];
59268
+ if (!teamParticipants.every(function (_a) {
59269
+ var participantType = _a.participantType;
59270
+ return participantType === TEAM_PARTICIPANT;
59271
+ })) {
59272
+ return { error: INVALID_PARTICIPANT_IDS };
59273
+ }
59274
+ if (!teamParticipantIds.length)
59275
+ teamParticipantIds.push.apply(teamParticipantIds, __spreadArray([], __read(teamParticipants.map(extractAttributes('participantId'))), false));
59276
+ var participantDetails = new Map();
59277
+ var participantStats = new Map();
59278
+ var participating = new Map();
59279
+ var teamMap = new Map();
59280
+ var initStats = function (participantId, participantName) {
59281
+ if (participantName === void 0) { participantName = ''; }
59282
+ return participantStats.get(participantId) ||
59283
+ (participantStats.set(participantId, {
59284
+ participantName: participantName,
59285
+ participantId: participantId,
59286
+ competitorIds: [],
59287
+ competitiveness: {},
59288
+ matchUpStatuses: {},
59289
+ tiebreaks: [0, 0],
59290
+ matchUps: [0, 0],
59291
+ points: [0, 0],
59292
+ games: [0, 0],
59293
+ sets: [0, 0],
59294
+ }) &&
59295
+ participantStats.get(participantId));
59296
+ };
59297
+ try {
59298
+ for (var teamParticipants_1 = __values(teamParticipants), teamParticipants_1_1 = teamParticipants_1.next(); !teamParticipants_1_1.done; teamParticipants_1_1 = teamParticipants_1.next()) {
59299
+ var teamParticipant = teamParticipants_1_1.value;
59300
+ var participantId = teamParticipant.participantId, individualParticipantIds = teamParticipant.individualParticipantIds;
59301
+ teamMap.set(participantId, individualParticipantIds !== null && individualParticipantIds !== void 0 ? individualParticipantIds : []);
59302
+ initStats(participantId, teamParticipant.participantName);
59303
+ }
59304
+ }
59305
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59306
+ finally {
59307
+ try {
59308
+ if (teamParticipants_1_1 && !teamParticipants_1_1.done && (_b = teamParticipants_1.return)) _b.call(teamParticipants_1);
59309
+ }
59310
+ finally { if (e_1) throw e_1.error; }
59311
+ }
59312
+ if (teamParticipantId && !teamMap.get(teamParticipantId))
59313
+ return decorateResult({
59314
+ result: { error: PARTICIPANT_NOT_FOUND },
59315
+ context: { teamParticipantId: teamParticipantId },
59316
+ });
59317
+ if (opponentParticipantId && !teamMap.get(opponentParticipantId))
59318
+ return decorateResult({
59319
+ result: { error: PARTICIPANT_NOT_FOUND },
59320
+ context: { opponentParticipantId: opponentParticipantId },
59321
+ });
59322
+ var relevantMatchUps = [];
59323
+ var getSideParticipantIds = function (sides) {
59324
+ var e_8, _a, e_9, _b, e_10, _c;
59325
+ var sideParticipantIds = [[], []];
59326
+ try {
59327
+ for (var sides_1 = __values(sides), sides_1_1 = sides_1.next(); !sides_1_1.done; sides_1_1 = sides_1.next()) {
59328
+ var side = sides_1_1.value;
59329
+ var participant = side.participant;
59330
+ if (participant === null || participant === void 0 ? void 0 : participant.participantName) {
59331
+ participantDetails.set(participant.participantId, {
59332
+ participantName: participant.participantName,
59333
+ ratings: participant.ratings,
59334
+ });
59335
+ }
59336
+ }
59337
+ }
59338
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
59339
+ finally {
59340
+ try {
59341
+ if (sides_1_1 && !sides_1_1.done && (_a = sides_1.return)) _a.call(sides_1);
59342
+ }
59343
+ finally { if (e_8) throw e_8.error; }
59344
+ }
59345
+ var getCompetitorIds = function (_a) {
59346
+ var _b, _c, _d, _e, _f;
59347
+ var side = _a.side, individualParticipantIds = _a.individualParticipantIds;
59348
+ return ((side.participantId &&
59349
+ (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) ||
59350
+ individualParticipantIds.includes(side.participantId)) && [
59351
+ side.participantId,
59352
+ ]) ||
59353
+ (((_c = (_b = side.participant) === null || _b === void 0 ? void 0 : _b.individualParticipantIds) === null || _c === void 0 ? void 0 : _c.length) &&
59354
+ (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) ||
59355
+ intersection(individualParticipantIds, (_d = side.participant) === null || _d === void 0 ? void 0 : _d.individualParticipantIds).length === ((_f = (_e = side.participant) === null || _e === void 0 ? void 0 : _e.individualParticipantIds) === null || _f === void 0 ? void 0 : _f.length)) &&
59356
+ side.participant.individualParticipantIds));
59357
+ };
59358
+ if (teamMap.size) {
59359
+ var processSides = function (thisTeamId, individualParticipantIds) {
59360
+ var e_11, _a, e_12, _b;
59361
+ try {
59362
+ for (var sides_3 = __values(sides), sides_3_1 = sides_3.next(); !sides_3_1.done; sides_3_1 = sides_3.next()) {
59363
+ var side = sides_3_1.value;
59364
+ if (!side.participant)
59365
+ continue;
59366
+ var competitorIds = getCompetitorIds({
59367
+ individualParticipantIds: individualParticipantIds,
59368
+ side: side,
59369
+ });
59370
+ if (competitorIds === null || competitorIds === void 0 ? void 0 : competitorIds.length) {
59371
+ var sideNumber = side.sideNumber;
59372
+ if (!sideNumber)
59373
+ continue;
59374
+ var ids = [thisTeamId];
59375
+ if (withIndividualStats)
59376
+ ids.push.apply(ids, __spreadArray([], __read(competitorIds), false));
59377
+ sideParticipantIds[sideNumber - 1] = ids;
59378
+ var stats = participantStats.get(thisTeamId);
59379
+ try {
59380
+ for (var _c = (e_12 = void 0, __values(competitorIds.filter(Boolean))), _d = _c.next(); !_d.done; _d = _c.next()) {
59381
+ var id = _d.value;
59382
+ if (stats && !stats.competitorIds.includes(id))
59383
+ stats.competitorIds.push(id);
59384
+ }
59385
+ }
59386
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
59387
+ finally {
59388
+ try {
59389
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
59390
+ }
59391
+ finally { if (e_12) throw e_12.error; }
59392
+ }
59393
+ }
59394
+ }
59395
+ }
59396
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
59397
+ finally {
59398
+ try {
59399
+ if (sides_3_1 && !sides_3_1.done && (_a = sides_3.return)) _a.call(sides_3);
59400
+ }
59401
+ finally { if (e_11) throw e_11.error; }
59402
+ }
59403
+ };
59404
+ if (teamParticipantId) {
59405
+ var processForTeam = !opponentParticipantId ||
59406
+ sides.every(function (side) {
59407
+ side.participant &&
59408
+ (getCompetitorIds({
59409
+ side: side,
59410
+ individualParticipantIds: teamMap.get(teamParticipantId),
59411
+ }) ||
59412
+ getCompetitorIds({
59413
+ side: side,
59414
+ individualParticipantIds: teamMap.get(opponentParticipantId),
59415
+ }));
59416
+ });
59417
+ if (processForTeam)
59418
+ processSides(teamParticipantId, teamMap.get(teamParticipantId));
59419
+ }
59420
+ else {
59421
+ try {
59422
+ for (var teamMap_1 = __values(teamMap), teamMap_1_1 = teamMap_1.next(); !teamMap_1_1.done; teamMap_1_1 = teamMap_1.next()) {
59423
+ var _d = __read(teamMap_1_1.value, 2), thisTeamId = _d[0], individualParticipantIds = _d[1];
59424
+ processSides(thisTeamId, individualParticipantIds);
59425
+ }
59426
+ }
59427
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
59428
+ finally {
59429
+ try {
59430
+ if (teamMap_1_1 && !teamMap_1_1.done && (_b = teamMap_1.return)) _b.call(teamMap_1);
59431
+ }
59432
+ finally { if (e_9) throw e_9.error; }
59433
+ }
59434
+ }
59435
+ }
59436
+ else if (withIndividualStats) {
59437
+ try {
59438
+ // no teams so process individuals
59439
+ for (var sides_2 = __values(sides), sides_2_1 = sides_2.next(); !sides_2_1.done; sides_2_1 = sides_2.next()) {
59440
+ var side = sides_2_1.value;
59441
+ if (!side.participant)
59442
+ continue;
59443
+ var competitorIds = getCompetitorIds({
59444
+ individualParticipantIds: [],
59445
+ side: side,
59446
+ });
59447
+ var sideNumber = side.sideNumber;
59448
+ if (!sideNumber)
59449
+ continue;
59450
+ sideParticipantIds[sideNumber - 1] = competitorIds;
59451
+ }
59452
+ }
59453
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
59454
+ finally {
59455
+ try {
59456
+ if (sides_2_1 && !sides_2_1.done && (_c = sides_2.return)) _c.call(sides_2);
59457
+ }
59458
+ finally { if (e_10) throw e_10.error; }
59459
+ }
59460
+ }
59461
+ return sideParticipantIds;
59462
+ };
59463
+ var _loop_1 = function (matchUp) {
59464
+ if (!isObject(matchUp))
59465
+ return { value: { error: INVALID_MATCHUP } };
59466
+ var matchUpStatus = matchUp.matchUpStatus, matchUpFormat = matchUp.matchUpFormat, matchUpType = matchUp.matchUpType, winningSide = matchUp.winningSide, score = matchUp.score, sides = matchUp.sides;
59467
+ if (!sides ||
59468
+ !score ||
59469
+ matchUpType === TEAM_MATCHUP ||
59470
+ matchUpStatus === BYE)
59471
+ return "continue";
59472
+ var sideParticipantIds = getSideParticipantIds(sides);
59473
+ if (!sideParticipantIds.filter(Boolean).length)
59474
+ return "continue";
59475
+ var competitiveness = withCompetitiveProfiles &&
59476
+ winningSide &&
59477
+ ((_k = getMatchUpCompetitiveProfile({ matchUp: matchUp })) === null || _k === void 0 ? void 0 : _k.competitiveness);
59478
+ relevantMatchUps.push(matchUp);
59479
+ var setsTally = countSets({
59480
+ matchUpStatus: matchUpStatus,
59481
+ matchUpFormat: matchUpFormat,
59482
+ tallyPolicy: tallyPolicy,
59483
+ winningSide: winningSide,
59484
+ score: score,
59485
+ });
59486
+ var gamesTally = countGames({
59487
+ matchUpStatus: matchUpStatus,
59488
+ matchUpFormat: matchUpFormat,
59489
+ tallyPolicy: tallyPolicy,
59490
+ winningSide: winningSide,
59491
+ score: score,
59492
+ });
59493
+ var _v = countPoints({
59494
+ matchUpFormat: matchUpFormat,
59495
+ score: score,
59496
+ }), pointsTally = _v.pointsTally, tiebreaksTally = _v.tiebreaksTally;
59497
+ sideParticipantIds.forEach(function (ids, index) {
59498
+ var e_13, _a;
59499
+ var _b;
59500
+ var _loop_2 = function (id) {
59501
+ var participantName = (_b = participantDetails.get(id)) === null || _b === void 0 ? void 0 : _b.participantName;
59502
+ var stats = initStats(id, participantName);
59503
+ if (stats) {
59504
+ var teamSumTally = function (stat, tally) {
59505
+ return tally.forEach(function (t, i) { return (stats[stat][i] += t); });
59506
+ };
59507
+ var tiebreaks = index
59508
+ ? __spreadArray([], __read(tiebreaksTally), false).reverse()
59509
+ : tiebreaksTally;
59510
+ var points = index ? __spreadArray([], __read(pointsTally), false).reverse() : pointsTally;
59511
+ var games = index ? __spreadArray([], __read(gamesTally), false).reverse() : gamesTally;
59512
+ var sets = index ? __spreadArray([], __read(setsTally), false).reverse() : setsTally;
59513
+ teamSumTally('tiebreaks', tiebreaks);
59514
+ teamSumTally('points', points);
59515
+ teamSumTally('games', games);
59516
+ teamSumTally('sets', sets);
59517
+ if (winningSide) {
59518
+ var tallyIndex = winningSide - 1 === index ? 0 : 1;
59519
+ stats.matchUps[tallyIndex] += 1;
59520
+ }
59521
+ if (competitiveness) {
59522
+ var attr = competitiveness.toLowerCase();
59523
+ if (!stats.competitiveness[attr])
59524
+ stats.competitiveness[attr] = [0, 0];
59525
+ stats.competitiveness[attr][index] += 1;
59526
+ }
59527
+ if (matchUpStatus) {
59528
+ var attr = matchUpStatus.toLowerCase();
59529
+ if (!stats.matchUpStatuses[attr])
59530
+ stats.matchUpStatuses[attr] = 0;
59531
+ stats.matchUpStatuses[attr] += 1;
59532
+ }
59533
+ }
59534
+ };
59535
+ try {
59536
+ for (var ids_1 = (e_13 = void 0, __values(ids)), ids_1_1 = ids_1.next(); !ids_1_1.done; ids_1_1 = ids_1.next()) {
59537
+ var id = ids_1_1.value;
59538
+ _loop_2(id);
59539
+ }
59540
+ }
59541
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
59542
+ finally {
59543
+ try {
59544
+ if (ids_1_1 && !ids_1_1.done && (_a = ids_1.return)) _a.call(ids_1);
59545
+ }
59546
+ finally { if (e_13) throw e_13.error; }
59547
+ }
59548
+ });
59549
+ };
59550
+ try {
59551
+ for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
59552
+ var matchUp = matchUps_1_1.value;
59553
+ var state_1 = _loop_1(matchUp);
59554
+ if (typeof state_1 === "object")
59555
+ return state_1.value;
59556
+ }
59557
+ }
59558
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
59559
+ finally {
59560
+ try {
59561
+ if (matchUps_1_1 && !matchUps_1_1.done && (_c = matchUps_1.return)) _c.call(matchUps_1);
59562
+ }
59563
+ finally { if (e_2) throw e_2.error; }
59564
+ }
59565
+ var statsattributes = ['tiebreaks', 'matchUps', 'points', 'games', 'sets'];
59566
+ var competitivenessAttributes = ['competitive', 'routine', 'decisive'];
59567
+ var ratio = new Map();
59568
+ var add = function (a, b) { return (a !== null && a !== void 0 ? a : 0) + (b !== null && b !== void 0 ? b : 0); };
59569
+ try {
59570
+ for (var _q = __values(participantStats.entries()), _r = _q.next(); !_r.done; _r = _q.next()) {
59571
+ var _s = __read(_r.value, 2), participantId = _s[0], stats = _s[1];
59572
+ try {
59573
+ for (var statsattributes_1 = (e_4 = void 0, __values(statsattributes)), statsattributes_1_1 = statsattributes_1.next(); !statsattributes_1_1.done; statsattributes_1_1 = statsattributes_1.next()) {
59574
+ var attr = statsattributes_1_1.value;
59575
+ var total = stats[attr].reduce(add);
59576
+ if (total) {
59577
+ var value = stats[attr][0] / total;
59578
+ var accessor = "".concat(attr, "Ratio");
59579
+ var fixedValue = parseFloat(value.toFixed(2));
59580
+ stats[accessor] = fixedValue;
59581
+ participating.set(participantId, true);
59582
+ if (!ratio.has(accessor))
59583
+ ratio.set(accessor, []);
59584
+ (_l = ratio.get(accessor)) === null || _l === void 0 ? void 0 : _l.push(fixedValue);
59585
+ }
59586
+ }
59587
+ }
59588
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
59589
+ finally {
59590
+ try {
59591
+ if (statsattributes_1_1 && !statsattributes_1_1.done && (_e = statsattributes_1.return)) _e.call(statsattributes_1);
59592
+ }
59593
+ finally { if (e_4) throw e_4.error; }
59594
+ }
59595
+ try {
59596
+ for (var competitivenessAttributes_1 = (e_5 = void 0, __values(competitivenessAttributes)), competitivenessAttributes_1_1 = competitivenessAttributes_1.next(); !competitivenessAttributes_1_1.done; competitivenessAttributes_1_1 = competitivenessAttributes_1.next()) {
59597
+ var attr = competitivenessAttributes_1_1.value;
59598
+ var total = (_o = (_m = stats.competitiveness) === null || _m === void 0 ? void 0 : _m[attr]) === null || _o === void 0 ? void 0 : _o.reduce(add);
59599
+ if (total) {
59600
+ var value = stats.competitiveness[attr][0] / total;
59601
+ var accessor = "".concat(attr, "Ratio");
59602
+ var fixedValue = parseFloat(value.toFixed(2));
59603
+ stats[accessor] = fixedValue;
59604
+ }
59605
+ }
59606
+ }
59607
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
59608
+ finally {
59609
+ try {
59610
+ if (competitivenessAttributes_1_1 && !competitivenessAttributes_1_1.done && (_f = competitivenessAttributes_1.return)) _f.call(competitivenessAttributes_1);
59611
+ }
59612
+ finally { if (e_5) throw e_5.error; }
59613
+ }
59614
+ }
59615
+ }
59616
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
59617
+ finally {
59618
+ try {
59619
+ if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
59620
+ }
59621
+ finally { if (e_3) throw e_3.error; }
59622
+ }
59623
+ if (!teamParticipantId) {
59624
+ var highLowSort = function (a, b) { return b - a; };
59625
+ try {
59626
+ for (var _t = __values(participantStats.values()), _u = _t.next(); !_u.done; _u = _t.next()) {
59627
+ var stats = _u.value;
59628
+ try {
59629
+ for (var statsattributes_2 = (e_7 = void 0, __values(statsattributes)), statsattributes_2_1 = statsattributes_2.next(); !statsattributes_2_1.done; statsattributes_2_1 = statsattributes_2.next()) {
59630
+ var attr = statsattributes_2_1.value;
59631
+ // now rank each team by their ratio on each attribute
59632
+ var accessor = "".concat(attr, "Ratio");
59633
+ if (typeof stats[accessor] === 'number') {
59634
+ var index = (_p = ratio
59635
+ .get(accessor)) === null || _p === void 0 ? void 0 : _p.sort(highLowSort).indexOf(stats[accessor]);
59636
+ if (typeof index === 'number' && index >= 0) {
59637
+ var rankAccessor = "".concat(attr, "Rank");
59638
+ stats[rankAccessor] = index + 1;
59639
+ }
59640
+ }
59641
+ }
59642
+ }
59643
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
59644
+ finally {
59645
+ try {
59646
+ if (statsattributes_2_1 && !statsattributes_2_1.done && (_h = statsattributes_2.return)) _h.call(statsattributes_2);
59647
+ }
59648
+ finally { if (e_7) throw e_7.error; }
59649
+ }
59650
+ }
59651
+ }
59652
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
59653
+ finally {
59654
+ try {
59655
+ if (_u && !_u.done && (_g = _t.return)) _g.call(_t);
59656
+ }
59657
+ finally { if (e_6) throw e_6.error; }
59658
+ }
59659
+ }
59660
+ var result = __assign({ relevantMatchUps: relevantMatchUps }, SUCCESS);
59661
+ if (teamParticipantId) {
59662
+ result.teamStats = participantStats.get(teamParticipantId);
59663
+ if (opponentParticipantId)
59664
+ result.opponentStats = participantStats.get(opponentParticipantId);
59665
+ }
59666
+ else {
59667
+ result.participatingTeamsCount = participating.size;
59668
+ }
59669
+ result.allParticipantStats = __spreadArray([], __read(participantStats.values()), false);
59670
+ return result;
59671
+ }
59672
+
59255
59673
  function getAvgWTN(_a) {
59256
59674
  var eventType = _a.eventType, matchUps = _a.matchUps, eventId = _a.eventId, drawId = _a.drawId;
59257
59675
  var matchUpFormatCounts = {};
@@ -59463,298 +59881,10 @@ function getPositionManipulations(_a) {
59463
59881
  })) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.slice(1);
59464
59882
  }
59465
59883
 
59466
- function getTeamStats(_a) {
59467
- var e_1, _b, e_2, _c, e_3, _d, e_4, _e, e_5, _f, e_6, _g;
59468
- var _h, _j, _k, _l;
59469
- var opponentParticipantId = _a.opponentParticipantId, teamParticipantId = _a.teamParticipantId, tournamentRecord = _a.tournamentRecord, tallyPolicy = _a.tallyPolicy, matchUps = _a.matchUps;
59470
- if (!tournamentRecord)
59471
- return { error: MISSING_TOURNAMENT_RECORD };
59472
- if (matchUps && !Array.isArray(matchUps))
59473
- return { error: INVALID_MATCHUP };
59474
- matchUps = matchUps || allTournamentMatchUps({ tournamentRecord: tournamentRecord }).matchUps;
59475
- if (!(matchUps === null || matchUps === void 0 ? void 0 : matchUps.length))
59476
- return { error: MISSING_MATCHUPS };
59477
- var teamParticipantIds = [];
59478
- if (opponentParticipantId)
59479
- teamParticipantIds.push(opponentParticipantId);
59480
- if (teamParticipantId)
59481
- teamParticipantIds.push(teamParticipantId);
59482
- var participantFilters = !teamParticipantIds.length
59483
- ? { participantTypes: [TEAM_PARTICIPANT] }
59484
- : { participantIds: teamParticipantIds };
59485
- var teamParticipants = (_h = getParticipants$1({ participantFilters: participantFilters, tournamentRecord: tournamentRecord }).participants) !== null && _h !== void 0 ? _h : [];
59486
- if (!teamParticipants.every(function (_a) {
59487
- var participantType = _a.participantType;
59488
- return participantType === TEAM_PARTICIPANT;
59489
- })) {
59490
- return { error: INVALID_PARTICIPANT_IDS };
59491
- }
59492
- if (!teamParticipantIds.length)
59493
- teamParticipantIds.push.apply(teamParticipantIds, __spreadArray([], __read(teamParticipants.map(extractAttributes('participantId'))), false));
59494
- var teamStats = new Map();
59495
- var teamMap = new Map();
59496
- try {
59497
- for (var teamParticipants_1 = __values(teamParticipants), teamParticipants_1_1 = teamParticipants_1.next(); !teamParticipants_1_1.done; teamParticipants_1_1 = teamParticipants_1.next()) {
59498
- var teamParticipant = teamParticipants_1_1.value;
59499
- var participantId = teamParticipant.participantId, individualParticipantIds = teamParticipant.individualParticipantIds;
59500
- teamMap.set(participantId, individualParticipantIds !== null && individualParticipantIds !== void 0 ? individualParticipantIds : []);
59501
- teamStats.set(participantId, {
59502
- participantName: (_j = teamParticipant.participantName) !== null && _j !== void 0 ? _j : '',
59503
- matchUpStatuses: {},
59504
- competitorIds: [],
59505
- tiebreaks: [0, 0],
59506
- matchUps: [0, 0],
59507
- points: [0, 0],
59508
- participantId: participantId,
59509
- games: [0, 0],
59510
- sets: [0, 0],
59511
- });
59512
- }
59513
- }
59514
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
59515
- finally {
59516
- try {
59517
- if (teamParticipants_1_1 && !teamParticipants_1_1.done && (_b = teamParticipants_1.return)) _b.call(teamParticipants_1);
59518
- }
59519
- finally { if (e_1) throw e_1.error; }
59520
- }
59521
- if (teamParticipantId && !teamMap.get(teamParticipantId))
59522
- return decorateResult({
59523
- result: { error: PARTICIPANT_NOT_FOUND },
59524
- context: { teamParticipantId: teamParticipantId },
59525
- });
59526
- if (opponentParticipantId && !teamMap.get(opponentParticipantId))
59527
- return decorateResult({
59528
- result: { error: PARTICIPANT_NOT_FOUND },
59529
- context: { opponentParticipantId: opponentParticipantId },
59530
- });
59531
- var relevantMatchUps = [];
59532
- var getTeamParticipantIds = function (sides) {
59533
- var e_7, _a, e_8, _b, e_9, _c;
59534
- var _d, _e;
59535
- var sideTeamParticipantIds = [];
59536
- var isTeamSide = function (side, individualParticipantIds) {
59537
- var _a, _b, _c, _d, _e;
59538
- return !!((side.participantId &&
59539
- individualParticipantIds.includes(side.participantId)) ||
59540
- (((_b = (_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipantIds) === null || _b === void 0 ? void 0 : _b.length) &&
59541
- intersection(individualParticipantIds, (_c = side.participant) === null || _c === void 0 ? void 0 : _c.individualParticipantIds).length === ((_e = (_d = side.participant) === null || _d === void 0 ? void 0 : _d.individualParticipantIds) === null || _e === void 0 ? void 0 : _e.length)));
59542
- };
59543
- try {
59544
- for (var teamMap_1 = __values(teamMap), teamMap_1_1 = teamMap_1.next(); !teamMap_1_1.done; teamMap_1_1 = teamMap_1.next()) {
59545
- var _f = __read(teamMap_1_1.value, 2), teamParticipantId_1 = _f[0], individualParticipantIds = _f[1];
59546
- try {
59547
- for (var sides_1 = (e_8 = void 0, __values(sides)), sides_1_1 = sides_1.next(); !sides_1_1.done; sides_1_1 = sides_1.next()) {
59548
- var side = sides_1_1.value;
59549
- if (!side.participant)
59550
- continue;
59551
- if (isTeamSide(side, individualParticipantIds)) {
59552
- var sideNumber = side.sideNumber;
59553
- if (!sideNumber)
59554
- continue;
59555
- sideTeamParticipantIds[sideNumber - 1] = teamParticipantId_1;
59556
- var competitorIds = ((_e = (_d = side.participant) === null || _d === void 0 ? void 0 : _d.individualParticipantIds) === null || _e === void 0 ? void 0 : _e.length)
59557
- ? side.participant.individualParticipantIds
59558
- : [side.participant.participantId];
59559
- var stats = teamStats.get(teamParticipantId_1);
59560
- try {
59561
- for (var competitorIds_1 = (e_9 = void 0, __values(competitorIds)), competitorIds_1_1 = competitorIds_1.next(); !competitorIds_1_1.done; competitorIds_1_1 = competitorIds_1.next()) {
59562
- var id = competitorIds_1_1.value;
59563
- if (stats && !stats.competitorIds.includes(id))
59564
- stats.competitorIds.push(id);
59565
- }
59566
- }
59567
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
59568
- finally {
59569
- try {
59570
- if (competitorIds_1_1 && !competitorIds_1_1.done && (_c = competitorIds_1.return)) _c.call(competitorIds_1);
59571
- }
59572
- finally { if (e_9) throw e_9.error; }
59573
- }
59574
- }
59575
- }
59576
- }
59577
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
59578
- finally {
59579
- try {
59580
- if (sides_1_1 && !sides_1_1.done && (_b = sides_1.return)) _b.call(sides_1);
59581
- }
59582
- finally { if (e_8) throw e_8.error; }
59583
- }
59584
- }
59585
- }
59586
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
59587
- finally {
59588
- try {
59589
- if (teamMap_1_1 && !teamMap_1_1.done && (_a = teamMap_1.return)) _a.call(teamMap_1);
59590
- }
59591
- finally { if (e_7) throw e_7.error; }
59592
- }
59593
- return sideTeamParticipantIds;
59594
- };
59595
- var _loop_1 = function (matchUp) {
59596
- if (!isObject(matchUp))
59597
- return { value: { error: INVALID_MATCHUP } };
59598
- var matchUpStatus = matchUp.matchUpStatus, matchUpFormat = matchUp.matchUpFormat, matchUpType = matchUp.matchUpType, winningSide = matchUp.winningSide, score = matchUp.score, sides = matchUp.sides;
59599
- if (!sides ||
59600
- !score ||
59601
- matchUpType === TEAM_MATCHUP ||
59602
- matchUpStatus === BYE)
59603
- return "continue";
59604
- var teamParticipantIds_1 = getTeamParticipantIds(sides);
59605
- if (!teamParticipantIds_1.filter(Boolean).length)
59606
- return "continue";
59607
- relevantMatchUps.push(matchUp);
59608
- var setsTally = countSets({
59609
- matchUpStatus: matchUpStatus,
59610
- matchUpFormat: matchUpFormat,
59611
- tallyPolicy: tallyPolicy,
59612
- winningSide: winningSide,
59613
- score: score,
59614
- });
59615
- var gamesTally = countGames({
59616
- matchUpStatus: matchUpStatus,
59617
- matchUpFormat: matchUpFormat,
59618
- tallyPolicy: tallyPolicy,
59619
- winningSide: winningSide,
59620
- score: score,
59621
- });
59622
- var _r = countPoints({
59623
- matchUpFormat: matchUpFormat,
59624
- score: score,
59625
- }), pointsTally = _r.pointsTally, tiebreaksTally = _r.tiebreaksTally;
59626
- teamParticipantIds_1.forEach(function (teamParticipantId, index) {
59627
- if (teamParticipantId) {
59628
- var stats_1 = teamStats.get(teamParticipantId);
59629
- if (stats_1) {
59630
- var teamSumTally = function (stat, tally) {
59631
- return tally.forEach(function (t, i) { return (stats_1[stat][i] += t); });
59632
- };
59633
- var tiebreaks = index
59634
- ? __spreadArray([], __read(tiebreaksTally), false).reverse()
59635
- : tiebreaksTally;
59636
- var points = index ? __spreadArray([], __read(pointsTally), false).reverse() : pointsTally;
59637
- var games = index ? __spreadArray([], __read(gamesTally), false).reverse() : gamesTally;
59638
- var sets = index ? __spreadArray([], __read(setsTally), false).reverse() : setsTally;
59639
- teamSumTally('tiebreaks', tiebreaks);
59640
- teamSumTally('points', points);
59641
- teamSumTally('games', games);
59642
- teamSumTally('sets', sets);
59643
- if (winningSide) {
59644
- var tallyIndex = winningSide - 1 === index ? 0 : 1;
59645
- stats_1.matchUps[tallyIndex] += 1;
59646
- }
59647
- if (matchUpStatus) {
59648
- if (!stats_1.matchUpStatuses[matchUpStatus])
59649
- stats_1.matchUpStatuses[matchUpStatus] = 0;
59650
- stats_1.matchUpStatuses[matchUpStatus] += 1;
59651
- }
59652
- }
59653
- }
59654
- });
59655
- };
59656
- try {
59657
- for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
59658
- var matchUp = matchUps_1_1.value;
59659
- var state_1 = _loop_1(matchUp);
59660
- if (typeof state_1 === "object")
59661
- return state_1.value;
59662
- }
59663
- }
59664
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
59665
- finally {
59666
- try {
59667
- if (matchUps_1_1 && !matchUps_1_1.done && (_c = matchUps_1.return)) _c.call(matchUps_1);
59668
- }
59669
- finally { if (e_2) throw e_2.error; }
59670
- }
59671
- var attrs = ['tiebreaks', 'matchUps', 'points', 'games', 'sets'];
59672
- var ratio = new Map();
59673
- var add = function (a, b) { return (a !== null && a !== void 0 ? a : 0) + (b !== null && b !== void 0 ? b : 0); };
59674
- try {
59675
- for (var _m = __values(teamStats.values()), _o = _m.next(); !_o.done; _o = _m.next()) {
59676
- var stats = _o.value;
59677
- try {
59678
- for (var attrs_1 = (e_4 = void 0, __values(attrs)), attrs_1_1 = attrs_1.next(); !attrs_1_1.done; attrs_1_1 = attrs_1.next()) {
59679
- var attr = attrs_1_1.value;
59680
- var total = stats[attr].reduce(add);
59681
- if (total) {
59682
- var value = stats[attr][0] / total;
59683
- var accessor = "".concat(attr, "Ratio");
59684
- var fixedValue = parseFloat(value.toFixed(2));
59685
- stats[accessor] = fixedValue;
59686
- if (!ratio.has(accessor))
59687
- ratio.set(accessor, []);
59688
- (_k = ratio.get(accessor)) === null || _k === void 0 ? void 0 : _k.push(fixedValue);
59689
- }
59690
- }
59691
- }
59692
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
59693
- finally {
59694
- try {
59695
- if (attrs_1_1 && !attrs_1_1.done && (_e = attrs_1.return)) _e.call(attrs_1);
59696
- }
59697
- finally { if (e_4) throw e_4.error; }
59698
- }
59699
- }
59700
- }
59701
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
59702
- finally {
59703
- try {
59704
- if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
59705
- }
59706
- finally { if (e_3) throw e_3.error; }
59707
- }
59708
- var highLowSort = function (a, b) { return b - a; };
59709
- try {
59710
- for (var _p = __values(teamStats.values()), _q = _p.next(); !_q.done; _q = _p.next()) {
59711
- var stats = _q.value;
59712
- try {
59713
- for (var attrs_2 = (e_6 = void 0, __values(attrs)), attrs_2_1 = attrs_2.next(); !attrs_2_1.done; attrs_2_1 = attrs_2.next()) {
59714
- var attr = attrs_2_1.value;
59715
- var accessor = "".concat(attr, "Ratio");
59716
- if (typeof stats[accessor] === 'number') {
59717
- var index = (_l = ratio
59718
- .get(accessor)) === null || _l === void 0 ? void 0 : _l.sort(highLowSort).indexOf(stats[accessor]);
59719
- if (typeof index === 'number' && index >= 0) {
59720
- var rankAccessor = "".concat(attr, "Rank");
59721
- stats[rankAccessor] = index + 1;
59722
- }
59723
- }
59724
- }
59725
- }
59726
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
59727
- finally {
59728
- try {
59729
- if (attrs_2_1 && !attrs_2_1.done && (_g = attrs_2.return)) _g.call(attrs_2);
59730
- }
59731
- finally { if (e_6) throw e_6.error; }
59732
- }
59733
- }
59734
- }
59735
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
59736
- finally {
59737
- try {
59738
- if (_q && !_q.done && (_f = _p.return)) _f.call(_p);
59739
- }
59740
- finally { if (e_5) throw e_5.error; }
59741
- }
59742
- var result = __assign({ relevantMatchUps: relevantMatchUps }, SUCCESS);
59743
- if (teamParticipantId) {
59744
- result.teamStats = teamStats.get(teamParticipantId);
59745
- if (opponentParticipantId)
59746
- result.opponentStats = teamStats.get(opponentParticipantId);
59747
- }
59748
- else {
59749
- result.allTeamStats = __spreadArray([], __read(teamStats.values()), false);
59750
- }
59751
- return result;
59752
- }
59753
-
59754
59884
  var reportGovernor = {
59755
59885
  getStructureReports: getStructureReports,
59756
59886
  getEntryStatusReports: getEntryStatusReports,
59757
- getTeamStats: getTeamStats,
59887
+ getParticipantStats: getParticipantStats,
59758
59888
  };
59759
59889
 
59760
59890
  function setDrawParticipantRepresentativeIds(_a) {
@@ -65229,17 +65359,18 @@ function getEvents(_a) {
65229
65359
  var _c, _d, _e;
65230
65360
  var processParticipant = function (participant) {
65231
65361
  var e_12, _a;
65232
- var _b, _c, _d, _e, _f;
65233
- if ((_b = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _b === void 0 ? void 0 : _b[eventType]) {
65362
+ var _b, _c, _d, _e, _f, _g, _h;
65363
+ if (((_b = eventsMap[eventId].draws) === null || _b === void 0 ? void 0 : _b[drawId]) &&
65364
+ ((_c = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _c === void 0 ? void 0 : _c[eventType])) {
65234
65365
  try {
65235
- for (var _g = (e_12 = void 0, __values((_d = (_c = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _c === void 0 ? void 0 : _c[eventType]) !== null && _d !== void 0 ? _d : [])), _h = _g.next(); !_h.done; _h = _g.next()) {
65236
- var rating = _h.value;
65366
+ for (var _j = (e_12 = void 0, __values((_e = (_d = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _d === void 0 ? void 0 : _d[eventType]) !== null && _e !== void 0 ? _e : [])), _k = _j.next(); !_k.done; _k = _j.next()) {
65367
+ var rating = _k.value;
65237
65368
  var scaleName = rating.scaleName;
65238
- if (!eventsMap[eventId].draws[drawId].ratings[scaleName])
65369
+ if (!((_f = eventsMap[eventId].draws[drawId]) === null || _f === void 0 ? void 0 : _f.ratings[scaleName]))
65239
65370
  eventsMap[eventId].draws[drawId].ratings[scaleName] = [];
65240
- var accessor = (_e = ratingsParameters[scaleName]) === null || _e === void 0 ? void 0 : _e.accessor;
65371
+ var accessor = (_g = ratingsParameters[scaleName]) === null || _g === void 0 ? void 0 : _g.accessor;
65241
65372
  if (accessor) {
65242
- var value = parseFloat((_f = rating.scaleValue) === null || _f === void 0 ? void 0 : _f[accessor]);
65373
+ var value = parseFloat((_h = rating.scaleValue) === null || _h === void 0 ? void 0 : _h[accessor]);
65243
65374
  if (value) {
65244
65375
  eventsMap[eventId].draws[drawId].ratings[scaleName].push(value);
65245
65376
  }
@@ -65249,7 +65380,7 @@ function getEvents(_a) {
65249
65380
  catch (e_12_1) { e_12 = { error: e_12_1 }; }
65250
65381
  finally {
65251
65382
  try {
65252
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
65383
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
65253
65384
  }
65254
65385
  finally { if (e_12) throw e_12.error; }
65255
65386
  }