feat: enhance auction interactions and player statistics UI
This commit is contained in:
1 parent
6c582ba3cf
commit
be4de61bb7
115 files changed
+13292
-2871
No files matched your search
@@ -45,6 +45,7 @@ import {
|
||||
MatchStatsUserRecordFragment,
|
||||
} from './match-stats.repository';
|
||||
import { MatchStatsService } from './match-stats.service';
|
||||
import { presentStatsCard, statsDate } from './internal-stats-presentation';
|
||||
import {
|
||||
InternalGameDetail,
|
||||
InternalRecord,
|
||||
@@ -55,7 +56,7 @@ const DEFAULT_LIST_LIMIT = 20;
|
||||
const MAX_LIST_LIMIT = 50;
|
||||
const MAX_MATCH_SCAN = 300;
|
||||
const MIN_HIGHLIGHT_GAMES = 5;
|
||||
const MATCH_DETAIL_RESPONSE_CACHE_VERSION = 8;
|
||||
const MATCH_DETAIL_RESPONSE_CACHE_VERSION = 9;
|
||||
const INCOMPLETE_MATCH_DETAIL_TTL_SECONDS = 60;
|
||||
|
||||
interface CommunityStatsContext {
|
||||
@@ -139,6 +140,7 @@ export class CommunityStatsService {
|
||||
'projection.formatType': 1,
|
||||
'projection.outcome': 1,
|
||||
'projection.series': 1,
|
||||
'projection.games': 1,
|
||||
})
|
||||
.lean()
|
||||
.exec();
|
||||
@@ -148,6 +150,9 @@ export class CommunityStatsService {
|
||||
this.presentOfficialResult(competition),
|
||||
]),
|
||||
);
|
||||
const sources = new Map(
|
||||
competitions.map((source) => [source.matchId.toString(), source]),
|
||||
);
|
||||
return {
|
||||
...pagination,
|
||||
matches: cards.map(({ card, sourceCompetitionId, sourceRevision }) => {
|
||||
@@ -161,10 +166,20 @@ export class CommunityStatsService {
|
||||
(resultPresentation.type === 'official' &&
|
||||
sourceCompetitionId === resultPresentation.competitionId &&
|
||||
sourceRevision === resultPresentation.sourceRevision);
|
||||
return {
|
||||
const presented = {
|
||||
...(canUseGames ? card : this.adjustCardForRange(card, [])),
|
||||
resultPresentation,
|
||||
};
|
||||
const source = sources.get(card.matchId);
|
||||
return source && canUseGames
|
||||
? presentStatsCard(
|
||||
presented,
|
||||
presentCompetitionDetail({
|
||||
...source,
|
||||
teams: source.teams.map((team) => ({ ...team, members: [] })),
|
||||
}),
|
||||
)
|
||||
: presented;
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -192,7 +207,24 @@ export class CommunityStatsService {
|
||||
return {
|
||||
cards: visible.map((fragment) => ({
|
||||
card: this.adjustCardForRange(
|
||||
fragment.matchCard as unknown as InternalMatchCardView,
|
||||
{
|
||||
...(fragment.matchCard as unknown as InternalMatchCardView),
|
||||
games: (
|
||||
fragment.matchCard as unknown as InternalMatchCardView
|
||||
).games.map((game) => {
|
||||
const detail = fragment.gameDetails?.find(
|
||||
(item) => item.gameNumber === game.gameNumber,
|
||||
);
|
||||
return {
|
||||
...game,
|
||||
analysisAvailability: !detail
|
||||
? ('pending' as const)
|
||||
: detail.rawAvailable === false
|
||||
? ('missing' as const)
|
||||
: ('available' as const),
|
||||
};
|
||||
}),
|
||||
},
|
||||
(fragment.gameDetails ?? []).filter((game) =>
|
||||
this.isGameInRange(game.gameCreation, context),
|
||||
),
|
||||
@@ -226,6 +258,7 @@ export class CommunityStatsService {
|
||||
const records = this.applyChampionFilter(dataset.records, filters);
|
||||
response = {
|
||||
rows: this.buildLeaderboardRows(records),
|
||||
lane: filters.lane,
|
||||
season: dataset.season,
|
||||
};
|
||||
await this.cacheService.set(key, response);
|
||||
@@ -275,6 +308,7 @@ export class CommunityStatsService {
|
||||
|
||||
const response: TeamInsightsResponse = {
|
||||
season: dataset.season,
|
||||
totals: dataset.totals,
|
||||
sideWinRate: {
|
||||
blue: this.percent(blueWins, blueGames),
|
||||
red: this.percent(redWins, redGames),
|
||||
@@ -464,7 +498,18 @@ export class CommunityStatsService {
|
||||
}
|
||||
}
|
||||
const response: InternalMatchDetailResponse = {
|
||||
match,
|
||||
match: presentStatsCard(
|
||||
{
|
||||
...match,
|
||||
games: (match.games ?? []).map((game) => ({
|
||||
...game,
|
||||
analysisAvailability:
|
||||
games.find((linked) => linked.game.gameNumber === game.gameNumber)
|
||||
?.analysisAvailability ?? 'pending',
|
||||
})),
|
||||
},
|
||||
dataset.competition,
|
||||
),
|
||||
competition: dataset.competition,
|
||||
games: games.map(({ game, official, analysisAvailability }) => ({
|
||||
gameNumber: game.gameNumber,
|
||||
@@ -708,11 +753,24 @@ export class CommunityStatsService {
|
||||
});
|
||||
const gameDetails: Array<Pick<InternalGameDetail, 'winnerSide'>> = [];
|
||||
const records: InternalRecord[] = [];
|
||||
const participants = new Set<string>();
|
||||
let matches = 0,
|
||||
analyzedGames = 0;
|
||||
for (const fragment of fragments) {
|
||||
const games = fragment.gameDetails.filter((game) =>
|
||||
this.isGameInRange(game.gameCreation, context),
|
||||
);
|
||||
const gameNumbers = new Set(games.map(({ gameNumber }) => gameNumber));
|
||||
if (games.length) matches += 1;
|
||||
const gameNumbers = new Set(
|
||||
games
|
||||
.filter((game) => game.rawAvailable !== false)
|
||||
.map(({ gameNumber }) => gameNumber),
|
||||
);
|
||||
analyzedGames += gameNumbers.size;
|
||||
const allNumbers = new Set(games.map((game) => game.gameNumber));
|
||||
fragment.records
|
||||
.filter((record) => allNumbers.has(record.gameNumber))
|
||||
.forEach((record) => participants.add(record.userId));
|
||||
gameDetails.push(...games);
|
||||
records.push(
|
||||
...fragment.records.filter(({ gameNumber }) =>
|
||||
@@ -720,7 +778,17 @@ export class CommunityStatsService {
|
||||
),
|
||||
);
|
||||
}
|
||||
return { season: context.season, records, gameDetails };
|
||||
return {
|
||||
season: context.season,
|
||||
records,
|
||||
gameDetails,
|
||||
totals: {
|
||||
matches,
|
||||
games: gameDetails.length,
|
||||
analyzedGames,
|
||||
players: participants.size,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async buildBaseDataset(
|
||||
@@ -850,7 +918,8 @@ export class CommunityStatsService {
|
||||
userId: params.userId,
|
||||
fromGameCreation: context.from?.getTime(),
|
||||
toGameCreation: context.to?.getTime(),
|
||||
limit: MAX_MATCH_SCAN,
|
||||
// The inspector needs the latest 20 of each lane, even in older events.
|
||||
limit: params.filters.includePositionCounts ? 0 : MAX_MATCH_SCAN,
|
||||
};
|
||||
let fragments =
|
||||
await this.matchStatsRepository.findUserRecordFragments(fragmentQuery);
|
||||
@@ -885,8 +954,31 @@ export class CommunityStatsService {
|
||||
};
|
||||
const response: UserInternalHistoryResponse = {
|
||||
season: context.season,
|
||||
...(params.filters.includePositionCounts
|
||||
? {
|
||||
positionCounts: Object.fromEntries(
|
||||
['ALL', 'TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY'].map(
|
||||
(lane) => [
|
||||
lane,
|
||||
Math.min(
|
||||
20,
|
||||
this.applyChampionFilter(allUserRecords, {
|
||||
championId: params.filters.championId,
|
||||
}).filter(
|
||||
(record) =>
|
||||
lane === 'ALL' || record.teamPosition === lane,
|
||||
).length,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
playerStats: records.length
|
||||
? this.toLeaderboardRow(userId, records)
|
||||
: null,
|
||||
championStats: this.buildUserChampionStats(
|
||||
allUserRecords,
|
||||
this.applyChampionFilter(allUserRecords, { lane: params.filters.lane }),
|
||||
context.season,
|
||||
),
|
||||
summary: this.buildUserSummary(records, visible.length || limit),
|
||||
@@ -913,6 +1005,11 @@ export class CommunityStatsService {
|
||||
fragment.records.filter(
|
||||
(record) =>
|
||||
record.userId === userId &&
|
||||
!fragment.gameDetails?.some(
|
||||
(game) =>
|
||||
game.gameNumber === record.gameNumber &&
|
||||
game.rawAvailable === false,
|
||||
) &&
|
||||
this.isGameInRange(record.gameCreation, context),
|
||||
),
|
||||
)
|
||||
@@ -1129,13 +1226,13 @@ export class CommunityStatsService {
|
||||
const community = await CommunityModel.findById(communityId).exec();
|
||||
if (!community) throw new NotFoundException('Community not found.');
|
||||
const season = this.resolveSeason(community, filters.seasonId);
|
||||
const from = filters.from
|
||||
? new Date(filters.from)
|
||||
let from = filters.from
|
||||
? statsDate(filters.from, false)
|
||||
: season.startedAt
|
||||
? new Date(season.startedAt)
|
||||
: null;
|
||||
const to = filters.to
|
||||
? new Date(filters.to)
|
||||
let to = filters.to
|
||||
? statsDate(filters.to, true)
|
||||
: season.endedAt
|
||||
? new Date(season.endedAt)
|
||||
: null;
|
||||
@@ -1148,6 +1245,11 @@ export class CommunityStatsService {
|
||||
if (from && to && from.getTime() > to.getTime()) {
|
||||
throw new BadRequestException('Invalid date range.');
|
||||
}
|
||||
// A date filter narrows the selected season; it never escapes it.
|
||||
if (season.startedAt && (!from || from < new Date(season.startedAt)))
|
||||
from = new Date(season.startedAt);
|
||||
if (season.endedAt && (!to || to > new Date(season.endedAt)))
|
||||
to = new Date(season.endedAt);
|
||||
return { community, season, from, to };
|
||||
}
|
||||
|
||||
@@ -1419,6 +1521,7 @@ export class CommunityStatsService {
|
||||
return {
|
||||
matchId: record.riotMatchId,
|
||||
internalMatchId: record.matchId,
|
||||
internalMatchTitle: record.title,
|
||||
gameNumber: record.gameNumber,
|
||||
queueId: 0,
|
||||
queueLabel: '내전',
|
||||
@@ -1443,6 +1546,7 @@ export class CommunityStatsService {
|
||||
wardsPlaced: record.wardsPlaced,
|
||||
wardsKilled: record.wardsKilled,
|
||||
damageDealtToChampions: record.damageDealtToChampions,
|
||||
damageShare: record.damageShare,
|
||||
damageTaken: record.damageTaken,
|
||||
goldEarned: record.gold,
|
||||
items: record.items,
|
||||
@@ -1493,8 +1597,11 @@ export class CommunityStatsService {
|
||||
records: InternalRecord[],
|
||||
filters: CommunityStatsFilters,
|
||||
): InternalRecord[] {
|
||||
if (!filters.championId) return records;
|
||||
return records.filter((record) => record.championId === filters.championId);
|
||||
return records.filter(
|
||||
(record) =>
|
||||
(!filters.championId || record.championId === filters.championId) &&
|
||||
(!filters.lane || record.teamPosition === filters.lane),
|
||||
);
|
||||
}
|
||||
|
||||
private isGameInRange(
|
||||
@@ -1533,6 +1640,8 @@ export class CommunityStatsService {
|
||||
summonerName: record.summonerName,
|
||||
championId: record.championId,
|
||||
matchId: record.riotMatchId,
|
||||
internalMatchId: record.matchId,
|
||||
gameNumber: record.gameNumber,
|
||||
isSingleGame: true,
|
||||
};
|
||||
}
|
||||
@@ -1621,7 +1730,7 @@ export class CommunityStatsService {
|
||||
cacheScope,
|
||||
JSON.stringify([
|
||||
MATCH_STATS_BUILDER_VERSION,
|
||||
scope === 'matches' ? 'matches-page-v1' : scope,
|
||||
`${scope}:presentation-v2`,
|
||||
filters.seasonId ?? 'current',
|
||||
filters.from ?? '',
|
||||
filters.to ?? '',
|
||||
@@ -1632,6 +1741,8 @@ export class CommunityStatsService {
|
||||
filters.format ?? '',
|
||||
filters.playerId ?? '',
|
||||
filters.cursorMatchId ?? '',
|
||||
filters.lane ?? '',
|
||||
...(filters.includePositionCounts ? ['position-windows-v1'] : []),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user