tods-competition-factory 1.8.16 → 1.8.17

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.17';
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;
@@ -59252,6 +59252,425 @@ function getEntryStatusReports(_a) {
59252
59252
  };
59253
59253
  }
59254
59254
 
59255
+ function getParticipantStats(_a) {
59256
+ var e_1, _b, e_2, _c, e_3, _d, e_4, _e, e_5, _f, e_6, _g, e_7, _h;
59257
+ var _j, _k, _l, _m, _o, _p;
59258
+ var withCompetitiveProfiles = _a.withCompetitiveProfiles, opponentParticipantId = _a.opponentParticipantId, withIndividualStats = _a.withIndividualStats, teamParticipantId = _a.teamParticipantId, tournamentRecord = _a.tournamentRecord, tallyPolicy = _a.tallyPolicy, matchUps = _a.matchUps;
59259
+ if (!tournamentRecord)
59260
+ return { error: MISSING_TOURNAMENT_RECORD };
59261
+ if (matchUps && !Array.isArray(matchUps))
59262
+ return { error: INVALID_MATCHUP };
59263
+ matchUps = matchUps || allTournamentMatchUps({ tournamentRecord: tournamentRecord }).matchUps;
59264
+ if (!(matchUps === null || matchUps === void 0 ? void 0 : matchUps.length))
59265
+ return { error: MISSING_MATCHUPS };
59266
+ var teamParticipantIds = [];
59267
+ if (opponentParticipantId)
59268
+ teamParticipantIds.push(opponentParticipantId);
59269
+ if (teamParticipantId)
59270
+ teamParticipantIds.push(teamParticipantId);
59271
+ var participantFilters = !teamParticipantIds.length
59272
+ ? { participantTypes: [TEAM_PARTICIPANT] }
59273
+ : { participantIds: teamParticipantIds };
59274
+ var teamParticipants = (_j = getParticipants$1({ participantFilters: participantFilters, tournamentRecord: tournamentRecord }).participants) !== null && _j !== void 0 ? _j : [];
59275
+ if (!teamParticipants.every(function (_a) {
59276
+ var participantType = _a.participantType;
59277
+ return participantType === TEAM_PARTICIPANT;
59278
+ })) {
59279
+ return { error: INVALID_PARTICIPANT_IDS };
59280
+ }
59281
+ if (!teamParticipantIds.length)
59282
+ teamParticipantIds.push.apply(teamParticipantIds, __spreadArray([], __read(teamParticipants.map(extractAttributes('participantId'))), false));
59283
+ var participantStats = new Map();
59284
+ var participantNameMap = new Map();
59285
+ var participating = new Map();
59286
+ var teamMap = new Map();
59287
+ var initStats = function (participantId, participantName) {
59288
+ if (participantName === void 0) { participantName = ''; }
59289
+ return participantStats.get(participantId) ||
59290
+ (participantStats.set(participantId, {
59291
+ participantName: participantName,
59292
+ participantId: participantId,
59293
+ competitorIds: [],
59294
+ competitiveness: {},
59295
+ matchUpStatuses: {},
59296
+ tiebreaks: [0, 0],
59297
+ matchUps: [0, 0],
59298
+ points: [0, 0],
59299
+ games: [0, 0],
59300
+ sets: [0, 0],
59301
+ }) &&
59302
+ participantStats.get(participantId));
59303
+ };
59304
+ try {
59305
+ for (var teamParticipants_1 = __values(teamParticipants), teamParticipants_1_1 = teamParticipants_1.next(); !teamParticipants_1_1.done; teamParticipants_1_1 = teamParticipants_1.next()) {
59306
+ var teamParticipant = teamParticipants_1_1.value;
59307
+ var participantId = teamParticipant.participantId, individualParticipantIds = teamParticipant.individualParticipantIds;
59308
+ teamMap.set(participantId, individualParticipantIds !== null && individualParticipantIds !== void 0 ? individualParticipantIds : []);
59309
+ initStats(participantId, teamParticipant.participantName);
59310
+ }
59311
+ }
59312
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59313
+ finally {
59314
+ try {
59315
+ if (teamParticipants_1_1 && !teamParticipants_1_1.done && (_b = teamParticipants_1.return)) _b.call(teamParticipants_1);
59316
+ }
59317
+ finally { if (e_1) throw e_1.error; }
59318
+ }
59319
+ if (teamParticipantId && !teamMap.get(teamParticipantId))
59320
+ return decorateResult({
59321
+ result: { error: PARTICIPANT_NOT_FOUND },
59322
+ context: { teamParticipantId: teamParticipantId },
59323
+ });
59324
+ if (opponentParticipantId && !teamMap.get(opponentParticipantId))
59325
+ return decorateResult({
59326
+ result: { error: PARTICIPANT_NOT_FOUND },
59327
+ context: { opponentParticipantId: opponentParticipantId },
59328
+ });
59329
+ var relevantMatchUps = [];
59330
+ var getSideParticipantIds = function (sides) {
59331
+ var e_8, _a, e_9, _b, e_10, _c;
59332
+ var _d;
59333
+ var sideParticipantIds = [[], []];
59334
+ try {
59335
+ for (var sides_1 = __values(sides), sides_1_1 = sides_1.next(); !sides_1_1.done; sides_1_1 = sides_1.next()) {
59336
+ var side = sides_1_1.value;
59337
+ if ((_d = side.participant) === null || _d === void 0 ? void 0 : _d.participantName)
59338
+ participantNameMap.set(side.participant.participantId, side.participant.participantName);
59339
+ }
59340
+ }
59341
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
59342
+ finally {
59343
+ try {
59344
+ if (sides_1_1 && !sides_1_1.done && (_a = sides_1.return)) _a.call(sides_1);
59345
+ }
59346
+ finally { if (e_8) throw e_8.error; }
59347
+ }
59348
+ var getCompetitorIds = function (_a) {
59349
+ var _b, _c, _d, _e, _f;
59350
+ var side = _a.side, individualParticipantIds = _a.individualParticipantIds;
59351
+ return ((side.participantId &&
59352
+ (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) ||
59353
+ individualParticipantIds.includes(side.participantId)) && [
59354
+ side.participantId,
59355
+ ]) ||
59356
+ (((_c = (_b = side.participant) === null || _b === void 0 ? void 0 : _b.individualParticipantIds) === null || _c === void 0 ? void 0 : _c.length) &&
59357
+ (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) ||
59358
+ 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)) &&
59359
+ side.participant.individualParticipantIds));
59360
+ };
59361
+ if (teamMap.size) {
59362
+ var processSides = function (thisTeamId, individualParticipantIds) {
59363
+ var e_11, _a, e_12, _b;
59364
+ try {
59365
+ for (var sides_3 = __values(sides), sides_3_1 = sides_3.next(); !sides_3_1.done; sides_3_1 = sides_3.next()) {
59366
+ var side = sides_3_1.value;
59367
+ if (!side.participant)
59368
+ continue;
59369
+ var competitorIds = getCompetitorIds({
59370
+ individualParticipantIds: individualParticipantIds,
59371
+ side: side,
59372
+ });
59373
+ if (competitorIds === null || competitorIds === void 0 ? void 0 : competitorIds.length) {
59374
+ var sideNumber = side.sideNumber;
59375
+ if (!sideNumber)
59376
+ continue;
59377
+ var ids = [thisTeamId];
59378
+ if (withIndividualStats)
59379
+ ids.push.apply(ids, __spreadArray([], __read(competitorIds), false));
59380
+ sideParticipantIds[sideNumber - 1] = ids;
59381
+ var stats = participantStats.get(thisTeamId);
59382
+ try {
59383
+ for (var _c = (e_12 = void 0, __values(competitorIds.filter(Boolean))), _d = _c.next(); !_d.done; _d = _c.next()) {
59384
+ var id = _d.value;
59385
+ if (stats && !stats.competitorIds.includes(id))
59386
+ stats.competitorIds.push(id);
59387
+ }
59388
+ }
59389
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
59390
+ finally {
59391
+ try {
59392
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
59393
+ }
59394
+ finally { if (e_12) throw e_12.error; }
59395
+ }
59396
+ }
59397
+ }
59398
+ }
59399
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
59400
+ finally {
59401
+ try {
59402
+ if (sides_3_1 && !sides_3_1.done && (_a = sides_3.return)) _a.call(sides_3);
59403
+ }
59404
+ finally { if (e_11) throw e_11.error; }
59405
+ }
59406
+ };
59407
+ if (teamParticipantId) {
59408
+ var processForTeam = !opponentParticipantId ||
59409
+ sides.every(function (side) {
59410
+ side.participant &&
59411
+ (getCompetitorIds({
59412
+ side: side,
59413
+ individualParticipantIds: teamMap.get(teamParticipantId),
59414
+ }) ||
59415
+ getCompetitorIds({
59416
+ side: side,
59417
+ individualParticipantIds: teamMap.get(opponentParticipantId),
59418
+ }));
59419
+ });
59420
+ if (processForTeam)
59421
+ processSides(teamParticipantId, teamMap.get(teamParticipantId));
59422
+ }
59423
+ else {
59424
+ try {
59425
+ for (var teamMap_1 = __values(teamMap), teamMap_1_1 = teamMap_1.next(); !teamMap_1_1.done; teamMap_1_1 = teamMap_1.next()) {
59426
+ var _e = __read(teamMap_1_1.value, 2), thisTeamId = _e[0], individualParticipantIds = _e[1];
59427
+ processSides(thisTeamId, individualParticipantIds);
59428
+ }
59429
+ }
59430
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
59431
+ finally {
59432
+ try {
59433
+ if (teamMap_1_1 && !teamMap_1_1.done && (_b = teamMap_1.return)) _b.call(teamMap_1);
59434
+ }
59435
+ finally { if (e_9) throw e_9.error; }
59436
+ }
59437
+ }
59438
+ }
59439
+ else if (withIndividualStats) {
59440
+ try {
59441
+ // no teams so process individuals
59442
+ for (var sides_2 = __values(sides), sides_2_1 = sides_2.next(); !sides_2_1.done; sides_2_1 = sides_2.next()) {
59443
+ var side = sides_2_1.value;
59444
+ if (!side.participant)
59445
+ continue;
59446
+ var competitorIds = getCompetitorIds({
59447
+ individualParticipantIds: [],
59448
+ side: side,
59449
+ });
59450
+ var sideNumber = side.sideNumber;
59451
+ if (!sideNumber)
59452
+ continue;
59453
+ sideParticipantIds[sideNumber - 1] = competitorIds;
59454
+ }
59455
+ }
59456
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
59457
+ finally {
59458
+ try {
59459
+ if (sides_2_1 && !sides_2_1.done && (_c = sides_2.return)) _c.call(sides_2);
59460
+ }
59461
+ finally { if (e_10) throw e_10.error; }
59462
+ }
59463
+ }
59464
+ return sideParticipantIds;
59465
+ };
59466
+ var _loop_1 = function (matchUp) {
59467
+ if (!isObject(matchUp))
59468
+ return { value: { error: INVALID_MATCHUP } };
59469
+ var matchUpStatus = matchUp.matchUpStatus, matchUpFormat = matchUp.matchUpFormat, matchUpType = matchUp.matchUpType, winningSide = matchUp.winningSide, score = matchUp.score, sides = matchUp.sides;
59470
+ if (!sides ||
59471
+ !score ||
59472
+ matchUpType === TEAM_MATCHUP ||
59473
+ matchUpStatus === BYE)
59474
+ return "continue";
59475
+ var sideParticipantIds = getSideParticipantIds(sides);
59476
+ if (!sideParticipantIds.filter(Boolean).length)
59477
+ return "continue";
59478
+ var competitiveness = withCompetitiveProfiles &&
59479
+ winningSide &&
59480
+ ((_k = getMatchUpCompetitiveProfile({ matchUp: matchUp })) === null || _k === void 0 ? void 0 : _k.competitiveness);
59481
+ relevantMatchUps.push(matchUp);
59482
+ var setsTally = countSets({
59483
+ matchUpStatus: matchUpStatus,
59484
+ matchUpFormat: matchUpFormat,
59485
+ tallyPolicy: tallyPolicy,
59486
+ winningSide: winningSide,
59487
+ score: score,
59488
+ });
59489
+ var gamesTally = countGames({
59490
+ matchUpStatus: matchUpStatus,
59491
+ matchUpFormat: matchUpFormat,
59492
+ tallyPolicy: tallyPolicy,
59493
+ winningSide: winningSide,
59494
+ score: score,
59495
+ });
59496
+ var _v = countPoints({
59497
+ matchUpFormat: matchUpFormat,
59498
+ score: score,
59499
+ }), pointsTally = _v.pointsTally, tiebreaksTally = _v.tiebreaksTally;
59500
+ sideParticipantIds.forEach(function (ids, index) {
59501
+ var e_13, _a;
59502
+ var _loop_2 = function (id) {
59503
+ var stats = initStats(id, participantNameMap.get(id));
59504
+ if (stats) {
59505
+ var teamSumTally = function (stat, tally) {
59506
+ return tally.forEach(function (t, i) { return (stats[stat][i] += t); });
59507
+ };
59508
+ var tiebreaks = index
59509
+ ? __spreadArray([], __read(tiebreaksTally), false).reverse()
59510
+ : tiebreaksTally;
59511
+ var points = index ? __spreadArray([], __read(pointsTally), false).reverse() : pointsTally;
59512
+ var games = index ? __spreadArray([], __read(gamesTally), false).reverse() : gamesTally;
59513
+ var sets = index ? __spreadArray([], __read(setsTally), false).reverse() : setsTally;
59514
+ teamSumTally('tiebreaks', tiebreaks);
59515
+ teamSumTally('points', points);
59516
+ teamSumTally('games', games);
59517
+ teamSumTally('sets', sets);
59518
+ if (winningSide) {
59519
+ var tallyIndex = winningSide - 1 === index ? 0 : 1;
59520
+ stats.matchUps[tallyIndex] += 1;
59521
+ }
59522
+ if (competitiveness) {
59523
+ var attr = competitiveness.toLowerCase();
59524
+ if (!stats.competitiveness[attr])
59525
+ stats.competitiveness[attr] = [0, 0];
59526
+ stats.competitiveness[attr][index] += 1;
59527
+ }
59528
+ if (matchUpStatus) {
59529
+ var attr = matchUpStatus.toLowerCase();
59530
+ if (!stats.matchUpStatuses[attr])
59531
+ stats.matchUpStatuses[attr] = 0;
59532
+ stats.matchUpStatuses[attr] += 1;
59533
+ }
59534
+ }
59535
+ };
59536
+ try {
59537
+ 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()) {
59538
+ var id = ids_1_1.value;
59539
+ _loop_2(id);
59540
+ }
59541
+ }
59542
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
59543
+ finally {
59544
+ try {
59545
+ if (ids_1_1 && !ids_1_1.done && (_a = ids_1.return)) _a.call(ids_1);
59546
+ }
59547
+ finally { if (e_13) throw e_13.error; }
59548
+ }
59549
+ });
59550
+ };
59551
+ try {
59552
+ for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
59553
+ var matchUp = matchUps_1_1.value;
59554
+ var state_1 = _loop_1(matchUp);
59555
+ if (typeof state_1 === "object")
59556
+ return state_1.value;
59557
+ }
59558
+ }
59559
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
59560
+ finally {
59561
+ try {
59562
+ if (matchUps_1_1 && !matchUps_1_1.done && (_c = matchUps_1.return)) _c.call(matchUps_1);
59563
+ }
59564
+ finally { if (e_2) throw e_2.error; }
59565
+ }
59566
+ var statsattributes = ['tiebreaks', 'matchUps', 'points', 'games', 'sets'];
59567
+ var competitivenessAttributes = ['competitive', 'routine', 'decisive'];
59568
+ var ratio = new Map();
59569
+ var add = function (a, b) { return (a !== null && a !== void 0 ? a : 0) + (b !== null && b !== void 0 ? b : 0); };
59570
+ try {
59571
+ for (var _q = __values(participantStats.entries()), _r = _q.next(); !_r.done; _r = _q.next()) {
59572
+ var _s = __read(_r.value, 2), participantId = _s[0], stats = _s[1];
59573
+ try {
59574
+ 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()) {
59575
+ var attr = statsattributes_1_1.value;
59576
+ var total = stats[attr].reduce(add);
59577
+ if (total) {
59578
+ var value = stats[attr][0] / total;
59579
+ var accessor = "".concat(attr, "Ratio");
59580
+ var fixedValue = parseFloat(value.toFixed(2));
59581
+ stats[accessor] = fixedValue;
59582
+ participating.set(participantId, true);
59583
+ if (!ratio.has(accessor))
59584
+ ratio.set(accessor, []);
59585
+ (_l = ratio.get(accessor)) === null || _l === void 0 ? void 0 : _l.push(fixedValue);
59586
+ }
59587
+ }
59588
+ }
59589
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
59590
+ finally {
59591
+ try {
59592
+ if (statsattributes_1_1 && !statsattributes_1_1.done && (_e = statsattributes_1.return)) _e.call(statsattributes_1);
59593
+ }
59594
+ finally { if (e_4) throw e_4.error; }
59595
+ }
59596
+ try {
59597
+ 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()) {
59598
+ var attr = competitivenessAttributes_1_1.value;
59599
+ var total = (_o = (_m = stats.competitiveness) === null || _m === void 0 ? void 0 : _m[attr]) === null || _o === void 0 ? void 0 : _o.reduce(add);
59600
+ if (total) {
59601
+ var value = stats.competitiveness[attr][0] / total;
59602
+ var accessor = "".concat(attr, "Ratio");
59603
+ var fixedValue = parseFloat(value.toFixed(2));
59604
+ stats[accessor] = fixedValue;
59605
+ }
59606
+ }
59607
+ }
59608
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
59609
+ finally {
59610
+ try {
59611
+ if (competitivenessAttributes_1_1 && !competitivenessAttributes_1_1.done && (_f = competitivenessAttributes_1.return)) _f.call(competitivenessAttributes_1);
59612
+ }
59613
+ finally { if (e_5) throw e_5.error; }
59614
+ }
59615
+ }
59616
+ }
59617
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
59618
+ finally {
59619
+ try {
59620
+ if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
59621
+ }
59622
+ finally { if (e_3) throw e_3.error; }
59623
+ }
59624
+ if (!teamParticipantId) {
59625
+ var highLowSort = function (a, b) { return b - a; };
59626
+ try {
59627
+ for (var _t = __values(participantStats.values()), _u = _t.next(); !_u.done; _u = _t.next()) {
59628
+ var stats = _u.value;
59629
+ try {
59630
+ 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()) {
59631
+ var attr = statsattributes_2_1.value;
59632
+ // now rank each team by their ratio on each attribute
59633
+ var accessor = "".concat(attr, "Ratio");
59634
+ if (typeof stats[accessor] === 'number') {
59635
+ var index = (_p = ratio
59636
+ .get(accessor)) === null || _p === void 0 ? void 0 : _p.sort(highLowSort).indexOf(stats[accessor]);
59637
+ if (typeof index === 'number' && index >= 0) {
59638
+ var rankAccessor = "".concat(attr, "Rank");
59639
+ stats[rankAccessor] = index + 1;
59640
+ }
59641
+ }
59642
+ }
59643
+ }
59644
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
59645
+ finally {
59646
+ try {
59647
+ if (statsattributes_2_1 && !statsattributes_2_1.done && (_h = statsattributes_2.return)) _h.call(statsattributes_2);
59648
+ }
59649
+ finally { if (e_7) throw e_7.error; }
59650
+ }
59651
+ }
59652
+ }
59653
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
59654
+ finally {
59655
+ try {
59656
+ if (_u && !_u.done && (_g = _t.return)) _g.call(_t);
59657
+ }
59658
+ finally { if (e_6) throw e_6.error; }
59659
+ }
59660
+ }
59661
+ var result = __assign({ relevantMatchUps: relevantMatchUps }, SUCCESS);
59662
+ if (teamParticipantId) {
59663
+ result.teamStats = participantStats.get(teamParticipantId);
59664
+ if (opponentParticipantId)
59665
+ result.opponentStats = participantStats.get(opponentParticipantId);
59666
+ }
59667
+ else {
59668
+ result.participatingTeamsCount = participating.size;
59669
+ }
59670
+ result.allParticipantStats = __spreadArray([], __read(participantStats.values()), false);
59671
+ return result;
59672
+ }
59673
+
59255
59674
  function getAvgWTN(_a) {
59256
59675
  var eventType = _a.eventType, matchUps = _a.matchUps, eventId = _a.eventId, drawId = _a.drawId;
59257
59676
  var matchUpFormatCounts = {};
@@ -59463,298 +59882,10 @@ function getPositionManipulations(_a) {
59463
59882
  })) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.slice(1);
59464
59883
  }
59465
59884
 
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
59885
  var reportGovernor = {
59755
59886
  getStructureReports: getStructureReports,
59756
59887
  getEntryStatusReports: getEntryStatusReports,
59757
- getTeamStats: getTeamStats,
59888
+ getParticipantStats: getParticipantStats,
59758
59889
  };
59759
59890
 
59760
59891
  function setDrawParticipantRepresentativeIds(_a) {