Add timeline roam frames

This commit is contained in:
dahyeon committed 2026-07-02 23:50:10 -07:00
1 parent df0e43d884
commit d4e7cb6e8b
4 files changed
+296

No files matched your search

@@ -33,6 +33,7 @@ function createMatchPayload(matchId = 'KR_1') {
queueId: 420, queueId: 420,
participants: [ participants: [
{ {
participantId: 1,
puuid: 'target-puuid', puuid: 'target-puuid',
teamId: 100, teamId: 100,
teamPosition: 'MIDDLE', teamPosition: 'MIDDLE',
@@ -60,6 +61,7 @@ function createMatchPayload(matchId = 'KR_1') {
}, },
}, },
{ {
participantId: 2,
puuid: 'ally-puuid', puuid: 'ally-puuid',
teamId: 100, teamId: 100,
teamPosition: 'JUNGLE', teamPosition: 'JUNGLE',
@@ -428,6 +430,13 @@ describe('AnalysisPipelineService', () => {
'7': { position: { x: 14_000, y: 6_000 } }, '7': { position: { x: 14_000, y: 6_000 } },
}, },
}, },
{
timestamp: 8 * 60_000,
participantFrames: {
'1': { position: { x: 8_000, y: 7_000 } },
'2': { position: { x: 8_000, y: 7_000 } },
},
},
{ {
timestamp: 900_000, timestamp: 900_000,
events: [ events: [
@@ -503,6 +512,17 @@ describe('AnalysisPipelineService', () => {
monsterType: 'DRAGON', monsterType: 'DRAGON',
}, },
], ],
roamFrames: [
{
t: 8 * 60_000,
participantId: 1,
teamId: 100,
x: 8_000,
y: 7_000,
zone: 'river',
assignedLaneZone: 'middleLane',
},
],
}); });
}); });
@@ -369,6 +369,7 @@ export class AnalysisPipelineService {
feature.derived = { feature.derived = {
...this.timelineDerivedService.buildDerivedData( ...this.timelineDerivedService.buildDerivedData(
matchRecord.timeline, matchRecord.timeline,
matchRecord.raw,
), ),
}; };
feature.timelineProcessed = true; feature.timelineProcessed = true;
@@ -415,6 +415,148 @@ describe('TimelineDerivedService', () => {
); );
}); });
it('builds roam frames for non-jungle laners between 8 and 14 minutes', () => {
const rawMatch = {
info: {
participants: [
{ participantId: 1, teamId: 100, teamPosition: 'TOP' },
{ participantId: 2, teamId: 100, teamPosition: 'JUNGLE' },
{ participantId: 6, teamId: 200, teamPosition: 'MIDDLE' },
],
},
};
const derived = service.buildDerivedData(
createTimelinePayloadWithFrames([
{
timestamp: 7 * 60_000,
participantFrames: {
'1': { position: { x: 8_000, y: 7_000 } },
},
},
{
timestamp: 8 * 60_000,
participantFrames: {
'1': { position: { x: 8_000, y: 7_000 } },
'2': { position: { x: 8_000, y: 7_000 } },
'6': { position: { x: 14_200, y: 14_200 } },
},
},
{
timestamp: 9 * 60_000,
participantFrames: {
'1': { position: { x: 1_000, y: 9_000 } },
'6': { position: { x: 8_000, y: 7_000 } },
},
},
{
timestamp: 14 * 60_000,
participantFrames: {
'1': { position: { x: 9_000, y: 1_000 } },
},
},
{
timestamp: 15 * 60_000,
participantFrames: {
'1': { position: { x: 8_000, y: 7_000 } },
},
},
]),
rawMatch,
);
expect(derived.roamFrames).toEqual([
{
t: 8 * 60_000,
participantId: 1,
teamId: 100,
x: 8_000,
y: 7_000,
zone: 'river',
assignedLaneZone: 'topLane',
},
{
t: 9 * 60_000,
participantId: 6,
teamId: 200,
x: 8_000,
y: 7_000,
zone: 'river',
assignedLaneZone: 'middleLane',
},
{
t: 14 * 60_000,
participantId: 1,
teamId: 100,
x: 9_000,
y: 1_000,
zone: 'bottomLane',
assignedLaneZone: 'topLane',
},
]);
});
it('uses the participant own base only when filtering roam frames', () => {
const rawMatch = {
info: {
participants: [{ participantId: 1, teamId: 100, teamPosition: 'TOP' }],
},
};
const derived = service.buildDerivedData(
createTimelinePayloadWithFrames([
{
timestamp: 8 * 60_000,
participantFrames: {
'1': { position: { x: 600, y: 600 } },
},
},
{
timestamp: 9 * 60_000,
participantFrames: {
'1': { position: { x: 14_200, y: 14_200 } },
},
},
]),
rawMatch,
);
expect(derived.roamFrames).toEqual([
{
t: 9 * 60_000,
participantId: 1,
teamId: 100,
x: 14_200,
y: 14_200,
zone: 'redBase',
assignedLaneZone: 'topLane',
},
]);
});
it('omits roam frames when participant id or map zone is unknown', () => {
const rawMatch = {
info: {
participants: [
{ teamId: 100, teamPosition: 'TOP' },
{ participantId: 2, teamId: 100, teamPosition: 'MIDDLE' },
],
},
};
const derived = service.buildDerivedData(
createTimelinePayloadWithFrames([
{
timestamp: 8 * 60_000,
participantFrames: {
'1': { position: { x: 8_000, y: 7_000 } },
'2': { position: { x: -1, y: 7_500 } },
},
},
]),
rawMatch,
);
expect(derived.roamFrames).toEqual([]);
});
it('builds weighted advantage events for kills, plates, towers, and objectives', () => { it('builds weighted advantage events for kills, plates, towers, and objectives', () => {
const derived = service.buildDerivedData( const derived = service.buildDerivedData(
createTimelinePayload([ createTimelinePayload([
@@ -38,6 +38,13 @@ interface TimelineFrameSnapshot {
participantPositions: Map<number, TimelinePosition>; participantPositions: Map<number, TimelinePosition>;
} }
interface TimelineRoamParticipant {
participantId: number;
teamId: 100 | 200;
assignedLaneZone: SummonersRiftMapZone;
baseZone: SummonersRiftMapZone;
}
export interface TimelineFightCluster { export interface TimelineFightCluster {
startTimeMs: number; startTimeMs: number;
endTimeMs: number; endTimeMs: number;
@@ -77,11 +84,22 @@ export interface TimelineDeathEvent {
nearestAllyDistanceApprox: number | null; nearestAllyDistanceApprox: number | null;
} }
export interface TimelineRoamFrame {
t: number;
participantId: number;
teamId: number;
x: number;
y: number;
zone: SummonersRiftMapZone;
assignedLaneZone: SummonersRiftMapZone;
}
export interface TimelineDerivedData { export interface TimelineDerivedData {
fightClusters: TimelineFightCluster[]; fightClusters: TimelineFightCluster[];
advantageEvents: TimelineAdvantageEvent[]; advantageEvents: TimelineAdvantageEvent[];
deathEvents: TimelineDeathEvent[]; deathEvents: TimelineDeathEvent[];
objectiveWindows: TimelineObjectiveWindow[]; objectiveWindows: TimelineObjectiveWindow[];
roamFrames: TimelineRoamFrame[];
} }
const FIGHT_CLUSTER_MAX_GAP_MS = 15_000; const FIGHT_CLUSTER_MAX_GAP_MS = 15_000;
@@ -89,6 +107,8 @@ const FIGHT_CLUSTER_MAX_DISTANCE = 3_000;
const CLEANUP_WINDOW_MS = 5_000; const CLEANUP_WINDOW_MS = 5_000;
const OBJECTIVE_WINDOW_BEFORE_MS = 120_000; const OBJECTIVE_WINDOW_BEFORE_MS = 120_000;
const OBJECTIVE_WINDOW_AFTER_MS = 30_000; const OBJECTIVE_WINDOW_AFTER_MS = 30_000;
const ROAM_FRAME_START_MS = 8 * 60_000;
const ROAM_FRAME_END_MS = 14 * 60_000;
const OBJECTIVE_MONSTER_TYPES = new Set([ const OBJECTIVE_MONSTER_TYPES = new Set([
'DRAGON', 'DRAGON',
'RIFTHERALD', 'RIFTHERALD',
@@ -320,6 +340,68 @@ function opposingTeamId(teamId: 100 | 200 | undefined): 100 | 200 | undefined {
return undefined; return undefined;
} }
function assignedLaneZoneForRole(
teamPosition: string | undefined,
): SummonersRiftMapZone | undefined {
switch (teamPosition) {
case 'TOP':
return 'topLane';
case 'MIDDLE':
return 'middleLane';
case 'BOTTOM':
case 'UTILITY':
return 'bottomLane';
default:
return undefined;
}
}
function baseZoneForTeamId(
teamId: 100 | 200 | undefined,
): SummonersRiftMapZone | undefined {
switch (teamId) {
case 100:
return 'blueBase';
case 200:
return 'redBase';
default:
return undefined;
}
}
function parseRoamParticipants(
rawMatch: Record<string, unknown> | undefined,
): TimelineRoamParticipant[] {
const info = asRecord(rawMatch?.info);
return asArray(info.participants)
.map(asRecord)
.flatMap((participant) => {
const participantId = asParticipantId(participant.participantId);
const teamId = toTeamId(participant.teamId);
const assignedLaneZone = assignedLaneZoneForRole(
asString(participant.teamPosition),
);
const baseZone = baseZoneForTeamId(teamId);
if (
participantId === undefined ||
teamId === undefined ||
assignedLaneZone === undefined ||
baseZone === undefined
) {
return [];
}
return [
{
participantId,
teamId,
assignedLaneZone,
baseZone,
},
];
});
}
function scoringParticipantIds(event: TimelineChampionKillEvent): number[] { function scoringParticipantIds(event: TimelineChampionKillEvent): number[] {
return toSortedIds( return toSortedIds(
[ [
@@ -802,10 +884,60 @@ function buildDeathEvents(
}); });
} }
function buildRoamFrames(
frameSnapshots: TimelineFrameSnapshot[],
rawMatch: Record<string, unknown> | undefined,
): TimelineRoamFrame[] {
const roamParticipants = parseRoamParticipants(rawMatch);
if (roamParticipants.length === 0) {
return [];
}
return frameSnapshots.flatMap((frame) => {
if (
frame.timestamp < ROAM_FRAME_START_MS ||
frame.timestamp > ROAM_FRAME_END_MS
) {
return [];
}
return roamParticipants.flatMap((participant) => {
const position = frame.participantPositions.get(
participant.participantId,
);
if (!position) {
return [];
}
const zone = classifySummonersRiftPosition(position);
if (
zone === 'unknown' ||
zone === participant.assignedLaneZone ||
zone === participant.baseZone
) {
return [];
}
return [
{
t: frame.timestamp,
participantId: participant.participantId,
teamId: participant.teamId,
x: position.x,
y: position.y,
zone,
assignedLaneZone: participant.assignedLaneZone,
},
];
});
});
}
@Injectable() @Injectable()
export class TimelineDerivedService { export class TimelineDerivedService {
public buildDerivedData( public buildDerivedData(
timeline: Record<string, unknown>, timeline: Record<string, unknown>,
rawMatch?: Record<string, unknown>,
): TimelineDerivedData { ): TimelineDerivedData {
const { const {
advantageEvents, advantageEvents,
@@ -819,6 +951,7 @@ export class TimelineDerivedService {
advantageEvents, advantageEvents,
deathEvents: buildDeathEvents(championKills, frameSnapshots), deathEvents: buildDeathEvents(championKills, frameSnapshots),
objectiveWindows: buildObjectiveWindows(eliteMonsterKills), objectiveWindows: buildObjectiveWindows(eliteMonsterKills),
roamFrames: buildRoamFrames(frameSnapshots, rawMatch),
}; };
} }
} }