.
This commit is contained in:
1 parent
4baea89f89
commit
fd386ed202
32 files changed
+1128
-601
No files matched your search
@@ -9,6 +9,7 @@ import { ConnectionService } from '../global/database/connection.service';
|
||||
import {
|
||||
Match,
|
||||
MatchDocument,
|
||||
MatchSeriesResult,
|
||||
MatchStatus,
|
||||
PositionPreference,
|
||||
TierInfo,
|
||||
@@ -99,15 +100,7 @@ export class MatchService {
|
||||
(left, right) => left.gameNumber - right.gameNumber,
|
||||
);
|
||||
if (!obj.result.seriesResults?.length) {
|
||||
obj.result.seriesResults = [
|
||||
{
|
||||
blueGroupIndex: 1,
|
||||
redGroupIndex: 1,
|
||||
blueScore: obj.result.blueScore ?? 0,
|
||||
redScore: obj.result.redScore ?? 0,
|
||||
winnerSide: obj.result.winnerSide,
|
||||
},
|
||||
];
|
||||
obj.result.seriesResults = this.buildSeriesResults(obj.result.games);
|
||||
}
|
||||
}
|
||||
return {
|
||||
@@ -120,7 +113,6 @@ export class MatchService {
|
||||
})),
|
||||
teams: (obj.teams ?? []).map((team) => ({
|
||||
...team,
|
||||
groupIndex: team.groupIndex ?? 1,
|
||||
})),
|
||||
tournamentCodes: await this.tournamentCodeService.buildSlots(match),
|
||||
};
|
||||
@@ -239,4 +231,33 @@ export class MatchService {
|
||||
fetchedAt: tier.fetchedAt,
|
||||
};
|
||||
}
|
||||
|
||||
private buildSeriesResults(
|
||||
games: NonNullable<Match['result']>['games'],
|
||||
): MatchSeriesResult[] {
|
||||
const bySeries = new Map<string, MatchSeriesResult>();
|
||||
for (const game of games) {
|
||||
const teamAIndex = Math.min(game.blueTeamIndex, game.redTeamIndex);
|
||||
const teamBIndex = Math.max(game.blueTeamIndex, game.redTeamIndex);
|
||||
const key = `${teamAIndex}:${teamBIndex}`;
|
||||
const current =
|
||||
bySeries.get(key) ??
|
||||
({
|
||||
teamAIndex,
|
||||
teamBIndex,
|
||||
teamAWins: 0,
|
||||
teamBWins: 0,
|
||||
} satisfies MatchSeriesResult);
|
||||
if (game.winnerTeamIndex === teamAIndex) current.teamAWins += 1;
|
||||
if (game.winnerTeamIndex === teamBIndex) current.teamBWins += 1;
|
||||
current.winnerTeamIndex =
|
||||
current.teamAWins > current.teamBWins
|
||||
? teamAIndex
|
||||
: current.teamBWins > current.teamAWins
|
||||
? teamBIndex
|
||||
: undefined;
|
||||
bySeries.set(key, current);
|
||||
}
|
||||
return [...bySeries.values()];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user