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

@@ -0,0 +1,134 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
DEFAULT_LANE_CHECKPOINT,
pairLaneParticipants,
resolveCheckpointComparison,
} from "../src/lib/internal-game-matchups.ts";
function participant(
name: string,
side: "blue" | "red",
teamPosition: string,
gold: number,
cs: number,
xp: number,
) {
return {
name,
side,
teamPosition,
checkpoints: {
at15: {
timestamp: 900,
gold,
cs,
xp,
kills: side === "blue" ? 2 : 1,
deaths: side === "blue" ? 1 : 2,
assists: 3,
},
},
};
}
test("pairLaneParticipants matches shuffled players by normalized team position", () => {
const blue = [
participant("Blue ADC", "blue", "BOTTOM", 6_000, 120, 7_000),
participant("Blue Top", "blue", "TOP", 5_500, 110, 6_800),
participant("Blue Mid", "blue", "MID", 6_200, 115, 7_100),
];
const red = [
participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900),
participant("Red Top", "red", "TOP", 5_300, 105, 6_600),
participant("Red ADC", "red", "ADC", 5_800, 116, 6_850),
];
const pairs = pairLaneParticipants(blue, red);
assert.deepEqual(
pairs.map((pair) => [pair.position, pair.blue?.name, pair.red?.name]),
[
["TOP", "Blue Top", "Red Top"],
["MIDDLE", "Blue Mid", "Red Mid"],
["BOTTOM", "Blue ADC", "Red ADC"],
],
);
});
test("pairLaneParticipants leaves a duplicated role ambiguous instead of pairing by index", () => {
const blue = [
participant("Blue Top A", "blue", "TOP", 5_500, 110, 6_800),
participant("Blue Top B", "blue", "TOP", 5_000, 100, 6_200),
];
const red = [
participant("Red Top", "red", "TOP", 5_300, 105, 6_600),
];
assert.deepEqual(pairLaneParticipants(blue, red), [
{
position: "TOP",
blue: null,
red: red[0],
ambiguousBlue: true,
ambiguousRed: false,
},
]);
});
test("resolveCheckpointComparison calculates blue-side GD, CSD, and XPD", () => {
const blue = participant("Blue Mid", "blue", "MIDDLE", 6_200, 115, 7_100);
const red = participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900);
const comparison = resolveCheckpointComparison(blue, red, "at15");
assert.deepEqual(comparison, {
blue: blue.checkpoints.at15,
red: red.checkpoints.at15,
goldDiff: 300,
csDiff: 6,
xpDiff: 200,
});
});
test("resolveCheckpointComparison returns null when either checkpoint is unavailable", () => {
const blue = participant("Blue Mid", "blue", "MIDDLE", 6_200, 115, 7_100);
const red = participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900);
assert.equal(resolveCheckpointComparison(blue, red, "at10"), null);
assert.equal(resolveCheckpointComparison(blue, null, "at15"), null);
});
test("the lane panel defaults to 15 minutes and supports an available 10-minute comparison", () => {
assert.equal(DEFAULT_LANE_CHECKPOINT, "at15");
const blue = participant("Blue Mid", "blue", "MIDDLE", 6_200, 115, 7_100);
const red = participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900);
blue.checkpoints.at10 = {
timestamp: 590,
gold: 4_000,
cs: 75,
xp: 4_600,
kills: 1,
deaths: 0,
assists: 2,
};
red.checkpoints.at10 = {
timestamp: 590,
gold: 3_700,
cs: 69,
xp: 4_450,
kills: 0,
deaths: 1,
assists: 1,
};
assert.deepEqual(resolveCheckpointComparison(blue, red, "at10"), {
blue: blue.checkpoints.at10,
red: red.checkpoints.at10,
goldDiff: 300,
csDiff: 6,
xpDiff: 150,
});
});
@@ -0,0 +1,228 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
dragonTypeLabel,
filterTimelineEvents,
normalizeObjectiveEvents,
normalizeTimelineEvents,
projectObjectiveMarkers,
selectTimelineEventSource,
summarizeDragonTypes,
} from "../src/lib/internal-match-timeline.ts";
test("dragonTypeLabel maps Riot dragon subtypes to Korean labels", () => {
assert.deepEqual(
[
"AIR_DRAGON",
"EARTH_DRAGON",
"WATER_DRAGON",
"FIRE_DRAGON",
"HEXTECH_DRAGON",
"CHEMTECH_DRAGON",
"ELDER_DRAGON",
].map(dragonTypeLabel),
["바람", "대지", "바다", "화염", "마법공학", "화학공학", "장로"],
);
assert.equal(dragonTypeLabel("UNKNOWN_DRAGON"), null);
assert.equal(dragonTypeLabel(undefined), null);
});
test("normalizeObjectiveEvents sorts events and adds conservative Korean labels", () => {
const events = normalizeObjectiveEvents([
{ timestamp: 1_443, side: "blue", type: "baron" },
{
timestamp: 339,
side: "blue",
type: "dragon",
monsterSubType: "EARTH_DRAGON",
},
{ timestamp: 963, side: "red", type: "riftHerald" },
{
timestamp: 1_356,
side: "red",
type: "dragon",
monsterSubType: "UNKNOWN_DRAGON",
},
{ timestamp: 530, side: "blue", type: "voidGrub" },
{ timestamp: 1_600, side: "red", type: "elderDragon" },
]);
assert.deepEqual(
events.map(({ timestamp, label, markerLabel }) => ({
timestamp,
label,
markerLabel,
})),
[
{ timestamp: 339, label: "대지 드래곤", markerLabel: "대지" },
{ timestamp: 530, label: "공허 유충", markerLabel: "유충" },
{ timestamp: 963, label: "협곡의 전령", markerLabel: "전령" },
{ timestamp: 1_356, label: "드래곤", markerLabel: "용" },
{ timestamp: 1_443, label: "바론", markerLabel: "바론" },
{ timestamp: 1_600, label: "장로 드래곤", markerLabel: "장로" },
],
);
});
test("summarizeDragonTypes groups repeated dragon types per side in event order", () => {
const events = normalizeObjectiveEvents([
{
timestamp: 300,
side: "blue",
type: "dragon",
monsterSubType: "FIRE_DRAGON",
},
{
timestamp: 600,
side: "red",
type: "dragon",
monsterSubType: "WATER_DRAGON",
},
{
timestamp: 900,
side: "blue",
type: "dragon",
monsterSubType: "FIRE_DRAGON",
},
{
timestamp: 1_200,
side: "blue",
type: "dragon",
monsterSubType: "HEXTECH_DRAGON",
},
{
timestamp: 1_500,
side: "red",
type: "dragon",
monsterSubType: "UNKNOWN_DRAGON",
},
]);
assert.deepEqual(summarizeDragonTypes(events, "blue"), [
{ label: "화염", count: 2 },
{ label: "마법공학", count: 1 },
]);
assert.deepEqual(summarizeDragonTypes(events, "red"), [
{ label: "바다", count: 1 },
]);
});
test("projectObjectiveMarkers anchors events to the latest available chart value", () => {
const events = normalizeObjectiveEvents([
{ timestamp: 10, side: "blue", type: "voidGrub" },
{ timestamp: 90, side: "red", type: "riftHerald" },
{ timestamp: 180, side: "blue", type: "baron" },
]);
assert.deepEqual(
projectObjectiveMarkers(events, [
{ timestamp: 0, value: 0 },
{ timestamp: 60, value: 100 },
{ timestamp: 120, value: 80 },
]).map(({ timestamp, value }) => ({ timestamp, value })),
[
{ timestamp: 10, value: 0 },
{ timestamp: 90, value: 100 },
{ timestamp: 180, value: 80 },
],
);
});
test("normalizeTimelineEvents labels and sorts objectives, kills, and structures", () => {
const events = normalizeTimelineEvents([
{
timestamp: 700,
side: "blue",
type: "tower",
killerParticipantId: 1,
towerType: "OUTER_TURRET",
},
{
timestamp: 500,
side: "red",
type: "championKill",
killerParticipantId: 6,
victimParticipantId: 1,
assistingParticipantIds: [7, 8],
},
{
timestamp: 300,
side: "blue",
type: "dragon",
monsterSubType: "FIRE_DRAGON",
},
{ timestamp: 800, side: "red", type: "inhibitor" },
]);
assert.deepEqual(
events.map(({ timestamp, category, label, markerLabel }) => ({
timestamp,
category,
label,
markerLabel,
})),
[
{
timestamp: 300,
category: "objective",
label: "화염 드래곤",
markerLabel: "화염",
},
{
timestamp: 500,
category: "kill",
label: "챔피언 처치",
markerLabel: "킬",
},
{
timestamp: 700,
category: "structure",
label: "포탑 파괴",
markerLabel: "포탑",
},
{
timestamp: 800,
category: "structure",
label: "억제기 파괴",
markerLabel: "억제기",
},
],
);
assert.equal(events[1].killerParticipantId, 6);
assert.equal(events[1].victimParticipantId, 1);
});
test("selectTimelineEventSource falls back to objective events during rolling updates", () => {
const objectives = [
{ timestamp: 300, side: "blue" as const, type: "voidGrub" as const },
];
const timeline = [
{ timestamp: 400, side: "red" as const, type: "championKill" as const },
];
assert.equal(selectTimelineEventSource(timeline, objectives), timeline);
assert.equal(selectTimelineEventSource([], objectives), objectives);
assert.equal(selectTimelineEventSource(undefined, objectives), objectives);
});
test("filterTimelineEvents filters event categories without changing order", () => {
const events = normalizeTimelineEvents([
{ timestamp: 300, side: "blue", type: "dragon" },
{ timestamp: 500, side: "red", type: "championKill" },
{ timestamp: 700, side: "blue", type: "tower" },
]);
assert.deepEqual(
filterTimelineEvents(events, "all").map((event) => event.timestamp),
[300, 500, 700],
);
assert.deepEqual(
filterTimelineEvents(events, "kill").map((event) => event.timestamp),
[500],
);
assert.deepEqual(
filterTimelineEvents(events, "structure").map((event) => event.timestamp),
[700],
);
});