feat: enrich internal match game analysis

This commit is contained in:
dahyeon committed 2026-07-13 09:35:25 +00:00
1 parent 9f698a8fec
commit aa675199af
22 files changed
+3123 -241

No files matched your search

+424 -10
View File
@@ -5,6 +5,7 @@ import {
AreaChart,
CartesianGrid,
Line,
ReferenceDot,
ReferenceLine,
ResponsiveContainer,
Tooltip,
@@ -28,6 +29,16 @@ import {
internalMatchGamePath,
} from "../lib/internal-match-routes";
import { LANE_LABELS } from "../lib/riot-history";
import {
filterTimelineEvents,
normalizeObjectiveEvents,
normalizeTimelineEvents,
projectTimelineEventMarkers,
selectTimelineEventSource,
summarizeDragonTypes,
type NormalizedTimelineEvent,
type TimelineEventFilter,
} from "../lib/internal-match-timeline";
import {
InternalGameAnalysisPanel,
InternalGameDetailTabBar,
@@ -58,6 +69,16 @@ const TIMELINE_METRICS: Array<{ id: TimelineMetric; label: string }> = [
{ id: "xp", label: "경험치" },
];
const TIMELINE_EVENT_FILTERS: Array<{
id: TimelineEventFilter;
label: string;
}> = [
{ id: "all", label: "전체" },
{ id: "objective", label: "오브젝트" },
{ id: "kill", label: "킬" },
{ id: "structure", label: "구조물" },
];
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
@@ -142,6 +163,16 @@ function formatPercent(value: number) {
return `${value}%`;
}
function formatDragonTypeSummary(
values: Array<{ label: string; count: number }>,
total: number,
) {
if (values.length === 0) return total > 0 ? "유형 정보 없음" : "-";
return values
.map(({ label, count }) => (count > 1 ? `${label}×${count}` : label))
.join(" · ");
}
function barWidth(value: number, max: number) {
return `${Math.max(0, Math.min(100, max > 0 ? (value / max) * 100 : 0))}%`;
}
@@ -411,13 +442,13 @@ function PlayerRow({
{participant.assists}
</div>
<div className="text-xs font-bold tabular-nums text-base-content/40">
{formatKda(
KDA {formatKda(
participant.kills,
participant.deaths,
participant.assists,
)}
<span className="ml-1 text-base-content/35">
({participant.killParticipation}%)
· KP {participant.killParticipation}%
</span>
</div>
</td>
@@ -451,6 +482,12 @@ function PlayerRow({
<span className="block text-base-content/35">
{participant.csPerMin}/m
</span>
<span className="mt-1 block font-bold text-base-content/55">
{formatCompactNumber(participant.gold)}
<span className="ml-1 font-normal text-base-content/30">
{formatNumber(participant.gpm)} GPM
</span>
</span>
</td>
<td className="px-3 py-2.5">
<ItemStrip participant={participant} manifest={manifest} />
@@ -486,13 +523,13 @@ function PlayerCard({
{participant.assists}
</div>
<div className="text-[11px] font-bold tabular-nums text-base-content/40">
{formatKda(
KDA {formatKda(
participant.kills,
participant.deaths,
participant.assists,
)}
<span className="ml-1 text-base-content/35">
({participant.killParticipation}%)
· KP {participant.killParticipation}%
</span>
</div>
</div>
@@ -527,13 +564,19 @@ function PlayerCard({
</div>
<div className="border border-base-content/8 px-2 py-1.5">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
CS
CS · 경제
</div>
<div className="mt-0.5 font-black text-base-content/70">
{participant.cs}
<span className="ml-1 font-bold text-base-content/35">
{participant.csPerMin}/m
</span>
<span className="mt-1 block text-base-content/60">
{formatCompactNumber(participant.gold)}
<span className="ml-1 font-bold text-base-content/35">
{formatNumber(participant.gpm)} GPM
</span>
</span>
</div>
</div>
<div className="border border-base-content/8 px-2 py-1.5">
@@ -701,11 +744,125 @@ function PostgameBreakdown({
);
})}
</div>
<ObjectiveComparisonStrip selectedGame={selectedGame} />
<GoldComparisonStrip selectedGame={selectedGame} detail={detail} />
</section>
);
}
function ObjectiveComparisonStrip({
selectedGame,
}: {
selectedGame: MatchGameDetail;
}) {
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
const redTeam = selectedGame.teams.find((team) => team.side === "red");
if (!blueTeam || !redTeam) return null;
const events = normalizeObjectiveEvents(selectedGame.objectiveEvents ?? []);
const blueDragonTypes = formatDragonTypeSummary(
summarizeDragonTypes(events, "blue"),
blueTeam.objectives.dragon,
);
const redDragonTypes = formatDragonTypeSummary(
summarizeDragonTypes(events, "red"),
redTeam.objectives.dragon,
);
const objectives = [
{
key: "tower",
label: "포탑",
blue: blueTeam.objectives.tower,
red: redTeam.objectives.tower,
},
{
key: "dragon",
label: "드래곤",
blue: blueTeam.objectives.dragon,
red: redTeam.objectives.dragon,
blueDetail: blueDragonTypes,
redDetail: redDragonTypes,
},
{
key: "inhibitor",
label: "억제기",
blue: blueTeam.objectives.inhibitor,
red: redTeam.objectives.inhibitor,
},
{
key: "baron",
label: "바론",
blue: blueTeam.objectives.baron,
red: redTeam.objectives.baron,
},
{
key: "riftHerald",
label: "전령",
blue: blueTeam.objectives.riftHerald,
red: redTeam.objectives.riftHerald,
},
{
key: "voidGrub",
label: "공허 유충",
blue: blueTeam.objectives.voidGrub,
red: redTeam.objectives.voidGrub,
},
{
key: "elderDragon",
label: "장로",
blue: blueTeam.objectives.elderDragon,
red: redTeam.objectives.elderDragon,
},
];
return (
<div className="border-t border-base-content/8 bg-base-content/[0.01]">
<h3 className="sr-only">오브젝트 비교</h3>
<div className="grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7">
{objectives.map((objective) => (
<div
key={objective.key}
className="border-b border-r border-base-content/8 px-3 py-2.5 last:border-r-0 lg:border-b-0"
aria-label={`${objective.label}: 블루 ${objective.blue}, 레드 ${objective.red}`}
>
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2 text-xs tabular-nums">
<span
className={`text-right font-black ${
objective.blue > objective.red
? "text-blue-400"
: "text-base-content/50"
}`}
>
{objective.blue}
</span>
<span className="text-[10px] font-bold text-base-content/35">
{objective.label}
</span>
<span
className={`font-black ${
objective.red > objective.blue
? "text-red-400"
: "text-base-content/50"
}`}
>
{objective.red}
</span>
</div>
{objective.key === "dragon" ? (
<div className="mt-1 grid grid-cols-2 gap-2 text-[9px] font-bold leading-tight">
<span className="text-right text-blue-400/70">
{objective.blueDetail}
</span>
<span className="text-red-400/70">{objective.redDetail}</span>
</div>
) : null}
</div>
))}
</div>
</div>
);
}
function GoldComparisonStrip({
selectedGame,
detail,
@@ -848,14 +1005,74 @@ function TimelineTooltip({
);
}
function timelineEventKey(event: NormalizedTimelineEvent, index: number) {
return [
event.timestamp,
event.side ?? "unknown",
event.type,
event.killerParticipantId ?? "none",
event.victimParticipantId ?? "none",
index,
].join(":");
}
function timelineParticipantLabel(
participant: MatchGameParticipant | undefined,
manifest: ReturnType<typeof useDdragonManifest>["data"],
) {
if (!participant) return null;
const championName =
championDisplayName(manifest, participant.championId) ??
String(participant.championId);
return `${participant.summonerName} (${championName})`;
}
function timelineEventActors(
event: NormalizedTimelineEvent,
participantById: ReadonlyMap<number, MatchGameParticipant>,
manifest: ReturnType<typeof useDdragonManifest>["data"],
) {
const killer = timelineParticipantLabel(
event.killerParticipantId === undefined
? undefined
: participantById.get(event.killerParticipantId),
manifest,
);
const victim = timelineParticipantLabel(
event.victimParticipantId === undefined
? undefined
: participantById.get(event.victimParticipantId),
manifest,
);
const assistants = (event.assistingParticipantIds ?? [])
.map((participantId) =>
timelineParticipantLabel(participantById.get(participantId), manifest),
)
.filter((label): label is string => Boolean(label));
const assistLabel =
assistants.length > 0 ? ` · 도움 ${assistants.join(", ")}` : "";
if (event.type === "championKill") {
if (killer && victim) return `${killer} → ${victim}${assistLabel}`;
if (killer) return `${killer} 처치${assistLabel}`;
if (victim) return `${victim} 사망`;
}
if (killer) return `${killer} 기여${assistLabel}`;
return null;
}
function TimelineGraph({
selectedGame,
detail,
manifest,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const [metric, setMetric] = useState<TimelineMetric>("gold");
const [eventFilter, setEventFilter] = useState<TimelineEventFilter>("all");
const [selectedEventKey, setSelectedEventKey] = useState<string | null>(null);
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
const redTeam = selectedGame.teams.find((team) => team.side === "red");
const blueTeamName = blueTeam
@@ -883,6 +1100,41 @@ function TimelineGraph({
...chartData.map((point) => Math.abs(point.value)),
);
const finalPoint = chartData[chartData.length - 1];
const timelineEvents = normalizeTimelineEvents(
selectTimelineEventSource(
selectedGame.timelineEvents,
selectedGame.objectiveEvents ?? [],
),
);
const visibleEvents = filterTimelineEvents(timelineEvents, eventFilter);
const visibleEventEntries = visibleEvents.map((event) => {
const index = timelineEvents.indexOf(event);
return {
event,
key: timelineEventKey(event, index),
};
});
const selectedEvent = visibleEventEntries.find(
(entry) => entry.key === selectedEventKey,
);
const selectedTimestamp = selectedEvent?.event.timestamp ?? null;
const timelineMarkers = projectTimelineEventMarkers(
visibleEventEntries.map(({ event, key }) => ({ ...event, eventKey: key })),
chartData,
);
const participantById = new Map<number, MatchGameParticipant>();
for (const team of selectedGame.teams) {
for (const participant of team.participants) {
if (participant.participantId !== undefined) {
participantById.set(participant.participantId, participant);
}
}
}
const chartMaxTimestamp = Math.max(
selectedGame.gameDuration,
finalPoint?.timestamp ?? 0,
timelineEvents[timelineEvents.length - 1]?.timestamp ?? 0,
);
const finalLeader =
finalPoint?.leaderSide === "blue"
? blueTeamName
@@ -901,11 +1153,16 @@ function TimelineGraph({
: "타임라인 대기"}
</div>
</div>
<div className="flex w-full border border-base-content/10 bg-base-content/[0.02] sm:w-auto">
<div
className="flex w-full border border-base-content/10 bg-base-content/[0.02] sm:w-auto"
role="group"
aria-label="경기 흐름 지표"
>
{TIMELINE_METRICS.map((item) => (
<button
key={item.id}
type="button"
aria-pressed={metric === item.id}
onClick={() => setMetric(item.id)}
className={`min-w-24 flex-1 border-r border-base-content/8 px-4 py-2 text-xs font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary sm:flex-none ${
metric === item.id
@@ -921,7 +1178,11 @@ function TimelineGraph({
{chartData.length > 0 ? (
<div className="px-2 py-4 sm:px-4">
<div className="h-[260px] min-w-0 w-full">
<ResponsiveContainer width="100%" height="100%">
<ResponsiveContainer
width="100%"
height="100%"
initialDimension={{ width: 800, height: 260 }}
>
<AreaChart
data={chartData}
margin={{ top: 12, right: 12, bottom: 0, left: 0 }}
@@ -933,6 +1194,8 @@ function TimelineGraph({
/>
<XAxis
dataKey="timestamp"
type="number"
domain={[0, chartMaxTimestamp]}
minTickGap={28}
tickFormatter={(value) =>
`${Math.round(Number(value) / 60)}분`
@@ -965,6 +1228,14 @@ function TimelineGraph({
stroke="currentColor"
strokeOpacity={0.25}
/>
{selectedTimestamp !== null ? (
<ReferenceLine
x={selectedTimestamp}
stroke="currentColor"
strokeDasharray="3 3"
strokeOpacity={0.35}
/>
) : null}
<Area
type="monotone"
dataKey="positive"
@@ -994,6 +1265,44 @@ function TimelineGraph({
}}
isAnimationActive={false}
/>
{timelineMarkers.map((event) => {
const selected = event.eventKey === selectedEventKey;
const markerRadius =
event.category === "objective"
? 4
: event.category === "structure"
? 3.5
: 2.5;
return (
<ReferenceDot
key={event.eventKey}
x={event.timestamp}
y={event.value}
r={selected ? 5.5 : markerRadius}
fill={
event.side === "blue"
? "#3b82f6"
: event.side === "red"
? "#ef4444"
: "currentColor"
}
stroke="currentColor"
strokeWidth={selected ? 2 : 1}
ifOverflow="extendDomain"
label={
selected
? {
value: event.markerLabel,
position: "top",
fontSize: 10,
fontWeight: 800,
fill: "currentColor",
}
: undefined
}
/>
);
})}
</AreaChart>
</ResponsiveContainer>
</div>
@@ -1008,6 +1317,106 @@ function TimelineGraph({
타임라인 데이터가 아직 없습니다
</div>
)}
{timelineEvents.length > 0 ? (
<div className="border-t border-base-content/8 px-4 py-3">
<div className="flex flex-wrap items-baseline justify-between gap-2">
<h3 className="text-xs font-black text-base-content">주요 사건</h3>
<p className="text-[11px] font-bold text-base-content/30">
항목을 선택하면 그래프의 해당 시점을 강조합니다
</p>
</div>
<div
className="mt-3 flex w-full overflow-x-auto border border-base-content/10 bg-base-content/[0.02] sm:w-fit"
role="group"
aria-label="사건 유형 필터"
>
{TIMELINE_EVENT_FILTERS.map((filter) => (
<button
key={filter.id}
type="button"
aria-pressed={eventFilter === filter.id}
onClick={() => setEventFilter(filter.id)}
className={`min-w-20 flex-1 border-r border-base-content/8 px-3 py-2 text-[11px] font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary sm:flex-none ${
eventFilter === filter.id
? "bg-primary text-primary-content"
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
{filter.label}
</button>
))}
</div>
<ul
className="m-0 mt-3 grid max-h-64 list-none gap-1.5 overflow-y-auto p-0 sm:grid-cols-2 lg:grid-cols-3"
aria-label="시간순 주요 사건"
>
{visibleEventEntries.map(({ event, key }) => {
const selected = key === selectedEventKey;
const teamName =
event.side === "blue"
? blueTeamName
: event.side === "red"
? redTeamName
: null;
const actorLabel = timelineEventActors(
event,
participantById,
manifest,
);
return (
<li key={key} className="min-w-0">
<button
type="button"
aria-pressed={selected}
onClick={() => setSelectedEventKey(selected ? null : key)}
className={`grid h-full w-full grid-cols-[3.25rem_3.25rem_minmax(0,1fr)] items-start gap-2 border px-2.5 py-2 text-left text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${
selected
? "border-primary bg-primary/8"
: "border-base-content/8 hover:bg-base-content/[0.03]"
}`}
>
<span className="font-mono font-black tabular-nums text-base-content/55">
{formatDuration(event.timestamp)}
</span>
<span
className={`text-[10px] font-black uppercase tracking-wider ${
event.side === "blue"
? "text-blue-400"
: event.side === "red"
? "text-red-400"
: "text-base-content/35"
}`}
>
{event.side ? sideLabel(event.side) : "-"}
</span>
<span className="min-w-0">
<span className="block truncate font-bold text-base-content/75">
{teamName ? (
<span className="sr-only">{teamName} </span>
) : null}
{event.label}
</span>
{actorLabel ? (
<span
className="mt-0.5 block truncate text-[10px] font-bold text-base-content/35"
title={actorLabel}
>
{actorLabel}
</span>
) : null}
</span>
</button>
</li>
);
})}
</ul>
{visibleEventEntries.length === 0 ? (
<p className="py-6 text-center text-xs font-bold text-base-content/35">
이 유형의 사건이 없습니다
</p>
) : null}
</div>
) : null}
</section>
);
}
@@ -1045,7 +1454,7 @@ function TeamTable({
<th className="w-[120px] px-3 py-2.5 text-center">가한 피해량</th>
<th className="w-[120px] px-3 py-2.5 text-center">받은 피해량</th>
<th className="w-[80px] px-3 py-2.5 text-center">시야</th>
<th className="w-[76px] px-3 py-2.5 text-center">CS</th>
<th className="w-[96px] px-3 py-2.5 text-center">CS · 경제</th>
<th className="w-[260px] px-3 py-2.5">아이템</th>
</tr>
</thead>
@@ -1306,6 +1715,13 @@ export default function MatchGameDetailPage() {
manifest={ddragon}
/>
<TimelineGraph
key={selectedGame.riotMatchId}
selectedGame={selectedGame}
detail={detail}
manifest={ddragon}
/>
<div className="mt-5 space-y-4">
<InternalGameDetailTabBar
activeTab={activeTab}
@@ -1325,8 +1741,6 @@ export default function MatchGameDetailPage() {
}
/>
</div>
<TimelineGraph selectedGame={selectedGame} detail={detail} />
</main>
);
}